Skip to content

Instantly share code, notes, and snippets.

@imjoshdean
Last active January 8, 2016 16:57
Show Gist options
  • Save imjoshdean/12f79a935a48355f5685 to your computer and use it in GitHub Desktop.
Save imjoshdean/12f79a935a48355f5685 to your computer and use it in GitHub Desktop.
WindowState close function that works with arrays of windows.
var WindowState = Construct.extend({ }, {
/*
Example usage:
WindowState.close('preferences');
WindowState.close('debug', true);
WindowState.close('notification', true, function(win) {
return win.callID = 12345;
});
*/
close: function(win, force, predicate) {
if(this[win]) {
if(can.isArray(this[win])) {
// if no predicate is defined, _.filter will return the entire list
_.filter(this[win], predicate).forEach(this.proxy(function(item) {
var index = this[win].indexOf(item);
item.close(true);
this[win].splice(index, 1);
}));
}
else {
this[win].close(true);
this[win] = undefined;
}
return true;
}
if(win.id) {
if(this.main && this.main.id === win.id) {
this.savePosition('main');
if (force) {
// log out from CAS and close window
Endo.CAS.logout();
ExoUtils.stopPresenter();
win.close();
} else {
this.hide(win);
}
} else if (this.preferences && this.preferences.id === win.id) {
// preferences data last update before closing
if (Endo.PreferencesActionThread) {
Endo.PreferencesActionThread.finalUpdate(
this.proxy(function(win) {
win.close();
},
win));
}
} else {
win.close();
}
return true;
}
return false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment