Fix deleting links and files in bulletin

This commit is contained in:
chris 2012-12-31 18:03:13 +08:00
parent ded1d9f44c
commit 9937b4ac9b
5 changed files with 19 additions and 67 deletions

View File

@ -207,31 +207,6 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
# PUT /bulletins/1.xml # PUT /bulletins/1.xml
def update def update
if params[:bulletin_link]
@bulletin_link = BulletinLink.find(params[:id])
@link_url = panel_announcement_back_end_bulletin_path(@bulletin_link)
respond_to do |format|
if @bulletin_link.update_attributes(params[:bulletin_link])
# format.html { redirect_to(panel_announcement_back_end_bulletins_url) }
format.js { render 'update_bulletin_link' }
end
end
elsif params[:bulletin_file]
@bulletin_file = BulletinFile.find(params[:id])
@file_url = panel_announcement_back_end_bulletin_path(@bulletin_file)
respond_to do |format|
if @bulletin_file.update_attributes(params[:bulletin_file])
# format.html { redirect_to(panel_announcement_back_end_bulletins_url) }
format.js { render 'update_bulletin_file' }
end
end
else
@bulletin = Bulletin.find(params[:id]) @bulletin = Bulletin.find(params[:id])
@ -362,10 +337,10 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
def clean_values def clean_values
if params[:bulletin] if params[:bulletin]
params[:bulletin][:bulletin_links_attributes].each_with_index do |link, index| params[:bulletin][:bulletin_links_attributes].each_with_index do |link, index|
params[:bulletin][:bulletin_links_attributes].delete(index.to_s) if link[1]['url'].blank? and link[1]['title'].blank? params[:bulletin][:bulletin_links_attributes].delete(index.to_s) if link[1]['url'].blank? and link[1]['title_translations'].blank?
end rescue nil end rescue nil
params[:bulletin][:bulletin_files_attributes].each_with_index do |link, index| params[:bulletin][:bulletin_files_attributes].each_with_index do |link, index|
params[:bulletin][:bulletin_files_attributes].delete(index.to_s) if link[1]['file'].blank? and link[1]['title'].blank? params[:bulletin][:bulletin_files_attributes].delete(index.to_s) if link[1]['file'].blank? and link[1]['title_translations'].blank?
end rescue nil end rescue nil
end end
end end

View File

@ -51,7 +51,7 @@ class Bulletin
validates :title, :at_least_one => true validates :title, :at_least_one => true
before_save :check_deadline, :update_avliable_language, :clean_values before_save :check_deadline, :update_avliable_language, :clean_values#, :save_bulletin_links, :save_bulletin_files
searchable do searchable do
text :titles do text :titles do

View File

@ -253,39 +253,16 @@
<p><%= t("sys.limit_of_upload_file_size",:best_size => '3MB') %></p> <p><%= t("sys.limit_of_upload_file_size",:best_size => '3MB') %></p>
<p><%= t("sys.preview_only_for_img") %></p> <p><%= t("sys.preview_only_for_img") %></p>
</div> </div>
<div>
<table class="table table-condensed">
<thead>
<tr>
<th>File Name</th>
<th class="span2">Chinese</th>
<th class="span2">English</th>
<th class="span1"></th>
</tr>
</thead>
<tfoot>
<tr>
<td>File Name</td>
<td><input type="checkbox" id="optionsCheckbox" value="true" disabled /></td>
<td><input type="checkbox" id="optionsCheckbox" value="true" disabled checked /></td>
<td><a class="action" data-toggle="modal" href="#modal-link"><i class="icon-pencil"></i></a><a class="action" href=""><i class="icon-remove"></i></a></td>
</tr>
</tfoot>
<tbody id="messages">
</tbody>
</table>
</div>
</td> </td>
</tr> </tr>
</tfoot> </tfoot>
<tbody> <tbody>
<% @bulletin.bulletin_files.each_with_index do |bulletin_file, i| %>
<%# @bulletin.bulletin_files.each_with_index do |bulletin_file, i| %>
<%#= fields_for "bulletin[bulletin_files][]", bulletin_file do |f| %> <%#= fields_for "bulletin[bulletin_files][]", bulletin_file do |f| %>
<%#= f.fields_for :bulletin_files do |f| %> <%= f.fields_for :bulletin_files, bulletin_file do |f| %>
<%#= render :partial => 'form_bulletin_file', :object => bulletin_file, :locals => {:f => f, :i => i} %> <%= render :partial => 'form_bulletin_file', :object => bulletin_file, :locals => {:f => f, :i => i} %>
<%# end %> <% end %>
<%# end %> <% end %>
</tbody> </tbody>
</table> </table>

View File

@ -66,7 +66,7 @@
<%= f.hidden_field :id %> <%= f.hidden_field :id %>
<%= hidden_field_tag :tr, (dom_id form_bulletin_file) %> <%= hidden_field_tag :tr, (dom_id form_bulletin_file) %>
<a class="remove_existing_record"><i class="icon-remove"></i></a> <a class="remove_existing_record"><i class="icon-remove"></i></a>
<%= f.hidden_field :should_destroy, :value => nil, :class => 'should_destroy' %> <%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %>
<% end %> <% end %>
</span> </span>

View File

@ -41,7 +41,7 @@
<%= f.hidden_field :id %> <%= f.hidden_field :id %>
<%= hidden_field_tag :tr, (dom_id form_bulletin_link) %> <%= hidden_field_tag :tr, (dom_id form_bulletin_link) %>
<a class="remove_existing_record"><i class="icon-remove"></i></a> <a class="remove_existing_record"><i class="icon-remove"></i></a>
<%= f.hidden_field :should_destroy, :value => nil, :class => 'should_destroy' %> <%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %>
<% end %> <% end %>
</span> </span>
</td> </td>