source: Dev/branches/rest-dojo-ui/client/rft/pages/session.js @ 377

Last change on this file since 377 was 374, checked in by jkraaijeveld, 13 years ago

Can now edit basic question properties and store them.

File size: 3.4 KB
Line 
1define(['dojo/_base/declare',
2        'dojo/_base/lang',
3        'dojo/_base/event',
4        'dojo/_base/Deferred',
5    'rft/elastic/ElasticSearchFilteringSelect',
6    'rft/elastic/ElasticReadStore',
7        'rft/store',
8        'rft/ui/_Page',
9        'rft/content',
10    'rft/ui/AccountListView'
11    ],
12        function(declare,lang,event,Deferred,ElasticSearchFilteringSelect,ElasticReadStore,store,_Page,content,AccountListView){
13                return declare('rft.pages.session',[_Page],{
14                        session: null,
15                        _listView: null,
16            _select: null,
17                        onVisit: function() {
18                                if ( this.pageArgs.uid ) {
19                                        Deferred.when(store.get(this.pageArgs.uid))
20                                        .then(lang.hitch(this,function(obj){
21                                                this.session = obj;
22                        this._setupListView();
23                        this._refresh();
24                                        }));
25                    this._setupAutoComplete();
26                                } else {
27                                        throw "No valid uid or session passed!";
28                                }
29                        },
30                        onLeave: function() {
31                                this.inherited(arguments);
32                        },
33            _refresh: function() {
34                this.titleNode.innerHTML = this.session.title || '';
35                this.propertiesForm.set('value',this.session);
36            },
37            onInvite: function() {
38                this._addAccount(this._select.item.i);
39                this._select.reset();
40            },
41            onSave: function(evt) {
42                lang.mixin(this.session,this.propertiesForm.get('value'));
43                store.put(this.session)
44                .then(function(){
45                    content.goTo('sessions');
46                });
47                event.stop(evt);
48                return false;
49            },
50            onDiscard: function(evt) {
51                this.propertiesForm.reset();
52                event.stop(evt);
53                content.goTo('sessions');
54                return false;
55            },
56            _addAccount: function(item) {
57                if (!this.session.accounts)
58                    this.session.accounts = [];
59                this.session.accounts.push(item);
60                this._listView.insertItem(item);
61            },
62            _removeAccount: function(item) {
63                this.session.accounts.splice(this.session.accounts.indexOf(item), 1);
64            },
65            _setupListView: function() {
66                this._listView = new AccountListView( {
67                    controller: this,
68                    removeCallback: lang.hitch(this, this._removeAccount)
69                }).placeAt(this.listViewNode);
70                for (account in this.session.accounts) {
71                    this._listView.insertItem(this.session.accounts[account]);
72                }
73
74                this._listView.startup();
75            },
76            _setupAutoComplete: function() {
77
78                var accountStore = new ElasticReadStore({
79                    url: "http://localhost:9200/rft/_search",
80                    requestMethod: "POST"
81                });
82                this._select = new ElasticSearchFilteringSelect({
83                    name: "accountBox",
84                    store: accountStore,
85                    autoComplete: false,
86                    required: false,
87                    labelType: "text",
88                    placeHolder: "Enter email address here...",
89                    pageSize: 10,
90                    hasDownArrow: false,
91                    style: "width: 400",
92                    searchAttr: "title",
93                    id: "accountText"
94                }, "accountBox");
95                this._select.startup();
96            }
97
98
99                });
100});
101
Note: See TracBrowser for help on using the repository browser.