From eb2b4b80b7b136baf526a8a81a108f090c052963 Mon Sep 17 00:00:00 2001 From: Matt Fu Date: Fri, 16 Mar 2012 15:48:13 +0800 Subject: [PATCH 1/2] add new files --- .../app/models/bulletin - %BDƻs.rb | 101 ++++++++++++++++++ .../fact_checks/_list_table.html.erb.can_del | 15 +++ .../fact_checks/_privilege_user.html.erb | 7 ++ .../fact_checks/index.html.erb.can_del | 50 +++++++++ .../back_end/fact_checks/setting.html.erb | 20 ++++ .../back_end/fact_checks/setting.js.erb | 1 + .../widget/bulletins/index.html - %BDƻs.erb | 42 ++++++++ 7 files changed, 236 insertions(+) create mode 100644 vendor/built_in_modules/announcement/app/models/bulletin - %BDƻs.rb create mode 100644 vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/_list_table.html.erb.can_del create mode 100644 vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/_privilege_user.html.erb create mode 100644 vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/index.html.erb.can_del create mode 100644 vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/setting.html.erb create mode 100644 vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/setting.js.erb create mode 100644 vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/index.html - %BDƻs.erb diff --git a/vendor/built_in_modules/announcement/app/models/bulletin - %BDƻs.rb b/vendor/built_in_modules/announcement/app/models/bulletin - %BDƻs.rb new file mode 100644 index 00000000..c65e65f7 --- /dev/null +++ b/vendor/built_in_modules/announcement/app/models/bulletin - %BDƻs.rb @@ -0,0 +1,101 @@ +# encoding: utf-8 + +class Bulletin + include Mongoid::Document + include Mongoid::Timestamps + include Mongoid::MultiParameterAttributes + + # field :category_id, :type => Integer + field :title + # has_one :title_variable, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy + # has_one :subtitle_variable, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy + # has_one :text_variable, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy + field :subtitle + field :text + field :postdate , :type => Date + field :deadline , :type => Date + # field :url + field :create_user_id + field :update_user_id + + field :is_top, :type => Boolean, :default => false + + mount_uploader :image, ImageUploader + + belongs_to :bulletin_category + + embeds_many :bulletin_links, :cascade_callbacks => true + embeds_many :bulletin_files, :cascade_callbacks => true + + # has_many :bulletin_files, :autosave => true, :dependent => :destroy + + accepts_nested_attributes_for :bulletin_files, :allow_destroy => true + accepts_nested_attributes_for :bulletin_links, :allow_destroy => true + + # validates_presence_of :title_variable + validates_presence_of :title + + after_save :save_bulletin_links + after_save :save_bulletin_files + + + def self.search( search = nil, category_id = nil ) + + if category_id.to_s.size > 0 and search.to_s.size > 0 + + key = /#{search}/ + + find(:all, :conditions => {title: key, bulletin_category_id: category_id}).desc( :is_top, :postdate ) + + elsif category_id.to_s.size > 0 and search.to_s.size < 1 + + find(:all, :conditions => {bulletin_category_id: category_id}).desc( :is_top, :postdate ) + + elsif search.to_s.size > 0 and category_id.to_s.size < 1 + + key = /#{search}/ + + find(:all, :conditions => {title: key}).desc( :is_top, :postdate ) + else + + find(:all).desc( :is_top, :postdate) + + end + + end + + + def self.widget_datas + + date_now = Time.now + + # find(:all, :conditions => {:postdate => {"$lte" => Date.today}, deadline: nil} ).desc( :is_top, :postdate) + # where( :postdate.lte => date_now ).where( :deadline => nil ).desc(:is_top, :postdate) + # any_of({ :title => "test" },{:deadline => nil, :title => "123"}) + any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).limit(5) + + + end + + + def is_top? + self.is_top + end + + def save_bulletin_links + self.bulletin_links.each do |t| + if t.should_destroy + t.destroy + end + end + end + + def save_bulletin_files + self.bulletin_files.each do |t| + if t.should_destroy + t.destroy + end + end + end + +end \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/_list_table.html.erb.can_del b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/_list_table.html.erb.can_del new file mode 100644 index 00000000..59bac03a --- /dev/null +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/_list_table.html.erb.can_del @@ -0,0 +1,15 @@ +

<%= bulletin_category.key %>

+ + + + + + + + + + +<% bulletin_category.bulletins.each do |post| %> + <%= render :partial => 'panel/announcement/back_end/bulletins/bulletins', :locals => {:post => post,:fact_check_allow=>true} %> +<% end %> +
<%= t('bulletin.status') %><%= t('bulletin.category') %><%= t('bulletin.title') %><%= t('bulletin.postdate') %><%= t('bulletin.deadline') %><%= t('bulletin.action') %>
\ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/_privilege_user.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/_privilege_user.html.erb new file mode 100644 index 00000000..347b15b2 --- /dev/null +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/_privilege_user.html.erb @@ -0,0 +1,7 @@ +<%= content_tag :div ,:id => "users_checkbox_ary", do -%> +<% sys_users = User.all -%> + <% sys_users.each do |user| -%> + <%= label_tag "lab-user-#{user.id}", user.name rescue '' -%> + <%= check_box_tag "[users][#{user.id}]", 'true',users.include?(user) -%> + <% end -%> +<% end -%> \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/index.html.erb.can_del b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/index.html.erb.can_del new file mode 100644 index 00000000..32f3d820 --- /dev/null +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/index.html.erb.can_del @@ -0,0 +1,50 @@ +<%= render 'panel/announcement/back_end/bulletins/filter' %> + + <%= render 'panel/announcement/back_end/bulletins/bulletins' %> +
+
+ <%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t('admin.add'), new_panel_announcement_back_end_bulletin_path, :class => 'btn btn-primary' %> +
+ + \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/setting.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/setting.html.erb new file mode 100644 index 00000000..d5d589cf --- /dev/null +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/setting.html.erb @@ -0,0 +1,20 @@ +<%= label_tag :fact_check_setting, t("announcement.bulletin.fact_check_setting") %> +
+<%= form_tag('', :remote => true) %> +<%= label_tag :category, t("announcement.bulletin.category") %> +<%= select_tag "category_id", options_from_collection_for_select(@bulletin_categorys, "id", "key") %> + +
+<%= label_tag :role, t("admin.roles") %> +<%= content_tag :div do -%> + <% form_tag :action => "update_setting" do %> + <%= render :partial => "privilege_user", :locals => {:users => @users_array} %> + <%= submit_tag "Update" %> + <% end -%> +<% end -%> + + \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/setting.js.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/setting.js.erb new file mode 100644 index 00000000..a01c9d6a --- /dev/null +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks/setting.js.erb @@ -0,0 +1 @@ +$("#users_checkbox_ary").replaceWith('<%= (render :partial => 'privilege_user', :locals => {:users => @users_array}).html_safe%>'); \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/index.html - %BDƻs.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/index.html - %BDƻs.erb new file mode 100644 index 00000000..2c4cd153 --- /dev/null +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/index.html - %BDƻs.erb @@ -0,0 +1,42 @@ + + +<% if @bulletin and !@bulletin.nil? %> + +
+

<%= @bulletin.title %>

+

<%= @bulletin.subtitle %>

+ <%= link_to "read more >",panel_announcement_front_end_bulletin_path(@bulletin.id) %> + read more > +
+ +<% end %> + +<% if @bulletins and !@bulletins.nil? %> + +
+

news

+ +<%= link_to "read more >",panel_announcement_front_end_bulletins_path(), :class => "btn" %> +read more > +
+ +
+

news

+ +<%= link_to "read more >",panel_announcement_front_end_bulletins_path(), :class => "btn" %> +read more > +
+ +<% end %> From c7a333f99034ff0095d8f6d655834b251ee454a3 Mon Sep 17 00:00:00 2001 From: Matt Fu Date: Fri, 16 Mar 2012 15:51:59 +0800 Subject: [PATCH 2/2] after merge --- .../bulletins/_bulletin_link.html - %BDƻs.erb | 27 +++++++++++++++++++ .../_bulletin_link2.html - %BDƻs.erb | 16 +++++++++++ .../back_end/bulletins/index.html - %BDƻs.erb | 9 +++++++ 3 files changed, 52 insertions(+) create mode 100644 vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin_link.html - %BDƻs.erb create mode 100644 vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin_link2.html - %BDƻs.erb create mode 100644 vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html - %BDƻs.erb diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin_link.html - %BDƻs.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin_link.html - %BDƻs.erb new file mode 100644 index 00000000..33d1ba1e --- /dev/null +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin_link.html - %BDƻs.erb @@ -0,0 +1,27 @@ + +
" class='list_item'> +
+ + <%= f.label :link_url %> + <%= f.text_field :url %> + + <%= f.label :link_name %> + <%#= f.text_field :name %> + <%= f.fields_for :i18n_variable, (bulletin_link.new_record? ? bulletin_link.build_i18n_variable : bulletin_link.i18n_variable) do |f| %> + <% @site_valid_locales.each do |locale| %> + <%= I18nVariable.first(:conditions => {:key => locale})[I18n.locale] %> + <%= f.text_field locale, :style => "width:130px" %> + <% end %> + <% end %> + + + <% if bulletin_link.new_record? %> + <%= t(:delete) %> + <% else %> + <%= f.hidden_field :id %> + <%= t(:delete) %> + <%= f.hidden_field :should_destroy, :value => nil, :class => 'should_destroy' %> + <% end %> + +
+
diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin_link2.html - %BDƻs.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin_link2.html - %BDƻs.erb new file mode 100644 index 00000000..c44b5c92 --- /dev/null +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin_link2.html - %BDƻs.erb @@ -0,0 +1,16 @@ + + "> + <%= link_to bulletin_link2.i18n_variable.zh_tw, bulletin_link2.url, :target => '_blank' %> + <%= link_to bulletin_link2.i18n_variable.en, bulletin_link2.url, :target => '_blank' %> + + + <%= f.hidden_field :id %> + + <%= f.hidden_field :should_destroy, :value => nil, :class => 'should_destroy' %> + + + + + + + \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html - %BDƻs.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html - %BDƻs.erb new file mode 100644 index 00000000..d37d2134 --- /dev/null +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html - %BDƻs.erb @@ -0,0 +1,9 @@ +<%= render 'filter' %> + + <%= render 'bulletins' %> +
+ +
+ <%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t('admin.add'), new_panel_announcement_back_end_bulletin_path, :class => 'btn btn-primary' %> +
+