From 4b838b5ef56b637f493de7a7ea00f3365d8cb652 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Jan 2012 18:38:50 +0800 Subject: [PATCH] edit announcement upload & show --- .../back_end/bulletin_categorys_controller.rb | 1 + .../back_end/bulletins_controller.rb | 28 ++++-- .../announcement/app/models/bulletin.rb | 15 ++- .../app/models/bulletin_category.rb | 5 +- .../announcement/app/models/bulletin_file.rb | 3 +- .../bulletin_categorys/_form.html.erb | 32 ++++-- .../bulletin_categorys/index.html.erb | 8 +- .../back_end/bulletins/_form.html.erb | 12 ++- .../bulletins/index.html - ¦³¤ÀÃþ.erb | 64 ++++++++++++ .../back_end/bulletins/index.html.erb | 35 +++---- .../back_end/bulletins/show.html.erb | 98 +++++++++---------- 11 files changed, 196 insertions(+), 105 deletions(-) create mode 100644 vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html - ¦³¤ÀÃþ.erb diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_categorys_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_categorys_controller.rb index fd0eae9f..fb06768f 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_categorys_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_categorys_controller.rb @@ -36,6 +36,7 @@ class Panel::Announcement::BackEnd::BulletinCategorysController < ApplicationCon # GET /bulletins/1/edit def edit @bulletin_category = BulletinCategory.find(params[:id]) + @i18n_variable = @bulletin_category.i18n_variable end # POST /bulletins diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb index 5aaadd88..ee95a91c 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb @@ -2,12 +2,16 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController layout 'admin' + before_filter :authenticate_user! + before_filter :is_admin? + def index # @bulletins = Bulletin.all # @bulletins = Bulletin.desc("postdate desc") get_categorys(params[:bulletin_category_id]) - @bulletins = Bulletin.where("bulletin_category_id" => params[:bulletin_category_id]).desc("postdate") if params[:bulletin_category_id] + # @bulletins = Bulletin.where("bulletin_category_id" => params[:bulletin_category_id]).desc("postdate") if params[:bulletin_category_id] + @bulletins = Bulletin.desc("postdate") respond_to do |format| @@ -19,16 +23,16 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController # GET /bulletins/1 # GET /bulletins/1.xml def show - # @bulletin = Bulletin.find(params[:id]) + @bulletin = Bulletin.find(params[:id]) # get_categorys - @bulletin_categorys = BulletinCategory.where("_id" => params[:id]) + # @bulletin_categorys = BulletinCategory.where("_id" => params[:id]) - if params[:id] - @bulletins = Bulletin.where("bulletin_category_id" => params[:id]) - else - @bulletins = Bulletin.desc("postdate desc") - end + # if params[:id] + # @bulletins = Bulletin.where("bulletin_category_id" => params[:id]) + # else + # @bulletins = Bulletin.desc("postdate desc") + # end respond_to do |format| format.html # show.html.erb @@ -55,6 +59,7 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController # GET /bulletins/1/edit def edit @bulletin = Bulletin.find(params[:id]) + # @summary_variable = @bulletin.summary_variable get_categorys end @@ -62,6 +67,9 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController # POST /bulletins.xml def create @bulletin = Bulletin.new(params[:bulletin]) + + @bulletin.create_user_id = current_user.id + @bulletin.update_user_id = current_user.id respond_to do |format| if @bulletin.save @@ -80,6 +88,8 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController def update @bulletin = Bulletin.find(params[:id]) + @bulletin.update_user_id = current_user.id + # @bulletin.image.clear if params[:bulletin][:image_del] == '1' if params[:bulletin][:image_del] == '1' @bulletin.remove_image! @@ -104,7 +114,7 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController # DELETE /bulletins/1.xml def destroy @bulletin = Bulletin.find(params[:id]) - @bulletin.bulletin_files.destroy + # @bulletin.bulletin_files.destroy @bulletin.destroy respond_to do |format| diff --git a/vendor/built_in_modules/announcement/app/models/bulletin.rb b/vendor/built_in_modules/announcement/app/models/bulletin.rb index ceab1e42..51095004 100644 --- a/vendor/built_in_modules/announcement/app/models/bulletin.rb +++ b/vendor/built_in_modules/announcement/app/models/bulletin.rb @@ -6,22 +6,27 @@ class Bulletin include Mongoid::MultiParameterAttributes # field :category_id, :type => Integer - field :title, :type => String - field :subtitle, :type => String - field :text, :type => String + field :title + field :summary + field :text field :postdate , :type => Date field :deadline , :type => Date + field :url + field :create_user_id + field :update_user_id mount_uploader :image, ImageUploader belongs_to :bulletin_category # embeds_many :bulletin_files - has_many :bulletin_files, :autosave => true, :dependent => :destroy + embeds_many :bulletin_files, :cascade_callbacks => true + + # has_many :bulletin_files, :autosave => true, :dependent => :destroy accepts_nested_attributes_for :bulletin_files, :allow_destroy => true - validates_presence_of :title, :subtitle, :text + validates_presence_of :title after_save :save_bulletin_files diff --git a/vendor/built_in_modules/announcement/app/models/bulletin_category.rb b/vendor/built_in_modules/announcement/app/models/bulletin_category.rb index 652b5548..bff246d1 100644 --- a/vendor/built_in_modules/announcement/app/models/bulletin_category.rb +++ b/vendor/built_in_modules/announcement/app/models/bulletin_category.rb @@ -3,10 +3,11 @@ class BulletinCategory include Mongoid::Document include Mongoid::Timestamps - include Mongoid::MultiParameterAttributes + # include Mongoid::MultiParameterAttributes field :key - field :name + # field :name + has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy has_many :bulletins diff --git a/vendor/built_in_modules/announcement/app/models/bulletin_file.rb b/vendor/built_in_modules/announcement/app/models/bulletin_file.rb index 5483a58e..28062d40 100644 --- a/vendor/built_in_modules/announcement/app/models/bulletin_file.rb +++ b/vendor/built_in_modules/announcement/app/models/bulletin_file.rb @@ -11,6 +11,7 @@ class BulletinFile # field :to_save, :type => Boolean field :should_destroy, :type => Boolean - belongs_to :bulletin + # belongs_to :bulletin + embedded_in :bulletin end diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletin_categorys/_form.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletin_categorys/_form.html.erb index 3445cec4..68c12afd 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletin_categorys/_form.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletin_categorys/_form.html.erb @@ -1,15 +1,29 @@ - <%= f.error_messages %> -
- <%= f.label :key %>
- <%= f.text_field :key %> -
-
- <%= f.label :name %>
- <%= f.text_field :name %> -
+
+ + + + + <% @site_valid_locales.each do |locale| %> + + <% end %> + + + + + + <% end %> + <% end %> + + +
<%= t('bulletin_category.key') %><%= I18nVariable.first(:conditions => {:key => locale})[I18n.locale] %>
<%= f.text_field :key %> + <%= f.fields_for :i18n_variable, (@bulletin_category.new_record? ? @bulletin_category.build_i18n_variable : @bulletin_category.i18n_variable) do |f| %> + <% @site_valid_locales.each do |locale| %> + <%= f.text_field locale, :style => "width:130px" %>
+
<%= f.submit %>
+ \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletin_categorys/index.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletin_categorys/index.html.erb index 254f0e91..ee7fbd6d 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletin_categorys/index.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletin_categorys/index.html.erb @@ -20,14 +20,18 @@ - + <% @site_valid_locales.each do |locale| %> + + <% end %> <% @bulletin_categorys.each do |post| %> - + <% @site_valid_locales.each do |locale| %> + + <% end %>
<%= t('bulletin_category.key') %><%= t('bulletin_category.name') %><%= I18nVariable.first(:conditions => {:key => locale})[I18n.locale] %><%= t('bulletin.action') %>
<%= post.key %><%= post.name %><%= post.i18n_variable[locale] rescue nil %> <%= link_to t('bulletin_category.edit'), edit_panel_announcement_back_end_bulletin_category_path(post) %> | <%= link_to t('bulletin_category.delete'), panel_announcement_back_end_bulletin_category_path(post), :confirm => t('announcement.sure?'), :method => :delete %> 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 04e015d4..b840a60b 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 @@ -4,7 +4,7 @@
<%= f.label :category %>
- <%= f.select :bulletin_category_id, @bulletin_categorys.collect {|t| [ t.name, t.id ]} %> + <%= f.select :bulletin_category_id, @bulletin_categorys.collect {|t| [ t.i18n_variable[I18n.locale], t.id ]} %>
@@ -22,8 +22,8 @@
- <%= f.label :subtitle %>
- <%= f.text_field :subtitle %> + <%= f.label :summary %>
+ <%= f.text_area :summary, :rows => 10, :cols => 40 %>
@@ -40,6 +40,12 @@
<%= f.label :deadline %>
<%= f.date_select :deadline, :use_month_numbers => true, :prompt => { :day => 'Select day', :month => 'Select month', :year => 'Select year'} %> + <%#= f.date_select :deadline, :order => [:year, :month, :day],:default => 1.years.from_now, :use_month_numbers => true %> +
+ +
+ <%= f.label :url %>
+ <%= f.text_field :url, :size => 60 %>
diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html - ¦³¤ÀÃþ.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html - ¦³¤ÀÃþ.erb new file mode 100644 index 00000000..80dc0e7e --- /dev/null +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html - ¦³¤ÀÃþ.erb @@ -0,0 +1,64 @@ +<% content_for :secondary do %> +
+
+
+
+
+
    +
  • <%= link_to t('bulletin.new_announcement'), new_panel_announcement_back_end_bulletin_path %>
  • +
  • <%= link_to t('bulletin.new_announcement_class'), panel_announcement_back_end_bulletin_categorys_path %>
  • +
+<% end -%> + +<%= flash_messages %> + +

<%= t('bulletin.list_announcement') %>

+
+
+
+
+
+ +<% @bulletin_categorys.each do |t| %> + +

<%= link_to t.i18n_variable[I18n.locale], panel_announcement_back_end_bulletins_path(:bulletin_category_id => t.id ) %>

+ + + + + + + + + + + + + + <% t.bulletins.each do |post| %> + + + + + + + + + + + + <% end %> + +
<%= t('bulletin.category') %><%= t('bulletin.title') %><%= t('bulletin.image') %><%= t('bulletin.file') %><%= t('bulletin.text') %><%= t('bulletin.postdate') %><%= t('bulletin.deadline') %><%= t('bulletin.action') %>
<%= link_to post.bulletin_category.i18n_variable[I18n.locale], panel_announcement_front_end_bulletin_path(post) %><%= post.title %><%= link_to t('bulletin.image'), post.image.url, {:target => '_blank', :title => post.alt} if post.image.file %> + <% post.bulletin_files.each do | bfile | %> + <%= link_to bfile.filetitle, bfile.file.url, {:target => '_blank', :title => bfile.description} if bfile.file.file %> + <% end %> + <%= truncate(post.text,:length=>15) %><%= post.postdate %><%= post.deadline %> + <%= link_to t('bulletin.edit'), edit_panel_announcement_back_end_bulletin_path(post) %> | + <%= link_to t('bulletin.delete'), panel_announcement_back_end_bulletin_path(post), :confirm => t('announcement.sure?'), :method => :delete, :confirm => 'Are you sure?' %> +
+ +<% end %> + +
+ diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html.erb index ad25217e..71895eef 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html.erb @@ -6,6 +6,7 @@
  • <%= link_to t('bulletin.new_announcement'), new_panel_announcement_back_end_bulletin_path %>
  • +
  • <%= link_to t('bulletin.announcement_list'), panel_announcement_back_end_bulletins_path %>
  • <%= link_to t('bulletin.new_announcement_class'), panel_announcement_back_end_bulletin_categorys_path %>
<% end -%> @@ -19,37 +20,25 @@

-<% @bulletin_categorys.each do |t| %> - -

<%= link_to t.name, panel_announcement_back_end_bulletins_path(:bulletin_category_id => t.id ) %>

- - - - - - - + + + - <% t.bulletins.each do |post| %> + <% @bulletins.each do |post| %> - - - - - - + - + + +
<%= t('bulletin.category') %><%= t('bulletin.title') %><%= t('bulletin.subtitle') %><%= t('bulletin.image') %><%= t('bulletin.file') %><%= t('bulletin.text') %><%= t('bulletin.status') %> <%= t('bulletin.postdate') %> <%= t('bulletin.deadline') %><%= t('bulletin.category') %><%= t('bulletin.title') %> <%= t('bulletin.action') %>
<%= link_to post.bulletin_category.name, panel_announcement_front_end_bulletin_path(post) %><%= post.title %><%= post.subtitle %><%= link_to t('bulletin.image'), post.image.url, :target => '_blank' if post.image.file %> - <% post.bulletin_files.each do | bfile | %> - <%= link_to bfile.filetitle, bfile.file.url, :target => '_blank' if bfile.file.file %> - <% end %> - <%= truncate(post.text,:length=>15) %> <%= post.postdate %><%= post.deadline %><%= (post.deadline) ? post.deadline : t('bulletin.no_deadline') %><%= post.bulletin_category.i18n_variable[I18n.locale] %><%#= link_to post.title, panel_announcement_front_end_bulletin_path(post) %> + <%= link_to post.title, panel_announcement_back_end_bulletin_path(post) %> + <%= link_to t('bulletin.edit'), edit_panel_announcement_back_end_bulletin_path(post) %> | <%= link_to t('bulletin.delete'), panel_announcement_back_end_bulletin_path(post), :confirm => t('announcement.sure?'), :method => :delete, :confirm => 'Are you sure?' %> @@ -60,7 +49,5 @@
-<% end %> -
diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/show.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/show.html.erb index 35fbf4a5..4cf1132c 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/show.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/show.html.erb @@ -1,59 +1,57 @@ -<% content_for :secondary do %> -
-
-
-
-
-
    -
  • <%= link_to t('bulletin.new_announcement'), new_panel_announcement_back_end_bulletin_path, :class => 'seclink1' %>
  • -
  • <%= link_to t('bulletin.new_announcement_class'), panel_announcement_back_end_bulletin_categorys_path, :class => 'seclink1' %>
  • -
-<% end -%> +<% # encoding: utf-8 %> -<%= flash_messages %> - -

<%= t('bulletin.list_announcement') %>

-
-



-<% @bulletin_categorys.each do |t| %> +

<%= flash_messages %>

-

<%= t.name %>

- - - - - - - - - - - - - <% @bulletins.each do |post| %> - - - - - - - - - - +
    +
  • + <%= t('announcement.category') %> + <%= @bulletin.bulletin_category.i18n_variable[I18n.locale] %> +
  • +
  • + <%= t('announcement.postdate') %> + <%= @bulletin.postdate %> +
  • +
  • + <%= t('announcement.title') %> + <%= @bulletin.title %> +
  • +
  • + <%#= image_tag(@bulletin.image.url, :size => "320x240") if @bulletin.image.file %> + <%= link_to image_tag(@bulletin.image.url, :size => "320x240"), @bulletin.image.url, {:target => '_blank', :title => @bulletin.image_filename} if @bulletin.image.file %> +
  • +
  • + <%= t('announcement.summary') %> + <%= @bulletin.summary %> +
  • +
  • + <%= t('announcement.text') %> + <%= @bulletin.text %> +
  • +
  • +
  • + <%= t('announcement.file') %> + <% @bulletin.bulletin_files.each do | bfile | %> + <%= link_to bfile.filetitle, bfile.file.url, {:target => '_blank', :title => bfile.description} if bfile.file.file %> <% end %> - -
<%= t('bulletin.category') %><%= t('bulletin.title') %><%= t('bulletin.subtitle') %><%= t('bulletin.text') %><%= t('bulletin.postdate') %><%= t('bulletin.deadline') %><%= t('bulletin.action') %>
<%= post.bulletin_category.name rescue nil %><%= post.title %><%= post.subtitle %><%= truncate(post.text,:length=>15) %><%= post.postdate %><%= post.deadline %> - <%#= link_to t('bulletin.show'), panel_announcement_back_end_bulletin_path(post) %> - <%= link_to t('bulletin.edit'), edit_panel_announcement_back_end_bulletin_path(post) %> | - <%= link_to t('bulletin.delete'), panel_announcement_back_end_bulletin_path(post), :confirm => t('announcement.sure?'), :method => :delete %> -
+ +
  • + <% if @bulletin.url? %> + <%= t('announcement.url') %> + <%= link_to @bulletin.url, @bulletin.url, :target => '_blank' %> + <% end %> +
  • +
  • + <%= t('announcement.張貼者') %> + <%= User.find(@bulletin.create_user_id).name %> +
  • +
  • + <%= t('announcement.最後修改時間') %> + <%= @bulletin.updated_at %> +
  • -<% end %> - -
    +<%= link_back %>