Created
August 16, 2011 17:34
-
-
Save rsobers/1149641 to your computer and use it in GitHub Desktop.
BugMonkey script to warn user to update elapsed time when saving a case
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 sWarning = "The elapsed time has not been updated for " | |
+ "this case!\n\n" | |
+ "Do you want to save anyway?"; | |
var fHasEstimate = ((goBug.hrsOrigEst + goBug.hrsCurrEst) > 0); | |
if (!fHasEstimate) return; | |
if (!window.clickBugSubmit) return; | |
window.clickBugSubmit = (function(fnOrig) { | |
return function(e, elForm, fXMLSubmit, sValue, bOK) { | |
if (bOK) { | |
var hrsElapsed = stripNonNumeric($("#hrsElapsedExtraNew").val()); | |
var fElapsedChanged = (goBug.hrsElapsed != hrsElapsed); | |
if (!fElapsedChanged && !confirm(sWarning)) { | |
return cancel(e); | |
} | |
} | |
return fnOrig.apply(this, arguments); | |
}; | |
})(window.clickBugSubmit); | |
// This function removes non-numeric characters | |
function stripNonNumeric(str) { | |
str += ''; | |
var rgx = /^\d|\.|-$/; | |
var out = ''; | |
for (var i = 0; i < str.length; i++) { | |
if (rgx.test(str.charAt(i))) { | |
if (!((str.charAt(i) == '.' && out.indexOf('.') != -1) || (str.charAt(i) == '-' && out.length != 0))) { | |
out += str.charAt(i); | |
} | |
} | |
} | |
return out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment