Skip to content

Instantly share code, notes, and snippets.

@rsobers
Created August 16, 2011 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsobers/1149641 to your computer and use it in GitHub Desktop.
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
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