no more flash uploader only HTML5 goodness
This commit is contained in:
parent
d21f32d849
commit
b60b1378f8
1
Gemfile
1
Gemfile
@ -25,7 +25,6 @@ gem 'rails-backbone', '0.5.4'
|
||||
gem 'handlebars-rails', :git => 'git://github.com/yabawock/handlebars-rails.git'
|
||||
gem 'codemirror-rails'
|
||||
gem 'tinymce-rails'
|
||||
gem 'uploadify-rails', :git => 'git://github.com/nragaz/uploadify-rails.git'
|
||||
gem 'flash_cookie_session', '~> 1.1.1'
|
||||
|
||||
gem 'locomotive_liquid', '2.2.2', :require => 'liquid'
|
||||
|
@ -1,9 +1,18 @@
|
||||
class Locomotive.Models.ContentAsset extends Backbone.Model
|
||||
|
||||
paramRoot: 'content_asset'
|
||||
|
||||
urlRoot: "#{Locomotive.mount_on}/content_assets"
|
||||
|
||||
initialize: ->
|
||||
@prepare()
|
||||
|
||||
prepare: ->
|
||||
@set
|
||||
image: @get('content_type') == 'image'
|
||||
|
||||
return @
|
||||
|
||||
class Locomotive.Models.ContentAssetsCollection extends Backbone.Collection
|
||||
|
||||
model: Locomotive.Models.ContentAsset
|
||||
|
@ -1,31 +0,0 @@
|
||||
window.Locomotive.Uploadify =
|
||||
|
||||
build: (el, options) ->
|
||||
multipart_params = @_get_default_multipart_params()
|
||||
|
||||
el.uploadify
|
||||
script: options.url
|
||||
multi: true
|
||||
queueID: null
|
||||
buttonText: 'edit'
|
||||
buttonImg: null
|
||||
width: options.width || 30
|
||||
height: options.height || 30
|
||||
hideButton: true
|
||||
wmode: 'transparent'
|
||||
auto: true
|
||||
fileExt: options.file_ext || '*.jpg;*.png;*.jpeg;*.gif'
|
||||
fileDesc: 'Only .jpg, .png, .jpeg, .gif'
|
||||
removeCompleted: true
|
||||
fileDataName: options.data_name
|
||||
scriptData: multipart_params
|
||||
onComplete: (a, b, c, response, data) ->
|
||||
model = JSON.parse(response)
|
||||
options.success(model)
|
||||
onError: (a, b, c, errorObj) ->
|
||||
options.error(errorObj) if options.error
|
||||
|
||||
_get_default_multipart_params: ->
|
||||
_.tap { _method: 'post', '_http_accept': 'application/json' }, (params) ->
|
||||
params[$('meta[name=csrf-param]').attr('content')] = encodeURI(encodeURIComponent($('meta[name=csrf-token]').attr('content')));
|
||||
params[$('meta[name=key-param]').attr('content')] = $('meta[name=key-token]').attr('content');
|
@ -15,14 +15,17 @@ class Locomotive.Views.ContentAssets.PickerView extends Locomotive.Views.Shared.
|
||||
@collection.fetch()
|
||||
|
||||
build_uploader: (el, link) ->
|
||||
window.Locomotive.Uploadify.build el,
|
||||
url: link.attr('href')
|
||||
data_name: el.attr('name')
|
||||
height: link.outerHeight()
|
||||
width: link.outerWidth()
|
||||
file_ext: '*.png;*.gif;*.jpg;*.jpeg;*.pdf;*.doc;*.docx;*.xls;*.xlsx;*.txt;*.zip'
|
||||
success: (model) => @collection.add(model)
|
||||
error: (msg) => @shake()
|
||||
link.bind 'click', (event) ->
|
||||
event.stopPropagation() & event.preventDefault()
|
||||
el.click()
|
||||
|
||||
el.bind 'change', (event) =>
|
||||
_.each event.target.files, (file) =>
|
||||
asset = new Locomotive.Models.ContentAsset(source: file)
|
||||
asset.save {},
|
||||
headers: { 'X-Flash': true }
|
||||
success: (model, response) => @collection.add(model.prepare())
|
||||
error: => @shake()
|
||||
|
||||
add_asset: (asset, first) ->
|
||||
view = new Locomotive.Views.ContentAssets.PickerItemView model: asset, parent: @
|
||||
|
@ -31,8 +31,9 @@ class Locomotive.Views.Shared.AssetPickerView extends Backbone.View
|
||||
create_dialog: ->
|
||||
@dialog = $(@el).dialog
|
||||
modal: true
|
||||
zIndex: 998
|
||||
width: 650,
|
||||
create: =>
|
||||
create: (event, ui) =>
|
||||
$('.ui-widget-overlay').bind 'click', => @close()
|
||||
|
||||
$(@el).prev().find('.ui-dialog-title').html(@$('h2').html())
|
||||
@ -41,18 +42,13 @@ class Locomotive.Views.Shared.AssetPickerView extends Backbone.View
|
||||
|
||||
actions.find('#close-link').click (event) => @close(event)
|
||||
|
||||
open: =>
|
||||
open: (event, ui, extra) =>
|
||||
actions = $(@el).parent().find('.ui-dialog-buttonpane')
|
||||
el = actions.find('input[type=file]')
|
||||
link = actions.find('#upload-link')
|
||||
|
||||
@build_uploader(el, link)
|
||||
|
||||
actions.find('.button-wrapper').hover(
|
||||
=> link.addClass('hover'),
|
||||
=> link.removeClass('hover')
|
||||
)
|
||||
|
||||
@open()
|
||||
|
||||
open: ->
|
||||
|
@ -53,7 +53,7 @@ class Locomotive.Views.Snippets.FormView extends Locomotive.Views.Shared.FormVie
|
||||
lineNumbers: false
|
||||
passDelay: 50
|
||||
tabMode: 'shift'
|
||||
theme: 'default'
|
||||
theme: 'default medium'
|
||||
onChange: (editor) => @model.set(template: editor.getValue())
|
||||
|
||||
after_inputs_fold: ->
|
||||
|
@ -55,7 +55,7 @@ class Locomotive.Views.ThemeAssets.FormView extends Locomotive.Views.Shared.Form
|
||||
|
||||
enable_source_file: ->
|
||||
# only in HTML 5
|
||||
@$('#theme_asset_source').bind 'change', (event) =>
|
||||
@$('.formtastic #theme_asset_source').bind 'change', (event) =>
|
||||
input = $(event.target)[0]
|
||||
if input.files?
|
||||
@model.set(source: input.files[0])
|
||||
|
@ -18,13 +18,17 @@ class Locomotive.Views.ThemeAssets.ImagePickerView extends Locomotive.Views.Shar
|
||||
@collection.fetch data: { content_type: 'image' }
|
||||
|
||||
build_uploader: (el, link) ->
|
||||
window.Locomotive.Uploadify.build el,
|
||||
url: link.attr('href')
|
||||
data_name: el.attr('name')
|
||||
height: link.outerHeight()
|
||||
width: link.outerWidth()
|
||||
link.bind 'click', (event) ->
|
||||
event.stopPropagation() & event.preventDefault()
|
||||
el.click()
|
||||
|
||||
el.bind 'change', (event) =>
|
||||
_.each event.target.files, (file) =>
|
||||
asset = new Locomotive.Models.ThemeAsset(source: file)
|
||||
asset.save {},
|
||||
headers: { 'X-Flash': true }
|
||||
success: (model) => @collection.add(model)
|
||||
error: (msg) => @shake()
|
||||
error: => @shake()
|
||||
|
||||
select_asset: (event) ->
|
||||
event.stopPropagation() & event.preventDefault()
|
||||
|
@ -9,4 +9,8 @@
|
||||
font-weight: normal;
|
||||
|
||||
@include background-image(linear-gradient(top, #f0f0f0, #f9f9f9 4px, #f9f9f9 4px, #ffffff 12px, #ffffff));
|
||||
|
||||
.medium {
|
||||
height: 250px !important;
|
||||
}
|
||||
}
|
@ -102,22 +102,16 @@
|
||||
top: 8px;
|
||||
right: 10px;
|
||||
|
||||
z-index: 1003;
|
||||
|
||||
a {
|
||||
@include light-button;
|
||||
}
|
||||
|
||||
&.upload {
|
||||
#theme_asset_sourceUploader, #content_asset_sourceUploader {
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
right: 0px;
|
||||
z-index: 1001;
|
||||
input[type=file] {
|
||||
z-index: 1003;
|
||||
}
|
||||
|
||||
a {
|
||||
z-index: 1000;
|
||||
}
|
||||
} // .button-wrapper.upload
|
||||
} // .button-wrapper
|
||||
|
||||
} // .ui-dialog-buttonpane
|
||||
|
@ -10,7 +10,6 @@ module Locomotive
|
||||
|
||||
def create
|
||||
@content_asset = current_site.content_assets.create(params[:content_asset])
|
||||
puts @content_asset.errors.inspect
|
||||
respond_with @content_asset
|
||||
end
|
||||
|
||||
|
@ -9,10 +9,11 @@
|
||||
|
||||
.dialog-actions
|
||||
= link_to t('locomotive.buttons.close'), '#', :id => 'close-link'
|
||||
.button-wrapper.upload
|
||||
= file_field_tag 'content_asset[source]'
|
||||
= link_to t('.upload'), content_assets_url(:json), :class => 'new', :id => 'upload-link'
|
||||
|
||||
.button-wrapper.upload
|
||||
= form_tag theme_assets_url(:json), :class => 'quick-upload' do
|
||||
= file_field_tag 'theme_asset[source]', :multiple => 'multiple'
|
||||
= link_to t('locomotive.theme_assets.image_picker.upload'), theme_assets_url(:json), :class => 'new', :id => 'upload-link'
|
||||
|
||||
%script{ :type => 'text/html', :id => 'content_asset' }
|
||||
|
||||
|
@ -8,8 +8,10 @@
|
||||
|
||||
.dialog-actions
|
||||
= link_to t('locomotive.buttons.close'), '#', :id => 'close-link'
|
||||
|
||||
.button-wrapper.upload
|
||||
= file_field_tag 'theme_asset[source]'
|
||||
= form_tag theme_assets_url(:json), :class => 'quick-upload' do
|
||||
= file_field_tag 'theme_asset[source]', :multiple => 'multiple'
|
||||
= link_to t('locomotive.theme_assets.image_picker.upload'), theme_assets_url(:json), :class => 'new', :id => 'upload-link'
|
||||
|
||||
%script{ :type => 'text/html', :id => 'theme_asset' }
|
||||
|
Loading…
Reference in New Issue
Block a user