From b315215bed45f23179402ee59bb8dbff3e59d895 Mon Sep 17 00:00:00 2001 From: Fu Matthew Date: Wed, 6 Feb 2013 19:51:53 +0800 Subject: [PATCH 1/6] first version of multi categories and tags --- .../javascripts/inc/update_cates_and_tags.js | 17 +++++ .../admin/page_parts_controller.rb | 12 +++ app/controllers/admin/pages_controller.rb | 8 ++ app/controllers/default_widget_controller.rb | 75 +++++++++++++------ app/helpers/admin/page_parts_helper.rb | 21 +++++- app/models/page.rb | 4 +- app/models/page_part.rb | 2 + .../_widget_data_source_category.html.erb | 4 +- .../_widget_data_source_tag.html.erb | 4 +- app/views/admin/page_parts/edit.html.erb | 8 +- app/views/admin/pages/edit.html.erb | 1 + lib/tasks/migrate.rake | 20 +++++ 12 files changed, 142 insertions(+), 34 deletions(-) create mode 100644 app/assets/javascripts/inc/update_cates_and_tags.js diff --git a/app/assets/javascripts/inc/update_cates_and_tags.js b/app/assets/javascripts/inc/update_cates_and_tags.js new file mode 100644 index 00000000..bb41a183 --- /dev/null +++ b/app/assets/javascripts/inc/update_cates_and_tags.js @@ -0,0 +1,17 @@ +function update_cates_and_tags() +{ + $('.select_option,.select_all').removeAttr('disabled'); + $(".select_all:checked").each(function( obj ) { + $(this).parent().siblings('label').find('.select_option').attr('disabled',true); + $(this).parent().siblings('label').find('.select_option').removeAttr('checked'); + }); + $(".select_option:checked").each(function( obj ) { + $(this).parent().siblings('label').find('.select_all').attr('disabled',true); + $(this).parent().siblings('label').find('.select_all').removeAttr('checked'); + }); +} + +$(document).ready(function(){ + update_cates_and_tags(); + $("#widget_data_source_category,#widget_data_source_tag,#app_page_category,#app_page_tag").find('input').change(function(){update_cates_and_tags()}); +}); \ No newline at end of file diff --git a/app/controllers/admin/page_parts_controller.rb b/app/controllers/admin/page_parts_controller.rb index d591dd83..508034f2 100644 --- a/app/controllers/admin/page_parts_controller.rb +++ b/app/controllers/admin/page_parts_controller.rb @@ -54,6 +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] ) @@ -63,6 +64,17 @@ class Admin::PagePartsController < ApplicationController if params[:page_part][:module_app].blank? params[:page_part][:module_app] = nil end + + if params[:page_part][:tag].include?("nil") + params[:page_part][:tag] = [] + end + + if params[:page_part][:category].include?("nil") + params[:page_part][:category] = [] + end + + + if @part.update_attributes(params[:page_part]) set_children_sub_menu(@part) if @part.public_r_tag && @part.public_r_tag.eql?('sub_menu') flash.now[:notice] = t('update.success.content') diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index f2de0c9e..46e2ecd0 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -97,6 +97,14 @@ helper Admin::PagePartsHelper params[:page][:frontend_field] = params[:page][:frontend_field].zip( params[:page][:frontend_field_type] ) if params[:page][:frontend_field] params[:page][:frontend_field_type] = nil + if params[:page][:tag].include?("nil") + params[:page][:tag] = [] + end + + if params[:page][:category].include?("nil") + params[:page][:category] = [] + end + if @item.update_attributes(params[:page]) flash[:notice] = t('update.success.page') respond_to do |format| diff --git a/app/controllers/default_widget_controller.rb b/app/controllers/default_widget_controller.rb index 956a2a53..0963b18a 100644 --- a/app/controllers/default_widget_controller.rb +++ b/app/controllers/default_widget_controller.rb @@ -10,31 +10,60 @@ class DefaultWidgetController< OrbitWidgetController @page_part.module_app.enable_frontend? end + def query_for_default_widget + ori_class_name = @default_widget["query"].split('.')[0] + result = nil + result_objects = nil + if !params["tag_id"].blank? + @tags = Tag.find(params["tag_id"]) rescue nil + result_ids = nil + if params["category_id"].blank? + result_ids = @tags.collect{|tag| tag.send(ori_class_name.downcase.pluralize).entries.collect{|t| t.id}}.flatten + else + result_ids = @tags.collect{|tag| tag.send(ori_class_name.downcase.pluralize).where(:category_id=>params["category_id"]).available_for_lang(I18n.locale).can_display.collect{|t| t.id}}.flatten + end + result = eval("#{ori_class_name}.where(:id=>result_ids)") + elsif params["category_id"].blank? + result = eval(@default_widget["query"]) + else + result = eval("#{ori_class_name}.where(:category_id=>params['category_id'])") + end + result.available_for_lang(I18n.locale).can_display + end + def default_widget @tag_class = nil - - @default_widget = @page_part.module_app.get_default_widget - @widget_image_field = @default_widget["image"] || @default_widget[:image] - data_limit = case @page_part - when Page - @fields = @page_part.frontend_field - @page_part.frontend_data_count.is_a?(Fixnum) ? @page_part.frontend_data_count : (@page_part.frontend_data_count.to_i rescue 3) - when PagePart - @fields = @page_part.widget_field - @page_part.widget_data_count.is_a?(Fixnum) ? @page_part.widget_data_count : (@page_part.widget_data_count.to_i rescue 3) - end - @data = eval(@default_widget["query"]).limit(data_limit).includes(@widget_image_field).desc(:created_at) - case params[:type] - when "typeA" - @tag_class = 'default_widget_typeA' - render "typeA" - when /typeB_/ - @tag_class = "default_widget_#{params[:type]}" - render "typeB" - when "typeC" - @tag_class = 'default_widget_typeC' - render "typeC" - end + @default_widget = @page_part.module_app.get_default_widget + @widget_image_field = @default_widget["image"] || @default_widget[:image] + case @page_part + when Page + @fields = @page_part.frontend_field + @data_limit = @page_part.frontend_data_count.is_a?(Fixnum) ? @page_part.frontend_data_count : (@page_part.frontend_data_count.to_i rescue 3) + @paginate = true + @page_id = @page_part.id + when PagePart + @fields = @page_part.widget_field + @data_limit = @page_part.widget_data_count.is_a?(Fixnum) ? @page_part.widget_data_count : (@page_part.widget_data_count.to_i rescue 3) + end + if @paginate + @data = query_for_default_widget.includes(@widget_image_field).page(params[:page_main]).per(@data_limit) + else + @data = query_for_default_widget.limit(@data_limit).includes(@widget_image_field) + end + case params[:type] + when "typeA" + @tag_class = 'default_widget_typeA' + @partial = "typeA" + render "typeA" + when /typeB_/ + @tag_class = "default_widget_#{params[:type]}" + @partial = "typeB" + render "typeB" + when "typeC" + @tag_class = 'default_widget_typeC' + @partial = "typeC" + render "typeC" + end end diff --git a/app/helpers/admin/page_parts_helper.rb b/app/helpers/admin/page_parts_helper.rb index 898b139e..f1cf1421 100644 --- a/app/helpers/admin/page_parts_helper.rb +++ b/app/helpers/admin/page_parts_helper.rb @@ -84,17 +84,17 @@ module Admin::PagePartsHelper def tag_checked_value(part,radio_value) if radio_value.blank? - (part.nil? || part[:tag].blank?)? true : false + (part.nil? || part[:tag].blank?) ? true : false else - part and (part[:tag] == radio_value.to_s) ? true : false + part and (part[:tag].include?(radio_value.to_s)) ? true : false end end def category_checked_value(part,radio_value) if radio_value.blank? - (part.nil? || part[:category].blank?)? true : false + (part.nil? || part[:category].blank?) ? true : false else - part and (part[:category] == radio_value.to_s) ? true : false + part and (part[:category].include?(radio_value.to_s)) ? true : false end end @@ -117,6 +117,19 @@ module Admin::PagePartsHelper end end + def nil_checkbox_button(part,tag_or_cate) + field_name = case part + when PagePart + 'page_part' + when Page + 'page' + end + content_tag :label,:class=>"radio inline" do + op = check_box_tag("#{field_name}[#{tag_or_cate}][]", 'nil' , eval("#{tag_or_cate}_checked_value(part,'')"),:class=>'select_all') + op << I18n.t("default_widget.no_value") + end + end + def nil_radio_button(part,tag_or_cate) field_name = case part when PagePart diff --git a/app/models/page.rb b/app/models/page.rb index bc257eaa..545105fd 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -8,8 +8,8 @@ class Page < Item field :content, localize: true field :app_frontend_url field :theme_id, :type => BSON::ObjectId, :default => nil - field :category, :default => '' - field :tag, :default => '' + field :category,type: Array, :default => [] + field :tag, type: Array,:default => [] field :view_count, :type => Integer, :default => 0 field :page_title, localize: true diff --git a/app/models/page_part.rb b/app/models/page_part.rb index b48c8060..4b0d4a8c 100644 --- a/app/models/page_part.rb +++ b/app/models/page_part.rb @@ -11,6 +11,8 @@ class PagePart field :public_r_tag_option, :default => nil field :page_title, localize: true field :widget_path + field :category,type: Array, :default => [] + field :tag, type: Array,:default => [] field :widget_style field :widget_field , :type => Array diff --git a/app/views/admin/page_parts/_widget_data_source_category.html.erb b/app/views/admin/page_parts/_widget_data_source_category.html.erb index d088c645..c3e4c21d 100644 --- a/app/views/admin/page_parts/_widget_data_source_category.html.erb +++ b/app/views/admin/page_parts/_widget_data_source_category.html.erb @@ -10,9 +10,9 @@
<% if @categories %>
- <%= nil_radio_button(object,:category) %> + <%= nil_checkbox_button(object,:category) %> <%= content_tag_for(:label, @categories,:class=>"radio inline") do |category|%> - <%= radio_button_tag("#{field_name}[category]", category.id, category_checked_value(object,category.id) )%> + <%= check_box_tag("#{field_name}[category][]", category.id, category_checked_value(object,category.id),:class=>'select_option' )%> <%= category.title%> <% end %>
diff --git a/app/views/admin/page_parts/_widget_data_source_tag.html.erb b/app/views/admin/page_parts/_widget_data_source_tag.html.erb index bcb3e9c3..c067aede 100644 --- a/app/views/admin/page_parts/_widget_data_source_tag.html.erb +++ b/app/views/admin/page_parts/_widget_data_source_tag.html.erb @@ -10,9 +10,9 @@
<% if @categories %>
- <%= nil_radio_button(object,:tag) %> + <%= nil_checkbox_button(object,:tag) %> <%= content_tag_for(:label, @tags,:class=>"radio inline") do |tag|%> - <%= radio_button_tag("#{field_name}[tag]", tag.id, tag_checked_value(object,tag.id) ) %> + <%= check_box_tag("#{field_name}[tag][]", tag.id, tag_checked_value(object,tag.id),:class=>'select_option' ) %> <%= tag[I18n.locale]%> <% end if @tags%>
diff --git a/app/views/admin/page_parts/edit.html.erb b/app/views/admin/page_parts/edit.html.erb index 907cc7eb..198e4255 100644 --- a/app/views/admin/page_parts/edit.html.erb +++ b/app/views/admin/page_parts/edit.html.erb @@ -2,4 +2,10 @@ <%= render 'admin/items/site_map_left_bar' %> <% end -%> -<%= render 'edit' %> \ No newline at end of file + + + + +<%= render 'edit' %> + +<%=javascript_include_tag "inc/update_cates_and_tags.js" %> \ No newline at end of file diff --git a/app/views/admin/pages/edit.html.erb b/app/views/admin/pages/edit.html.erb index 8bd76634..8c3c0711 100644 --- a/app/views/admin/pages/edit.html.erb +++ b/app/views/admin/pages/edit.html.erb @@ -4,3 +4,4 @@ <% end -%> <%= render 'edit' %> +<%=javascript_include_tag "inc/update_cates_and_tags.js" %> \ No newline at end of file diff --git a/lib/tasks/migrate.rake b/lib/tasks/migrate.rake index f3b16f16..9770f151 100644 --- a/lib/tasks/migrate.rake +++ b/lib/tasks/migrate.rake @@ -492,4 +492,24 @@ namespace :migrate do pp.save end end + + task :convert_cate_tag_type => :environment do + [Page,PagePart].each do |obj| + obj.all.each do |pp| + if pp.category.blank? + pp.category = [] + else + pp.category = [pp.category] + end + + if pp.tag.blank? + pp.tag = [] + else + pp.tag = [pp.tag] + end + pp.save + end + end + end + end From d6dd38744b9f7a2fafc5c277a04ab792c4c41db8 Mon Sep 17 00:00:00 2001 From: Fu Matthew Date: Sat, 23 Feb 2013 11:34:47 +0800 Subject: [PATCH 2/6] fix javascript disable checkbox failed after cate and tags being reloaded. --- app/assets/javascripts/inc/update_cates_and_tags.js | 6 +++++- app/views/admin/page_parts/_edit.html.erb | 2 ++ app/views/admin/page_parts/edit.html.erb | 4 +--- app/views/admin/page_parts/reload_widgets.js.erb | 2 ++ app/views/admin/pages/_form.html.erb | 1 + app/views/admin/pages/edit.html.erb | 3 +-- app/views/admin/pages/reload_frontend_pages.js.erb | 2 ++ 7 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/inc/update_cates_and_tags.js b/app/assets/javascripts/inc/update_cates_and_tags.js index bb41a183..223cd8d7 100644 --- a/app/assets/javascripts/inc/update_cates_and_tags.js +++ b/app/assets/javascripts/inc/update_cates_and_tags.js @@ -11,7 +11,11 @@ function update_cates_and_tags() }); } +function rebind(){ + $("#widget_data_source_category,#widget_data_source_tag,#app_page_category,#app_page_tag").find('input').change(function(){update_cates_and_tags()}); +} + $(document).ready(function(){ update_cates_and_tags(); - $("#widget_data_source_category,#widget_data_source_tag,#app_page_category,#app_page_tag").find('input').change(function(){update_cates_and_tags()}); + rebind(); }); \ No newline at end of file diff --git a/app/views/admin/page_parts/_edit.html.erb b/app/views/admin/page_parts/_edit.html.erb index 812f50c7..79cc057d 100644 --- a/app/views/admin/page_parts/_edit.html.erb +++ b/app/views/admin/page_parts/_edit.html.erb @@ -19,3 +19,5 @@
<% end %> + +<%=javascript_include_tag "inc/update_cates_and_tags.js" %> \ No newline at end of file diff --git a/app/views/admin/page_parts/edit.html.erb b/app/views/admin/page_parts/edit.html.erb index 198e4255..b6578129 100644 --- a/app/views/admin/page_parts/edit.html.erb +++ b/app/views/admin/page_parts/edit.html.erb @@ -6,6 +6,4 @@ -<%= render 'edit' %> - -<%=javascript_include_tag "inc/update_cates_and_tags.js" %> \ No newline at end of file +<%= render 'edit' %> \ No newline at end of file diff --git a/app/views/admin/page_parts/reload_widgets.js.erb b/app/views/admin/page_parts/reload_widgets.js.erb index c32e07c2..afe62dd3 100644 --- a/app/views/admin/page_parts/reload_widgets.js.erb +++ b/app/views/admin/page_parts/reload_widgets.js.erb @@ -16,3 +16,5 @@ $('#widget_setting').html("<%=j render :partial=> 'reset',:locals=>{:label_i18n=>'default_widget.select_widget_style'}%>"); $('#widget_list select').html("<%= j options_for_select([]) %>"); <% end %> +update_cates_and_tags(); +rebind(); \ No newline at end of file diff --git a/app/views/admin/pages/_form.html.erb b/app/views/admin/pages/_form.html.erb index 8198cda6..e3a626bc 100644 --- a/app/views/admin/pages/_form.html.erb +++ b/app/views/admin/pages/_form.html.erb @@ -109,3 +109,4 @@
+<%=javascript_include_tag "inc/update_cates_and_tags.js" %> \ No newline at end of file diff --git a/app/views/admin/pages/edit.html.erb b/app/views/admin/pages/edit.html.erb index 8c3c0711..701b7ae0 100644 --- a/app/views/admin/pages/edit.html.erb +++ b/app/views/admin/pages/edit.html.erb @@ -3,5 +3,4 @@ <%= render 'admin/items/site_map_left_bar' %> <% end -%> -<%= render 'edit' %> -<%=javascript_include_tag "inc/update_cates_and_tags.js" %> \ No newline at end of file +<%= render 'edit' %> \ No newline at end of file diff --git a/app/views/admin/pages/reload_frontend_pages.js.erb b/app/views/admin/pages/reload_frontend_pages.js.erb index 09f0e13a..1d4ce1f8 100644 --- a/app/views/admin/pages/reload_frontend_pages.js.erb +++ b/app/views/admin/pages/reload_frontend_pages.js.erb @@ -31,3 +31,5 @@ $('#app_page_url').html("<%= t('default_widget.no_support_setting')%>"); $('#frontend_setting').html("<%= j render :partial => 'custom_frontend_setting' %>"); <% end %> +update_cates_and_tags(); +rebind(); \ No newline at end of file From 8592015b1b556e0a19f1ccd65ddf00dbefaa19ee Mon Sep 17 00:00:00 2001 From: Fu Matthew Date: Sat, 23 Feb 2013 15:19:04 +0800 Subject: [PATCH 3/6] fixed Widget data count should be available for other widgets, not only for default widget. The availability of this option must be set in the init --- .../page_parts/_default_widget_setting.html.erb | 13 ------------- app/views/admin/page_parts/_module_widget.html.erb | 9 +++++++++ app/views/admin/pages/_form.html.erb | 9 +++++++++ 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/app/views/admin/page_parts/_default_widget_setting.html.erb b/app/views/admin/page_parts/_default_widget_setting.html.erb index f4546178..741da7d5 100644 --- a/app/views/admin/page_parts/_default_widget_setting.html.erb +++ b/app/views/admin/page_parts/_default_widget_setting.html.erb @@ -2,11 +2,9 @@ <% when PagePart %> <% object_name = 'page_part' %> <% field_name = 'widget_field' %> - <% data_count = 'widget_data_count' %> <% when Page %> <% object_name = 'page' %> <% field_name = 'frontend_field' %> - <% data_count = 'frontend_data_count' %> <% end %>
@@ -41,16 +39,5 @@

<% end %> -
-
- - <%= label_tag t("default_widget.widget_data_count") %> - -
-
- - <%= text_field_tag "#{object_name}[#{data_count}]",object.send(data_count) %> - -
\ No newline at end of file diff --git a/app/views/admin/page_parts/_module_widget.html.erb b/app/views/admin/page_parts/_module_widget.html.erb index e1f81263..2ed647e7 100644 --- a/app/views/admin/page_parts/_module_widget.html.erb +++ b/app/views/admin/page_parts/_module_widget.html.erb @@ -45,3 +45,12 @@
<%= render :partial => 'widget_setting' ,:locals=>{:f=>f,:object=>@part} %>
+ +
+ +
+ <%= text_field_tag "page_part[widget_data_count]",@part.widget_data_count %> +
+
diff --git a/app/views/admin/pages/_form.html.erb b/app/views/admin/pages/_form.html.erb index e3a626bc..98ab5249 100644 --- a/app/views/admin/pages/_form.html.erb +++ b/app/views/admin/pages/_form.html.erb @@ -66,6 +66,15 @@ <%= render :partial => 'frontend_setting', :locals=>{:object=>@item,:f=>f} %> +
+ +
+ <%= text_field_tag "page[frontend_data_count]",@item.frontend_data_count %> +
+
+
<%= f.label :is_published, "#{t('front_page.is_published')} ?", :class => 'control-label' %> From 73bca03b332f33f56e63378746b313a089ac79be Mon Sep 17 00:00:00 2001 From: Fu Matthew Date: Sat, 23 Feb 2013 15:19:51 +0800 Subject: [PATCH 4/6] fix default widget link --- app/controllers/admin/page_parts_controller.rb | 4 ++-- app/controllers/default_widget_controller.rb | 3 --- app/helpers/admin/page_parts_helper.rb | 11 +++++------ app/helpers/default_widget_helper.rb | 4 ++-- .../admin/page_parts/_default_widget_setting.html.erb | 2 +- app/views/admin/page_parts/reload_widget_field.js.erb | 2 +- 6 files changed, 11 insertions(+), 15 deletions(-) diff --git a/app/controllers/admin/page_parts_controller.rb b/app/controllers/admin/page_parts_controller.rb index 508034f2..8d106ebc 100644 --- a/app/controllers/admin/page_parts_controller.rb +++ b/app/controllers/admin/page_parts_controller.rb @@ -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] ) @@ -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') diff --git a/app/controllers/default_widget_controller.rb b/app/controllers/default_widget_controller.rb index 6f05c0ff..686a0316 100644 --- a/app/controllers/default_widget_controller.rb +++ b/app/controllers/default_widget_controller.rb @@ -60,15 +60,12 @@ class DefaultWidgetController< OrbitWidgetController when "typeA" @tag_class = 'default_widget_typeA' @partial = "typeA" - render "typeA" when /typeB_/ @tag_class = "default_widget_#{params[:type]}" @partial = "typeB" - render "typeB" when "typeC" @tag_class = 'default_widget_typeC' @partial = "typeC" - render "typeC" end end end diff --git a/app/helpers/admin/page_parts_helper.rb b/app/helpers/admin/page_parts_helper.rb index f1cf1421..b285cfa4 100644 --- a/app/helpers/admin/page_parts_helper.rb +++ b/app/helpers/admin/page_parts_helper.rb @@ -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' diff --git a/app/helpers/default_widget_helper.rb b/app/helpers/default_widget_helper.rb index fdaa638f..af2ac239 100644 --- a/app/helpers/default_widget_helper.rb +++ b/app/helpers/default_widget_helper.rb @@ -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) @@ -51,7 +51,7 @@ module DefaultWidgetHelper eval eval("#{method_entry}(#{options})") when BSON::ObjectId object = "'#{object.to_s}'" - eval("#{method_entry}(#{object}, #{options})") + eval("#{method_entry}(#{{:id => object}.merge options})") when Hash eval("#{method_entry}(#{object.merge options})") else diff --git a/app/views/admin/page_parts/_default_widget_setting.html.erb b/app/views/admin/page_parts/_default_widget_setting.html.erb index 741da7d5..3e7d2689 100644 --- a/app/views/admin/page_parts/_default_widget_setting.html.erb +++ b/app/views/admin/page_parts/_default_widget_setting.html.erb @@ -35,7 +35,7 @@ <%= select_tag "#{object_name}[#{field_name}_type][]", widget_fiield_type_options(i), :include_blank => true %>
- <%= field_link_switch(i,object_name,field_name) %> + <%= link_to_field_switch(i,object_name,field_name) %>

<% end %> diff --git a/app/views/admin/page_parts/reload_widget_field.js.erb b/app/views/admin/page_parts/reload_widget_field.js.erb index 32482e51..ae8d75f2 100644 --- a/app/views/admin/page_parts/reload_widget_field.js.erb +++ b/app/views/admin/page_parts/reload_widget_field.js.erb @@ -1 +1 @@ -$("#<%= params[:dom_id] %>").parents(".rows").find(".link_switch_holder").html("<%= j field_link_switch(@index,'page_part','widget_field',nil,@choosen_field) %>"); \ No newline at end of file +$("#<%= params[:dom_id] %>").parents(".rows").find(".link_switch_holder").html("<%= j link_to_field_switch(@index,'page_part','widget_field',nil,@choosen_field) %>"); \ No newline at end of file From 0be1c45c81509066f7e8a85ee176e8dfb0248dfb Mon Sep 17 00:00:00 2001 From: Fu Matthew Date: Sat, 23 Feb 2013 18:29:50 +0800 Subject: [PATCH 5/6] link to more --- .../admin/page_parts/_module_widget.html.erb | 10 +++------- .../admin/page_parts/reload_widgets.js.erb | 2 +- app/views/admin/pages/_form.html.erb | 10 ++-------- .../admin/pages/reload_frontend_pages.js.erb | 3 ++- app/views/default_widget/_typeB.html.erb | 1 - app/views/default_widget/_typeC.html.erb | 1 - .../default_widget/default_widget.html.erb | 5 ++++- lib/orbit_app.rb | 1 + lib/orbit_app/module/registration.rb | 17 ++++++++++++++-- lib/orbit_app/module/widget.rb | 20 ++++++++++++++----- .../announcement/config/locales/zh_tw.yml | 1 + vendor/built_in_modules/announcement/init.rb | 2 ++ 12 files changed, 46 insertions(+), 27 deletions(-) diff --git a/app/views/admin/page_parts/_module_widget.html.erb b/app/views/admin/page_parts/_module_widget.html.erb index 2ed647e7..0862ae29 100644 --- a/app/views/admin/page_parts/_module_widget.html.erb +++ b/app/views/admin/page_parts/_module_widget.html.erb @@ -46,11 +46,7 @@ <%= render :partial => 'widget_setting' ,:locals=>{:f=>f,:object=>@part} %> -
- -
- <%= text_field_tag "page_part[widget_data_count]",@part.widget_data_count %> -
+
+ <%= render :partial=>'admin/pages/data_count_field',:locals=>{:field_name=>"page_part[widget_data_count]",:field_value=>@part.widget_data_count } %>
+ diff --git a/app/views/admin/page_parts/reload_widgets.js.erb b/app/views/admin/page_parts/reload_widgets.js.erb index afe62dd3..4e162167 100644 --- a/app/views/admin/page_parts/reload_widgets.js.erb +++ b/app/views/admin/page_parts/reload_widgets.js.erb @@ -2,7 +2,7 @@ $('#widget_list select').html("<%= j options_for_select(@module_app.widgets.collect{|k,v| [I18n.t(v['i18n']),k]},@part.widget_path) %>"); $("#widget_data_source_category").html("<%= j render :partial => 'widget_data_source_category',:locals=>{:object=>@part} %>"); $("#widget_data_source_tag").html("<%= j render :partial => 'widget_data_source_tag',:locals=>{:object=>@part} %>"); - + $("#data_count").html("<%= j render :partial => 'admin/pages/data_count_field',:locals=>{:field_name=>'page_part[widget_data_count]',:field_value=>@part.widget_data_count } %>"); <% if @part %> <% if show_default_widget_setting_panel %> $('#widget_setting').html("<%= j render :partial => 'default_widget_style_panel' %>"); diff --git a/app/views/admin/pages/_form.html.erb b/app/views/admin/pages/_form.html.erb index 98ab5249..d3308bc6 100644 --- a/app/views/admin/pages/_form.html.erb +++ b/app/views/admin/pages/_form.html.erb @@ -66,16 +66,10 @@ <%= render :partial => 'frontend_setting', :locals=>{:object=>@item,:f=>f} %>
-
- -
- <%= text_field_tag "page[frontend_data_count]",@item.frontend_data_count %> -
+
+ <%= render :partial=>'data_count_field',:locals=>{:field_name=>"page[frontend_data_count]",:field_value=>@item.frontend_data_count} %>
-
<%= f.label :is_published, "#{t('front_page.is_published')} ?", :class => 'control-label' %>
diff --git a/app/views/admin/pages/reload_frontend_pages.js.erb b/app/views/admin/pages/reload_frontend_pages.js.erb index 1d4ce1f8..215ec3fb 100644 --- a/app/views/admin/pages/reload_frontend_pages.js.erb +++ b/app/views/admin/pages/reload_frontend_pages.js.erb @@ -1,7 +1,8 @@ <% if @module_app %> $('#app_page_category').html("<%= j render :partial => 'admin/page_parts/widget_data_source_category' ,:locals=>{:object=>@page}%>"); $('#app_page_tag').html("<%= j render :partial => 'admin/page_parts/widget_data_source_tag',:locals=>{:object=>@page} %>"); - + $("#data_count").html("<%= j render :partial => 'admin/pages/data_count_field',:locals=>{:field_name=>'page[frontend_data_count]',:field_value=>@page.frontend_data_count} %>"); + <% if !@module_app.app_pages.blank? %> $('#app_page_url').html("<%= escape_javascript(select 'page', 'app_frontend_url', options_for_select(@app_frontend_urls, @app_frontend_urls.first)) %>"); <%else %> diff --git a/app/views/default_widget/_typeB.html.erb b/app/views/default_widget/_typeB.html.erb index fcf70065..ff2b8bdd 100644 --- a/app/views/default_widget/_typeB.html.erb +++ b/app/views/default_widget/_typeB.html.erb @@ -13,5 +13,4 @@ <% end %> <% end %> -
more
<% end %> diff --git a/app/views/default_widget/_typeC.html.erb b/app/views/default_widget/_typeC.html.erb index d3b3e49f..24729b08 100644 --- a/app/views/default_widget/_typeC.html.erb +++ b/app/views/default_widget/_typeC.html.erb @@ -11,5 +11,4 @@ <% end %> <% end %> -
more
<% end %> diff --git a/app/views/default_widget/default_widget.html.erb b/app/views/default_widget/default_widget.html.erb index b134d8ad..fe46de2c 100644 --- a/app/views/default_widget/default_widget.html.erb +++ b/app/views/default_widget/default_widget.html.erb @@ -1,4 +1,7 @@ <%= render @partial %> <% if @paginate %> <%= paginate @data, :param_name => :page_main, :params => {:same_page_id => @page_id} %> -<% end %> \ No newline at end of file +<% end %> +<% if @page_part.module_app %> + <%= @page_part.module_app.get_registration.default_widget_setting.link_to_more_tag(request,params) %> +<% end %> diff --git a/lib/orbit_app.rb b/lib/orbit_app.rb index 5b20f7a5..0d801751 100644 --- a/lib/orbit_app.rb +++ b/lib/orbit_app.rb @@ -3,6 +3,7 @@ require "orbit_app/dsl" require "orbit_app/helper/renderer" require "orbit_app/helper/side_bar_renderer" require "orbit_app/helper/context_link_renderer" +require "orbit_app/helper/default_widget_tag_helper" require "orbit_app/module/side_bar" require "orbit_app/module/widget" require "orbit_app/module/front_end" diff --git a/lib/orbit_app/module/registration.rb b/lib/orbit_app/module/registration.rb index 9856f7d3..9a300a0f 100644 --- a/lib/orbit_app/module/registration.rb +++ b/lib/orbit_app/module/registration.rb @@ -28,7 +28,7 @@ module OrbitApp end class DataSheet - attr_reader :name,:key,:base_path,:module_label + attr_reader :name,:key,:base_path,:module_label,:data_count def initialize(name, &block) @name = name @@ -36,6 +36,7 @@ module OrbitApp @side_bar = nil @front_end_app_pages = nil @module_label = 'rulingcom.errors.init.module_app_noname' + @data_count = 1..3 # as default block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given? setup_module_app end @@ -86,6 +87,10 @@ module OrbitApp @front_end_app_pages.nil? ? [] : @front_end_app_pages.to_module_app_format end + def get_data_count + @data_count + end + def get_widget_by_path(path) if @widget_set @widget_set.find_by_path(path) @@ -94,6 +99,14 @@ module OrbitApp end end + def default_widget_setting + @widget_set.default_widget_setting + end + + def widget_setting + @widget_set + end + def get_widgets @widget_set.nil? ? {} : @widget_set.to_module_app_format end @@ -127,7 +140,7 @@ module OrbitApp # @default_widget = widget_set.default_widget end - %w{module_label category base_url version organization author intro update_info}.each do |field| + %w{data_count module_label category base_url version organization author intro update_info}.each do |field| define_method(field){|var| instance_variable_set( "@" + field, var)} end diff --git a/lib/orbit_app/module/widget.rb b/lib/orbit_app/module/widget.rb index 7e99b2a9..3389b5b1 100644 --- a/lib/orbit_app/module/widget.rb +++ b/lib/orbit_app/module/widget.rb @@ -34,6 +34,10 @@ module OrbitApp define_method(field){|var| instance_variable_set( "@" + field, var)} end + # def data_count(var) + # @data_count = var + # end + def find_by_path(path) @widgets.each do |widget| return widget if widget.name == path @@ -44,10 +48,14 @@ module OrbitApp eval(@categories_query) rescue nil end - def get_tags + def get_tags eval(@tags_query) rescue nil end + def default_widget_setting + @default_widget + end + def default_widget(&block) @default_widget = DefaultWidget.new(&block) end @@ -85,6 +93,7 @@ module OrbitApp end class DefaultWidget + include DefaultWidgetTagHelper STYLE = ["typeA","typeB_style2","typeB_style3","typeB_style4","typeC"] def initialize(&block) @@ -95,9 +104,10 @@ module OrbitApp block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given? end - def more_link_to(label_i18n,path_method) - @more_link[:label_i18n] = label_i18n - @more_link[:path_method] = path_method + + def link_to_more(*args) + @more_link[:label_i18n] = (args[1] ? args[1][:title_i18n] : 'default_widget.default_link_to_more' ) + @more_link[:path_method] = args[0] end def self.get_interface_args @@ -106,7 +116,7 @@ module OrbitApp end def to_module_app_format - {"query"=>@query,"image"=>@image} rescue nil + {"query"=>@query,"image"=>@image,"more_link"=>@more_link} rescue nil end def link_field(field_name,setting) diff --git a/vendor/built_in_modules/announcement/config/locales/zh_tw.yml b/vendor/built_in_modules/announcement/config/locales/zh_tw.yml index d24c1265..45769028 100644 --- a/vendor/built_in_modules/announcement/config/locales/zh_tw.yml +++ b/vendor/built_in_modules/announcement/config/locales/zh_tw.yml @@ -27,6 +27,7 @@ zh_tw: approval_setting: 審核權限 tags: 標籤 default_widget: + to_more: 更多 bulletin_category_with_title: 分類 title: 標題 postdate: 張貼日期 diff --git a/vendor/built_in_modules/announcement/init.rb b/vendor/built_in_modules/announcement/init.rb index 2dd1628a..ab54a438 100644 --- a/vendor/built_in_modules/announcement/init.rb +++ b/vendor/built_in_modules/announcement/init.rb @@ -18,6 +18,7 @@ module Announcement end category ["BulletinCategory"] + data_count 3..10 widgets do default_widget do @@ -26,6 +27,7 @@ module Announcement field :postdate link_field :title,{:method => 'panel_announcement_front_end_bulletin_path',:args=>:self} link_field :bulletin_category_with_title,{:method => 'panel_announcement_front_end_bulletins_path',:args=>{:category_id => [:bulletin_category,:id]}} + link_to_more 'panel_announcement_front_end_bulletins_path',:title_i18n=> 'announcement.default_widget.to_more' end categories_query 'BulletinCategory.all' From 5f832a17d497258b310692d0bc818a58c7847bd1 Mon Sep 17 00:00:00 2001 From: Fu Matthew Date: Mon, 25 Feb 2013 12:49:06 +0800 Subject: [PATCH 6/6] fix widget field reload --- app/assets/javascripts/page_edit.js.erb | 2 +- app/controllers/admin/page_parts_controller.rb | 1 + app/controllers/admin/pages_controller.rb | 8 ++++++++ app/views/admin/pages/_data_count_field.html.erb | 6 ++++++ app/views/admin/pages/reload_widget_field.js.erb | 1 + config/routes.rb | 1 + lib/orbit_app/helper/default_widget_tag_helper.rb | 12 ++++++++++++ lib/orbit_app/module/registration.rb | 2 +- lib/tasks/migrate.rake | 2 +- 9 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 app/views/admin/pages/_data_count_field.html.erb create mode 100644 app/views/admin/pages/reload_widget_field.js.erb create mode 100644 lib/orbit_app/helper/default_widget_tag_helper.rb diff --git a/app/assets/javascripts/page_edit.js.erb b/app/assets/javascripts/page_edit.js.erb index b7771692..f989628a 100644 --- a/app/assets/javascripts/page_edit.js.erb +++ b/app/assets/javascripts/page_edit.js.erb @@ -43,7 +43,7 @@ $("#tag_list select").live('change', function() { }); $("select.widget_field_select").live('change', function() { - $.getScript(get_object_path() + '/reload_after_widget_field_changed?widget_field_value='+ $(this).val()+'&dom_id=' + $(this).attr("id") + '&field_seri=' +$(this).attr('field_seri')); + $.getScript(get_object_path() + '/reload_after_widget_field_changed?widget_field_value='+ $(this).val()+'&dom_id=' + $(this).attr("id") + '&field_seri=' +$(this).attr('field_seri')+ '&module_app_id=' +$("#page_module_app_id,page_part_module_app_id").val()); }); $('.part_kind').live('click', function() { diff --git a/app/controllers/admin/page_parts_controller.rb b/app/controllers/admin/page_parts_controller.rb index 8d106ebc..aeb76562 100644 --- a/app/controllers/admin/page_parts_controller.rb +++ b/app/controllers/admin/page_parts_controller.rb @@ -108,6 +108,7 @@ class Admin::PagePartsController < ApplicationController @part = PagePart.find params[:id] @choosen_field = params[:widget_field_value] @module_app = @part.module_app + @module_app = ModuleApp.find params[:module_app_id] if @module_app.nil? end def reload_widgets diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index c15c9d22..a5cba320 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -180,4 +180,12 @@ helper Admin::PagePartsHelper end end + def reload_widget_field + @index = params[:field_seri].to_i + @page = Page.find params[:id] + @choosen_field = params[:widget_field_value] + @module_app = @page.module_app + @module_app = ModuleApp.find params[:module_app_id] if @module_app.nil? + end + end diff --git a/app/views/admin/pages/_data_count_field.html.erb b/app/views/admin/pages/_data_count_field.html.erb new file mode 100644 index 00000000..48f355f0 --- /dev/null +++ b/app/views/admin/pages/_data_count_field.html.erb @@ -0,0 +1,6 @@ + +
+ <%= select_tag(field_name,options_for_select(@module_app.get_registration.get_data_count,field_value )) %> +
\ No newline at end of file diff --git a/app/views/admin/pages/reload_widget_field.js.erb b/app/views/admin/pages/reload_widget_field.js.erb new file mode 100644 index 00000000..0f6bd1f7 --- /dev/null +++ b/app/views/admin/pages/reload_widget_field.js.erb @@ -0,0 +1 @@ +$("#<%= params[:dom_id] %>").parents(".rows").find(".link_switch_holder").html("<%= j link_to_field_switch(@index,'page','frontend_field',nil,@choosen_field) %>"); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index cc272ffc..8ceb71c9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -90,6 +90,7 @@ Orbit::Application.routes.draw do get 'reload_themes' get 'reload_after_module_changed',:action=>'reload_frontend_pages' get 'reload_after_list_changed',:action=> 'reload_front_end_setting' + get 'reload_after_widget_field_changed',:action=> 'reload_widget_field' end end diff --git a/lib/orbit_app/helper/default_widget_tag_helper.rb b/lib/orbit_app/helper/default_widget_tag_helper.rb new file mode 100644 index 00000000..52160398 --- /dev/null +++ b/lib/orbit_app/helper/default_widget_tag_helper.rb @@ -0,0 +1,12 @@ +module DefaultWidgetTagHelper + include Renderer + include AdminHelper + + def link_to_more_tag(req,params) + @request = req + @params =params + content_tag :div,:class=> 'more' do + link_to I18n.t(@more_link[:label_i18n]),eval(@more_link[:path_method]) + end + end +end \ No newline at end of file diff --git a/lib/orbit_app/module/registration.rb b/lib/orbit_app/module/registration.rb index 9a300a0f..5dbc3605 100644 --- a/lib/orbit_app/module/registration.rb +++ b/lib/orbit_app/module/registration.rb @@ -36,7 +36,7 @@ module OrbitApp @side_bar = nil @front_end_app_pages = nil @module_label = 'rulingcom.errors.init.module_app_noname' - @data_count = 1..3 # as default + @data_count = 1..15 # as default block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given? setup_module_app end diff --git a/lib/tasks/migrate.rake b/lib/tasks/migrate.rake index c448eed7..0a5ca9b2 100644 --- a/lib/tasks/migrate.rake +++ b/lib/tasks/migrate.rake @@ -208,6 +208,7 @@ namespace :migrate do pp.save end end + end task :clean_parts => :environment do PagePart.where(widget_style: /\d/, kind: 'module_widget').each{|part| part.update_attributes({kind: 'text', widget_style: nil, widget_field: nil})} @@ -231,7 +232,6 @@ namespace :migrate do Page.all.each do |page| page.save end - end end