-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.js
58 lines (43 loc) · 1.12 KB
/
router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use strict';
var $ = require('jquery'),
Backbone = require('backbone')
Backbone.$ = $
require('backbone.subroute')
require('./less/main.less')
Backbone.View.prototype.close = function(){
this.remove();
this.unbind();
}
var indexView = require('./views/IndexView'),
NewView = require('./views/NewView')
module.exports = Backbone.SubRoute.extend({
routes:{
'': 'index',
'new': 'new',
'view/:id': 'detail'
},
index: function(){
console.info('subrouter -- categories home')
this.appView(new indexView({
collection: global.cartapacio.collections.categories
}))
},
new: function(){
console.info('subrouter -- categores new')
this.appView(new NewView())
},
detail: function(id){
console.info('subrouter -- categories detail')
var model = global.cartapacio.collections.categories.get(id)
this.appView(new NewView({model:model}))
},
appView: function(view){
var self = this
if (this.currentView){
self.currentView.close();
}
this.currentView = view;
this.currentView.render();
$('.main-content').html(this.currentView.el);
}
})