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
def edit
@bulletin_category = BulletinCategory.find(params[:id])
@i18n_variable = @bulletin_category.i18n_variable
end
# POST /bulletins

View File

@ -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
@ -63,6 +68,9 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController
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
# 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
@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|

View File

@ -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

View File

@ -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

View File

@ -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

View File

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

View File

@ -20,14 +20,18 @@
<table>
<tr>
<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>
</tr>
<% @bulletin_categorys.each do |post| %>
<tr>
<td><%= post.key %></td>
<td><%= post.name %></td>
<% @site_valid_locales.each do |locale| %>
<td><%= post.i18n_variable[locale] rescue nil %></td>
<% end %>
<td>
<%= 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 %>

View File

@ -4,7 +4,7 @@
<div class="field">
<%= 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 class="field">
@ -22,8 +22,8 @@
</div>
<div class="field">
<%= f.label :subtitle %><br />
<%= f.text_field :subtitle %>
<%= f.label :summary %><br />
<%= f.text_area :summary, :rows => 10, :cols => 40 %>
</div>
<div class="field">
@ -40,6 +40,12 @@
<div class="field">
<%= 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, :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>

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 />
<ul class="list">
<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>
</ul>
<% end -%>
@ -19,37 +20,25 @@
<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>
<tr>
<th><%= t('bulletin.category') %></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.status') %></th>
<th><%= t('bulletin.postdate') %></th>
<th><%= t('bulletin.deadline') %></th>
<th><%= t('bulletin.category') %></th>
<th><%= t('bulletin.title') %></th>
<th><%= t('bulletin.action') %></th>
</tr>
<% t.bulletins.each do |post| %>
<% @bulletins.each do |post| %>
<tr>
<td><%= link_to post.bulletin_category.name, panel_announcement_front_end_bulletin_path(post) %></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></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>
<%= 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 @@
</table>
<% end %>
<br />

View File

@ -1,59 +1,57 @@
<% 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, :class => 'seclink1' %></li>
<li><%= link_to t('bulletin.new_announcement_class'), panel_announcement_back_end_bulletin_categorys_path, :class => 'seclink1' %></li>
</ul>
<% end -%>
<% # encoding: utf-8 %>
<%= flash_messages %>
<h1><%= t('bulletin.list_announcement') %></h1>
<br />
<br />
<br />
<br />
<br />
<% @bulletin_categorys.each do |t| %>
<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>
<p id="notice"><%= flash_messages %></p>
<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 %>
</table>
</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>
<br />
<%= link_back %>