upload many theme assets at once

This commit is contained in:
did 2011-12-07 03:25:30 -08:00
parent 4da434deb1
commit d21f32d849
7 changed files with 59 additions and 35 deletions

View File

@ -37,6 +37,7 @@ class Locomotive.Views.Shared.ListView extends Backbone.View
(@_item_views ||= []).push(view) (@_item_views ||= []).push(view)
@$('.no-items').hide()
@$('ul').append(view.render().el) @$('ul').append(view.render().el)
remove_item: (item) -> remove_item: (item) ->

View File

@ -25,23 +25,21 @@ class Locomotive.Views.ThemeAssets.IndexView extends Backbone.View
return @ return @
build_uploader: -> build_uploader: ->
el = @$('.quick-upload input[type=file]') form = @$('#theme-assets-quick-upload')
link = @$('.quick-upload a.new') input = form.find('input[type=file]')
window.Locomotive.Uploadify.build el, link = form.find('a.new')
url: link.attr('href')
data_name: el.attr('name') link.bind 'click', (event) ->
file_ext: '*.jpg;*.png;*.jpeg;*.gif;*.flv;*.swf;*.ttf;*.js;*.css;*.mp3' event.stopPropagation() & event.preventDefault()
height: link.outerHeight() input.click()
width: link.outerWidth()
success: (model) => @add_asset(model) input.bind 'change', (event) =>
error: (msg) => _.each event.target.files, (file) =>
console.log(msg) asset = new Locomotive.Models.ThemeAsset(source: file)
$.growl('alert', msg) asset.save {}, success: @add_asset, headers: { 'X-Flash': true }
add_asset: (model) -> add_asset: (model) ->
console.log(model) list_view = @pick_list_view(model.get('content_type'))
list_view = @pick_list_view(model.content_type)
console.log(list_view)
list_view.collection.add(model) list_view.collection.add(model)
render_snippets: -> render_snippets: ->

View File

@ -359,6 +359,16 @@ p span.code {
@include single-text-shadow(#fff, 0px, 0px, 1px); @include single-text-shadow(#fff, 0px, 0px, 1px);
} }
/* ___ quick upload ___ */
form.quick-upload {
display: inline;
input[type=file] {
visibility: hidden;
}
}

View File

@ -11,9 +11,7 @@
%ul{ :id => 'import-steps', :class => 'list', :'data-url' => import_url(:json), :'data-success-message' => t('.messages.success'), :'data-failure-message' => t('.messages.failure') } %ul{ :id => 'import-steps', :class => 'list', :'data-url' => import_url(:json), :'data-success-message' => t('.messages.success'), :'data-failure-message' => t('.messages.failure') }
- %w(site content_types assets snippets pages).each do |step| - %w(site content_types assets snippets pages).each do |step|
%li{ :id => "#{step}-step" } %li{ :id => "#{step}-step" }
%em %strong= t(".steps.#{step}")
%strong
= link_to t(".steps.#{step}"), '#'
.more .more
.states .states
   

View File

@ -29,9 +29,10 @@
- content_for :buttons do - content_for :buttons do
- if can?(:manage, Locomotive::ThemeAsset) - if can?(:manage, Locomotive::ThemeAsset)
.button-wrapper.quick-upload = form_tag theme_assets_url(:json), :id => 'theme-assets-quick-upload', :class => 'quick-upload' do
= file_field_tag 'theme_asset[source]' = file_field_tag 'theme_asset[source]', :multiple => 'multiple'
= local_action_button :quick_upload, theme_assets_url(:json), :class => 'new' = local_action_button :quick_upload, '#', :class => 'new'
= local_action_button t('locomotive.snippets.index.new'), new_snippet_url, :class => 'new' if can?(:manage, Locomotive::Snippet) = local_action_button t('locomotive.snippets.index.new'), new_snippet_url, :class => 'new' if can?(:manage, Locomotive::Snippet)
= local_action_button :new, new_theme_asset_url, :class => 'new' if can?(:manage, Locomotive::ThemeAsset) = local_action_button :new, new_theme_asset_url, :class => 'new' if can?(:manage, Locomotive::ThemeAsset)

View File

@ -24,16 +24,25 @@ x edit my site
x edit my account x edit my account
x create a new site x create a new site
x create a new accounts x create a new accounts
- theme assets x theme assets
x polish the page x polish the page
x snippets x snippets
x delete in ajax x delete in ajax
- upload many files at once x upload many files at once
- site picker
- import/export - import/export
- QU - QU
- site picker
- content types - content types
- change in main menu
- manage custom_fields
- list
- crud
- move content instances into their own collection
- manage contents
- list
- crud
- message to notify people if their browser is too old
- install a site by default at the first installation (without asking) - install a site by default at the first installation (without asking)

View File

@ -12,13 +12,14 @@ module Locomotive
if get? if get?
display resource display resource
elsif has_errors? elsif has_errors?
Rails.logger.debug "--> ERRORS #{resource.errors.inspect}" # FIXME: debug purpose with_flash_message(:alert) do
with_flash_message(:alert) do |message|
display resource.errors, :status => :unprocessable_entity display resource.errors, :status => :unprocessable_entity
end end
elsif post? elsif post?
set_flash_message! in_header = controller.request.headers['X-Flash'] == 'true'
display resource, :location => api_location with_flash_message(:notice, in_header) do
display resource, :location => api_location
end
elsif put? elsif put?
with_flash_message do |message| with_flash_message do |message|
display resource, :status => :ok, :location => api_location display resource, :status => :ok, :location => api_location
@ -38,16 +39,22 @@ module Locomotive
protected protected
def with_flash_message(type = :notice) def with_flash_message(type = :notice, in_header = true)
set_flash_message! if in_header
message = controller.flash[type] set_flash_message!
message = controller.flash[type]
controller.headers['X-Message'] = message controller.headers['X-Message'] = message
controller.headers['X-Message-Type'] = type controller.headers['X-Message-Type'] = type
yield(message) if block_given? yield if block_given?
controller.flash.discard # reset flash messages ! controller.flash.discard # reset flash messages !
else
set_flash_message!
yield if block_given?
end
end end
end end