diff --git a/app/assets/javascripts/tinymce_orbit.js.erb b/app/assets/javascripts/tinymce_orbit.js.erb index 51f86b6f..f12bfa3d 100644 --- a/app/assets/javascripts/tinymce_orbit.js.erb +++ b/app/assets/javascripts/tinymce_orbit.js.erb @@ -62,14 +62,16 @@ function myFileBrowser(field_name, url, type, win) { tinyMCE.activeEditor.windowManager.open({ file : cmsURL, title : 'File Browser', - width : 850, // Your dimensions may differ - toy around with them! - height : 455, + width : 530, // Your dimensions may differ - toy around with them! + height : 350, resizable : "no", inline : "no", // This parameter only has an effect if you use the inlinepopups plugin! close_previous : "no" }, { window : win, input : field_name, + alt : "alt", + title : "title" }); return false; } diff --git a/app/assets/stylesheets/message.css b/app/assets/stylesheets/message.css index 9ee1d45d..7206bd72 100644 --- a/app/assets/stylesheets/message.css +++ b/app/assets/stylesheets/message.css @@ -1,7 +1,7 @@ /*message*/ .error{ - color:red; + color: #B94A48; } .notice, .message{ 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/helpers/admin/asset_helper.rb b/app/helpers/admin/asset_helper.rb new file mode 100644 index 00000000..818a2340 --- /dev/null +++ b/app/helpers/admin/asset_helper.rb @@ -0,0 +1,11 @@ +module Admin::AssetHelper + + def show_all_fields(asset, field) + a = [] + @site_valid_locales.each do |locale| + a << asset.send(field)[locale] rescue nil + end + a.join(' - ') + end + +end \ No newline at end of file diff --git a/app/models/asset.rb b/app/models/asset.rb index 9819934f..22c4ae2d 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -3,21 +3,43 @@ class Asset include Mongoid::Document include Mongoid::Timestamps - mount_uploader :data, AssetUploader + mount_uploader :data, FileAssetUploader 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 + 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/uploaders/asset_uploader.rb b/app/uploaders/asset_uploader.rb index f59e20a0..7b5749c9 100644 --- a/app/uploaders/asset_uploader.rb +++ b/app/uploaders/asset_uploader.rb @@ -48,8 +48,8 @@ class AssetUploader < CarrierWave::Uploader::Base # end # Override the filename of the uploaded files: - def filename - model.filename - end + # def filename + # model.filename + # end end diff --git a/app/uploaders/file_asset_uploader.rb b/app/uploaders/file_asset_uploader.rb new file mode 100644 index 00000000..1f60f00b --- /dev/null +++ b/app/uploaders/file_asset_uploader.rb @@ -0,0 +1,55 @@ +# encoding: utf-8 + +class FileAssetUploader < CarrierWave::Uploader::Base + require 'mime/types' + + process :set_content_type + + def set_content_type(*args) + content_type = file.content_type == ('binary/octet-stream' || 'application/octet-stream') || file.content_type.blank? ? MIME::Types.type_for(original_filename).first.to_s : file.content_type + self.file.instance_variable_set(:@content_type, content_type) + end + + # Include RMagick or ImageScience support: + # include CarrierWave::RMagick + # include CarrierWave::ImageScience + + # Choose what kind of storage to use for this uploader: + # storage :file + # storage :s3 + + # Override the directory where uploaded files will be stored. + # This is a sensible default for uploaders that are meant to be mounted: + def store_dir + "assets/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + end + + # Provide a default URL as a default if there hasn't been a file uploaded: + # def default_url + # "/images/fallback/" + [version_name, "default.png"].compact.join('_') + # end + + # Process files as they are uploaded: + # process :scale => [200, 300] + # + # def scale(width, height) + # # do something + # end + + # Create different versions of your uploaded files: + # version :thumb do + # process :scale => [50, 50] + # end + + # Add a white list of extensions which are allowed to be uploaded. + # For images you might use something like this: + # def extension_white_list + # %w(jpg jpeg gif png) + # end + + # Override the filename of the uploaded files: + # def filename + # model.filename.force_encoding("UTF-8") + # end + +end 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 @@