add info field

This commit is contained in:
unknown 2012-12-05 20:32:28 +08:00 committed by chris
parent e68c52bc00
commit 7d3c535e01
5 changed files with 50 additions and 29 deletions

View File

@ -8,6 +8,9 @@ class Admin::InfosController < ApplicationController
def index def index
@attributes = Info.all.entries @attributes = Info.all.entries
@roles = Role.excludes('disabled' => true)
render :template => 'admin/attributes/index' render :template => 'admin/attributes/index'
end end
@ -22,7 +25,7 @@ class Admin::InfosController < ApplicationController
def edit def edit
@attribute = Info.find(params[:id]) @attribute = Info.find(params[:id])
@attribute_fields_upper_object = [@attribute] # @attribute_fields_upper_object = [@attribute]
render :template => 'admin/attributes/edit' render :template => 'admin/attributes/edit'
end end
@ -49,10 +52,20 @@ class Admin::InfosController < ApplicationController
end end
def add_attribute_field def add_attribute_field
attribute = Info.find(params[:info_id]) rescue nil attribute = Info.find(params[:info_id]) rescue nil
@attribute_field_counter = attribute.attribute_fields.count @attribute_field_counter = attribute.attribute_fields.count
@attribute_field = attribute.attribute_fields.build @attribute_field = attribute.attribute_fields.build
@attribute_field.save @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 end
protected protected

View File

@ -4,6 +4,7 @@ class AttributeField
include ::AttributeFieldsHelper include ::AttributeFieldsHelper
field :key field :key
field :af_count
field :markup ,:default=>"text_field" field :markup ,:default=>"text_field"
field :option_list ,:type => Hash,:default => {} field :option_list ,:type => Hash,:default => {}
field :markup_options,:type => Hash field :markup_options,:type => Hash

View File

@ -0,0 +1 @@
$('<%= j render :partial => 'shared/attribute_field/attribute_field', :collection => [@attribute_field] %>').appendTo('#attribute_field_list').hide().fadeIn();

View File

@ -19,12 +19,13 @@
</div> </div>
</div> </div>
<% @attribute_fields_upper_object.each do |attribute|%> <div class="map-block back attributes">
<div class="map-block back attributes"> <h4><span><%= @attribute.title+ t(:attributes)%></span></h4>
<h4><span><%= attribute.title+ t(:attributes)%></span></h4> <div id="attribute_field_list">
<%= render :partial=>"shared/attribute_field/attribute_field",:collection=>attribute.attribute_fields%> <%= render :partial=>"shared/attribute_field/attribute_field",:collection=>@attribute.attribute_fields%>
</div> </div>
<% end %> </div>
</div> </div>
<div class="form-actions form-fixed pagination-right"> <div class="form-actions form-fixed pagination-right">
<%= 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%> <%= 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%>

View File

@ -1,24 +1,29 @@
<div class="form-horizontal"> <div class="form-horizontal">
<%
attribute_field.af_count ? @af_counter = attribute_field_counter + attribute_field.af_count : @af_counter = attribute_field_counter
%>
<%= @af_counter %>
<%#= attribute_field_counter %>
<legend> <legend>
<button class="onoff pull-right <%= attribute_field.disabled ? 'disabled' : ''%>">ON</button> <button class="onoff pull-right <%= attribute_field.disabled ? 'disabled' : ''%>">ON</button>
<%= hidden_field "info[attribute_fields][#{attribute_field_counter}]","disabled",:value=>attribute_field.disabled,:class=>"attribute_field_disabled"%> <%= hidden_field "info[attribute_fields][#{@af_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}]","to_delete",:value=>false,:class=>"attribute_field_to_delete"%>
<a class="btn btn-small pull-right btn-danger remove_attribute" href="#"><i class="icon-trash icon-large"></i> <%= t(:delete_)%></a> <a class="btn btn-small pull-right btn-danger remove_attribute" href="#"><i class="icon-trash icon-large"></i> <%= t(:delete_)%></a>
<div class="clear"> <div class="clear">
<div class="control-group pull-left"> <div class="control-group pull-left">
<label class="control-label" for="key"><%= t(:key) %></label> <label class="control-label" for="key"><%= t(:key) %></label>
<div class="multipleInput"> <div class="multipleInput">
<div class="controls"> <div class="controls">
<%= 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%>
</div> </div>
</div> </div>
</div> </div>
<%= 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]"}%>
<div class="control-group pull-left"> <div class="control-group pull-left">
<label class="control-label" for=""><%= t(:type)%></label> <label class="control-label" for=""><%= t(:type)%></label>
<div class="controls"> <div class="controls">
<%#= select_tag "info[attribute_fields][#{attribute_field_counter}][markup]" do %> <%#= select_tag "info[attribute_fields][#{@af_counter}][markup]" do %>
<select class="dataType" name=<%= "info[attribute_fields][#{attribute_field_counter}][markup]"%>> <select class="dataType" name=<%= "info[attribute_fields][#{@af_counter}][markup]"%>>
<%LIST[:markups].each do |key,val|%> <%LIST[:markups].each do |key,val|%>
<option value="<%= key %>" <%= attribute_field.markup == key ? 'selected="selected"' : '' %> ref="<%=val["panel"]%>"><%=t("lists.markups."+key)%></option > <option value="<%= key %>" <%= attribute_field.markup == key ? 'selected="selected"' : '' %> ref="<%=val["panel"]%>"><%=t("lists.markups."+key)%></option >
<% end %> <% end %>
@ -33,25 +38,25 @@
<label class="control-label"><%= t(:options)%></label> <label class="control-label"><%= t(:options)%></label>
<div class="controls"> <div class="controls">
<label class="checkbox inline"> <label class="checkbox inline">
<%= check_box_tag("info[attribute_fields][#{attribute_field_counter}][typeA][cross_lang]","true",attribute_field["typeA"]["cross_lang"]) %> <%= check_box_tag("info[attribute_fields][#{@af_counter}][typeA][cross_lang]","true",attribute_field["typeA"]["cross_lang"]) %>
<%= t(:cross_lang)%> <%= t(:cross_lang)%>
</label> </label>
<label class="checkbox inline"> <label class="checkbox inline">
<%= check_box_tag("info[attribute_fields][#{attribute_field_counter}][typeA][add_more]","true",attribute_field["typeA"]["add_more"]) %> <%= check_box_tag("info[attribute_fields][#{@af_counter}][typeA][add_more]","true",attribute_field["typeA"]["add_more"]) %>
<%= t(:add_more)%> <%= t(:add_more)%>
</label> </label>
</div> </div>
</div> </div>
<%= 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 %> <% end %>
<%= content_tag :div,:class=>show_type_panel(attribute_field,"typeB") do %> <%= 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?%> <% 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%> <%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 #of self_defined_markup_options?%>
<% end %> <% end %>
@ -59,17 +64,17 @@
<div class="control-group"> <div class="control-group">
<label class="control-label"><%= t("date.format")%></label> <label class="control-label"><%= t("date.format")%></label>
<div class="controls"> <div class="controls">
<%= 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"] %>
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label"><%= t("date.range")%></label> <label class="control-label"><%= t("date.range")%></label>
<div class="controls"> <div class="controls">
<label class="radio inline"> <label class="radio inline">
<%= radio_button("info[attribute_fields][#{attribute_field_counter}][typeC]", "is_range", "false",:checked => (!attribute_field.date_is_range? ? true : false)) %><%= t(:yes_)%> <%= radio_button("info[attribute_fields][#{@af_counter}][typeC]", "is_range", "false",:checked => (!attribute_field.date_is_range? ? true : false)) %><%= t(:yes_)%>
</label> </label>
<label class="radio inline"> <label class="radio inline">
<%= radio_button("info[attribute_fields][#{attribute_field_counter}][typeC]", "is_range", "true",:checked => (attribute_field.date_is_range? ? true : false)) %><%= t(:no_)%> <%= radio_button("info[attribute_fields][#{@af_counter}][typeC]", "is_range", "true",:checked => (attribute_field.date_is_range? ? true : false)) %><%= t(:no_)%>
</label> </label>
</div> </div>
</div> </div>
@ -77,10 +82,10 @@
<label class="control-label"><%= t("date.calendar")%></label> <label class="control-label"><%= t("date.calendar")%></label>
<div class="controls"> <div class="controls">
<label class="radio inline"> <label class="radio inline">
<%= radio_button("info[attribute_fields][#{attribute_field_counter}][typeC]", "calendar", "west_calendar",:checked =>(attribute_field["typeC"]["calendar"]== "west_calendar" ? true : false)) %><%= t("date.west_calendar")%> <%= radio_button("info[attribute_fields][#{@af_counter}][typeC]", "calendar", "west_calendar",:checked =>(attribute_field["typeC"]["calendar"]== "west_calendar" ? true : false)) %><%= t("date.west_calendar")%>
</label> </label>
<label class="radio inline"> <label class="radio inline">
<%= radio_button("info[attribute_fields][#{attribute_field_counter}][typeC]", "calendar", "tw_calendar",:checked =>(attribute_field["typeC"]["calendar"]== "tw_calendar" ? true : false)) %><%= t("date.tw_calendar")%> <%= radio_button("info[attribute_fields][#{@af_counter}][typeC]", "calendar", "tw_calendar",:checked =>(attribute_field["typeC"]["calendar"]== "tw_calendar" ? true : false)) %><%= t("date.tw_calendar")%>
</label> </label>
</div> </div>
</div> </div>
@ -90,16 +95,16 @@
<label class="control-label"><%= t(:options)%></label> <label class="control-label"><%= t(:options)%></label>
<div class="controls"> <div class="controls">
<label class="checkbox inline"> <label class="checkbox inline">
<%= check_box_tag("info[attribute_fields][#{attribute_field_counter}][typeD][cross_lang]","true",attribute_field["typeD"]["cross_lang"]) %> <%= check_box_tag("info[attribute_fields][#{@af_counter}][typeD][cross_lang]","true",attribute_field["typeD"]["cross_lang"]) %>
<%= t(:cross_lang)%> <%= t(:cross_lang)%>
</label> </label>
</div> </div>
</div> </div>
<%= 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 %> <% end %>
<%= content_tag :div,:class=>show_type_panel(attribute_field,"typeE") do%> <%= 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 %> <% end %>
</div> </div>
<%= 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%>
</div> </div>