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

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

Session page now has support for autocompletion (currently works on question titles but can change it easily if we introduce users).

File size: 2.9 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._refresh();
23                                        }));
24                    this._setupAutoComplete();
25                    this._setupListView();
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({ title : this._select.displayedValue });
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                this._listView.insertItem(item);
58            },
59            _setupListView: function() {
60                this._listView = new AccountListView( {
61                    controller: this
62                }).placeAt(this.listViewNode);
63                this._listView.startup();
64            },
65            _setupAutoComplete: function() {
66
67                var accountStore = new ElasticReadStore({
68                    url: "http://localhost:9200/rft/_search",
69                    requestMethod: "POST"
70                });
71                this._select = new ElasticSearchFilteringSelect({
72                    name: "accountBox",
73                    store: accountStore,
74                    autoComplete: false,
75                    required: false,
76                    labelType: "text",
77                    placeHolder: "Enter email address here...",
78                    pageSize: 10,
79                    hasDownArrow: false,
80                    style: "width: 400",
81                    searchAttr: "title",
82                    id: "accountText"
83                }, "accountBox");
84                this._select.startup();
85            }
86
87
88                });
89});
90
Note: See TracBrowser for help on using the repository browser.