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