1 | define([ |
---|
2 | 'dojo/_base/array', |
---|
3 | 'dojo/_base/declare', |
---|
4 | 'dojo/_base/Deferred', |
---|
5 | 'dojo/_base/event', |
---|
6 | 'dojo/_base/lang', |
---|
7 | '../search', |
---|
8 | '../store', |
---|
9 | '../app/Page', |
---|
10 | '../app/Router', |
---|
11 | '../ui/ThresholdFilteringSelect', |
---|
12 | '../ui/lists/AccountListView', |
---|
13 | 'dojo/text!./session.html' |
---|
14 | ],function(array,declare,Deferred,event,lang,search,store,Page,Router,ThresholdFilteringSelect,AccountListView,template){ |
---|
15 | return declare([Page],{ |
---|
16 | templateString: template, |
---|
17 | session: null, |
---|
18 | _accountList: null, |
---|
19 | _select: null, |
---|
20 | startup: function() { |
---|
21 | if ( this._started ) { return; } |
---|
22 | this.inherited(arguments); |
---|
23 | if ( this.sessionId ) { |
---|
24 | this._loadSession(); |
---|
25 | this._setupAutoComplete(); |
---|
26 | } else { |
---|
27 | throw "No valid uid or session passed!"; |
---|
28 | } |
---|
29 | }, |
---|
30 | _loadSession: function() { |
---|
31 | if ( this.sessionId === "new" ) { |
---|
32 | this.session = { |
---|
33 | type: 'SessionTemplate' |
---|
34 | }; |
---|
35 | } else { |
---|
36 | Deferred.when(store.get(this.sessionId)) |
---|
37 | .then(lang.hitch(this,function(obj){ |
---|
38 | this.session = obj; |
---|
39 | this._setupAccountList(); |
---|
40 | this._refresh(); |
---|
41 | })); |
---|
42 | } |
---|
43 | }, |
---|
44 | _refresh: function() { |
---|
45 | this.titleNode.innerHTML = this.session.title || ''; |
---|
46 | this.propertiesForm.set('value',this.session); |
---|
47 | }, |
---|
48 | onInvite: function() { |
---|
49 | this._addAccount(this._select.item.i); |
---|
50 | this._select.reset(); |
---|
51 | }, |
---|
52 | onSave: function(evt) { |
---|
53 | lang.mixin(this.session,this.propertiesForm.get('value')); |
---|
54 | this.session.accounts = array.map(this._accountList.getItems(),function(item){ |
---|
55 | return store.getIdentity(item); |
---|
56 | }); |
---|
57 | store.put(this.session) |
---|
58 | .then(function(){ |
---|
59 | Router.go('/sessions'); |
---|
60 | }); |
---|
61 | event.stop(evt); |
---|
62 | return false; |
---|
63 | }, |
---|
64 | onDiscard: function(evt) { |
---|
65 | this.propertiesForm.reset(); |
---|
66 | event.stop(evt); |
---|
67 | Router.go('/sessions'); |
---|
68 | return false; |
---|
69 | }, |
---|
70 | _addAccount: function(item) { |
---|
71 | this._accountList.insertItem(item); |
---|
72 | }, |
---|
73 | _setupAccountList: function() { |
---|
74 | this._accountList = new AccountListView().placeAt(this.accountListNode); |
---|
75 | this._accountList.startup(); |
---|
76 | for (var account in this.session.accounts) { |
---|
77 | this._accountList.insertItem(this.session.accounts[account]); |
---|
78 | } |
---|
79 | }, |
---|
80 | _setupAutoComplete: function() { |
---|
81 | this._select = new ThresholdFilteringSelect({ |
---|
82 | store: search, |
---|
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 | }, this.accountSelector); |
---|
92 | this._select.startup(); |
---|
93 | } |
---|
94 | |
---|
95 | |
---|
96 | }); |
---|
97 | }); |
---|
98 | |
---|