diff --git a/app/assets/javascripts/locomotive/application.js.coffee b/app/assets/javascripts/locomotive/application.js.coffee index 0a5d3f92..c4b86dd8 100644 --- a/app/assets/javascripts/locomotive/application.js.coffee +++ b/app/assets/javascripts/locomotive/application.js.coffee @@ -1,6 +1,5 @@ #= require_self #= require_tree . -#= require_tree ./templates #= require_tree ./models #= require_tree ./views #= require_tree ./routers diff --git a/app/assets/javascripts/locomotive/views/pages/list_view.js.coffee b/app/assets/javascripts/locomotive/views/pages/list_view.js.coffee index 87d5398f..100701b6 100644 --- a/app/assets/javascripts/locomotive/views/pages/list_view.js.coffee +++ b/app/assets/javascripts/locomotive/views/pages/list_view.js.coffee @@ -12,6 +12,37 @@ class Locomotive.Views.Pages.ListView extends Backbone.View return @ make_sortable: -> + self = @ + + @$('ul.folder').sortable + handle: 'em' + axis: 'y' + update: (event, ui) -> self.call_sort $(@) + + call_sort: (folder) -> + $.rails.ajax + url: folder.attr('data-url') + type: 'post' + dataType: 'json' + data: + children: (_.map folder.sortable('toArray'), (el) -> el.replace('item-', '')) + _method: 'put' + success: @.on_successful_sort + error: @.on_failed_sort + + # on_sort: (data) -> + on_successful_sort: (data, status, xhr) -> + window.foo = xhr + $.growl('success', xhr.getResponseHeader('Flash')); + + on_failed_sort: (data, status, xhr) -> + $.growl('error', xhr.getResponseHeader('Flash')); + + # $.post($(@).attr('data-url'), params, function(data) { + # var error = typeof(data.error) != 'undefined'; + # $.growl((error ? 'error' : 'success'), (error ? data.error : data.notice)); + # }, 'json'); + # TODO # $('#pages-list ul.folder').sortable({ # 'handle': 'em', diff --git a/lib/locomotive/responder.rb b/lib/locomotive/responder.rb index 59d23518..75b72143 100644 --- a/lib/locomotive/responder.rb +++ b/lib/locomotive/responder.rb @@ -8,14 +8,6 @@ module Locomotive super || has_errors? end - def api_behavior(error) - puts "api_behavior here" - - super - - puts "api_behavior there" - end - # def api_behavior(error) # raise error unless resourceful? # @@ -31,6 +23,8 @@ module Locomotive # end def to_json + + if get? display resource elsif has_errors? @@ -38,12 +32,37 @@ module Locomotive elsif post? display resource, :status => :created, :location => api_location elsif put? - display resource, :status => :ok, :location => api_location + with_flash_message(:notice) do |message| + # puts "put ? yes #{controller.flash[:notice]} / #{resource.inspect}" + # controller.headers[:notice] => controller.flash[:notice] + puts "put ? yes, message = #{message}" + + display resource, :status => :ok, :location => api_location + end elsif has_empty_resource_definition? display empty_resource, :status => :ok else - head :ok + # head :ok + puts "youpi !!!" + display :notice => controller.flash[:notice], :status => :ok end + + controller.flash.discard # reset flash messages ! + end + + protected + + def with_flash_message(type) + puts "@alert = #{@alert} / @notice = #{@notice}" + set_flash_message! + message = controller.flash[type] + + # controller.headers[:"flash-#{type.to_s.capitalize}"] = message + controller.headers[:flash] = message + + yield(message) if block_given? + + controller.flash.discard # reset flash messages ! end # def api_behavior(error)