fix default widget link

This commit is contained in:
Fu Matthew 2013-02-23 15:19:51 +08:00 committed by chris
parent d7699e1a46
commit 8a8bfcb8fb
5 changed files with 11 additions and 12 deletions

View File

@ -54,7 +54,7 @@ class Admin::PagePartsController < ApplicationController
end
def update
binding.pry
@part = PagePart.find(params[:id])
params[:page_part][:widget_field] = params[:page_part][:widget_field].zip( params[:page_part][:widget_field_type],params[:page_part][:widget_field_is_link] ) if params[:page_part][:widget_field]
@ -73,7 +73,7 @@ class Admin::PagePartsController < ApplicationController
params[:page_part][:category] = []
end
params[:page_part][:widget_field].each{|t| t[2] = (t[2]=="true" ? true : false )}
if @part.update_attributes(params[:page_part])
set_children_sub_menu(@part) if @part.public_r_tag && @part.public_r_tag.eql?('sub_menu')

View File

@ -21,11 +21,10 @@ module Admin::PagePartsHelper
end
end
def field_link_switch(i,object_name,field_name,local_item=nil,prefill_value=nil)
def link_to_field_switch(i,object_name,field_name,local_item=nil,prefill_value=nil) #link_to_field is for showing
local_item = @part if local_item.nil? && @part
local_item = @page if local_item.nil? && @page
res = ''
choosen_value = prefill_value || (local_item[:widget_field][i][0] rescue nil)
if choosen_value
@ -38,13 +37,13 @@ module Admin::PagePartsHelper
if choosen_field_is_link
value = case local_item
when Page
local_item[:frontend_field][i][2]
local_item[:frontend_field][i][2] rescue false
when PagePart
local_item[:widget_field][i][2]
local_item[:widget_field][i][2] rescue false
end
res = label_tag '' do
check_box_tag("#{object_name}[#{field_name}_is_link][]", value = "true", value) + I18n.t("default_widget.field_is_link")
check_box_tag("#{object_name}[#{field_name}_is_link][]", "true", value) + I18n.t("default_widget.field_is_link")
end
else # choosen_field_not_link
res = hidden_field_tag "#{object_name}[#{field_name}_is_link][]", 'false'

View File

@ -6,7 +6,7 @@ module DefaultWidgetHelper
def link_to_field(row_data,field, switch, options=nil)
method_ary = @page_part.module_app.widget_fields_link_method
field = field.to_sym
if(method_ary.has_key?(field) and (switch == "true"))
if(method_ary.has_key?(field) and (switch == true))
url = case method_ary[field][:args]
when nil # no args
get_data_link(method_ary[field]["method"], options)

View File

@ -35,7 +35,7 @@
<%= select_tag "#{object_name}[#{field_name}_type][]", widget_fiield_type_options(i), :include_blank => true %> <br />
</span>
<span class="span5 link_switch_holder">
<%= field_link_switch(i,object_name,field_name) %>
<%= link_to_field_switch(i,object_name,field_name) %>
</span>
</div><br/>
<% end %>

View File

@ -1 +1 @@
$("#<%= params[:dom_id] %>").parents(".rows").find(".link_switch_holder").html("<%= j field_link_switch(@index,'page_part','widget_field',nil,@choosen_field) %>");
$("#<%= params[:dom_id] %>").parents(".rows").find(".link_switch_holder").html("<%= j link_to_field_switch(@index,'page_part','widget_field',nil,@choosen_field) %>");