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 05e2181c..5302d8d6 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] ) if params[:page_part][:widget_field] @@ -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 77930205..c15c9d22 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -96,6 +96,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 bb7600eb..b97a2f6c 100644 --- a/app/controllers/default_widget_controller.rb +++ b/app/controllers/default_widget_controller.rb @@ -10,6 +10,27 @@ 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 if !params[:id].blank? redirect_to eval("#{@page_part.module_app.widget_fields_link_method['title']['method']}('#{params[:id]}', {inner: #{params[:inner] || true}})") 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 1f13d64c..be9c02e7 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 @@