1 | define(['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 | this.session.accounts.push(item); |
---|
58 | this._listView.insertItem(item); |
---|
59 | }, |
---|
60 | _removeAccount: function(item) { |
---|
61 | this.session.accounts.splice(this.session.accounts.indexOf(item), 1); |
---|
62 | }, |
---|
63 | _setupListView: function() { |
---|
64 | this._listView = new AccountListView( { |
---|
65 | controller: this, |
---|
66 | removeCallback: lang.hitch(this, this._removeAccount) |
---|
67 | }).placeAt(this.listViewNode); |
---|
68 | for (account in this.session.accounts) { |
---|
69 | this._listView.insertItem(this.session.accounts[account]); |
---|
70 | } |
---|
71 | |
---|
72 | this._listView.startup(); |
---|
73 | }, |
---|
74 | _setupAutoComplete: function() { |
---|
75 | |
---|
76 | var accountStore = new ElasticReadStore({ |
---|
77 | url: "http://localhost:9200/rft/_search", |
---|
78 | requestMethod: "POST" |
---|
79 | }); |
---|
80 | this._select = new ElasticSearchFilteringSelect({ |
---|
81 | name: "accountBox", |
---|
82 | store: accountStore, |
---|
83 | autoComplete: false, |
---|
84 | required: false, |
---|
85 | labelType: "text", |
---|
86 | placeHolder: "Enter email address here...", |
---|
87 | pageSize: 10, |
---|
88 | hasDownArrow: false, |
---|
89 | style: "width: 400", |
---|
90 | searchAttr: "title", |
---|
91 | id: "accountText" |
---|
92 | }, "accountBox"); |
---|
93 | this._select.startup(); |
---|
94 | } |
---|
95 | |
---|
96 | |
---|
97 | }); |
---|
98 | }); |
---|
99 | |
---|