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.1 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.office_data = new Collection(); // Listen to app events // this.listenTo(app, '', this.onEvent, this); }, routes: { 'office_data/list': 'listAction', 'office_data/create': 'createAction', 'office_data/edit/:id': 'editAction', 'office_data/:id': 'viewAction' }, /** * url update causes to show all office_data */ listAction: function() { logger.debug('listAction'); this.cached = { state: 'office_data:viewall' }; app.trigger('office_data:viewall'); this.render(ListView, { collection: this.collection }); this.collection.fetch(); }, /** * url update causes to edit one office_data * @param id */ viewAction: function(id) { logger.debug('viewAction'); this.cached = { state: 'office_data:edit', id: id }; app.trigger('office_data:edit', id); var viewModel = this.collection.get(id); this.render(ItemView, { model: viewModel }, true); }, /** * url update cause to create a new office_data */ createAction: function() { logger.debug('createAction'); this.cached = { state: 'office_data:create' }; app.trigger('office_data:create'); this.render(CreateView, { model: new Model({}) }, true); }, /** * url update cause to edit a office_data * @param id */ editAction: function(id) { logger.debug('editAction'); this.cached = { state: 'office_data:create' }; app.trigger('office_data: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; });