Subpanel top refresh causes spurious contents in the subpanel list?

I have some strange behavior I don't understand, and I don't like not understanding...

When the Case loads, the Emails subpanel displays emails that have nothing to do with the case... and then seems to filter them down to what's actually supposed to be there.
But what's worse, for some users, the spurious emails persist thus muddling up the subpanel with unrelated emails...

I seem to have tracked this down to a custom script I put in last night, but it doesn't make sense to me that this would be the cause... yet removing it seems to fix the problem...

Background:

In the Cases module I have the standard Emails subpanel with some custom Panel-Top buttons one of which is "Internal Compose"
The "Internal Compose" opens the email drawer and puts some template data in the body of the Email with information from the Case, and sets the To addresses to the Engineers on the Case as found in the "Engineers" subpanel on the Case. Engineers are Users (custom N-M relationship Cases-Users).

So far so good.

When I add an Engineer from the subpanel (Link and existing User) and click the Custom Compose, the Engineer I just added is not included in the To.

This is clearly explained by the fact that the API that builds the data for the Panel-top button on Email has already run when the Emails subpanel was loaded. So the thought is, reload the Panel-top on Email when an Engineer is added. Simple right?

To solve this issue I wanted to refresh Emails Panel-Top when the Engineer subpanel list view is re-rendered (with the new Engineer we just added).

I therefore added a script to do this.
 custom/Users/clients/base/views/subpanel-list/subpanel-list.js

({  extendsFrom: 'SubpanelListView',
  initialize: function(options){
    this._super('initialize',[options]);
    this.on('render', this.refreshEmailPanelTop, this);
  },
  // force reload of emails subpanel on Cases module for internal compose with 
  // just added engineers.
  refreshEmailPanelTop: function() {
    var module = this.context.parent.get('module');
    if(module == 'Cases'){
      this.context.parent.trigger('panel-top:refresh', 'archived_emails');
    }
  },
})  

BUT (why is there always a but...??), as I said above, when the Case loads, the Emails subpanel loads emails that have nothing to do with the case... and then seems to filter them down to what's actually supposed to be there.
And what's worse, for some users, the spurious emails persist thus muddling up the subpanel with unrelated emails...

Does it make any sense that the script above would cause this?

thanks,
FrancescaS
Parents Reply Children