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

Last change on this file since 365 was 365, checked in by jkraaijeveld, 13 years ago
File size: 2.9 KB
Line 
1define(['dojo/_base/declare',
2        'dojo/_base/lang',
3        'dojo/_base/event',
4        'dojo/_base/Deferred',
5    'dijit/form/FilteringSelect',
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,FilteringSelect,ElasticReadStore,store,_Page,content,AccountListView){
13                return declare('rft.pages.session',[_Page],{
14                        session: null,
15                        listView: null,
16                        onVisit: function() {
17                                if ( this.pageArgs.uid ) {
18                                        Deferred.when(store.get(this.pageArgs.uid))
19                                        .then(lang.hitch(this,function(obj){
20                                                this.session = obj;
21                        this._refresh();
22                                        }));
23                    this._setupAutoComplete();
24                    this._setupListView();
25                                } else {
26                                        throw "No valid uid or session passed!";
27                                }
28                        },
29                        onLeave: function() {
30                                this.inherited(arguments);
31                        },
32            _refresh: function() {
33                this.titleNode.innerHTML = this.session.title || '';
34                this.propertiesForm.set('value',this.session);
35            },
36            onInvite: function() {
37                this._addAccount({ title : this.accountBox.get('value') });
38                this.accountBox.set('value', "");
39            },
40            onSave: function(evt) {
41                lang.mixin(this.session,this.propertiesForm.get('value'));
42                store.put(this.session)
43                .then(function(){
44                    content.goTo('sessions');
45                });
46                event.stop(evt);
47                return false;
48            },
49            onDiscard: function(evt) {
50                this.propertiesForm.reset();
51                event.stop(evt);
52                content.goTo('sessions');
53                return false;
54            },
55            _addAccount: function(item) {
56                this.listView.insertItem(item);
57            },
58            _setupListView: function() {
59                this.listView = new AccountListView( {
60                    controller: this
61                }).placeAt(this.listViewNode);
62                this.listView.startup();
63            },
64            _setupAutoComplete: function() {
65
66                var accountStore = new ElasticReadStore({
67                    url: "http://localhost:9200/rft/_search",
68                    requestMethod: "POST"
69                });
70                var accountText = new FilteringSelect({
71                    name: "accountBox",
72                    store: accountStore,
73                    autoComplete: false,
74                    required: true,
75                    labelType: "text",
76                    placeHolder: "Enter email address here...",
77                    pageSize: 10,
78                    hasDownArrow: false,
79                    style: "width: 400",
80                    searchAttr: "title",
81                    id: "accountText"
82                }, "accountBox");
83                accountText.startup();
84            }
85
86
87                });
88});
89
Note: See TracBrowser for help on using the repository browser.