source: Dev/branches/rest-dojo-ui/client/rft/pages/sessions.js @ 416

Last change on this file since 416 was 416, checked in by hendrikvanantwerpen, 12 years ago

Don't create new documents before editing them, because
our validation will reject them.

File size: 2.9 KB
Line 
1define([
2    'dojo/_base/declare',
3    'dojo/_base/lang',
4    'dojo/date/stamp',
5    '../store',
6    '../app/Router',
7    '../app/Page',
8    '../ui/ObjectBox',
9    'dojo/text!./sessions.html'
10],function(declare,lang,dateStamp,store,Router,Page,ObjectBox,template){
11    return declare([Page],{
12        templateString: template,
13        templateActions: null,
14        sessionActions: null,
15        startup: function() {
16            if ( this._started ) { return; }
17            this.inherited(arguments);
18            this.templateActions = {
19                "Edit": function(obj){
20                    Router.go('/session/'+store.getIdentity(obj));
21                },
22                "Delete": lang.hitch(this,function(obj){
23                    store.remove(store.getIdentity(obj),store.getRevision(obj))
24                    .then(lang.hitch(this,function(){
25                        this._refresh();
26                    }));
27                }),
28                "Publish": lang.hitch(this,this._publishSession)
29            };
30            this.sessionActions = {
31                "Facilitate": function(obj){
32                    Router.go('run',{uid:store.getIdentity(obj)});
33                },
34                "Delete": lang.hitch(this,function(obj){
35                    store.remove(store.getIdentity(obj),store.getRevision(obj))
36                    .then(lang.hitch(this,function(){
37                        this._refresh();
38                    }));
39                })
40            };
41            this._refresh();
42        },
43        _refresh: function() {
44            this.containerTemplates.set('content','');
45            this.containerSessions.set('content','');
46            this._refreshByType('SessionTemplate',this.containerTemplates.domNode,this.templateActions);
47            this._refreshByType('SessionInstance',this.containerSessions.domNode,this.sessionActions);
48        },
49        _refreshByType: function(type,container,actions) {
50            store.query("_design/default/_view/by_type",{key:type})
51            .forEach(lang.hitch(this,function(obj){
52                var widget = new ObjectBox({
53                    actions: actions
54                }).placeAt(container, "last");
55                widget.startup();
56                widget.set('value',obj);
57            }));
58        },
59        onAddSessionTemplate: function(){
60            Router.go('/session/new');
61        },
62        _publishSession: function(sessionTemplate) {
63            var session = lang.clone(sessionTemplate);
64            delete session[store.idProperty];
65            delete session[store.revProperty];
66            session.type = "SessionInstance";
67            session.publicationDate = store.timestamp();
68            session.creator = "Igor Mayer";
69            store.add(session)
70            .then(lang.hitch(this,function(){
71                this._refresh();
72                this.tabContainer.selectChild(this.sessionsTab);
73            }));
74        }
75    });
76});
Note: See TracBrowser for help on using the repository browser.