Created
April 16, 2014 09:18
-
-
Save piecyk/10839308 to your computer and use it in GitHub Desktop.
This file contains 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 _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