From 10731dc211948412f4daecf25ac6cf71e1f46bd3 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 16 Jul 2012 16:13:38 +0800 Subject: [PATCH] demo widget --- app/models/module_app.rb | 3 +- app/models/page_part.rb | 2 + .../admin/page_parts/_module_widget.html.erb | 13 +- .../admin/page_parts/reload_widgets.js.erb | 2 +- lib/parsers/parser_common.rb | 2 +- .../announcement/announcement.json | 11 +- .../widget/bulletins_controller.rb | 241 +++++++++- .../announcement/app/models/bulletin.rb | 2 + .../back_end/bulletins/_form.html.erb | 7 + .../bulletins/_form_bulletin_link.html.erb | 2 +- .../widget/bulletins/_index.html.erb | 412 +++++++++++++++++- .../announcement/config/routes.rb | 2 +- 12 files changed, 675 insertions(+), 24 deletions(-) diff --git a/app/models/module_app.rb b/app/models/module_app.rb index 7ad4ac1d..315bc93e 100644 --- a/app/models/module_app.rb +++ b/app/models/module_app.rb @@ -14,7 +14,8 @@ class ModuleApp field :enable_frontend, type: Boolean, :default => true field :app_pages ,type: Array - field :widgets ,type: Array + # field :widgets ,type: Array + field :widgets ,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 diff --git a/app/models/page_part.rb b/app/models/page_part.rb index 52eafdf3..1cb095b2 100644 --- a/app/models/page_part.rb +++ b/app/models/page_part.rb @@ -10,6 +10,8 @@ class PagePart field :public_r_tag_object_id, :default => nil field :public_r_tag_option, :default => nil field :widget_path + field :widget_style + field :widget_data_count has_one :i18n_variable, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy diff --git a/app/views/admin/page_parts/_module_widget.html.erb b/app/views/admin/page_parts/_module_widget.html.erb index 1a1dd63c..87439e3f 100644 --- a/app/views/admin/page_parts/_module_widget.html.erb +++ b/app/views/admin/page_parts/_module_widget.html.erb @@ -15,6 +15,12 @@ <%= f.select :widget_path, @module_app.widgets.collect{|widget| [widget.humanize, widget]}, :selected => @part.widget_path %> + <%#= f.select :widget_path, @module_app.widgets.collect{|k,v| k}, :selected => @part.widget_path %> + + + +<%= @module_app.widget_indexs.collect { |k,v| v } %> + <%= f.select :widget_style, @module_app.widget_styles.each, :selected => @part.widget_style, :include_blank => 'None' %> : @@ -25,4 +31,9 @@ <%= t :or_lower %> <%= render 'widget_tags' %> - \ No newline at end of file + + +
+<%= f.label :widget_data_count %> +<%= f.text_field :widget_data_count %> +
\ 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 2b851ce0..87e00ef1 100644 --- a/app/views/admin/page_parts/reload_widgets.js.erb +++ b/app/views/admin/page_parts/reload_widgets.js.erb @@ -1,3 +1,3 @@ -$('#widget_list select').html("<%= j options_for_select(@module_app.widgets.collect{|widget| [widget.humanize, widget]}) %>") +$('#widget_list select').html("<%= j options_for_select(@module_app.widgets.collect{|k,v| k}) %>") $('#widget_category').html("<%= j render 'widget_categories' %>") $('#widget_tag').html("<%= j render 'widget_tags' %>") \ No newline at end of file diff --git a/lib/parsers/parser_common.rb b/lib/parsers/parser_common.rb index 32820a6f..06c937de 100644 --- a/lib/parsers/parser_common.rb +++ b/lib/parsers/parser_common.rb @@ -187,7 +187,7 @@ module ParserCommon ret << part.i18n_variable[I18n.locale] rescue '' when 'module_widget' url = "/panel/#{part.module_app.key}/widget/#{part.widget_path}?inner=true" - options = "&category_id=#{!part[:category].blank? ? part[:category].blank? : category}&tag_id=#{!part[:tag].blank? ? part[:tag] : tag}&page=#{params[:page]}&part_title=#{Rack::Utils.escape(part_title).gsub("+", "%20") rescue nil}" + options = "&category_id=#{!part[:category].blank? ? part[:category].blank? : category}&tag_id=#{!part[:tag].blank? ? part[:tag] : tag}&page=#{params[:page]}&part_title=#{Rack::Utils.escape(part_title).gsub("+", "%20") rescue nil}&widget_style=#{part.widget_style}&widget_data_count=#{part[:widget_data_count]}" ret << "
" when 'public_r_tag' ret << "" diff --git a/vendor/built_in_modules/announcement/announcement.json b/vendor/built_in_modules/announcement/announcement.json index b23ec572..83e0fb51 100644 --- a/vendor/built_in_modules/announcement/announcement.json +++ b/vendor/built_in_modules/announcement/announcement.json @@ -1,12 +1,15 @@ { - "title": "announcement", + "title": "announcement", "version": "0.1", "organization": "Rulingcom", "author": "RD dep", "intro": "A simple blog……", "update_info": "Some info", "create_date": "11-11-2011", - "app_pages": ["bulletins"], - "widgets": ["bulletins", "bulletins_and_web_links"], - "enable_frontend": true + "app_pages": ["bulletins"], + "widgets": { + "index":["1","2","3","4","5","6","7","8","9",,"10","11","12","13","14","15","16","17","18","19"], + "bulletins_and_web_links":[] + }, + "enable_frontend": true } diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb index 299dcec9..fcdd7559 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb @@ -9,17 +9,252 @@ class Panel::Announcement::Widget::BulletinsController < OrbitWidgetController # GET /bulletins.xml def index + + if params[:widget_data_count] + @page_num = params[:widget_data_count]; + else + @page_num = 4; + end + @title = params[:part_title] + + @widget_style = params[:widget_style] + date_now = Time.now if !params[:category_id].blank? - @bulletins = Bulletin.can_display.where(:bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(4) + @bulletins = Bulletin.can_display.where(:bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(5) @current_category = BulletinCategory.from_id(params[:category_id]) rescue nil elsif !params[:tag_id].blank? @tag = AnnouncementTag.find(params[:tag_id]) rescue nil @tag = AnnouncementTag.where(key: params[:tag_id])[0] unless @tag - @bulletins = @tag.bulletins.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(4) + @bulletins = @tag.bulletins.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(@page_num) else - @bulletins = Bulletin.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(4) + @bulletins = Bulletin.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(@page_num) + end + + get_categorys + + end + + def bulletins_list_2 + + if params[:widget_data_count] + @page_num = params[:widget_data_count]; + else + @page_num = 4; + end + + @title = params[:part_title] + date_now = Time.now + if !params[:category_id].blank? + @bulletins = Bulletin.can_display.where(:bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(5) + @current_category = BulletinCategory.from_id(params[:category_id]) rescue nil + elsif !params[:tag_id].blank? + @tag = AnnouncementTag.find(params[:tag_id]) rescue nil + @tag = AnnouncementTag.where(key: params[:tag_id])[0] unless @tag + @bulletins = @tag.bulletins.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(@page_num) + else + @bulletins = Bulletin.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(@page_num) + end + + get_categorys + + end + + def bulletins_list_3 + + if params[:widget_data_count] + @page_num = params[:widget_data_count]; + else + @page_num = 4; + end + + @title = params[:part_title] + date_now = Time.now + if !params[:category_id].blank? + @bulletins = Bulletin.can_display.where(:bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(5) + @current_category = BulletinCategory.from_id(params[:category_id]) rescue nil + elsif !params[:tag_id].blank? + @tag = AnnouncementTag.find(params[:tag_id]) rescue nil + @tag = AnnouncementTag.where(key: params[:tag_id])[0] unless @tag + @bulletins = @tag.bulletins.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(@page_num) + else + @bulletins = Bulletin.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(@page_num) + end + + get_categorys + + end + + def bulletins_list_4 + + if params[:widget_data_count] + @page_num = params[:widget_data_count]; + else + @page_num = 4; + end + + @title = params[:part_title] + date_now = Time.now + if !params[:category_id].blank? + @bulletins = Bulletin.can_display.where(:bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(5) + @current_category = BulletinCategory.from_id(params[:category_id]) rescue nil + elsif !params[:tag_id].blank? + @tag = AnnouncementTag.find(params[:tag_id]) rescue nil + @tag = AnnouncementTag.where(key: params[:tag_id])[0] unless @tag + @bulletins = @tag.bulletins.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(@page_num) + else + @bulletins = Bulletin.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(@page_num) + end + + get_categorys + + end + + def bulletins_list_5 + + if params[:widget_data_count] + @page_num = params[:widget_data_count]; + else + @page_num = 4; + end + + @title = params[:part_title] + date_now = Time.now + if !params[:category_id].blank? + @bulletins = Bulletin.can_display.where(:bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(5) + @current_category = BulletinCategory.from_id(params[:category_id]) rescue nil + elsif !params[:tag_id].blank? + @tag = AnnouncementTag.find(params[:tag_id]) rescue nil + @tag = AnnouncementTag.where(key: params[:tag_id])[0] unless @tag + @bulletins = @tag.bulletins.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(@page_num) + else + @bulletins = Bulletin.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(@page_num) + end + + get_categorys + + end + + def bulletins_list_6 + + if params[:widget_data_count] + @page_num = params[:widget_data_count]; + else + @page_num = 4; + end + + @title = params[:part_title] + date_now = Time.now + if !params[:category_id].blank? + @bulletins = Bulletin.can_display.where(:bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(5) + @current_category = BulletinCategory.from_id(params[:category_id]) rescue nil + elsif !params[:tag_id].blank? + @tag = AnnouncementTag.find(params[:tag_id]) rescue nil + @tag = AnnouncementTag.where(key: params[:tag_id])[0] unless @tag + @bulletins = @tag.bulletins.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(@page_num) + else + @bulletins = Bulletin.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(@page_num) + end + + get_categorys + + end + + def bulletins_list_7 + + if params[:widget_data_count] + @page_num = params[:widget_data_count]; + else + @page_num = 4; + end + + @title = params[:part_title] + date_now = Time.now + if !params[:category_id].blank? + @bulletins = Bulletin.can_display.where(:bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(5) + @current_category = BulletinCategory.from_id(params[:category_id]) rescue nil + elsif !params[:tag_id].blank? + @tag = AnnouncementTag.find(params[:tag_id]) rescue nil + @tag = AnnouncementTag.where(key: params[:tag_id])[0] unless @tag + @bulletins = @tag.bulletins.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(@page_num) + else + @bulletins = Bulletin.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(@page_num) + end + + get_categorys + + end + + def bulletins_list_8 + + if params[:widget_data_count] + @page_num = params[:widget_data_count]; + else + @page_num = 4; + end + + @title = params[:part_title] + date_now = Time.now + if !params[:category_id].blank? + @bulletins = Bulletin.can_display.where(:bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(5) + @current_category = BulletinCategory.from_id(params[:category_id]) rescue nil + elsif !params[:tag_id].blank? + @tag = AnnouncementTag.find(params[:tag_id]) rescue nil + @tag = AnnouncementTag.where(key: params[:tag_id])[0] unless @tag + @bulletins = @tag.bulletins.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(@page_num) + else + @bulletins = Bulletin.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(@page_num) + end + + get_categorys + + end + + def bulletins_list_9 + + if params[:widget_data_count] + @page_num = params[:widget_data_count]; + else + @page_num = 4; + end + + @title = params[:part_title] + date_now = Time.now + if !params[:category_id].blank? + @bulletins = Bulletin.can_display.where(:bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(5) + @current_category = BulletinCategory.from_id(params[:category_id]) rescue nil + elsif !params[:tag_id].blank? + @tag = AnnouncementTag.find(params[:tag_id]) rescue nil + @tag = AnnouncementTag.where(key: params[:tag_id])[0] unless @tag + @bulletins = @tag.bulletins.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(@page_num) + else + @bulletins = Bulletin.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(@page_num) + end + + get_categorys + + end + + def bulletins_list_and_pic + + if params[:widget_data_count] + @page_num = params[:widget_data_count]; + else + @page_num = 4; + end + + @title = params[:part_title] + date_now = Time.now + if !params[:category_id].blank? + @bulletins = Bulletin.can_display.where(:bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(@page_num) + @current_category = BulletinCategory.from_id(params[:category_id]) rescue nil + elsif !params[:tag_id].blank? + @tag = AnnouncementTag.find(params[:tag_id]) rescue nil + @tag = AnnouncementTag.where(key: params[:tag_id])[0] unless @tag + @bulletins = @tag.bulletins.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(@page_num) + else + @bulletins = Bulletin.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page] ).per(@page_num) end get_categorys diff --git a/vendor/built_in_modules/announcement/app/models/bulletin.rb b/vendor/built_in_modules/announcement/app/models/bulletin.rb index 589da320..db4f4011 100644 --- a/vendor/built_in_modules/announcement/app/models/bulletin.rb +++ b/vendor/built_in_modules/announcement/app/models/bulletin.rb @@ -12,6 +12,8 @@ class Bulletin has_one :subtitle, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy has_one :text, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy has_and_belongs_to_many :tags, :class_name => "AnnouncementTag" + + field :title2, localize: true field :postdate , :type => DateTime field :deadline , :type => DateTime diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb index c515dc65..6fb50cbe 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb @@ -147,6 +147,12 @@ <%= f.text_field locale, :class=>'post-title' %> <% end %> + + <%= f.label :title2 %> + <%= f.fields_for :title2_translations do |f| %> + <%= I18nVariable.from_locale(locale) %> + <%= f.text_field locale, :class=>'post-title', :value => (@bulletin.title2_translations[locale] rescue nil) %> + <% end %>
<%= f.label :subtitle %> @@ -275,6 +281,7 @@ <% content_for :page_specific_javascript do %> + <%= javascript_include_tag "bulletin_form" %> <%= javascript_include_tag "inc/jquery.imagesloaded.js" %>