first version of multi categories and tags
This commit is contained in:
parent
4bc3a57862
commit
99e67c8719
|
@ -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()});
|
||||
});
|
|
@ -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')
|
||||
|
|
|
@ -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|
|
||||
|
|
|
@ -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}})")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
<div class="well controls">
|
||||
<% if @categories %>
|
||||
<fieldset>
|
||||
<%= 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 %>
|
||||
</fieldset>
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
<div class="well controls">
|
||||
<% if @categories %>
|
||||
<fieldset>
|
||||
<%= 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%>
|
||||
</fieldset>
|
||||
|
|
|
@ -2,4 +2,10 @@
|
|||
<%= render 'admin/items/site_map_left_bar' %>
|
||||
<% end -%>
|
||||
|
||||
<%= render 'edit' %>
|
||||
|
||||
|
||||
|
||||
|
||||
<%= render 'edit' %>
|
||||
|
||||
<%=javascript_include_tag "inc/update_cates_and_tags.js" %>
|
|
@ -4,3 +4,4 @@
|
|||
<% end -%>
|
||||
|
||||
<%= render 'edit' %>
|
||||
<%=javascript_include_tag "inc/update_cates_and_tags.js" %>
|
|
@ -214,4 +214,23 @@ namespace :migrate do
|
|||
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
|
||||
|
|
Reference in New Issue