diff --git a/app/assets/javascripts/tinymce_orbit.js.erb b/app/assets/javascripts/tinymce_orbit.js.erb index 51f86b6fd..f12bfa3df 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 9ee1d45da..7206bd727 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 fb4865a21..58f4a746d 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 000000000..818a23401 --- /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 9819934f0..22c4ae2da 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 f59e20a09..7b5749c93 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 000000000..1f60f00bc --- /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 9eb4e77a1..3a8dc4396 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 86e5f86aa..43cb5927d 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/admin/assets/create.js.erb b/app/views/admin/assets/create.js.erb index 38c7992c0..f307f6f90 100644 --- a/app/views/admin/assets/create.js.erb +++ b/app/views/admin/assets/create.js.erb @@ -3,10 +3,13 @@ // document.domain = 'moxiecode.com'; var tinymce=null,tinyMCEPopup,tinyMCE;tinyMCEPopup={init:function(){var b=this,a,c;a=b.getWin();tinymce=a.tinymce;tinyMCE=a.tinyMCE;b.editor=tinymce.EditorManager.activeEditor;b.params=b.editor.windowManager.params;b.features=b.editor.windowManager.features;b.dom=b.editor.windowManager.createInstance("tinymce.dom.DOMUtils",document);if(b.features.popup_css!==false){b.dom.loadCSS(b.features.popup_css||b.editor.settings.popup_css)}b.listeners=[];b.onInit={add:function(e,d){b.listeners.push({func:e,scope:d})}};b.isWindow=!b.getWindowArg("mce_inline");b.id=b.getWindowArg("mce_window_id");b.editor.windowManager.onOpen.dispatch(b.editor.windowManager,window)},getWin:function(){return(!window.frameElement&&window.dialogArguments)||opener||parent||top},getWindowArg:function(c,b){var a=this.params[c];return tinymce.is(a)?a:b},getParam:function(b,a){return this.editor.getParam(b,a)},getLang:function(b,a){return this.editor.getLang(b,a)},execCommand:function(d,c,e,b){b=b||{};b.skip_focus=1;this.restoreSelection();return this.editor.execCommand(d,c,e,b)},resizeToInnerSize:function(){var a=this;setTimeout(function(){var b=a.dom.getViewPort(window);a.editor.windowManager.resizeBy(a.getWindowArg("mce_width")-b.w,a.getWindowArg("mce_height")-b.h,a.id||window)},10)},executeOnLoad:function(s){this.onInit.add(function(){eval(s)})},storeSelection:function(){this.editor.windowManager.bookmark=tinyMCEPopup.editor.selection.getBookmark(1)},restoreSelection:function(){var a=tinyMCEPopup;if(!a.isWindow&&tinymce.isIE){a.editor.selection.moveToBookmark(a.editor.windowManager.bookmark)}},requireLangPack:function(){var b=this,a=b.getWindowArg("plugin_url")||b.getWindowArg("theme_url");if(a&&b.editor.settings.language&&b.features.translate_i18n!==false&&b.editor.settings.language_load!==false){a+="/langs/"+b.editor.settings.language+"_dlg.js";if(!tinymce.ScriptLoader.isDone(a)){document.write('