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