first version of multi categories and tags
This commit is contained in:
parent
96455f31e1
commit
b315215bed
|
@ -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
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
binding.pry
|
||||||
@part = PagePart.find(params[:id])
|
@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] )
|
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?
|
if params[:page_part][:module_app].blank?
|
||||||
params[:page_part][:module_app] = nil
|
params[:page_part][:module_app] = nil
|
||||||
end
|
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])
|
if @part.update_attributes(params[:page_part])
|
||||||
set_children_sub_menu(@part) if @part.public_r_tag && @part.public_r_tag.eql?('sub_menu')
|
set_children_sub_menu(@part) if @part.public_r_tag && @part.public_r_tag.eql?('sub_menu')
|
||||||
flash.now[:notice] = t('update.success.content')
|
flash.now[:notice] = t('update.success.content')
|
||||||
|
|
|
@ -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] = params[:page][:frontend_field].zip( params[:page][:frontend_field_type] ) if params[:page][:frontend_field]
|
||||||
params[:page][:frontend_field_type] = nil
|
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])
|
if @item.update_attributes(params[:page])
|
||||||
flash[:notice] = t('update.success.page')
|
flash[:notice] = t('update.success.page')
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|
|
@ -10,31 +10,60 @@ class DefaultWidgetController< OrbitWidgetController
|
||||||
@page_part.module_app.enable_frontend?
|
@page_part.module_app.enable_frontend?
|
||||||
end
|
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
|
def default_widget
|
||||||
@tag_class = nil
|
@tag_class = nil
|
||||||
|
@default_widget = @page_part.module_app.get_default_widget
|
||||||
@default_widget = @page_part.module_app.get_default_widget
|
@widget_image_field = @default_widget["image"] || @default_widget[:image]
|
||||||
@widget_image_field = @default_widget["image"] || @default_widget[:image]
|
case @page_part
|
||||||
data_limit = case @page_part
|
when Page
|
||||||
when Page
|
@fields = @page_part.frontend_field
|
||||||
@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)
|
||||||
@page_part.frontend_data_count.is_a?(Fixnum) ? @page_part.frontend_data_count : (@page_part.frontend_data_count.to_i rescue 3)
|
@paginate = true
|
||||||
when PagePart
|
@page_id = @page_part.id
|
||||||
@fields = @page_part.widget_field
|
when PagePart
|
||||||
@page_part.widget_data_count.is_a?(Fixnum) ? @page_part.widget_data_count : (@page_part.widget_data_count.to_i rescue 3)
|
@fields = @page_part.widget_field
|
||||||
end
|
@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).desc(:created_at)
|
end
|
||||||
case params[:type]
|
if @paginate
|
||||||
when "typeA"
|
@data = query_for_default_widget.includes(@widget_image_field).page(params[:page_main]).per(@data_limit)
|
||||||
@tag_class = 'default_widget_typeA'
|
else
|
||||||
render "typeA"
|
@data = query_for_default_widget.limit(@data_limit).includes(@widget_image_field)
|
||||||
when /typeB_/
|
end
|
||||||
@tag_class = "default_widget_#{params[:type]}"
|
case params[:type]
|
||||||
render "typeB"
|
when "typeA"
|
||||||
when "typeC"
|
@tag_class = 'default_widget_typeA'
|
||||||
@tag_class = 'default_widget_typeC'
|
@partial = "typeA"
|
||||||
render "typeC"
|
render "typeA"
|
||||||
end
|
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
|
||||||
|
|
||||||
|
|
|
@ -84,17 +84,17 @@ module Admin::PagePartsHelper
|
||||||
|
|
||||||
def tag_checked_value(part,radio_value)
|
def tag_checked_value(part,radio_value)
|
||||||
if radio_value.blank?
|
if radio_value.blank?
|
||||||
(part.nil? || part[:tag].blank?)? true : false
|
(part.nil? || part[:tag].blank?) ? true : false
|
||||||
else
|
else
|
||||||
part and (part[:tag] == radio_value.to_s) ? true : false
|
part and (part[:tag].include?(radio_value.to_s)) ? true : false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def category_checked_value(part,radio_value)
|
def category_checked_value(part,radio_value)
|
||||||
if radio_value.blank?
|
if radio_value.blank?
|
||||||
(part.nil? || part[:category].blank?)? true : false
|
(part.nil? || part[:category].blank?) ? true : false
|
||||||
else
|
else
|
||||||
part and (part[:category] == radio_value.to_s) ? true : false
|
part and (part[:category].include?(radio_value.to_s)) ? true : false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -117,6 +117,19 @@ module Admin::PagePartsHelper
|
||||||
end
|
end
|
||||||
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)
|
def nil_radio_button(part,tag_or_cate)
|
||||||
field_name = case part
|
field_name = case part
|
||||||
when PagePart
|
when PagePart
|
||||||
|
|
|
@ -8,8 +8,8 @@ class Page < Item
|
||||||
field :content, localize: true
|
field :content, localize: true
|
||||||
field :app_frontend_url
|
field :app_frontend_url
|
||||||
field :theme_id, :type => BSON::ObjectId, :default => nil
|
field :theme_id, :type => BSON::ObjectId, :default => nil
|
||||||
field :category, :default => ''
|
field :category,type: Array, :default => []
|
||||||
field :tag, :default => ''
|
field :tag, type: Array,:default => []
|
||||||
field :view_count, :type => Integer, :default => 0
|
field :view_count, :type => Integer, :default => 0
|
||||||
field :page_title, localize: true
|
field :page_title, localize: true
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@ class PagePart
|
||||||
field :public_r_tag_option, :default => nil
|
field :public_r_tag_option, :default => nil
|
||||||
field :page_title, localize: true
|
field :page_title, localize: true
|
||||||
field :widget_path
|
field :widget_path
|
||||||
|
field :category,type: Array, :default => []
|
||||||
|
field :tag, type: Array,:default => []
|
||||||
|
|
||||||
field :widget_style
|
field :widget_style
|
||||||
field :widget_field , :type => Array
|
field :widget_field , :type => Array
|
||||||
|
|
|
@ -10,9 +10,9 @@
|
||||||
<div class="well controls">
|
<div class="well controls">
|
||||||
<% if @categories %>
|
<% if @categories %>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<%= nil_radio_button(object,:category) %>
|
<%= nil_checkbox_button(object,:category) %>
|
||||||
<%= content_tag_for(:label, @categories,:class=>"radio inline") do |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%>
|
<%= category.title%>
|
||||||
<% end %>
|
<% end %>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
|
@ -10,9 +10,9 @@
|
||||||
<div class="well controls">
|
<div class="well controls">
|
||||||
<% if @categories %>
|
<% if @categories %>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<%= nil_radio_button(object,:tag) %>
|
<%= nil_checkbox_button(object,:tag) %>
|
||||||
<%= content_tag_for(:label, @tags,:class=>"radio inline") do |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]%>
|
<%= tag[I18n.locale]%>
|
||||||
<% end if @tags%>
|
<% end if @tags%>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
|
@ -2,4 +2,10 @@
|
||||||
<%= render 'admin/items/site_map_left_bar' %>
|
<%= render 'admin/items/site_map_left_bar' %>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
|
|
||||||
<%= render 'edit' %>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<%= render 'edit' %>
|
||||||
|
|
||||||
|
<%=javascript_include_tag "inc/update_cates_and_tags.js" %>
|
|
@ -4,3 +4,4 @@
|
||||||
<% end -%>
|
<% end -%>
|
||||||
|
|
||||||
<%= render 'edit' %>
|
<%= render 'edit' %>
|
||||||
|
<%=javascript_include_tag "inc/update_cates_and_tags.js" %>
|
|
@ -492,4 +492,24 @@ namespace :migrate do
|
||||||
pp.save
|
pp.save
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue