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 | selectedObject: null, |
---|
5 | onVisit: function() { |
---|
6 | this._refresh(); |
---|
7 | }, |
---|
8 | _refresh: function() { |
---|
9 | this.containerTemplates.set('content',''); |
---|
10 | this.containerSessions.set('content',''); |
---|
11 | this._refreshByType('SessionTemplate',this.containerTemplates.domNode); |
---|
12 | this._refreshByType('SessionInstance',this.containerSessions.domNode); |
---|
13 | }, |
---|
14 | _refreshByType: function(type,container) { |
---|
15 | store.query("_design/default/_view/by_type",{key:type}) |
---|
16 | .forEach(lang.hitch(this,function(obj){ |
---|
17 | var widget = new ObjectBox({ |
---|
18 | title: obj.title || "Untitled", |
---|
19 | actions: { |
---|
20 | "Edit": function(){alert('Custom edit code');}, |
---|
21 | "Delete": lang.hitch(this,function(){ |
---|
22 | store.remove(store.getIdentity(obj),store.getRevision(obj)) |
---|
23 | .then(lang.hitch(this,function(){ |
---|
24 | this._refresh(); |
---|
25 | })); |
---|
26 | }), |
---|
27 | "Custom function": function(){alert('newCommand');}, |
---|
28 | "Publish": lang.hitch(this,this._publishSession,obj) |
---|
29 | } |
---|
30 | }); |
---|
31 | widget.startup(); |
---|
32 | widget.placeAt(container, "last"); |
---|
33 | })); |
---|
34 | }, |
---|
35 | onAddSessionTemplate: function(){ |
---|
36 | store.put({ |
---|
37 | type: 'SessionTemplate', |
---|
38 | title: 'TeamUp Basic Template' |
---|
39 | }) |
---|
40 | .then(lang.hitch(this,function(){ |
---|
41 | this._refresh(); |
---|
42 | })); |
---|
43 | }, |
---|
44 | _publishSession: function(sessionTemplate) { |
---|
45 | var publishDate = new Date(); |
---|
46 | var session = { |
---|
47 | type: "SessionInstance", |
---|
48 | title: sessionTemplate.title, |
---|
49 | date: publishDate.getDate()+"-"+publishDate.getMonth()+"-"+publishDate.getFullYear(), |
---|
50 | creator: "Igor Mayer" |
---|
51 | }; |
---|
52 | store.add(session) |
---|
53 | .then(lang.hitch(this,function(){ |
---|
54 | this._refresh(); |
---|
55 | })); |
---|
56 | } |
---|
57 | }); |
---|
58 | }); |
---|
59 | |
---|