UNPKG

grunt-doctrine

Version:

Grunt plugin to convert doctrine xml annotations into backbone models and collections. Useful in conjunction with doctrine apigility. Includes option to scaffold an entire BBB application

129 lines (96 loc) 3 kB
define(function(require, exports, module) { "use strict"; var app = require('app'); var logger = require("lib/console"); var Backbone = require('backbone'); var Collection = require("./Collection"); var Model = require("./Model"); var ItemView = require("./item/view"); var EditView = require("./edit/view"); var CreateView = require("./create/view"); var ListView = require("./list/view"); var Router = Backbone.Router.extend({ cached: {}, view: null, el: '.main', initialize: function() { this.collection = app.dataModel.staff = new Collection(); // Listen to app events // this.listenTo(app, '', this.onEvent, this); }, routes: { 'staff/list': 'listAction', 'staff/create': 'createAction', 'staff/edit/:id': 'editAction', 'staff/:id': 'viewAction' }, /** * url update causes to show all staff */ listAction: function() { logger.debug('listAction'); this.cached = { state: 'staff:viewall' }; app.trigger('staff:viewall'); this.render(ListView, { collection: this.collection }); this.collection.fetch(); }, /** * url update causes to edit one staff * @param id */ viewAction: function(id) { logger.debug('viewAction'); this.cached = { state: 'staff:edit', id: id }; app.trigger('staff:edit', id); var viewModel = this.collection.get(id); this.render(ItemView, { model: viewModel }, true); }, /** * url update cause to create a new staff */ createAction: function() { logger.debug('createAction'); this.cached = { state: 'staff:create' }; app.trigger('staff:create'); this.render(CreateView, { model: new Model({}) }, true); }, /** * url update cause to edit a staff * @param id */ editAction: function(id) { logger.debug('editAction'); this.cached = { state: 'staff:create' }; app.trigger('staff:create'); var editableModel = this.collection.get(id); this.render(EditView, { model: editableModel }, true); }, /** * Render a view */ render: function(ViewClass, dataObj, renderNow) { this.view = app.view.setView(this.el, new ViewClass(dataObj)); if (renderNow === true) { this.view.render(); } } }); module.exports = Router; });