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