a bit of battling with paperclip
Oleg
committed Dec 14, 2011
commit ef9bdfdb6574fc2cb091e525abee7bcbaa323f15
Showing 15
changed files with
75 additions
and 43 deletions
app/assets/javascripts/comfortable_mexican_sofa/elrte/elrte.sofa_image.js
+0
-1
| @@ | @@ -4,7 +4,6 @@ |
| this.constructor.prototype.constructor.call(this, rte, name); | |
| var self = this; | |
| - | self.rte = rte; |
| self.img_src = null; | |
| self.dialog = null; | |
app/assets/javascripts/comfortable_mexican_sofa/elrte/elrte.sofa_link.js
+34
-14
| @@ | @@ -2,23 +2,43 @@ |
| elRTE.prototype.ui.prototype.buttons.sofa_link = function(rte, name){ | |
| this.constructor.prototype.constructor.call(this, rte, name); | |
| - | var self = this; |
| + | var self = this; |
| + | self.link_url = null; |
| + | |
| + | // attaching event handler to the image insertion form |
| + | $(document).on('submit', '#cms_dialog form.link_url', function(){ |
| + | self.link_url = $(this).find('input[name=link_url]').val(); |
| + | self.set(); |
| + | return false; |
| + | }); |
| + | |
| + | this.set = function(){ |
| + | self.rte.history.add(); |
| + | |
| + | var link = $(this.rte.dom.create('a')).attr('href', href); |
| + | |
| + | self.rte.ui.update(); |
| + | self.dialog.dialog('close'); |
| + | } |
| this.command = function(){ | |
| - | dialog_opts = { |
| - | rtl : this.rte.rtl, |
| - | submit: function(e, d) { e.stopPropagation(); e.preventDefault(); self.set(); d.close(); }, |
| - | close : function() {self.rte.browser.msie && self.rte.selection.restoreIERange(); }, |
| - | dialog: { |
| - | width : 'auto', |
| - | width : 430, |
| - | title : this.rte.i18n('Link') |
| - | } |
| - | } |
| - | d = new elDialogForm(); |
| - | d.append('BALHHH'); |
| - | d.open(); |
| + | self.dialog = jQuery(jQuery('#cms_dialog').get(0) || jQuery('<div id="cms_dialog"></div>')); |
| + | self.dialog.dialog({ |
| + | title : rte.i18n('Link'), |
| + | modal : true, |
| + | resizable : false, |
| + | width : 800, |
| + | closeOnEscape : true, |
| + | autoOpen : false |
| + | }); |
| + | jQuery.ajax({ |
| + | url: '/' + $('meta[name="cms-admin-path"]').attr('content') + '/sites/' + $('meta[name="cms-site-id"]').attr('content') + '/dialog/link', |
| + | success: function(data){ |
| + | self.dialog.html(data); |
| + | self.dialog.dialog('open'); |
| + | } |
| + | }) |
| } | |
| this.update = function(){ | |
app/assets/stylesheets/comfortable_mexican_sofa/widgets.css
+6
-0
| @@ | @@ -9,6 +9,12 @@ |
| .ui-timepicker-div td { font-size: 90%; } | |
| /* -- elrte -------------------------------------------------------------- */ | |
| + | .el-dialogform-content iframe { |
| + | background: #fff; |
| + | } |
| .el-rte .toolbar ul li.sofa_image { | |
| background-position: -384px -2px | |
| + | } |
| + | .el-rte .toolbar ul li.sofa_link { |
| + | background-position:-244px -29px |
| } | |
| \ No newline at end of file | |
app/controllers/cms_admin/dialogs_controller.rb
+1
-1
| @@ | @@ -1,6 +1,6 @@ |
| class CmsAdmin::DialogsController < CmsAdmin::BaseController | |
| - | TEMPLATES = %w(image) |
| + | TEMPLATES = %w(image link) |
| def show | |
| if template = TEMPLATES.include?(params[:type])? params[:type] : nil | |
app/models/cms/file.rb
+1
-0
| @@ | @@ -19,6 +19,7 @@ class Cms::File < ActiveRecord::Base |
| ) | |
| } | |
| ) | |
| + | before_post_process :is_image? |
| # -- Relationships -------------------------------------------------------- | |
| belongs_to :site | |
app/views/cms_admin/dialogs/link.html.erb
+5
-0
| @@ | @@ -0,0 +1,5 @@ |
| + | <form class='link_url'> |
| + | <label for='link_url'> URL </label> |
| + | <input type='text' name='link_url' id='link_url'/> |
| + | <input type='submit' value='<%= t('.create') %>'/> |
| + | </form> |
| \ No newline at end of file | |
config/initializers/paperclip.rb
+0
-25
| @@ | @@ -1,28 +1,3 @@ |
| Paperclip.options[:command_path] = case Rails.env | |
| when 'development', 'test' then '/usr/local/bin' | |
| - | end |
| - | |
| - | if Rails.env.test? |
| - | class Paperclip::Attachment |
| - | def self.default_options |
| - | @default_options = { |
| - | :url => "/system/:attachment/:id/:style/:filename", |
| - | :path => ":rails_root/public:url", |
| - | :styles => {}, |
| - | :only_process => [], |
| - | :processors => [:thumbnail], |
| - | :convert_options => {}, |
| - | :source_file_options => {}, |
| - | :default_url => "/:attachment/:style/missing.png", |
| - | :default_style => :original, |
| - | :storage => :filesystem, |
| - | :use_timestamp => false, |
| - | :whiny => Paperclip.options[:whiny] || Paperclip.options[:whiny_thumbnails], |
| - | :use_default_time_zone => true, |
| - | :hash_digest => "SHA1", |
| - | :hash_data => ":class/:attachment/:id/:style/:updated_at", |
| - | :preserve_files => false |
| - | } |
| - | end |
| - | end |
| end | |
| \ No newline at end of file | |
config/locales/en.yml
+2
-0
| @@ | @@ -220,4 +220,6 @@ en: |
| dialogs: | |
| image: | |
| insert: Insert Image | |
| + | link: |
| + | create: Create Link |
| \ No newline at end of file | |
config/locales/es.yml
+2
-0
| @@ | @@ -220,3 +220,5 @@ es: |
| dialogs: | |
| image: | |
| insert: Insertar Imagen | |
| + | link: |
| + | create: Create Link |
test/fixtures/files/data.zip
+0
-0
test/functional/cms_admin/dialogs_controller_test.rb
+7
-0
| @@ | @@ -5,9 +5,16 @@ class CmsAdmin::DialogsControllerTest < ActionController::TestCase |
| def test_get_image_dialog | |
| get :show, :site_id => cms_sites(:default), :type => 'image' | |
| assert_response :success | |
| + | assert_template 'image' |
| assert_select "input[name=image_url]" | |
| end | |
| + | def test_get_link_dialog |
| + | get :show, :site_id => cms_sites(:default), :type => 'link' |
| + | assert_response :success |
| + | assert_template 'link' |
| + | end |
| + | |
| def test_get_invalid | |
| get :show, :site_id => cms_sites(:default), :type => 'invalid' | |
| assert_response :success | |
test/test_helper.rb
+3
-0
| @@ | @@ -4,6 +4,9 @@ ENV['RAILS_ENV'] = 'test' |
| require File.expand_path('../../config/environment', __FILE__) | |
| require 'rails/test_help' | |
| + | # No need to add cache-busters in test environment |
| + | Paperclip::Attachment.default_options[:use_timestamp] = false |
| + | |
| class ActiveSupport::TestCase | |
| # Disabling the noise | |
test/unit/models/file_test.rb
+12
-0
| @@ | @@ -43,6 +43,17 @@ class CmsFileTest < ActiveSupport::TestCase |
| end | |
| end | |
| + | def test_create_with_non_image |
| + | assert_difference 'Cms::File.count' do |
| + | file = cms_sites(:default).files.create!( |
| + | :file => fixture_file_upload('files/data.zip', 'application/zip') |
| + | ) |
| + | assert_equal 'Data', file.label |
| + | assert_equal 'data.zip', file.file_file_name |
| + | assert_equal 'application/zip', file.file_content_type |
| + | end |
| + | end |
| + | |
| def test_create_failure | |
| assert_no_difference 'Cms::File.count' do | |
| cms_sites(:default).files.create(:file => '') | |
| @@ | @@ -70,4 +81,5 @@ class CmsFileTest < ActiveSupport::TestCase |
| assert_equal 'image/jpeg', file.file_content_type | |
| assert file.is_image? | |
| end | |
| + | |
| end | |
test/unit/tags/page_file_test.rb
+1
-1
| @@ | @@ -97,7 +97,7 @@ class PageFileTagTest < ActiveSupport::TestCase |
| page.update_attributes!( | |
| :blocks_attributes => [ | |
| { :identifier => 'file', | |
| - | :content => fixture_file_upload('files/image.jpg') } |
| + | :content => fixture_file_upload('files/image.jpg', 'image/jpeg') } |
| ] | |
| ) | |
| file = Cms::File.last | |
test/unit/tags/page_files_test.rb
+1
-1
| @@ | @@ -90,7 +90,7 @@ class PageFilesTagTest < ActiveSupport::TestCase |
| page.update_attributes!( | |
| :blocks_attributes => [ | |
| { :identifier => 'file', | |
| - | :content => fixture_file_upload('files/image.jpg') } |
| + | :content => fixture_file_upload('files/image.jpg', 'image/jpeg') } |
| ] | |
| ) | |
| file = Cms::File.last | |