1 | define(['dojo/_base/declare','dojo/_base/lang','rft/store','rft/content','rft/ui/_Page','rft/ui/ObjectBox'], |
---|
2 | function(declare,lang,store,content,_Page,ObjectBox){ |
---|
3 | return declare('rft.pages.sessions',[_Page],{ |
---|
4 | templateActions: null, |
---|
5 | sessionActions: null, |
---|
6 | onVisit: function() { |
---|
7 | this.templateActions = { |
---|
8 | "Edit": function(obj){ |
---|
9 | content.goTo('session',{uid:store.getIdentity(obj)}); |
---|
10 | }, |
---|
11 | "Delete": lang.hitch(this,function(obj){ |
---|
12 | store.remove(store.getIdentity(obj),store.getRevision(obj)) |
---|
13 | .then(lang.hitch(this,function(){ |
---|
14 | this._refresh(); |
---|
15 | })); |
---|
16 | }), |
---|
17 | "Publish": lang.hitch(this,this._publishSession) |
---|
18 | }; |
---|
19 | this.sessionActions = { |
---|
20 | "Facilitate": function(obj){ |
---|
21 | content.goTo('run',{uid:store.getIdentity(obj)}); |
---|
22 | }, |
---|
23 | "Delete": lang.hitch(this,function(obj){ |
---|
24 | store.remove(store.getIdentity(obj),store.getRevision(obj)) |
---|
25 | .then(lang.hitch(this,function(){ |
---|
26 | this._refresh(); |
---|
27 | })); |
---|
28 | }) |
---|
29 | }; |
---|
30 | this._refresh(); |
---|
31 | }, |
---|
32 | _refresh: function() { |
---|
33 | this.containerTemplates.set('content',''); |
---|
34 | this.containerSessions.set('content',''); |
---|
35 | this._refreshByType('SessionTemplate',this.containerTemplates.domNode,this.templateActions); |
---|
36 | this._refreshByType('SessionInstance',this.containerSessions.domNode,this.sessionActions); |
---|
37 | }, |
---|
38 | _refreshByType: function(type,container,actions) { |
---|
39 | store.query("_design/default/_view/by_type",{key:type}) |
---|
40 | .forEach(lang.hitch(this,function(obj){ |
---|
41 | var widget = new ObjectBox({ |
---|
42 | actions: actions |
---|
43 | }).placeAt(container, "last"); |
---|
44 | widget.startup(); |
---|
45 | widget.set('value',obj); |
---|
46 | })); |
---|
47 | }, |
---|
48 | onAddSessionTemplate: function(){ |
---|
49 | store.put({ |
---|
50 | type: 'SessionTemplate' |
---|
51 | }) |
---|
52 | .then(lang.hitch(this,function(obj){ |
---|
53 | content.goTo('session',{uid:store.getIdentity(obj)}); |
---|
54 | })); |
---|
55 | }, |
---|
56 | _publishSession: function(sessionTemplate) { |
---|
57 | var publishDate = new Date(); |
---|
58 | var session = lang.clone(sessionTemplate); |
---|
59 | delete session[store.idProperty]; |
---|
60 | delete session[store.revProperty]; |
---|
61 | session.type = "SessionInstance"; |
---|
62 | session.date = publishDate.getDate()+"-"+publishDate.getMonth()+"-"+publishDate.getFullYear(); |
---|
63 | session.creator = "Igor Mayer"; |
---|
64 | store.add(session) |
---|
65 | .then(lang.hitch(this,function(){ |
---|
66 | this._refresh(); |
---|
67 | this.tabContainer.selectChild(this.sessionsTab); |
---|
68 | })); |
---|
69 | } |
---|
70 | }); |
---|
71 | }); |
---|
72 | |
---|