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

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

Now shows e-mails in the account: field in a session on the session page.

File size: 3.3 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            _accounts: null,
18                        onVisit: function() {
19                                if ( this.pageArgs.uid ) {
20                                        Deferred.when(store.get(this.pageArgs.uid))
21                                        .then(lang.hitch(this,function(obj){
22                                                this.session = obj;
23                        this._setupListView();
24                        this._refresh();
25                                        }));
26                    this._setupAutoComplete();
27                    this._accounts = [];
28                                } else {
29                                        throw "No valid uid or session passed!";
30                                }
31                        },
32                        onLeave: function() {
33                                this.inherited(arguments);
34                        },
35            _refresh: function() {
36                this.titleNode.innerHTML = this.session.title || '';
37                this.propertiesForm.set('value',this.session);
38            },
39            onInvite: function() {
40                this._addAccount(this._select.item.i);
41                this._select.reset();
42            },
43            onSave: function(evt) {
44                lang.mixin(this.session,this.propertiesForm.get('value'));
45                this.session.accounts = this._accounts;
46                store.put(this.session)
47                .then(function(){
48                    content.goTo('sessions');
49                });
50                event.stop(evt);
51                return false;
52            },
53            onDiscard: function(evt) {
54                this.propertiesForm.reset();
55                event.stop(evt);
56                content.goTo('sessions');
57                return false;
58            },
59            _addAccount: function(item) {
60                this._accounts.push(item);
61                this._listView.insertItem(item);
62            },
63            _setupListView: function() {
64                this._listView = new AccountListView( {
65                    controller: this
66                }).placeAt(this.listViewNode);
67                for (account in this.session.accounts) {
68                    this._accounts.push(this.session.accounts[account]);
69                    this._listView.insertItem({ "title" : this.session.accounts[account] });
70                }
71                this._listView.startup();
72            },
73            _setupAutoComplete: function() {
74
75                var accountStore = new ElasticReadStore({
76                    url: "http://localhost:9200/rft/_search",
77                    requestMethod: "POST"
78                });
79                this._select = new ElasticSearchFilteringSelect({
80                    name: "accountBox",
81                    store: accountStore,
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                    id: "accountText"
91                }, "accountBox");
92                this._select.startup();
93            }
94
95
96                });
97});
98
Note: See TracBrowser for help on using the repository browser.