edit announcement upload & show

This commit is contained in:
unknown 2012-01-12 18:38:50 +08:00
parent ec235bcaa3
commit 4b838b5ef5
11 changed files with 196 additions and 105 deletions

View File

@ -36,6 +36,7 @@ class Panel::Announcement::BackEnd::BulletinCategorysController < ApplicationCon
# GET /bulletins/1/edit # GET /bulletins/1/edit
def edit def edit
@bulletin_category = BulletinCategory.find(params[:id]) @bulletin_category = BulletinCategory.find(params[:id])
@i18n_variable = @bulletin_category.i18n_variable
end end
# POST /bulletins # POST /bulletins

View File

@ -2,12 +2,16 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController
layout 'admin' layout 'admin'
before_filter :authenticate_user!
before_filter :is_admin?
def index def index
# @bulletins = Bulletin.all # @bulletins = Bulletin.all
# @bulletins = Bulletin.desc("postdate desc") # @bulletins = Bulletin.desc("postdate desc")
get_categorys(params[:bulletin_category_id]) 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| respond_to do |format|
@ -19,16 +23,16 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController
# GET /bulletins/1 # GET /bulletins/1
# GET /bulletins/1.xml # GET /bulletins/1.xml
def show def show
# @bulletin = Bulletin.find(params[:id]) @bulletin = Bulletin.find(params[:id])
# get_categorys # get_categorys
@bulletin_categorys = BulletinCategory.where("_id" => params[:id]) # @bulletin_categorys = BulletinCategory.where("_id" => params[:id])
if params[:id] # if params[:id]
@bulletins = Bulletin.where("bulletin_category_id" => params[:id]) # @bulletins = Bulletin.where("bulletin_category_id" => params[:id])
else # else
@bulletins = Bulletin.desc("postdate desc") # @bulletins = Bulletin.desc("postdate desc")
end # end
respond_to do |format| respond_to do |format|
format.html # show.html.erb format.html # show.html.erb
@ -55,6 +59,7 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController
# GET /bulletins/1/edit # GET /bulletins/1/edit
def edit def edit
@bulletin = Bulletin.find(params[:id]) @bulletin = Bulletin.find(params[:id])
# @summary_variable = @bulletin.summary_variable
get_categorys get_categorys
end end
@ -63,6 +68,9 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController
def create def create
@bulletin = Bulletin.new(params[:bulletin]) @bulletin = Bulletin.new(params[:bulletin])
@bulletin.create_user_id = current_user.id
@bulletin.update_user_id = current_user.id
respond_to do |format| respond_to do |format|
if @bulletin.save if @bulletin.save
# format.html { redirect_to(panel_announcement_back_end_bulletin_url(@bulletin), :notice => t('announcement.create_bulletin_success')) } # format.html { redirect_to(panel_announcement_back_end_bulletin_url(@bulletin), :notice => t('announcement.create_bulletin_success')) }
@ -80,6 +88,8 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController
def update def update
@bulletin = Bulletin.find(params[:id]) @bulletin = Bulletin.find(params[:id])
@bulletin.update_user_id = current_user.id
# @bulletin.image.clear if params[:bulletin][:image_del] == '1' # @bulletin.image.clear if params[:bulletin][:image_del] == '1'
if params[:bulletin][:image_del] == '1' if params[:bulletin][:image_del] == '1'
@bulletin.remove_image! @bulletin.remove_image!
@ -104,7 +114,7 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController
# DELETE /bulletins/1.xml # DELETE /bulletins/1.xml
def destroy def destroy
@bulletin = Bulletin.find(params[:id]) @bulletin = Bulletin.find(params[:id])
@bulletin.bulletin_files.destroy # @bulletin.bulletin_files.destroy
@bulletin.destroy @bulletin.destroy
respond_to do |format| respond_to do |format|

View File

@ -6,22 +6,27 @@ class Bulletin
include Mongoid::MultiParameterAttributes include Mongoid::MultiParameterAttributes
# field :category_id, :type => Integer # field :category_id, :type => Integer
field :title, :type => String field :title
field :subtitle, :type => String field :summary
field :text, :type => String field :text
field :postdate , :type => Date field :postdate , :type => Date
field :deadline , :type => Date field :deadline , :type => Date
field :url
field :create_user_id
field :update_user_id
mount_uploader :image, ImageUploader mount_uploader :image, ImageUploader
belongs_to :bulletin_category belongs_to :bulletin_category
# embeds_many :bulletin_files # 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 accepts_nested_attributes_for :bulletin_files, :allow_destroy => true
validates_presence_of :title, :subtitle, :text validates_presence_of :title
after_save :save_bulletin_files after_save :save_bulletin_files

View File

@ -3,10 +3,11 @@
class BulletinCategory class BulletinCategory
include Mongoid::Document include Mongoid::Document
include Mongoid::Timestamps include Mongoid::Timestamps
include Mongoid::MultiParameterAttributes # include Mongoid::MultiParameterAttributes
field :key field :key
field :name # field :name
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
has_many :bulletins has_many :bulletins

View File

@ -11,6 +11,7 @@ class BulletinFile
# field :to_save, :type => Boolean # field :to_save, :type => Boolean
field :should_destroy, :type => Boolean field :should_destroy, :type => Boolean
belongs_to :bulletin # belongs_to :bulletin
embedded_in :bulletin
end end

View File

@ -1,15 +1,29 @@
<%= f.error_messages %>
<div class="field"> <div class="bulletin_categorys">
<%= f.label :key %><br /> <table border="0" cellspacing="0" cellpadding="0">
<%= f.text_field :key %> <thead class="list_head">
</div> <tr>
<div class="field"> <td><%= t('bulletin_category.key') %></td>
<%= f.label :name %><br /> <% @site_valid_locales.each do |locale| %>
<%= f.text_field :name %> <td><%= I18nVariable.first(:conditions => {:key => locale})[I18n.locale] %></td>
</div> <% end %>
</tr>
</thead>
<tbody>
<tr class="list_item">
<td><%= 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| %>
<td><%= f.text_field locale, :style => "width:130px" %></td>
<% end %>
<% end %>
</tr>
</tbody>
</table>
</div>
<div class="actions"> <div class="actions">
<%= f.submit %> <%= f.submit %>
</div> </div>

View File

@ -20,14 +20,18 @@
<table> <table>
<tr> <tr>
<th><%= t('bulletin_category.key') %></th> <th><%= t('bulletin_category.key') %></th>
<th><%= t('bulletin_category.name') %></th> <% @site_valid_locales.each do |locale| %>
<th><%= I18nVariable.first(:conditions => {:key => locale})[I18n.locale] %></th>
<% end %>
<th><%= t('bulletin.action') %></th> <th><%= t('bulletin.action') %></th>
</tr> </tr>
<% @bulletin_categorys.each do |post| %> <% @bulletin_categorys.each do |post| %>
<tr> <tr>
<td><%= post.key %></td> <td><%= post.key %></td>
<td><%= post.name %></td> <% @site_valid_locales.each do |locale| %>
<td><%= post.i18n_variable[locale] rescue nil %></td>
<% end %>
<td> <td>
<%= link_to t('bulletin_category.edit'), edit_panel_announcement_back_end_bulletin_category_path(post) %> | <%= 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 %> <%= link_to t('bulletin_category.delete'), panel_announcement_back_end_bulletin_category_path(post), :confirm => t('announcement.sure?'), :method => :delete %>

View File

@ -4,7 +4,7 @@
<div class="field"> <div class="field">
<%= f.label :category %><br /> <%= f.label :category %><br />
<%= 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 ]} %>
</div> </div>
<div class="field"> <div class="field">
@ -22,8 +22,8 @@
</div> </div>
<div class="field"> <div class="field">
<%= f.label :subtitle %><br /> <%= f.label :summary %><br />
<%= f.text_field :subtitle %> <%= f.text_area :summary, :rows => 10, :cols => 40 %>
</div> </div>
<div class="field"> <div class="field">
@ -40,6 +40,12 @@
<div class="field"> <div class="field">
<%= f.label :deadline %><br /> <%= f.label :deadline %><br />
<%= f.date_select :deadline, :use_month_numbers => true, :prompt => { :day => 'Select day', :month => 'Select month', :year => 'Select year'} %> <%= 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 %>
</div>
<div class="field">
<%= f.label :url %><br />
<%= f.text_field :url, :size => 60 %>
</div> </div>

View File

@ -0,0 +1,64 @@
<% content_for :secondary do %>
<br />
<br />
<br />
<br />
<br />
<ul class="list">
<li><%= link_to t('bulletin.new_announcement'), new_panel_announcement_back_end_bulletin_path %></li>
<li><%= link_to t('bulletin.new_announcement_class'), panel_announcement_back_end_bulletin_categorys_path %></li>
</ul>
<% end -%>
<%= flash_messages %>
<h1><%= t('bulletin.list_announcement') %></h1>
<br />
<br />
<br />
<br />
<br />
<% @bulletin_categorys.each do |t| %>
<h4><%= link_to t.i18n_variable[I18n.locale], panel_announcement_back_end_bulletins_path(:bulletin_category_id => t.id ) %></h4>
<table>
<tr>
<th><%= t('bulletin.category') %></th>
<th><%= t('bulletin.title') %></th>
<th><%= t('bulletin.image') %></th>
<th><%= t('bulletin.file') %></th>
<th><%= t('bulletin.text') %></th>
<th><%= t('bulletin.postdate') %></th>
<th><%= t('bulletin.deadline') %></th>
<th><%= t('bulletin.action') %></th>
</tr>
<% t.bulletins.each do |post| %>
<tr>
<td><%= link_to post.bulletin_category.i18n_variable[I18n.locale], panel_announcement_front_end_bulletin_path(post) %></td>
<td><%= post.title %></td>
<td><%= link_to t('bulletin.image'), post.image.url, {:target => '_blank', :title => post.alt} if post.image.file %></td>
<td>
<% post.bulletin_files.each do | bfile | %>
<%= link_to bfile.filetitle, bfile.file.url, {:target => '_blank', :title => bfile.description} if bfile.file.file %>
<% end %>
</td>
<td><%= truncate(post.text,:length=>15) %></td>
<td><%= post.postdate %></td>
<td><%= post.deadline %></td>
<td>
<%= 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?' %>
</td>
</tr>
<% end %>
</table>
<% end %>
<br />

View File

@ -6,6 +6,7 @@
<br /> <br />
<ul class="list"> <ul class="list">
<li><%= link_to t('bulletin.new_announcement'), new_panel_announcement_back_end_bulletin_path %></li> <li><%= link_to t('bulletin.new_announcement'), new_panel_announcement_back_end_bulletin_path %></li>
<li><%= link_to t('bulletin.announcement_list'), panel_announcement_back_end_bulletins_path %></li>
<li><%= link_to t('bulletin.new_announcement_class'), panel_announcement_back_end_bulletin_categorys_path %></li> <li><%= link_to t('bulletin.new_announcement_class'), panel_announcement_back_end_bulletin_categorys_path %></li>
</ul> </ul>
<% end -%> <% end -%>
@ -19,37 +20,25 @@
<br /> <br />
<br /> <br />
<% @bulletin_categorys.each do |t| %>
<h4><%= link_to t.name, panel_announcement_back_end_bulletins_path(:bulletin_category_id => t.id ) %></h4>
<table> <table>
<tr> <tr>
<th><%= t('bulletin.category') %></th> <th><%= t('bulletin.status') %></th>
<th><%= t('bulletin.title') %></th>
<th><%= t('bulletin.subtitle') %></th>
<th><%= t('bulletin.image') %></th>
<th><%= t('bulletin.file') %></th>
<th><%= t('bulletin.text') %></th>
<th><%= t('bulletin.postdate') %></th> <th><%= t('bulletin.postdate') %></th>
<th><%= t('bulletin.deadline') %></th> <th><%= t('bulletin.deadline') %></th>
<th><%= t('bulletin.category') %></th>
<th><%= t('bulletin.title') %></th>
<th><%= t('bulletin.action') %></th> <th><%= t('bulletin.action') %></th>
</tr> </tr>
<% t.bulletins.each do |post| %> <% @bulletins.each do |post| %>
<tr> <tr>
<td><%= link_to post.bulletin_category.name, panel_announcement_front_end_bulletin_path(post) %></td> <td></td>
<td><%= post.title %></td>
<td><%= post.subtitle %></td>
<td><%= link_to t('bulletin.image'), post.image.url, :target => '_blank' if post.image.file %></td>
<td>
<% post.bulletin_files.each do | bfile | %>
<%= link_to bfile.filetitle, bfile.file.url, :target => '_blank' if bfile.file.file %>
<% end %>
</td>
<td><%= truncate(post.text,:length=>15) %></td>
<td><%= post.postdate %></td> <td><%= post.postdate %></td>
<td><%= post.deadline %></td> <td><%= (post.deadline) ? post.deadline : t('bulletin.no_deadline') %></td>
<td><%= post.bulletin_category.i18n_variable[I18n.locale] %></td>
<td><%#= link_to post.title, panel_announcement_front_end_bulletin_path(post) %>
<%= link_to post.title, panel_announcement_back_end_bulletin_path(post) %>
</td>
<td> <td>
<%= link_to t('bulletin.edit'), edit_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?' %> <%= 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 @@
</table> </table>
<% end %>
<br /> <br />

View File

@ -1,59 +1,57 @@
<% content_for :secondary do %> <% # encoding: utf-8 %>
<br />
<br />
<br />
<br />
<br />
<ul class="list">
<li><%= link_to t('bulletin.new_announcement'), new_panel_announcement_back_end_bulletin_path, :class => 'seclink1' %></li>
<li><%= link_to t('bulletin.new_announcement_class'), panel_announcement_back_end_bulletin_categorys_path, :class => 'seclink1' %></li>
</ul>
<% end -%>
<%= flash_messages %>
<h1><%= t('bulletin.list_announcement') %></h1>
<br />
<br />
<br /> <br />
<br /> <br />
<br /> <br />
<% @bulletin_categorys.each do |t| %> <p id="notice"><%= flash_messages %></p>
<h4><%= t.name %></h4>
<table>
<tr>
<th><%= t('bulletin.category') %></th>
<th><%= t('bulletin.title') %></th>
<th><%= t('bulletin.subtitle') %></th>
<th><%= t('bulletin.text') %></th>
<th><%= t('bulletin.postdate') %></th>
<th><%= t('bulletin.deadline') %></th>
<th><%= t('bulletin.action') %></th>
</tr>
<% @bulletins.each do |post| %>
<tr>
<td><%= post.bulletin_category.name rescue nil %></td>
<td><%= post.title %></td>
<td><%= post.subtitle %></td>
<td><%= truncate(post.text,:length=>15) %></td>
<td><%= post.postdate %></td>
<td><%= post.deadline %></td>
<td>
<%#= 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 %>
</td>
</tr>
<ul>
<li>
<b><%= t('announcement.category') %></b>
<%= @bulletin.bulletin_category.i18n_variable[I18n.locale] %>
</li>
<li>
<b><%= t('announcement.postdate') %></b>
<%= @bulletin.postdate %>
</li>
<li>
<b><%= t('announcement.title') %></b>
<%= @bulletin.title %>
</li>
<li>
<%#= 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 %>
</li>
<li>
<b><%= t('announcement.summary') %></b>
<%= @bulletin.summary %>
</li>
<li>
<b><%= t('announcement.text') %></b>
<%= @bulletin.text %>
</li>
<li>
<li>
<b><%= t('announcement.file') %></b>
<% @bulletin.bulletin_files.each do | bfile | %>
<%= link_to bfile.filetitle, bfile.file.url, {:target => '_blank', :title => bfile.description} if bfile.file.file %>
<% end %> <% end %>
</li>
<li>
<% if @bulletin.url? %>
<b><%= t('announcement.url') %></b>
<%= link_to @bulletin.url, @bulletin.url, :target => '_blank' %>
<% end %>
</li>
<li>
<b><%= t('announcement.張貼者') %></b>
<%= User.find(@bulletin.create_user_id).name %>
</li>
<li>
<b><%= t('announcement.最後修改時間') %></b>
<%= @bulletin.updated_at %>
</li>
</table>
<% end %>
<br />
<%= link_back %>