source: Dev/trunk/client/qed/pages/session.js @ 441

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

Big cleanup of the question content.

  • Replaced old list implementations with a new one that behaves like a form widget.
  • All question content is now in separate widgets, not in the factory itself.
  • Added form and widget validation for question editing.
File size: 3.2 KB
Line 
1define([
2    'dojo/_base/array',
3    'dojo/_base/declare',
4    'dojo/_base/event',
5    'dojo/_base/lang',
6    'dojo/when',
7    '../search',
8    '../store',
9    '../app/Page',
10    '../app/Router',
11    '../widgets/ThresholdFilteringSelect',
12    '../model/classes/SessionTemplate',
13    '../model/widgets/AccountListView',
14    'dojo/text!./templates/session.html'
15],function(array,declare,event,lang,when,search,store,Page,Router,ThresholdFilteringSelect,SessionTemplate,AccountListView,template){
16    return declare([Page],{
17        templateString: template,
18        session: null,
19        _accountList: null,
20        _select: null,
21        startup: function() {
22            if ( this._started ) { return; }
23            this.inherited(arguments);
24            if ( this.sessionId ) {
25                this._loadSession();
26                this._setupAutoComplete();
27            } else {
28                throw "No valid uid or session passed!";
29            }
30        },
31        _loadSession: function() {
32            if ( this.sessionId === "new" ) {
33                this.session = SessionTemplate.create();
34            } else {
35                when(store.get(this.sessionId))
36                .then(lang.hitch(this,function(obj){
37                    this.session = obj;
38                    this._setupAccountList();
39                    this._refresh();
40                }));
41            }
42        },
43        _refresh: function() {
44            this.titleNode.innerHTML = SessionTemplate.DisplayTitle.get(this.session);
45            this.propertiesForm.set('value',this.session);
46        },
47        onInvite: function() {
48            this._addAccount(this._select.item.i);
49            this._select.reset();
50        },
51        onSave: function(evt) {
52            lang.mixin(this.session,this.propertiesForm.get('value'));
53            this.session.accounts = array.map(this._accountList.get('value'),
54                                              function(item){
55                                                  return store.getIdentity(item);
56            });
57            store.put(this.session)
58            .then(function(){
59                Router.go('/sessions');
60            });
61            event.stop(evt);
62            return false;
63        },
64        onDiscard: function(evt) {
65            this.propertiesForm.reset();
66            event.stop(evt);
67            Router.go('/sessions');
68            return false;
69        },
70        _addAccount: function(item) {
71            this._accountList.insertItem(item);
72        },
73        _setupAccountList: function() {
74            this._accountList = new AccountListView({
75                value: this.session.accounts
76            }).placeAt(this.accountListNode);
77            this._accountList.startup();
78        },
79        _setupAutoComplete: function() {
80            this._select = new ThresholdFilteringSelect({
81                store: search,
82                autoComplete: false,
83                required: false,
84                labelType: "text",
85                placeHolder: "Enter email address here...",
86                pageSize: 10,
87                hasDownArrow: false,
88                style: "width: 400",
89                searchAttr: "title"
90            }, this.accountSelector);
91            this._select.startup();
92        }
93
94
95    });
96});
97
Note: See TracBrowser for help on using the repository browser.