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)
@$('.no-items').hide()
@$('ul').append(view.render().el)
remove_item: (item) ->

View File

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

View File

@ -359,6 +359,16 @@ p span.code {
@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') }
- %w(site content_types assets snippets pages).each do |step|
%li{ :id => "#{step}-step" }
%em
%strong
= link_to t(".steps.#{step}"), '#'
%strong= t(".steps.#{step}")
.more
.states
 

View File

@ -29,9 +29,10 @@
- content_for :buttons do
- if can?(:manage, Locomotive::ThemeAsset)
.button-wrapper.quick-upload
= file_field_tag 'theme_asset[source]'
= local_action_button :quick_upload, theme_assets_url(:json), :class => 'new'
= form_tag theme_assets_url(:json), :id => 'theme-assets-quick-upload', :class => 'quick-upload' do
= file_field_tag 'theme_asset[source]', :multiple => 'multiple'
= 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 :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 create a new site
x create a new accounts
- theme assets
x theme assets
x polish the page
x snippets
x delete in ajax
- upload many files at once
- site picker
x upload many files at once
- import/export
- QU
- site picker
- 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)

View File

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