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

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

We can store answers for surveys now!

Introduces SurveyRun?, which can be edited. Workflow not quite clear yet. A
running survey can be accessed to leave a response. When the response
has an ID, it is loaded (used for closed surveys and continuations). A
researcher cannot create responses yet. He should also be able to add
comments to responses (that he creates).

Introduced caching of store requests.

Factored out path matching and formatting.

Put object creation in separate classes, to localize model/storage
dependency. Not consistent at the moment.

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.getItems(),function(item){
54                return store.getIdentity(item);
55            });
56            store.put(this.session)
57            .then(function(){
58                Router.go('/sessions');
59            });
60            event.stop(evt);
61            return false;
62        },
63        onDiscard: function(evt) {
64            this.propertiesForm.reset();
65            event.stop(evt);
66            Router.go('/sessions');
67            return false;
68        },
69        _addAccount: function(item) {
70            this._accountList.insertItem(item);
71        },
72        _setupAccountList: function() {
73            this._accountList = new AccountListView().placeAt(this.accountListNode);
74            this._accountList.startup();
75            for (var account in this.session.accounts) {
76                this._accountList.insertItem(this.session.accounts[account]);
77            }
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.