Subversion Repositories DevTools

Rev

Rev 183 | Rev 1339 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
 *    COMMON JAVASCRIPTS
 */

<!--
var clickedButton = false;
function check() {
   if (clickedButton) {
       clickedButton = false;
        return true;
    } else {
       return false;
   }
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;
  if(!d) d=document;
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
     d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) x=d.all[n];
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n);
  return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_jumpMenu(targ,selObj,restore){ //v3.1
  if (selObj.options[selObj.selectedIndex].value) {
     eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
     if (restore) selObj.selectedIndex=0;
  }
}

function Cascaded_Menu(targ,url,selObj,restore){ //v3.1
  if (selObj.options[selObj.selectedIndex].value) {
     eval(targ+".location='"+url+selObj.options[selObj.selectedIndex].value+"'");
     if (restore) selObj.selectedIndex=0;
  }
}

function MM_validateForm() { //v5.0
   var i,p,pl,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
   var REresults;
   var pass,passc;



   // Other general validations
   var cleanStrRE = /^[0-9a-z_\.\(\)\-]+$/i;
   var pkgRE = /^[a-z][a-z0-9_-]*[a-z0-9]$/i;
   var versionRE = /^[0-9a-z_\.\(\)\-]+$/i;
   var versionNumberRE = /^\d+\.\d+\.\d+$/;
   var re_patch_ver_format = /^\d+\.\d+\.\d+\.p\d+\.[a-zA-Z0-9]+$/;
   var urlRE = "^https?://[a-z1-9]";
   //character range disallowed
   var HTMLchr = /[\<\>\'\"]+/i;
   var alphanumRE = /^[a-z0-9]+$/i;

   for (i=0; i<(args.length-2); i+=3) {
      test=args[i+2];
      val=MM_findObj(args[i]);

      if (val) {
         nm=args[i+1];
         val=val.value;



         if (val!="") {
            if (test.indexOf('isEmail')!=-1) {
               p=val.indexOf('@');
               if (p<1 || p==(val.length-1) || test.charAt(0) == '@') errors+='- '+nm+' must contain an e-mail address.\n';
            }

            if (test.indexOf('isDate') != -1) {
               if (val.indexOf("/") != -1) {
                  tmpARR = val.split("/");
                  if (tmpARR.length == 3) {
                     if (!(tmpARR[0]>0  && tmpARR[0]<32  && tmpARR[1]>0 && tmpARR[1]<13 && tmpARR[2]>1900 && tmpARR[2]<9999)) {
                        errors += '- '+nm+' must be in DD/MM/YYYY format.\n';
                     }
                  } else {
                     errors += '- '+nm+' must be in DD/MM/YYYY format.\n';
                  }
               } else {
                  errors += '- '+nm+' must be in DD/MM/YYYY format.\n';
               }
            }

            if (test.indexOf('isPackage')!=-1) {
               REresults = val.search(pkgRE);
               if (REresults < 0) errors += val += ' - '+nm+' is not valid. Valid characters are A-Z a-z 0-9 - _\n'
                        + 'Names must start with a letter and cannot contain spaces or symbols other than - and _\n';
            }

            if (test.indexOf('isCleanStr')!=-1) {
               REresults = val.search(cleanStrRE);
               if (REresults < 0) errors += val += '- '+nm+' uses invalid character. Allowed characters are A-Z a-z 0-9 . - _\n';
            }

            if (test.indexOf('isVersionStr')!=-1) {
               REresults = val.search(versionRE);
               if (REresults < 0) errors += val += '- '+nm+' uses invalid character. Allowed characters are A-Z a-z 0-9 . - _\n';
            }

            if (test.indexOf('isPatchVersionStr')!=-1) {
               if ( !re_patch_ver_format.test(val) ) {
                  errors += val += '- '+nm+' is not of form (integer).(integer).(integer).p(integer).(extension)\n';
               }
            }

            if (test.indexOf('isCCPath')!=-1) {
               var CCPathRE = /^\\|\/[a-z]+[0-9a-z_\.\-\\\/ ]+$/i;

               REresults = val.search(CCPathRE);
               if (REresults < 0) errors += val += '- '+nm+' uses invalid character.\nAllowed characters are \\ / A-Z a-z 0-9 . - _ SPACE\nAnd the path must begin with \\ or /';
            }

            if (test.indexOf('isCCLabel')!=-1) {
               var CCLabelRE = /^[0-9a-z_\.\-]+$/i;

               REresults = val.search(CCLabelRE);
               if (REresults < 0) errors += val += '- '+nm+' uses invalid character. Allowed characters are A-Z a-z 0-9 . - _\n';
            }

            if (test.indexOf('isSVNTag')!=-1) {
               // Subversion TAG validation
               var SVNTagValidCharsRE = /^[0-9a-z_\.\-\/\@]+$/i;
               var SVNTagInValidTrunkAnywhereRE = /\/trunk\//i;
               var SVNTagInValidAt = /@[0-9]*[^0-9$]+/i;
               var SVNTagInValidSlashAtBOL = /^\/.*$/i;
               var SVNTagInValidTrunkRE = /\/trunk[^@]+/i;
               var SVNTagInValidSlashAt = /\/@/i;
               var SVNTagInValidAtSlash = /@\//i;
               var SVNTagInValidSlash = /^.*\/\/.*$/i;
               var SVNTagValidTagAnywhereRE = /^.*\/tags\/.*$/i;
               var SVNTagValidBranchAnywhereRE = /^.*\/branches\/.*$/i;
               var SVNTagValidTrunkAtNumberRE = /^.*\/trunk@[0-9]+$/i;

               if (val.search(SVNTagValidCharsRE) < 0)
                  errors += val += ' - '+nm+' uses invalid character. Allowed characters are / A-Z a-z 0-9 . - _ @\n';
               else {
                  if (val.search(SVNTagInValidTrunkAnywhereRE) >= 0)
                     errors += val += ' - '+nm+' contains /trunk/. This is not allowed.\n';
                  else {
                     if (val.search(SVNTagInValidAt) >= 0)
                        errors += val += ' - '+nm+' contains an @ symbol that is not followed by a numeric value and the end of the line.\n';
                     else {
                        if (val.search(SVNTagInValidSlashAtBOL) >= 0)
                           errors += val += ' - '+nm+' begins with a /. This is not allowed.\n';
                        else {
                           if (val.search(SVNTagInValidTrunkRE) >= 0)
                              errors += val += ' - '+nm+' contains invalid /trunk. This must be followed by an @<number>.\n';
                           else {
                              if ((val.search(SVNTagInValidSlashAt) >= 0) || (val.search(SVNTagInValidAtSlash) >= 0))
                                 errors += val += ' - '+nm+' contains /@ or @/. This is not allowed.\n';
                              else {
                                 if (val.search(SVNTagInValidSlash) >= 0)
                                    errors += val += ' - '+nm+' uses //. This is not allowed.\n';
                                 else {
                                    var count_valid_forms = 0;

                                    if (val.search(SVNTagValidTrunkAtNumberRE) >= 0) count_valid_forms++;

                                    if (val.search(SVNTagValidBranchAnywhereRE) >= 0) count_valid_forms++;

                                    if (val.search(SVNTagValidTagAnywhereRE) >= 0) count_valid_forms++;

                                    if (count_valid_forms == 0) errors += val += ' - '+nm+' does not end in /trunk@<number>,\nor does not contain /tags/ or /branches/\n';

                                    if (count_valid_forms > 1) errors += val += ' - '+nm+' cannot combine use of trunk, /tags/, or /branches/ in one subversion tag\n';
                                 }
                              }
                           }
                        }
                     }
                  }
               }
            }

            if (test.indexOf('isVersionNumber')!=-1) {
               REresults = val.search(versionNumberRE);
               if (REresults < 0) errors += val += ' - '+nm+' is formatted incorrectly.\nVersion number should be (major).(minor).(patch)(build)\ne.g. 1.0.2002\n';
            }

            if (test.indexOf('isURL')!=-1) {
               REresults = val.match(urlRE);
               if (REresults == null) errors += '"'+val+'" is not a valid URL.\n';
            }

            if (test.indexOf('isAlphaNum')!=-1) {
               REresults = val.match(alphanumRE);
               if (REresults == null) errors += '"'+nm+'" must be an alphanumeric value.\n';
            }

            if (test.indexOf('isChangePassword')!=-1) {
               pass=MM_findObj('FRpassword');
               passc=MM_findObj('FRpasswordc');
               if (pass.value!=passc.value) errors+='- Password confirmation does not match.\n';
            }

            if (test.indexOf('maxLength')!=-1) {
               p=test.indexOf(':');
               max=test.substring(p+1);
               if (val.length>max) errors+='- '+nm+' can be maximum '+max+' characters long.\n';
            }

            if (test.indexOf('notHTML')!=-1) {
               if (val.match(HTMLchr)) errors+='- '+nm+' has invalid characters like \'< > quotes\'\n';
            }

            if (test.charAt(0)=='R') {

               if (test.indexOf('isNumber') != -1) {
                  if (isNaN(val)) errors+='- '+nm+' must be a number.\n';
               }

               if (test.indexOf('inRange') != -1) {
                  p=test.indexOf(':');
                  min=test.substring(8,p);
                  max=test.substring(p+1);
                  if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
               }

               if (test.indexOf('inLength')!=-1) {
                   pl=test.indexOf('inLength')
                  p=test.indexOf(':');
                      min=test.substring(pl+8,p);
                      if (val.length<min) errors+='- '+nm+' must be at least '+min+' characters long.\n';
                }
            }
         } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n';


         if (test.indexOf('isPassword')!=-1) {
            pass=MM_findObj('FRpassword');
            passc=MM_findObj('FRpasswordc');
            if (!MM_findObj('FRdomainauth').checked) {
               if (test.indexOf('inLength')!=-1) {
                   pl=test.indexOf('inLength')
                  p=test.indexOf(':');
                      min=test.substring(pl+8,p);
                      if (val.length<min) errors+='- '+nm+' must be at least '+min+' characters long.\n';
                }
               if (pass.value!=passc.value) errors+='- Password confirmation does not match.\n';
            } else {
               if (MM_findObj('FRdomain_name').value=="") errors += '- Domain Name is required.\n';
            }
         }

         if (test.indexOf('isDomainName')!=-1) {
            if (MM_findObj('FRdomainauth').checked) {
               if (MM_findObj('FRdomain_name').value=="") errors += '- Domain Name is required.\n';
            }
         }

      }
   }

   if (errors) {
      alert('The following error(s) occurred:\n\n'+errors);
      clickedButton=false;
   } else {
      clickedButton=true;
   }
   document.MM_returnValue = (errors == '');

   if (MM_findObj('ProgressBar') && document.MM_returnValue) MM_findObj('ProgressBar').style.visibility='visible';
}

function isChecked(boxName, buttonId) {
  var formButton = document.getElementById(buttonId);
  var boxes = document.getElementsByName(boxName);
  var btnChecked = false;
  if (formButton) {
    for (var i = 0; i < boxes.length; i++) {
      if (boxes[i].checked) {
        btnChecked = true;
      }
    }

    if (btnChecked) {
      formButton.disabled = false;
      formButton.style.color="";
    }
    else {
      formButton.disabled = true;
      formButton.style.color="silver";
    }
  }
}

function confirmDelete(m)
{
   var agree=confirm('Are you sure you want to delete '+m+'?');
   if (agree) {
      if (MM_findObj('ProgressBar')) MM_findObj('ProgressBar').style.visibility='visible';
      return true;
   } else {
      return false;
   }
}

function confirmAction(m)
{
   var agree=confirm(m);
   if (agree) {
      if (MM_findObj('ProgressBar')) MM_findObj('ProgressBar').style.visibility='visible';
      return true;
   } else {
      return false;
   }
}

function DisplaySPAN(show) {
   if (show) {
      MM_findObj("spanHideDetails").style.display = "block";
      MM_findObj("spanPkgInfo").style.display = "block";
      MM_findObj("spanShowDetails").style.display = "none";
   } else {
      MM_findObj("spanHideDetails").style.display = "none";
      MM_findObj("spanPkgInfo").style.display = "none";
      MM_findObj("spanShowDetails").style.display = "block";
   }
}

function ToggleDisplay () {
   var i, args, div_name, visibility
   args=ToggleDisplay.arguments;
   for (i=0; i<(args.length); i+=1) {
      div_name=args[i];
      if ( MM_findObj(div_name).style.display == 'block' ) {
         MM_findObj(div_name).style.display = 'none';
      } else {
         MM_findObj(div_name).style.display = 'block';
      }

   }
}

function Visible () {

   var i, args, div_name, visibility
   args=Visible.arguments;
   for (i=0; i<(args.length); i+=2) {
      div_name=args[i];
      visibility=args[i+1]
      MM_findObj(div_name).style.display = visibility;

   }
}

function DisplayObjects () {
   var i, args, div_name
   args=DisplayObjects.arguments;
   for (i=0; i<(args.length); i+=1) {
      div_name=args[i];
      MM_findObj(div_name).style.display = 'block';
   }
}

function GetCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1) { endstr = document.cookie.length; }
   return unescape(document.cookie.substring(offset, endstr));
}


function GetCookie (name) {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;

   while (i < clen) {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg) return GetCookieVal (j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break;
   }

   return null;
}

function go_submit( formname, actionname )
{
   formname.action.value = actionname;
   formname.submit();
}

function ExpandAll()
{
   var elem

   if (document.all)
   {
      // Run this for IE
      elem = document.all;
   } else {
      // Run this for other browsers
      elem = document.getElementsByTagName('div');
   }

   for (i in elem)
   {
      if (elem[i].id)
      {
         if (elem[i].id.indexOf('SHORT_') == 0) elem[i].style.display = 'none';
         if (elem[i].id.indexOf('FULL_') == 0) elem[i].style.display = 'block';
      }
   }

}

function CollapseAll()
{
   var elem

   if (document.all)
   {
      // Run this for IE
      elem = document.all;
   } else {
      // Run this for other browsers
      elem = document.getElementsByTagName('div');
   }

   for (i in elem)
   {
      if (elem[i].id)
      {
         if (elem[i].id.indexOf('SHORT_') == 0) elem[i].style.display = 'block';
         if (elem[i].id.indexOf('FULL_') == 0) elem[i].style.display = 'none';
      }
   }

}


function height()
{
   if( typeof( window.innerWidth ) == 'number' )
   {
      h = window.innerHeight;
   }
   else if(document.documentElement&&(document.documentElement.clientHeight ))
   {
      h = document.documentElement.clientHeight;
   }
   else if( document.body &&   ( document.body.clientWidth || document.body.clientHeight ) )
   {
      h = document.body.clientHeight;
   }

   var e = document.getElementById("LayerDescription");

   if (navigator.userAgent.indexOf('Internet Explorer'))
   {
      e.style.height = h - 350 + "px";
      e.style.overflow = "auto";
   }
   else
   {
      // This line shouldn't be run by IE; it doesn't seem to work. It gets run in Firefox, etc.
      e.style.minHeight= h - 350 + "px";
      e.style.overflow = "auto";
   }
}

//////////////////////////////////////////////////////////////////////////////////////////////////
//
// MM_ValidateVersion(pkgName, versionBase, versionExt, isAutobuild)
//
//    pkgName       eg EA_DocGen
//    versionBase   eg 1.2.3
//    versionExt   eg .cr
//    isAutobuild   true or false
//    isPatch       true or false
//
// Returns true if version is valid, else false
//
// This function can and should be used instead of MM_validateForm to validate
// version numbers for new or reversioned package versions.
//
// So far, this function is used in the following situations:
//    1) Add new version to release (_form_new_version_page.asp)
//    2) Reversion existing version (_wform_rename_version.asp)
//    3) Add package to release (Form_add_pkg_versions.asp)
//////////////////////////////////////////////////////////////////////////////////////////////////
function MM_ValidateVersion(pkgName, versionBase, versionExt, isAutobuild, isPatch)
{
   var errString = MM_ValidateVersionReturningErrString(pkgName, versionBase, versionExt, isAutobuild, isPatch);
   if (errString.length > 0)
   {
      alert(errString);
      return false;
   }
   return true;
}

//////////////////////////////////////////////////////////////////////////////////////////////////
//
// MM_ValidateVersionReturningErrString(pkgName, versionBase, versionExt, isAutobuild)
//
//    pkgName       eg buildtool
//    versionBase   eg 1.2.3
//    versionExt   eg .cr
//    isAutobuild   true or false
//    isPatch       true or false
//
// Returns a non-zero-length error string if version is NOT valid, else returns a zero-length string
//
// The MM_validateForm function should be modified to use this if possible, although I currently
// do not believe it has access to all the necessary parameter values needed.
//
//////////////////////////////////////////////////////////////////////////////////////////////////
function MM_ValidateVersionReturningErrString(pkgName, versionBase, versionExt, isAutobuild, isPatch)
{
   var re_std_ver_format   = /^\d+\.\d+\.\d+$/;
   var re_patch_ver_format = /^\d+\.\d+\.\d+\.p\d+$/;
   var re_cots_ver_format  = /^[\w]+[\w\.\-]*$/;   // starts with letter or digit or underscore, subsequent chars can be letters or digits or _ or . or -
   var re_cots_ver_format_exc1 = /[-_.]+[-_.]+/;   // look for any two adjacent special characters
   var re_cots_ver_format_exc2 = /[0-9A-Za-z]+/;   // look for any alphanumeric char

   var forPkgName = "";
   if (pkgName != null && pkgName.length > 0)
   {
      forPkgName = ", for package " + pkgName;
   }

   if (!isAutobuild)
   {
      if ( versionBase.length == 0 )
      {
         return "Action failed: version number is of zero length" + forPkgName;
      }
      else if ( versionExt != ".cots" )
      {
         if ( isPatch )
         {
            if ( !re_patch_ver_format.test(versionBase) )
            {
               return "Action failed: patch version is not of form (integer).(integer).(integer).p(integer).(extension)" + forPkgName;
            }
         }
         else
         {
            if ( !re_std_ver_format.test(versionBase) )
            {
               return "Action failed: version is not of form (integer).(integer).(integer).(extension)" + forPkgName;
            }
         }
      }
      else if ( versionExt == ".cots")
      {
         if ( !re_cots_ver_format.test(versionBase) )
         {
            return "Action failed: COTS version must begin with letter/digit/underscore, cannot contain any whitespace, and only special characters underscore/dash/dot are allowed" + forPkgName;
         }

         if ( re_cots_ver_format_exc1.test(versionBase) )
         {
            return "Action failed: COTS version cannot contain two adjacent special characters (underscore/dash/dot)" + forPkgName;
         }

         if ( !re_cots_ver_format_exc2.test(versionBase) )
         {
            return "Action failed: COTS version must contain one or more alphanumeric characters" + forPkgName;
         }
      }
   }

   // everything ok - no error
   return "";
}



//-->