archive checkbox
This commit is contained in:
parent
2dd2abc8d2
commit
81fa2a7428
|
@ -77,17 +77,7 @@
|
||||||
<%# end -%>
|
<%# end -%>
|
||||||
|
|
||||||
<%= content_tag :li, :class => active_for_controllers('archive_files', 'tags', 'archive_file_categorys') do -%>
|
<%= content_tag :li, :class => active_for_controllers('archive_files', 'tags', 'archive_file_categorys') do -%>
|
||||||
<%= link_to content_tag(:i, nil, :class => 'icons-archive') + t('admin.archive'), panel_archive_back_end_archive_files_path %>
|
<%= link_to content_tag(:i, nil, :class => 'icons-asset') + t('admin.archive'), panel_archive_back_end_archive_files_path %>
|
||||||
<%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('archive_files', 'tags', 'archive_file_categorys')) do -%>
|
|
||||||
<%= content_tag :li, link_to(t('admin.all_articles'), panel_archive_back_end_archive_files_path), :class => active_for_action('archive_file', 'index') %>
|
|
||||||
<%= content_tag :li, link_to(t('admin.add_new'), new_panel_archive_back_end_archive_file_path), :class => active_for_action('archive_file', 'new') %>
|
|
||||||
<%= content_tag :li, link_to(t('admin.categories'), panel_archive_back_end_archive_file_categorys_path), :class => active_for_action('archive_file_categorys', 'index') %>
|
|
||||||
<%= content_tag :li, link_to(t('admin.tags'), panel_archive_back_end_tags_path), :class => active_for_action('tags', 'index') %>
|
|
||||||
<% end -%>
|
|
||||||
<% end -%>
|
|
||||||
|
|
||||||
<%= content_tag :li, :class => active_for_controllers('archive_files', 'tags', 'archive_file_categorys') do -%>
|
|
||||||
<%= link_to content_tag(:i, nil, :class => 'icons-archive') + t('admin.archive'), panel_archive_back_end_archive_files_path %>
|
|
||||||
<%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('archive_files', 'tags', 'archive_file_categorys')) do -%>
|
<%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('archive_files', 'tags', 'archive_file_categorys')) do -%>
|
||||||
<%= content_tag :li, link_to(t('admin.all_articles'), panel_archive_back_end_archive_files_path), :class => active_for_action('archive_file', 'index') %>
|
<%= content_tag :li, link_to(t('admin.all_articles'), panel_archive_back_end_archive_files_path), :class => active_for_action('archive_file', 'index') %>
|
||||||
<%= content_tag :li, link_to(t('admin.add_new'), new_panel_archive_back_end_archive_file_path), :class => active_for_action('archive_file', 'new') %>
|
<%= content_tag :li, link_to(t('admin.add_new'), new_panel_archive_back_end_archive_file_path), :class => active_for_action('archive_file', 'new') %>
|
||||||
|
|
|
@ -5,8 +5,9 @@ class ArchiveFile
|
||||||
include Mongoid::Timestamps
|
include Mongoid::Timestamps
|
||||||
include Mongoid::MultiParameterAttributes
|
include Mongoid::MultiParameterAttributes
|
||||||
|
|
||||||
|
PAYMENT_TYPES = @site_valid_locales
|
||||||
|
|
||||||
has_one :name, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
|
has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
|
||||||
|
|
||||||
has_and_belongs_to_many :tags, :class_name => "ArchiveTag"
|
has_and_belongs_to_many :tags, :class_name => "ArchiveTag"
|
||||||
|
|
||||||
|
@ -19,19 +20,23 @@ class ArchiveFile
|
||||||
|
|
||||||
belongs_to :archive_file_category
|
belongs_to :archive_file_category
|
||||||
|
|
||||||
validates_presence_of :name
|
has_many :archive_file_multiples, :autosave => true, :dependent => :destroy
|
||||||
|
|
||||||
before_save :set_key
|
accepts_nested_attributes_for :archive_file_multiples, :allow_destroy => true
|
||||||
|
|
||||||
|
validates_presence_of :title
|
||||||
|
|
||||||
|
after_save :save_archive_file_multiples
|
||||||
|
|
||||||
def self.search( category_id = nil )
|
def self.search( category_id = nil )
|
||||||
|
|
||||||
if category_id.to_s.size > 0
|
if category_id.to_s.size > 0
|
||||||
|
|
||||||
find(:all, :conditions => {archive_file_category_id: category_id}).desc( :is_top, :name )
|
find(:all, :conditions => {archive_file_category_id: category_id}).desc( :is_top, :title )
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
find(:all).desc( :is_top, :name)
|
find(:all).desc( :is_top, :title)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -40,7 +45,7 @@ class ArchiveFile
|
||||||
|
|
||||||
def self.widget_datas
|
def self.widget_datas
|
||||||
|
|
||||||
where( :is_hidden => false ).desc(:is_top, :name)
|
where( :is_hidden => false ).desc(:is_top, :title)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -48,15 +53,11 @@ class ArchiveFile
|
||||||
self.is_top
|
self.is_top
|
||||||
end
|
end
|
||||||
|
|
||||||
def name
|
def save_archive_file_multiples
|
||||||
@name ||= I18nVariable.first(:conditions => {:key => 'name', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
|
self.archive_file_multiples.each do |t|
|
||||||
end
|
if t.should_destroy
|
||||||
|
t.destroy
|
||||||
protected
|
end
|
||||||
|
|
||||||
def set_key
|
|
||||||
if name.new_record?
|
|
||||||
name.key = 'name'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
class ArchiveFileMultiple
|
||||||
|
|
||||||
|
include Mongoid::Document
|
||||||
|
include Mongoid::Timestamps
|
||||||
|
|
||||||
|
mount_uploader :file, AssetUploader
|
||||||
|
|
||||||
|
# field :filetitle
|
||||||
|
# field :description
|
||||||
|
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
|
||||||
|
|
||||||
|
field :should_destroy, :type => Boolean
|
||||||
|
|
||||||
|
belongs_to :archive_file
|
||||||
|
|
||||||
|
has_many :archive_file_multiple_langs, :autosave => true, :dependent => :destroy
|
||||||
|
|
||||||
|
accepts_nested_attributes_for :archive_file_multiple_langs, :allow_destroy => true
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,10 @@
|
||||||
|
class ArchiveFileMultipleLang
|
||||||
|
|
||||||
|
include Mongoid::Document
|
||||||
|
include Mongoid::Timestamps
|
||||||
|
|
||||||
|
field :choose_lang
|
||||||
|
|
||||||
|
belongs_to :archive_file_multiple
|
||||||
|
|
||||||
|
end
|
|
@ -19,7 +19,7 @@
|
||||||
</td>
|
</td>
|
||||||
<td><%= post.archive_file_category.i18n_variable[I18n.locale] %></td>
|
<td><%= post.archive_file_category.i18n_variable[I18n.locale] %></td>
|
||||||
<td>
|
<td>
|
||||||
<%= link_to post.name[I18n.locale], panel_archive_back_end_archive_file_path(post) %>
|
<%= link_to post.title[I18n.locale], panel_archive_back_end_archive_file_path(post) %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<% post.tags.each do |tag| %>
|
<% post.tags.each do |tag| %>
|
||||||
|
|
|
@ -46,7 +46,8 @@
|
||||||
<%= f.select :archive_file_category_id, @archive_file_categorys.collect {|t| [ t.i18n_variable[I18n.locale], t.id ]} %>
|
<%= f.select :archive_file_category_id, @archive_file_categorys.collect {|t| [ t.i18n_variable[I18n.locale], t.id ]} %>
|
||||||
|
|
||||||
<ul class="nav nav-tabs">
|
<ul class="nav nav-tabs">
|
||||||
<% @site_valid_locales.each_with_index do |locale, i| %>
|
<%# @site_valid_locales.each_with_index do |locale, i| %>
|
||||||
|
<% site_valid_locales_default_head.each_with_index do |locale, i| %>
|
||||||
<li <%= ( i == 0 ) ? " class='active'" : '' %>><a data-toggle="tab" href=".<%= locale %>"><%= I18nVariable.from_locale(locale) %></a></li>
|
<li <%= ( i == 0 ) ? " class='active'" : '' %>><a data-toggle="tab" href=".<%= locale %>"><%= I18nVariable.from_locale(locale) %></a></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -57,8 +58,8 @@
|
||||||
|
|
||||||
<div class="<%= locale %> fade tab-pane <%= ( i == 0 ) ? "in active" : '' %>">
|
<div class="<%= locale %> fade tab-pane <%= ( i == 0 ) ? "in active" : '' %>">
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<%= f.label :name %>
|
<%= f.label :title %>
|
||||||
<%= f.fields_for :name, (@archive_file.new_record? ? @archive_file.build_name : @archive_file.name ) do |f| %>
|
<%= f.fields_for :title, (@archive_file.new_record? ? @archive_file.build_title : @archive_file.title ) do |f| %>
|
||||||
<%= I18nVariable.from_locale(locale) %>
|
<%= I18nVariable.from_locale(locale) %>
|
||||||
<%= f.text_field locale, :class=>'post-title' %>
|
<%= f.text_field locale, :class=>'post-title' %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -70,6 +71,50 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div>
|
||||||
|
|
||||||
|
<div id='archive_file_multiples' class="archive_file_multiples_block">
|
||||||
|
|
||||||
|
<table class="table table-condensed">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>File</th>
|
||||||
|
<th>File Name</th>
|
||||||
|
<th class="span2"><%= t('呈現語系')%></th>
|
||||||
|
<th class="span1"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<td style="text-align:center" colspan="4">
|
||||||
|
<div id='add_archive_file_multiple' class="info_input archive_file_multiples_block">
|
||||||
|
<%= hidden_field_tag 'archive_file_multiple_field_count', @archive_file.archive_file_multiples.count %>
|
||||||
|
<a class="add"><span class="btn btn-primary btn-small"><i class="icon-plus icon-white"></i> ADD/新增</span></a>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
</tfoot>
|
||||||
|
<tbody>
|
||||||
|
|
||||||
|
<% @archive_file.archive_file_multiples.each_with_index do |archive_file_multiple, i| %>
|
||||||
|
<%= f.fields_for :archive_file_multiples, archive_file_multiple do |f| %>
|
||||||
|
<%= render :partial => 'form_file', :object => archive_file_multiple, :locals => {:f => f, :i => i} %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!--Post End-->
|
<!--Post End-->
|
||||||
|
@ -82,3 +127,27 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<% content_for :page_specific_javascript do %>
|
||||||
|
<%= javascript_include_tag "archive_form" %>
|
||||||
|
<script>
|
||||||
|
$('#add_archive_file_multiple a.add').live('click', function(){
|
||||||
|
var new_id = $(this).prev().attr('value');
|
||||||
|
var old_id = new RegExp("new_archive_file_multiples", "g");
|
||||||
|
$(this).prev().attr('value', parseInt(new_id) + 1);
|
||||||
|
$(this).parents('table').append(("<%= escape_javascript(add_attribute 'form_file', f, :archive_file_multiples) %>").replace(old_id, new_id));
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.archive_file_multiples_block a.delete').live('click', function(){
|
||||||
|
$(this).parents('.list_item').remove();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.action a.remove_existing_record').live('click', function(){
|
||||||
|
$(this).next('.should_destroy').attr('value', 1);
|
||||||
|
$("tr#archive_file_" + $(this).prev().attr('value')).hide();
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
<% end %>
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
<% # encoding: utf-8 %>
|
||||||
|
|
||||||
|
<tr id="<%= "archive_file_multiple_#{form_file.id}" if !form_file.new_record? %>" class='list_item'>
|
||||||
|
<td>
|
||||||
|
<div class="control-group">
|
||||||
|
<div class="controls">
|
||||||
|
<%= f.file_field :file %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
<div class="tab-content">
|
||||||
|
|
||||||
|
<% @site_valid_locales.each_with_index do |locale, i| %>
|
||||||
|
|
||||||
|
<div class="<%= locale %> fade tab-pane <%= ( i == 0 ) ? "in active" : '' %>">
|
||||||
|
|
||||||
|
<%= f.fields_for :i18n_variable, (form_file.new_record? ? form_file.build_i18n_variable : form_file.i18n_variable ) do |f| %>
|
||||||
|
<div class="control-group">
|
||||||
|
<label for="link-<%= locale %>" class="control-label"><%= I18nVariable.first(:conditions => {:key => locale})[I18n.locale] %></label>
|
||||||
|
<div class="controls">
|
||||||
|
<%= f.text_field locale, :id => "link-#{locale}", :class => "input-xlarge" %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<% @site_valid_locales.each do |locale| %>
|
||||||
|
<%= check_box_tag 'archive_file[archive_file_multiple][archive_file_multiple_langs_attributes][choose_lang][]', locale %>
|
||||||
|
<%= I18nVariable.from_locale(locale) %>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
<span class="action">
|
||||||
|
<% if form_file.new_record? %>
|
||||||
|
<a class="delete"><i class="icon-remove"></i></a>
|
||||||
|
<% else %>
|
||||||
|
<%= f.hidden_field :id %>
|
||||||
|
<a class="remove_existing_record"><i class="icon-remove"></i></a>
|
||||||
|
<%= f.hidden_field :should_destroy, :value => nil, :class => 'should_destroy' %>
|
||||||
|
<% end %>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th class="span1-2"><%= t('archive_file.status') %></th>
|
<th class="span1-2"><%= t('archive_file.status') %></th>
|
||||||
<th class="span1-2"><%= t('archive_file.category') %></th>
|
<th class="span1-2"><%= t('archive_file.category') %></th>
|
||||||
<th class="span1-2"><%= t('archive_file.name') %></th>
|
<th class="span1-2"><%= t('archive_file.title') %></th>
|
||||||
<th class="span1-2"><%= t('archive_file.tags') %></th>
|
<th class="span1-2"><%= t('archive_file.tags') %></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
Reference in New Issue