Last active
January 8, 2016 16:57
-
-
Save imjoshdean/12f79a935a48355f5685 to your computer and use it in GitHub Desktop.
WindowState close function that works with arrays of windows.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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