diff --git a/app/controllers/default_widget_controller.rb b/app/controllers/default_widget_controller.rb
index e4c805877..559538055 100644
--- a/app/controllers/default_widget_controller.rb
+++ b/app/controllers/default_widget_controller.rb
@@ -11,7 +11,7 @@ class DefaultWidgetController< OrbitWidgetController
@default_widget = @page_part.module_app.get_default_widget
@widget_image_field = @default_widget[:image]
data_limit = @page_part.widget_data_count.is_a?(Fixnum) ? @page_part.widget_data_count : (@page_part.widget_data_count.to_i rescue 3)
- @data = eval(@default_widget[:query]).limit(data_limit).includes(@widget_image_field)
+ @data = eval(@default_widget["query"]).limit(data_limit).includes(@widget_image_field)
@fields = @page_part.widget_field
case params[:type]
diff --git a/app/helpers/admin/page_parts_helper.rb b/app/helpers/admin/page_parts_helper.rb
index 33fff3095..8e2951f57 100644
--- a/app/helpers/admin/page_parts_helper.rb
+++ b/app/helpers/admin/page_parts_helper.rb
@@ -8,4 +8,15 @@ module Admin::PagePartsHelper
res.html_safe
end
end
+
+ def widget_field_options(i)
+ options = @module_app.widget_fields.collect{|widget_field| [I18n.t(widget_field[1]), widget_field[0]]}
+ options_for_select(options, (@part[:widget_field][i][0] if (@part && !@part[:widget_field].blank? && !@part[:widget_field][i].blank?)) )
+ end
+
+ def widget_fiield_type_options(i)
+ options = LIST[:widget_field_type].collect{|widget_field| [widget_field.humanize, widget_field]}
+ options_for_select(options, (@part[:widget_field][i][1] if (@part && !@part[:widget_field].blank? && !@part[:widget_field][i].blank?)) )
+ end
+
end
\ No newline at end of file
diff --git a/app/helpers/default_widget_helper.rb b/app/helpers/default_widget_helper.rb
new file mode 100644
index 000000000..df98abe34
--- /dev/null
+++ b/app/helpers/default_widget_helper.rb
@@ -0,0 +1,48 @@
+module DefaultWidgetHelper
+ def get_field_header(field)
+ I18n.t(@page_part.module_app.widget_fields.select{|t|t[0]==field}[0][1])
+ end
+
+ def link_to_field(row_data,field)
+ method_ary = @page_part.module_app.widget_fields_link_method
+ if method_ary.has_key? field
+ url = case method_ary[field]["args"]
+ when nil # no args
+ eval(method_ary[field]["method"])
+ when :self # passing self
+ eval "#{method_ary[field]['method']}('#{row_data.id}')"
+ else
+ ary = method_ary[field]["args"].clone
+ object_hash = ary.each do |key,val|
+ ary[key]= row_data.send(val[0]).send(val[1]).to_s
+ end
+ binding.pry
+ eval "#{method_ary[field]['method']}(#{object_hash})"
+ end
+
+ link_to row_data.send(field),url
+ else
+ row_data.send(field)
+ end
+ end
+
+ # def get_args_mapping(object,row_hash)
+ # first_hash = row_hash.first
+
+ # # row_data.send(method_ary[field]["args"])
+ # end
+
+
+ def get_row_data(row_data,field)
+ field_is_link = (field[0][1]== 'false' ? false : true )
+ field_setting = {:class=>field[0][1],:method=>field[0][0]}
+ if field_is_link
+ field_link = field[0][1].to_s + '_path'
+ binding.pry
+ link = link_to(row_data.send(field_setting[:method]),field_link.send(row_data))
+ content_tag(:span,link,:class=>field_setting[:class])
+ else
+ content_tag(:span,row_data.send(field_setting[:method]),:class=>field_setting[:class])
+ end
+ end
+end
\ No newline at end of file
diff --git a/app/helpers/default_widgets_helper.rb b/app/helpers/default_widgets_helper.rb
deleted file mode 100644
index b4be81413..000000000
--- a/app/helpers/default_widgets_helper.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-module DefaultWidgetsHelper
- def get_row_data(row_data,field)
- field_is_link = (field[0][1]== 'false' ? false : true )
- field_setting = {:class=>field[0][1],:method=>field[0][0]}
- if field_is_link
- field_link = field[0][1].to_s + '_path'
- binding.pry
- link = link_to(row_data.send(field_setting[:method]),field_link.send(row_data))
- content_tag(:span,link,:class=>field_setting[:class])
- else
- content_tag(:span,row_data.send(field_setting[:method]),:class=>field_setting[:class])
- end
- end
-end
\ No newline at end of file
diff --git a/app/models/module_app.rb b/app/models/module_app.rb
index d0cd88863..15657b2cb 100644
--- a/app/models/module_app.rb
+++ b/app/models/module_app.rb
@@ -19,6 +19,9 @@ class ModuleApp
field :widget_fields ,type: Array
field :widget_options,type:Hash
field :widget_options_fields_i18n,type:Hash
+ field :widget_fields_link_method,type:Hash
+ field :get_default_widget,type:Hash
+
has_many :managers,as: :managing_app ,:class_name => "AppManager" ,:dependent => :destroy#,:foreign_key => "managing_app_id",:inverse_of => :managing_app
has_many :sub_managers,as: :sub_managing_app ,:class_name => "AppManager", :dependent => :destroy#,:foreign_key => "sub_managing_app_id",:inverse_of => :sub_managing_app
@@ -30,13 +33,6 @@ class ModuleApp
before_save :set_key
- #>>>>>>>>>>>>> remove after app config applied
- def get_default_widget
- {:query=>'Bulletin.all',:image=> 'image'}
- end
- #<<<<<<<<<<<<@@
-
-
def is_manager?(user)
managing_users.include?(user)
end
diff --git a/app/views/admin/page_parts/_widget_fields.html.erb b/app/views/admin/page_parts/_widget_fields.html.erb
index 81b49992d..99f413284 100644
--- a/app/views/admin/page_parts/_widget_fields.html.erb
+++ b/app/views/admin/page_parts/_widget_fields.html.erb
@@ -4,8 +4,8 @@
<% @module_app.widget_fields.each_with_index do |widget_field, i| %>
<%= i+1 %>
- <%= select_tag "page_part[widget_field][]", options_for_select(@module_app.widget_fields.collect{|widget_field| [widget_field.humanize, widget_field]}, (@part[:widget_field][i][0] if (@part && !@part[:widget_field].blank? && !@part[:widget_field][i].blank?)) ), :include_blank => true %>
- <%= select_tag "page_part[widget_field_type][]", options_for_select(LIST[:widget_field_type].collect{|widget_field| [widget_field.humanize, widget_field]}, (@part[:widget_field][i][1] if (@part && !@part[:widget_field].blank? && !@part[:widget_field][i].blank?)) ), :include_blank => true %>
+ <%= select_tag "page_part[widget_field][]", widget_field_options(i), :include_blank => true %>
+ <%= select_tag "page_part[widget_field_type][]", widget_fiield_type_options(i), :include_blank => true %>
<% end %>
<%= label_tag :widget_data_count %>
diff --git a/app/views/default_widget/typeA.html.erb b/app/views/default_widget/typeA.html.erb
index b26bd3bc3..c797ce734 100644
--- a/app/views/default_widget/typeA.html.erb
+++ b/app/views/default_widget/typeA.html.erb
@@ -4,18 +4,14 @@
<% @fields.each do |field|%>
-
<% @data.each do |row_data| %>
<%= content_tag(:span,field[0],:class=>field[1])%>
+ <%= content_tag(:span,get_field_header(field[0]),:class=>field[1])%>
<% end %>