diff --git a/app/controllers/admin/infos_controller.rb b/app/controllers/admin/infos_controller.rb index c08d1386..e79fba7b 100644 --- a/app/controllers/admin/infos_controller.rb +++ b/app/controllers/admin/infos_controller.rb @@ -8,6 +8,9 @@ class Admin::InfosController < ApplicationController def index @attributes = Info.all.entries + + @roles = Role.excludes('disabled' => true) + render :template => 'admin/attributes/index' end @@ -22,7 +25,7 @@ class Admin::InfosController < ApplicationController def edit @attribute = Info.find(params[:id]) - @attribute_fields_upper_object = [@attribute] + # @attribute_fields_upper_object = [@attribute] render :template => 'admin/attributes/edit' end @@ -49,10 +52,20 @@ class Admin::InfosController < ApplicationController end def add_attribute_field + attribute = Info.find(params[:info_id]) rescue nil @attribute_field_counter = attribute.attribute_fields.count @attribute_field = attribute.attribute_fields.build @attribute_field.save + + @attribute_field[:af_count] = @attribute_field_counter + + @attribute = Info.find(params[:info_id]) + + respond_to do |format| + format.js { render 'admin/attributes/add_attribute_field' } + end + end protected diff --git a/app/models/user/attribute_field.rb b/app/models/user/attribute_field.rb index c0aabb9c..d486ccd0 100644 --- a/app/models/user/attribute_field.rb +++ b/app/models/user/attribute_field.rb @@ -4,6 +4,7 @@ class AttributeField include ::AttributeFieldsHelper field :key + field :af_count field :markup ,:default=>"text_field" field :option_list ,:type => Hash,:default => {} field :markup_options,:type => Hash diff --git a/app/views/admin/attributes/add_attribute_field.js.erb b/app/views/admin/attributes/add_attribute_field.js.erb new file mode 100644 index 00000000..dd3d7198 --- /dev/null +++ b/app/views/admin/attributes/add_attribute_field.js.erb @@ -0,0 +1 @@ +$('<%= j render :partial => 'shared/attribute_field/attribute_field', :collection => [@attribute_field] %>').appendTo('#attribute_field_list').hide().fadeIn(); diff --git a/app/views/admin/attributes/edit.html.erb b/app/views/admin/attributes/edit.html.erb index 6c980863..301bf18b 100644 --- a/app/views/admin/attributes/edit.html.erb +++ b/app/views/admin/attributes/edit.html.erb @@ -18,13 +18,14 @@ - - <% @attribute_fields_upper_object.each do |attribute|%> -
-

<%= attribute.title+ t(:attributes)%>

- <%= render :partial=>"shared/attribute_field/attribute_field",:collection=>attribute.attribute_fields%> -
- <% end %> + +
+

<%= @attribute.title+ t(:attributes)%>

+
+ <%= render :partial=>"shared/attribute_field/attribute_field",:collection=>@attribute.attribute_fields%> +
+
+
<%= link_to content_tag(:i,t(:add_attribute_field),:class=>"icon-plus icon-white"),admin_info_add_attribute_field_path(@attribute),:class=>"btn btn-primary",:remote => true%> diff --git a/app/views/shared/attribute_field/_attribute_field.html.erb b/app/views/shared/attribute_field/_attribute_field.html.erb index 5f28cd03..30623fbe 100644 --- a/app/views/shared/attribute_field/_attribute_field.html.erb +++ b/app/views/shared/attribute_field/_attribute_field.html.erb @@ -1,24 +1,29 @@
+ <% + attribute_field.af_count ? @af_counter = attribute_field_counter + attribute_field.af_count : @af_counter = attribute_field_counter + %> + <%= @af_counter %> + <%#= attribute_field_counter %> - <%= hidden_field "info[attribute_fields][#{attribute_field_counter}]","disabled",:value=>attribute_field.disabled,:class=>"attribute_field_disabled"%> - <%= hidden_field "info[attribute_fields][#{attribute_field_counter}]","to_delete",:value=>false,:class=>"attribute_field_to_delete"%> + <%= hidden_field "info[attribute_fields][#{@af_counter}]","disabled",:value=>attribute_field.disabled,:class=>"attribute_field_disabled"%> + <%= hidden_field "info[attribute_fields][#{@af_counter}]","to_delete",:value=>false,:class=>"attribute_field_to_delete"%> <%= t(:delete_)%>
- <%= text_field "info[attribute_fields][#{attribute_field_counter}]","key",:value=>attribute_field.key%> + <%= text_field "info[attribute_fields][#{@af_counter}]","key",:value=>attribute_field.key%>
- <%= render :partial=>"shared/attribute_field/placeholder_block",:locals=>{:values=>attribute_field.title_translations,:class_ext=>"pull-left",:label_ext=>t(:name),:field_name=>"info[attribute_fields][#{attribute_field_counter}][title_translations]"}%> + <%= render :partial=>"shared/attribute_field/placeholder_block",:locals=>{:values=>attribute_field.title_translations,:class_ext=>"pull-left",:label_ext=>t(:name),:field_name=>"info[attribute_fields][#{@af_counter}][title_translations]"}%>
- <%#= select_tag "info[attribute_fields][#{attribute_field_counter}][markup]" do %> - > <%LIST[:markups].each do |key,val|%> <% end %> @@ -33,25 +38,25 @@
- <%= render :partial=>"shared/attribute_field/placeholder_block",:locals=>{:values=>attribute_field["typeA"]["placeholder"],:field_name=>"info[attribute_fields][#{attribute_field_counter}][typeA][placeholder]"}%> + <%= render :partial=>"shared/attribute_field/placeholder_block",:locals=>{:values=>attribute_field["typeA"]["placeholder"],:field_name=>"info[attribute_fields][#{@af_counter}][typeA][placeholder]"}%> <% end %> <%= content_tag :div,:class=>show_type_panel(attribute_field,"typeB") do %> - <%= render :partial=>"shared/attribute_field/placeholder_block",:locals=>{:label_ext=>t(:initial),:values=>attribute_field["typeB"]["initial"],:field_name=>"info[attribute_fields][#{attribute_field_counter}][typeB][initial]"}%> + <%= render :partial=>"shared/attribute_field/placeholder_block",:locals=>{:label_ext=>t(:initial),:values=>attribute_field["typeB"]["initial"],:field_name=>"info[attribute_fields][#{@af_counter}][typeB][initial]"}%> <% if attribute_field.self_defined_markup_options?%> - <%= render :partial=>"shared/attribute_field/list_block",:locals=>{:values=>attribute_field["option_list"],:field_name=> "info[attribute_fields][#{attribute_field_counter}][attribute][role][statuses]"} %> + <%= render :partial=>"shared/attribute_field/list_block",:locals=>{:values=>attribute_field["option_list"],:field_name=> "info[attribute_fields][#{@af_counter}][attribute][role][statuses]"} %> <%else #normal list%> - <%= render :partial=>"shared/attribute_field/list_block",:locals=>{:values=>attribute_field["option_list"],:field_name=> "info[attribute_fields][#{attribute_field_counter}][typeB][option_list]"} %> + <%= render :partial=>"shared/attribute_field/list_block",:locals=>{:values=>attribute_field["option_list"],:field_name=> "info[attribute_fields][#{@af_counter}][typeB][option_list]"} %> <% end #of self_defined_markup_options?%> <% end %> @@ -59,17 +64,17 @@
- <%= select "info[attribute_fields][#{attribute_field_counter}][typeC]","format",Admin::AttributeValuesViewHelper::OPT,:class=>"dataType",:selected=>attribute_field["typeC"]["format"] %> + <%= select "info[attribute_fields][#{@af_counter}][typeC]","format",Admin::AttributeValuesViewHelper::OPT,:class=>"dataType",:selected=>attribute_field["typeC"]["format"] %>
@@ -77,10 +82,10 @@
@@ -90,16 +95,16 @@
- <%= render :partial=>"shared/attribute_field/placeholder_block",:locals=>{:field_name=>"info[attribute_fields][#{attribute_field_counter}][typeD][placeholder]",:values=>attribute_field["typeD"]["placeholder"]} %> + <%= render :partial=>"shared/attribute_field/placeholder_block",:locals=>{:field_name=>"info[attribute_fields][#{@af_counter}][typeD][placeholder]",:values=>attribute_field["typeD"]["placeholder"]} %> <% end %> <%= content_tag :div,:class=>show_type_panel(attribute_field,"typeE") do%> - <%= render :partial=>"shared/attribute_field/list_block",:locals=>{:field_name=>"info[attribute_fields][#{attribute_field_counter}][typeE][option_list]",:values=>attribute_field["option_list"]}%> + <%= render :partial=>"shared/attribute_field/list_block",:locals=>{:field_name=>"info[attribute_fields][#{@af_counter}][typeE][option_list]",:values=>attribute_field["option_list"]}%> <% end %>
- <%= hidden_field "info[attribute_fields][#{attribute_field_counter}]","id",:value=>attribute_field.id%> + <%= hidden_field "info[attribute_fields][#{@af_counter}]","id",:value=>attribute_field.id%>