fix the annoying bug of duplicated flash messages + first backbone view for the index pages section
This commit is contained in:
parent
aa1abd2e92
commit
6122983835
@ -5,6 +5,10 @@ class Locomotive.Views.ApplicationView extends Backbone.View
|
|||||||
render: ->
|
render: ->
|
||||||
@render_flash_messages(@options.flash)
|
@render_flash_messages(@options.flash)
|
||||||
|
|
||||||
|
if @options.view?
|
||||||
|
@view = new @options.view
|
||||||
|
@view.render()
|
||||||
|
|
||||||
return @
|
return @
|
||||||
|
|
||||||
render_flash_messages: (messages) ->
|
render_flash_messages: (messages) ->
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
Locomotive.Views.Pages ||= {}
|
||||||
|
|
||||||
|
class Locomotive.Views.Pages.IndexView extends Backbone.View
|
||||||
|
|
||||||
|
el: '#content'
|
||||||
|
|
||||||
|
render: ->
|
||||||
|
@index_view = new Locomotive.Views.Pages.ListView()
|
||||||
|
@index_view.render()
|
||||||
|
|
||||||
|
return @
|
@ -0,0 +1,29 @@
|
|||||||
|
Locomotive.Views.Pages ||= {}
|
||||||
|
|
||||||
|
class Locomotive.Views.Pages.ListView extends Backbone.View
|
||||||
|
|
||||||
|
el: '#pages-list'
|
||||||
|
|
||||||
|
render: ->
|
||||||
|
console.log('render list view');
|
||||||
|
|
||||||
|
@make_sortable()
|
||||||
|
|
||||||
|
return @
|
||||||
|
|
||||||
|
make_sortable: ->
|
||||||
|
# TODO
|
||||||
|
# $('#pages-list ul.folder').sortable({
|
||||||
|
# 'handle': 'em',
|
||||||
|
# 'axis': 'y',
|
||||||
|
# 'update': function(event, ui) {
|
||||||
|
# var params = $(this).sortable('serialize', { 'key': 'children[]' });
|
||||||
|
# params += '&_method=put';
|
||||||
|
# params += '&' + $('meta[name=csrf-param]').attr('content') + '=' + $('meta[name=csrf-token]').attr('content');
|
||||||
|
#
|
||||||
|
# $.post($(this).attr('data-url'), params, function(data) {
|
||||||
|
# var error = typeof(data.error) != 'undefined';
|
||||||
|
# $.growl((error ? 'error' : 'success'), (error ? data.error : data.notice));
|
||||||
|
# }, 'json');
|
||||||
|
# }
|
||||||
|
# });
|
@ -1,8 +1,5 @@
|
|||||||
- title t('.title')
|
- title t('.title')
|
||||||
|
|
||||||
/ - content_for :head do
|
|
||||||
/ = include_javascripts :pages
|
|
||||||
|
|
||||||
- content_for :submenu do
|
- content_for :submenu do
|
||||||
= render 'locomotive/shared/menu/contents'
|
= render 'locomotive/shared/menu/contents'
|
||||||
|
|
||||||
|
@ -18,7 +18,8 @@
|
|||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|
||||||
window.application_view = new Locomotive.Views.ApplicationView({
|
window.application_view = new Locomotive.Views.ApplicationView({
|
||||||
flash: #{flash.to_json}
|
flash: #{flash.to_json},
|
||||||
|
view: Locomotive.Views.#{controller.controller_name.camelize}.#{controller.action_name.camelize}View
|
||||||
});
|
});
|
||||||
window.application_view.render();
|
window.application_view.render();
|
||||||
|
|
||||||
|
@ -3,24 +3,45 @@ module Locomotive
|
|||||||
|
|
||||||
include ::Responders::FlashResponder
|
include ::Responders::FlashResponder
|
||||||
|
|
||||||
def api_behavior(error)
|
# by default flash_now messages if the resource has errors
|
||||||
raise error unless resourceful?
|
def set_flash_now?
|
||||||
|
super || has_errors?
|
||||||
# generate flash messages
|
end
|
||||||
set_flash_message!
|
|
||||||
|
|
||||||
|
def to_json
|
||||||
if get?
|
if get?
|
||||||
display resource
|
display resource
|
||||||
elsif has_errors?
|
elsif has_errors?
|
||||||
display({ :errors => resource.errors, :model => controller.send(:resource_instance_name), :alert => controller.flash[:alert] })
|
display resource.errors, :status => :unprocessable_entity
|
||||||
elsif post?
|
elsif post?
|
||||||
display resource, :status => :created, :location => resource_location
|
display resource, :status => :created, :location => api_location
|
||||||
|
elsif put?
|
||||||
|
display resource, :status => :ok, :location => api_location
|
||||||
|
elsif has_empty_resource_definition?
|
||||||
|
display empty_resource, :status => :ok
|
||||||
else
|
else
|
||||||
display({ :notice => controller.flash[:notice] })
|
head :ok
|
||||||
end
|
end
|
||||||
|
|
||||||
controller.flash.discard # reset flash messages !
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# def api_behavior(error)
|
||||||
|
# raise error unless resourceful?
|
||||||
|
#
|
||||||
|
# # generate flash messages
|
||||||
|
# set_flash_message!
|
||||||
|
#
|
||||||
|
# if get?
|
||||||
|
# display resource
|
||||||
|
# elsif has_errors?
|
||||||
|
# display({ :errors => resource.errors, :model => controller.send(:resource_instance_name), :alert => controller.flash[:alert] })
|
||||||
|
# elsif post?
|
||||||
|
# display resource, :status => :created, :location => resource_location
|
||||||
|
# else
|
||||||
|
# display({ :notice => controller.flash[:notice] })
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# controller.flash.discard # reset flash messages !
|
||||||
|
# end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user