Skip to content

Instantly share code, notes, and snippets.

@rsobers
Created August 23, 2011 15:21
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/1165409 to your computer and use it in GitHub Desktop.
Save rsobers/1165409 to your computer and use it in GitHub Desktop.
Estimate and Elapsed Warning
name: Estimate and Elapsed Warning
description: Warn user to enter estimated and elapsed time
author: Rob Sobers
version: 1.0.0.0
js:
if (!window.clickBugSubmit) return;
window.clickBugSubmit = (function(fnOrig) {
return function(e, elForm, fXMLSubmit, sValue, bOK) {
if(bOK) {
var fHasPriorEstimate = ((goBug.hrsOrigEst + goBug.hrsCurrEst) > 0);
var fHasNewEstimate = $('#hrsCurrEstNew').val().length > 0;
var fHasEstimate = (fHasPriorEstimate || fHasNewEstimate);
var hrsElapsed = stripNonNumeric($("#hrsElapsedExtraNew").val());
var fElapsedChanged = (goBug.hrsElapsed != hrsElapsed);
var sWarning = "";
if (!fHasEstimate) {
var sWarning =
"You have not entered an estimate for this case!\n\n" +
"Do you want to save anyway?";
} else if (!fElapsedChanged && fHasPriorEstimate) {
var sWarning =
"The elapsed time has not been updated for " +
"this case!\n\n" +
"Do you want to save anyway?";
}
if (sWarning.length > 0 && !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