Skip to content

Instantly share code, notes, and snippets.

@piecyk
Created April 16, 2014 09:18
Show Gist options
  • Save piecyk/10839308 to your computer and use it in GitHub Desktop.
Save piecyk/10839308 to your computer and use it in GitHub Desktop.
var _DC_ID = null;
function _getRetMsg() {
var ret = '';
switch ($state.current.name) {
case 'workspace.datacard.edit':
case 'bg-data.module.datacard.edit':
_DC_ID = $stateParams.id;
ret = 'dc edit ws';
break;
case 'workspace.datacard.transform':
case 'bg-data.module.datacard.transform':
_DC_ID = $stateParams.dcId;
ret = 'dc edit transform';
break;
}
return ret;
}
window.addEventListener('beforeunload', function(e) {
var confirmationMessage = _getRetMsg();
if (confirmationMessage !== '') {
if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
$injector.get('DataCardService').releaseLockDc(null, _DC_ID);
setTimeout( function() {
$injector.get('DataCardService').lockDc(null, _DC_ID);
});
}
(e || window.event).returnValue = confirmationMessage; //Gecko + IE
return confirmationMessage; //Webkit, Safari, Chrome etc.
}
});
window.addEventListener('unload', function(e) {
$injector.get('DataCardService').releaseLockDc(null, _DC_ID);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment