first draft for the json template response (tested on sorting pages)
This commit is contained in:
parent
bef9dd8e67
commit
596eb78a55
@ -1,6 +1,5 @@
|
||||
#= require_self
|
||||
#= require_tree .
|
||||
#= require_tree ./templates
|
||||
#= require_tree ./models
|
||||
#= require_tree ./views
|
||||
#= require_tree ./routers
|
||||
|
@ -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',
|
||||
|
@ -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?
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user