From c9cbec42396be5bd917a73c3e5f2a698ea30b1cf Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Thu, 17 May 2012 18:31:40 +0800 Subject: [PATCH 1/2] Asset changes, add description --- app/controllers/admin/assets_controller.rb | 2 +- app/models/asset.rb | 28 ++++++++++++++++++--- app/views/admin/assets/file_upload.html.erb | 22 ++++++++-------- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/app/controllers/admin/assets_controller.rb b/app/controllers/admin/assets_controller.rb index fb4865a2..58f4a746 100644 --- a/app/controllers/admin/assets_controller.rb +++ b/app/controllers/admin/assets_controller.rb @@ -30,7 +30,7 @@ class Admin::AssetsController < OrbitBackendController def create @asset = Asset.new(params[:asset]) - @asset.filename = @asset.i18n_variable[I18n.locale] rescue nil + @asset.filename = @asset.title[I18n.locale] rescue nil if @asset.filename && @asset.save respond_to do |format| format.js { diff --git a/app/models/asset.rb b/app/models/asset.rb index 34ba57e5..22c4ae2d 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -7,17 +7,39 @@ class Asset field :filename field :description + + has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy + has_one :description, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy - has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy - - validates_presence_of :filename, :data, :asset_category_id + validates_presence_of :title, :data, :description belongs_to :asset_category belongs_to :assetable, polymorphic: true has_and_belongs_to_many :tags, :class_name => "AssetTag" + before_save :set_key + + def title + @title ||= I18nVariable.first(:conditions => {:key => 'title', :language_value_id => self.id, :language_value_type => self.class}) rescue nil + end + + def description + @description ||= I18nVariable.first(:conditions => {:key => 'description', :language_value_id => self.id, :language_value_type => self.class}) rescue nil + end + def sorted_tags tags.order_by(I18n.locale, :asc) end + + protected + + def set_key + if title.new_record? + title.key = 'title' + end + if description.new_record? + description.key = 'description' + end + end end diff --git a/app/views/admin/assets/file_upload.html.erb b/app/views/admin/assets/file_upload.html.erb index 9d0c7fb0..ec546667 100644 --- a/app/views/admin/assets/file_upload.html.erb +++ b/app/views/admin/assets/file_upload.html.erb @@ -11,7 +11,7 @@
- <%= f.fields_for :i18n_variable, (@asset.new_record? ? @asset.build_i18n_variable : @asset.i18n_variable) do |f| %> + <%= f.fields_for :title, (@asset.new_record? ? @asset.build_title : @asset.title) do |f| %> <% @site_valid_locales.each do |locale| %> <%= content_tag :label do -%>
@@ -23,20 +23,18 @@ <% end %>
-
- <%= f.label :category, t('admin.category'), :class => "control-label" %> -
- <%= f.select :asset_category_id, @asset_categories.collect{|t| [ t.i18n_variable[I18n.locale], t.id ]}, {}, :class => "input-large" %> -
-
- +
- <% @tags.each do |tag| %> - <%= content_tag :label, :class => "checkbox inline" do -%> - <%= check_box_tag 'asset[tag_ids][]', tag.id, @asset.tag_ids.include?(tag.id) %> - <%= tag[I18n.locale] %> + <%= f.fields_for :description, (@asset.new_record? ? @asset.build_description : @asset.description) do |f| %> + <% @site_valid_locales.each do |locale| %> + <%= content_tag :label do -%> +
+ <%= I18nVariable.from_locale(locale) %> + <%= f.text_field locale, :class => "input-large" %> +
<% end %> + <% end %> <% end %>
From 27fd2d07146e044e02a4a1dd1d2c3d25cbf76920 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Thu, 17 May 2012 18:37:46 +0800 Subject: [PATCH 2/2] Hide assets links from side_bar --- app/views/admin/assets/_asset.html.erb | 4 ++-- app/views/admin/assets/_sort_headers.html.erb | 2 +- app/views/layouts/_side_bar.html.erb | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/views/admin/assets/_asset.html.erb b/app/views/admin/assets/_asset.html.erb index 9eb4e77a..3a8dc439 100644 --- a/app/views/admin/assets/_asset.html.erb +++ b/app/views/admin/assets/_asset.html.erb @@ -1,6 +1,6 @@ <%= check_box_tag 'to_delete[]', asset.id, false, :class => "checkbox_in_list" %> - <%= asset.i18n_variable[I18n.locale] rescue nil %> + <%= asset.title.i18n_variable[I18n.locale] rescue nil %>
@@ -12,7 +12,7 @@ <%= asset.data.file.content_type %> <%= number_to_human_size(asset.data.file.file_length) %> - <%= asset.category.i18n_variable[I18n.locale] rescue nil %> + <%= asset.description.i18n_variable[I18n.locale] rescue nil %>
diff --git a/app/views/admin/assets/_sort_headers.html.erb b/app/views/admin/assets/_sort_headers.html.erb index 86e5f86a..43cb5927 100644 --- a/app/views/admin/assets/_sort_headers.html.erb +++ b/app/views/admin/assets/_sort_headers.html.erb @@ -2,5 +2,5 @@ ['description', 'description', 'span1-2', 'admin.data'], ['intro', 'intro', 'span1-2', 'admin.file_type'], ['intro', 'intro', 'span1-2', 'admin.file_length'], - ['intro', 'intro', 'span1-2', 'admin.category'], + ['intro', 'intro', 'span1-2', 'admin.description'], ['intro', 'intro', 'span1-2', 'admin.tags']).html_safe %> diff --git a/app/views/layouts/_side_bar.html.erb b/app/views/layouts/_side_bar.html.erb index 53314765..ab5981a8 100644 --- a/app/views/layouts/_side_bar.html.erb +++ b/app/views/layouts/_side_bar.html.erb @@ -71,11 +71,11 @@ <% end -%> <% end -%> -<%= content_tag :li, :class => active_for_controllers('assets', '/admin/asset_tags', 'asset_categories') do -%> - <%= link_to content_tag(:i, nil, :class => 'icons-link') + t('admin.asset'), admin_assets_path %> - <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('assets', '/admin/asset_tags', 'asset_categories')) do -%> - <%= content_tag :li, link_to(t('admin.all_assets'), admin_assets_path), :class => active_for_action('assets', 'index') %> - <%= content_tag :li, link_to(t('admin.categories'), admin_asset_categories_path), :class => active_for_action('asset_categories', 'index') %> - <%= content_tag :li, link_to(t('admin.tags'), admin_asset_tags_path), :class => active_for_action('/admin/asset_tags', 'index') %> - <% end -%> -<% end -%> +<%#= content_tag :li, :class => active_for_controllers('assets', '/admin/asset_tags', 'asset_categories') do -%> + <%#= link_to content_tag(:i, nil, :class => 'icons-link') + t('admin.asset'), admin_assets_path %> + <%#= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('assets', '/admin/asset_tags', 'asset_categories')) do -%> + <%#= content_tag :li, link_to(t('admin.all_assets'), admin_assets_path), :class => active_for_action('assets', 'index') %> + <%#= content_tag :li, link_to(t('admin.categories'), admin_asset_categories_path), :class => active_for_action('asset_categories', 'index') %> + <%#= content_tag :li, link_to(t('admin.tags'), admin_asset_tags_path), :class => active_for_action('/admin/asset_tags', 'index') %> + <%# end -%> +<%# end -%>