diff --git a/app.js b/app.js index 7cebaca..f9fc67a 100644 --- a/app.js +++ b/app.js @@ -2,8 +2,8 @@ return { events: { // App - 'app.activated': 'onAppActivation', - 'ticket.requester.email.changed': 'onAppActivation', + 'app.created': 'init', + 'ticket.requester.email.changed': 'onRequesterEmailChanged', // Requests 'getUser.done': 'onGetUserDone', @@ -245,8 +245,7 @@ // EVENTS ================================================================== - // we use throttle because of race conditions when this fires twice in quick succession - onAppActivation: _.throttle(function() { + init: function() { var defaultStorage = { user: null, ticketsCounters: {}, @@ -264,19 +263,24 @@ var defaultOrgSelection = '[]'; this.storage.selectedOrgKeys = JSON.parse(this.setting('orgFields') || defaultOrgSelection); if (!this.locale) { this.countedAjax('getCurrentUserLocale'); } - _.defer((function() { - if (this.ticket().requester()) { - this.countedAjax('getUser', this.ticket().requester().id()); - this.countedAjax('getUserFields'); - if (!this.storage.locales) { - this.countedAjax('getLocales'); - } + if (this.ticket().requester()) { + this.requesterEmail = this.ticket().requester().email(); + this.countedAjax('getUser', this.ticket().requester().id()); + this.countedAjax('getUserFields'); + this.countedAjax('getOrganizationFields'); + if (!this.storage.locales) { + this.countedAjax('getLocales'); } - else { - this.switchTo('empty'); - } - }).bind(this)); - }, 1000, {leading: false}), + } else { + this.switchTo('empty'); + } + }, + + onRequesterEmailChanged: function(event, email) { + if (email && this.requesterEmail != email) { + this.init(); + } + }, onRequestsFinished: function() { if (!this.storage.user) return; @@ -333,7 +337,7 @@ this.$('.save').hide(); this.$('.wait-spin').show(); this.ajax('saveSelectedFields', keys, orgKeys) - .always(this.onAppActivation.bind(this)); + .always(this.init.bind(this)); }, onNotesOrDetailsChanged: _.debounce(function(e) { diff --git a/manifest.json b/manifest.json index fb35198..f88b2da 100644 --- a/manifest.json +++ b/manifest.json @@ -24,7 +24,10 @@ "defaultLocale": "en", "private": false, "singleInstall": true, - "location": ["ticket_sidebar", "new_ticket_sidebar"], + "location": [ + "ticket_sidebar", + "new_ticket_sidebar" + ], "frameworkVersion": "1.0", - "version": "1.0.3" + "version": "1.0.6" }