Subversion Repositories DevTools

Rev

Rev 3892 | Rev 3895 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
119 ghuddy 1
/*
129 ghuddy 2
 *    COMMON JAVASCRIPTS
119 ghuddy 3
 */
4
 
5
<!--
6
var clickedButton = false;
7
function check() {
129 ghuddy 8
   if (clickedButton) {
9
       clickedButton = false;
119 ghuddy 10
        return true;
11
    } else {
129 ghuddy 12
       return false;
13
   }
119 ghuddy 14
}
15
 
16
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
17
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
18
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
19
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
20
}
21
MM_reloadPage(true);
22
 
23
function MM_preloadImages() { //v3.0
24
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
25
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
26
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
27
}
28
 
29
function MM_swapImgRestore() { //v3.0
30
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
31
}
32
 
33
function MM_findObj(n, d) { //v4.0
121 hknight 34
  var p,i,x;
35
  if(!d) d=document;
119 ghuddy 36
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
129 ghuddy 37
     d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
119 ghuddy 38
  }
121 hknight 39
  if(!(x=d[n])&&d.all) x=d.all[n];
119 ghuddy 40
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
41
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
121 hknight 42
  if(!x && document.getElementById) x=document.getElementById(n);
119 ghuddy 43
  return x;
44
}
45
 
46
function MM_swapImage() { //v3.0
47
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
48
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
49
}
50
 
51
function MM_openBrWindow(theURL,winName,features) { //v2.0
2546 dpurdie 52
  window.open(theURL,winName,'left=20,top=20,'+features);
119 ghuddy 53
}
54
 
55
function MM_jumpMenu(targ,selObj,restore){ //v3.1
56
  if (selObj.options[selObj.selectedIndex].value) {
129 ghuddy 57
     eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
58
     if (restore) selObj.selectedIndex=0;
119 ghuddy 59
  }
60
}
61
 
62
function Cascaded_Menu(targ,url,selObj,restore){ //v3.1
63
  if (selObj.options[selObj.selectedIndex].value) {
129 ghuddy 64
     eval(targ+".location='"+url+selObj.options[selObj.selectedIndex].value+"'");
65
     if (restore) selObj.selectedIndex=0;
119 ghuddy 66
  }
67
}
68
 
69
function MM_validateForm() { //v5.0
1372 dpurdie 70
   var ii,p,pl,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
129 ghuddy 71
   var REresults;
72
   var pass,passc;
3894 dpurdie 73
   var showAlert = true;
121 hknight 74
 
129 ghuddy 75
   // Other general validations
76
   var cleanStrRE = /^[0-9a-z_\.\(\)\-]+$/i;
77
   var pkgRE = /^[a-z][a-z0-9_-]*[a-z0-9]$/i;
78
   var versionRE = /^[0-9a-z_\.\(\)\-]+$/i;
79
   var versionNumberRE = /^\d+\.\d+\.\d+$/;
145 ghuddy 80
   var re_patch_ver_format = /^\d+\.\d+\.\d+\.p\d+\.[a-zA-Z0-9]+$/;
129 ghuddy 81
   var urlRE = "^https?://[a-z1-9]";
82
   //character range disallowed
83
   var HTMLchr = /[\<\>\'\"]+/i;
171 brianf 84
   var alphanumRE = /^[a-z0-9]+$/i;
121 hknight 85
 
3894 dpurdie 86
   // Options are first
87
   for (ii=0; ii<(args.length-2) && args[ii].indexOf('--') == 0; ii++) {
88
    switch(args[ii].toLowerCase()) {
89
      case "--silent" :
90
        showAlert = false;
91
        break;
92
    }
93
  }
94
 
95
  // Iterate of arguments
96
  // These are in triplets
97
  //    Name of form object
98
  //    Text Prefix for error
99
  //    Type of Test to Perform
100
   for (; ii<(args.length-2); ii+=3) {
1372 dpurdie 101
      test=args[ii+2];
102
      val=MM_findObj(args[ii]);
121 hknight 103
 
129 ghuddy 104
      if (val) {
1372 dpurdie 105
         nm=args[ii+1];
129 ghuddy 106
         val=val.value;
121 hknight 107
 
129 ghuddy 108
         if (val!="") {
109
            if (test.indexOf('isEmail')!=-1) {
110
               p=val.indexOf('@');
111
               if (p<1 || p==(val.length-1) || test.charAt(0) == '@') errors+='- '+nm+' must contain an e-mail address.\n';
112
            }
121 hknight 113
 
129 ghuddy 114
            if (test.indexOf('isDate') != -1) {
115
               if (val.indexOf("/") != -1) {
116
                  tmpARR = val.split("/");
117
                  if (tmpARR.length == 3) {
118
                     if (!(tmpARR[0]>0  && tmpARR[0]<32  && tmpARR[1]>0 && tmpARR[1]<13 && tmpARR[2]>1900 && tmpARR[2]<9999)) {
119
                        errors += '- '+nm+' must be in DD/MM/YYYY format.\n';
120
                     }
121
                  } else {
122
                     errors += '- '+nm+' must be in DD/MM/YYYY format.\n';
123
                  }
124
               } else {
125
                  errors += '- '+nm+' must be in DD/MM/YYYY format.\n';
126
               }
127
            }
121 hknight 128
 
129 ghuddy 129
            if (test.indexOf('isPackage')!=-1) {
130
               REresults = val.search(pkgRE);
1372 dpurdie 131
               if (REresults < 0) errors += val + ' - '+nm+' is not valid. Valid characters are A-Z a-z 0-9 - _\n'
129 ghuddy 132
                        + 'Names must start with a letter and cannot contain spaces or symbols other than - and _\n';
133
            }
121 hknight 134
 
129 ghuddy 135
            if (test.indexOf('isCleanStr')!=-1) {
136
               REresults = val.search(cleanStrRE);
1372 dpurdie 137
               if (REresults < 0) errors += val + '- '+nm+' uses invalid character. Allowed characters are A-Z a-z 0-9 . - _\n';
129 ghuddy 138
            }
121 hknight 139
 
129 ghuddy 140
            if (test.indexOf('isVersionStr')!=-1) {
141
               REresults = val.search(versionRE);
1372 dpurdie 142
               if (REresults < 0) errors += val + '- '+nm+' uses invalid character. Allowed characters are A-Z a-z 0-9 . - _\n';
129 ghuddy 143
            }
121 hknight 144
 
145 ghuddy 145
            if (test.indexOf('isPatchVersionStr')!=-1) {
146
               if ( !re_patch_ver_format.test(val) ) {
1372 dpurdie 147
                  errors += val + '- '+nm+' is not of form (integer).(integer).(integer).p(integer).(extension)\n';
145 ghuddy 148
               }
149
            }
150
 
129 ghuddy 151
            if (test.indexOf('isCCPath')!=-1) {
152
               var CCPathRE = /^\\|\/[a-z]+[0-9a-z_\.\-\\\/ ]+$/i;
121 hknight 153
 
2362 dpurdie 154
               REresults = val.search(/^(\\|\/)/);
155
               if (REresults < 0) errors += val + '- '+nm+' must begin with \\ or /\n';
156
 
129 ghuddy 157
               REresults = val.search(CCPathRE);
2362 dpurdie 158
               if (REresults < 0) errors += val + '- '+nm+' uses invalid character.\nAllowed characters are \\ / A-Z a-z 0-9 . - _ SPACE\n';
129 ghuddy 159
            }
121 hknight 160
 
129 ghuddy 161
            if (test.indexOf('isCCLabel')!=-1) {
162
               var CCLabelRE = /^[0-9a-z_\.\-]+$/i;
121 hknight 163
 
129 ghuddy 164
               REresults = val.search(CCLabelRE);
2362 dpurdie 165
               if (REresults < 0) errors += val + '- '+nm+' uses invalid character.\nAllowed characters are A-Z a-z 0-9 . - _\n';
129 ghuddy 166
            }
121 hknight 167
 
129 ghuddy 168
            if (test.indexOf('isSVNTag')!=-1) {
1339 dpurdie 169
                // Subversion Tag validation
170
                var SVNTagValidPeg = /^@?\d+$/;
171
                var SVNTagRE = /^[0-9a-z_\.\-]+$/i;
172
 
173
               if ( val.search(SVNTagValidPeg) < 0) {
174
 
1372 dpurdie 175
                    var stripped;
176
                    stripped = val.replace (/@\d+$/,"");
177
                    if (stripped.search(SVNTagRE) < 0)
178
                        errors += val + '- '+nm+' uses invalid character. Allowed characters are A-Z a-z 0-9 . - _\n';
1339 dpurdie 179
               }
180
            }
1372 dpurdie 181
 
182
            if (test.indexOf('isSVNPegTag')!=-1 && ! errors) {
183
                // Subversion Tag has peg - Must have done valid check first
184
                var SVNTagPegged = /@?\d+$/;
185
 
186
                if ( val.search(SVNTagPegged) < 0) {
2636 dpurdie 187
                    errors += val + '- '+nm+' Must be pegged for Manually Versioned Package. ie:tag@pegNumber\n';
1372 dpurdie 188
               }
189
            }
1339 dpurdie 190
 
191
            if (test.indexOf('isSVNPath')!=-1) {
192
               // Subversion Base Path validation
193
               var SVNTagValidCharsRE = /^[0-9a-z_\.\-\/]+$/i;
129 ghuddy 194
               var SVNTagInValidSlashAtBOL = /^\/.*$/i;
1339 dpurdie 195
               var SVNTagInValidSlashAtEOL = /\/$/i;
129 ghuddy 196
               var SVNTagInValidSlash = /^.*\/\/.*$/i;
1339 dpurdie 197
               var SVNTagInValidTrunkAnywhereRE = /\/trunk\//i;
129 ghuddy 198
               var SVNTagValidTagAnywhereRE = /^.*\/tags\/.*$/i;
121 hknight 199
 
129 ghuddy 200
               if (val.search(SVNTagValidCharsRE) < 0)
1372 dpurdie 201
                  errors += val + ' - '+nm+' uses invalid character. Allowed characters are / A-Z a-z 0-9 . - _\n';
1339 dpurdie 202
               else if (val.search(SVNTagInValidSlashAtBOL) >= 0)
1372 dpurdie 203
                  errors += val + ' - '+nm+' begins with a /. This is not allowed.\n';
1339 dpurdie 204
               else if (val.search(SVNTagInValidSlashAtEOL) >= 0)
1372 dpurdie 205
                  errors += val + ' - '+nm+' ends with a /. This is not allowed.\n';
1339 dpurdie 206
               else if (val.search(SVNTagInValidSlash) >= 0)
1372 dpurdie 207
                  errors += val + ' - '+nm+' uses //. This is not allowed.\n';
1339 dpurdie 208
               else if (val.search(SVNTagValidTagAnywhereRE) >= 0)
1372 dpurdie 209
                     errors += val + ' - '+nm+' contains /tags/. This is not allowed.\n';
1339 dpurdie 210
               else if (val.search(SVNTagInValidTrunkAnywhereRE) >= 0)
1372 dpurdie 211
                     errors += val + ' - '+nm+' contains /trunk/. This is not allowed.\n';
129 ghuddy 212
               else {
1339 dpurdie 213
                        var bits = val.split("/");
214
                        if ( bits.length < 4 )
1372 dpurdie 215
                            errors += val + ' - Must contain at least 4 path items.\n';
1339 dpurdie 216
 
217
                        var ttbcount = 0;
1372 dpurdie 218
                        var i
1339 dpurdie 219
                        for (i=0; i < bits.length; i++ )
220
                        {
221
                            var el = bits[i];
222
                            if ( el == 'tags') ttbcount++;
223
                            if ( el == 'trunk') ttbcount++;
224
                            if ( el == 'branches') ttbcount++;
129 ghuddy 225
                        }
1339 dpurdie 226
                        if ( ttbcount != 1 )
1372 dpurdie 227
                            errors += val + ' - '+nm+' must contain exactly one of tags, trunk or branches. It contains '+ttbcount+'.\n';
1339 dpurdie 228
 
229
                        if ( bits.pop() == 'branches' )    
1372 dpurdie 230
                            errors += val + ' - '+nm+' must not end in branches.\n';
1339 dpurdie 231
 
129 ghuddy 232
                     }
233
            }
234
 
235
            if (test.indexOf('isVersionNumber')!=-1) {
236
               REresults = val.search(versionNumberRE);
1372 dpurdie 237
               if (REresults < 0) errors += val + ' - '+nm+' is formatted incorrectly.\nVersion number should be (major).(minor).(patch)(build)\ne.g. 1.0.2002\n';
129 ghuddy 238
            }
239
 
240
            if (test.indexOf('isURL')!=-1) {
241
               REresults = val.match(urlRE);
242
               if (REresults == null) errors += '"'+val+'" is not a valid URL.\n';
243
            }
244
 
171 brianf 245
            if (test.indexOf('isAlphaNum')!=-1) {
246
               REresults = val.match(alphanumRE);
247
               if (REresults == null) errors += '"'+nm+'" must be an alphanumeric value.\n';
248
            }
249
 
129 ghuddy 250
            if (test.indexOf('isChangePassword')!=-1) {
251
               pass=MM_findObj('FRpassword');
252
               passc=MM_findObj('FRpasswordc');
253
               if (pass.value!=passc.value) errors+='- Password confirmation does not match.\n';
254
            }
255
 
256
            if (test.indexOf('maxLength')!=-1) {
257
               p=test.indexOf(':');
258
               max=test.substring(p+1);
259
               if (val.length>max) errors+='- '+nm+' can be maximum '+max+' characters long.\n';
260
            }
261
 
262
            if (test.indexOf('notHTML')!=-1) {
263
               if (val.match(HTMLchr)) errors+='- '+nm+' has invalid characters like \'< > quotes\'\n';
264
            }
265
 
266
            if (test.charAt(0)=='R') {
267
 
268
               if (test.indexOf('isNumber') != -1) {
269
                  if (isNaN(val)) errors+='- '+nm+' must be a number.\n';
270
               }
271
 
272
               if (test.indexOf('inRange') != -1) {
273
                  p=test.indexOf(':');
274
                  min=test.substring(8,p);
275
                  max=test.substring(p+1);
276
                  if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
277
               }
278
 
279
               if (test.indexOf('inLength')!=-1) {
280
                   pl=test.indexOf('inLength')
281
                  p=test.indexOf(':');
282
                      min=test.substring(pl+8,p);
283
                      if (val.length<min) errors+='- '+nm+' must be at least '+min+' characters long.\n';
284
                }
285
            }
286
         } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n';
287
 
288
 
289
         if (test.indexOf('isPassword')!=-1) {
290
            pass=MM_findObj('FRpassword');
291
            passc=MM_findObj('FRpasswordc');
292
            if (!MM_findObj('FRdomainauth').checked) {
293
               if (test.indexOf('inLength')!=-1) {
294
                   pl=test.indexOf('inLength')
295
                  p=test.indexOf(':');
296
                      min=test.substring(pl+8,p);
297
                      if (val.length<min) errors+='- '+nm+' must be at least '+min+' characters long.\n';
298
                }
299
               if (pass.value!=passc.value) errors+='- Password confirmation does not match.\n';
300
            } else {
301
               if (MM_findObj('FRdomain_name').value=="") errors += '- Domain Name is required.\n';
302
            }
303
         }
304
 
305
         if (test.indexOf('isDomainName')!=-1) {
306
            if (MM_findObj('FRdomainauth').checked) {
307
               if (MM_findObj('FRdomain_name').value=="") errors += '- Domain Name is required.\n';
308
            }
309
         }
3892 dpurdie 310
      }
129 ghuddy 311
   }
312
 
313
   if (errors) {
3894 dpurdie 314
      if ( showAlert ) alert('The following error(s) occurred:\n\n'+errors);
129 ghuddy 315
      clickedButton=false;
316
   } else {
317
      clickedButton=true;
318
   }
319
   document.MM_returnValue = (errors == '');
3892 dpurdie 320
   document.MM_error = errors;
129 ghuddy 321
 
3894 dpurdie 322
   if (MM_findObj('ProgressBar') && document.MM_returnValue && showAlert)
3892 dpurdie 323
      MM_findObj('ProgressBar').style.visibility='visible';
119 ghuddy 324
}
325
 
326
function isChecked(boxName, buttonId) {
327
  var formButton = document.getElementById(buttonId);
328
  var boxes = document.getElementsByName(boxName);
329
  var btnChecked = false;
330
  if (formButton) {
331
    for (var i = 0; i < boxes.length; i++) {
332
      if (boxes[i].checked) {
333
        btnChecked = true;
334
      }
335
    }
121 hknight 336
 
119 ghuddy 337
    if (btnChecked) {
338
      formButton.disabled = false;
339
      formButton.style.color="";
340
    }
341
    else {
342
      formButton.disabled = true;
343
      formButton.style.color="silver";
344
    }
345
  }
346
}
347
 
348
function confirmDelete(m)
349
{
129 ghuddy 350
   var agree=confirm('Are you sure you want to delete '+m+'?');
351
   if (agree) {
352
      if (MM_findObj('ProgressBar')) MM_findObj('ProgressBar').style.visibility='visible';
353
      return true;
354
   } else {
355
      return false;
356
   }
119 ghuddy 357
}
358
 
359
function confirmAction(m)
360
{
129 ghuddy 361
   var agree=confirm(m);
362
   if (agree) {
363
      if (MM_findObj('ProgressBar')) MM_findObj('ProgressBar').style.visibility='visible';
364
      return true;
365
   } else {
366
      return false;
367
   }
119 ghuddy 368
}
369
 
370
function DisplaySPAN(show) {
129 ghuddy 371
   if (show) {
372
      MM_findObj("spanHideDetails").style.display = "block";
373
      MM_findObj("spanPkgInfo").style.display = "block";
374
      MM_findObj("spanShowDetails").style.display = "none";
375
   } else {
376
      MM_findObj("spanHideDetails").style.display = "none";
377
      MM_findObj("spanPkgInfo").style.display = "none";
378
      MM_findObj("spanShowDetails").style.display = "block";
379
   }
119 ghuddy 380
}
381
 
382
function ToggleDisplay () {
129 ghuddy 383
   var i, args, div_name, visibility
384
   args=ToggleDisplay.arguments;
385
   for (i=0; i<(args.length); i+=1) {
386
      div_name=args[i];
387
      if ( MM_findObj(div_name).style.display == 'block' ) {
388
         MM_findObj(div_name).style.display = 'none';
389
      } else {
390
         MM_findObj(div_name).style.display = 'block';
391
      }
121 hknight 392
 
129 ghuddy 393
   }
119 ghuddy 394
}
395
 
396
function Visible () {
121 hknight 397
 
129 ghuddy 398
   var i, args, div_name, visibility
399
   args=Visible.arguments;
400
   for (i=0; i<(args.length); i+=2) {
401
      div_name=args[i];
402
      visibility=args[i+1]
403
      MM_findObj(div_name).style.display = visibility;
121 hknight 404
 
129 ghuddy 405
   }
119 ghuddy 406
}
407
 
408
function DisplayObjects () {
129 ghuddy 409
   var i, args, div_name
410
   args=DisplayObjects.arguments;
411
   for (i=0; i<(args.length); i+=1) {
412
      div_name=args[i];
413
      MM_findObj(div_name).style.display = 'block';
414
   }
119 ghuddy 415
}
416
 
121 hknight 417
function GetCookieVal (offset) {
129 ghuddy 418
   var endstr = document.cookie.indexOf (";", offset);
419
   if (endstr == -1) { endstr = document.cookie.length; }
420
   return unescape(document.cookie.substring(offset, endstr));
119 ghuddy 421
}
422
 
423
 
121 hknight 424
function GetCookie (name) {
129 ghuddy 425
   var arg = name + "=";
426
   var alen = arg.length;
427
   var clen = document.cookie.length;
428
   var i = 0;
119 ghuddy 429
 
129 ghuddy 430
   while (i < clen) {
431
      var j = i + alen;
432
      if (document.cookie.substring(i, j) == arg) return GetCookieVal (j);
433
      i = document.cookie.indexOf(" ", i) + 1;
434
      if (i == 0) break;
435
   }
119 ghuddy 436
 
129 ghuddy 437
   return null;
119 ghuddy 438
}
439
 
440
function go_submit( formname, actionname )
441
{
129 ghuddy 442
   formname.action.value = actionname;
443
   formname.submit();
119 ghuddy 444
}
445
 
446
function ExpandAll()
447
{
129 ghuddy 448
   var elem
121 hknight 449
 
129 ghuddy 450
   if (document.all)
451
   {
452
      // Run this for IE
453
      elem = document.all;
454
   } else {
455
      // Run this for other browsers
456
      elem = document.getElementsByTagName('div');
457
   }
121 hknight 458
 
129 ghuddy 459
   for (i in elem)
460
   {
461
      if (elem[i].id)
462
      {
463
         if (elem[i].id.indexOf('SHORT_') == 0) elem[i].style.display = 'none';
464
         if (elem[i].id.indexOf('FULL_') == 0) elem[i].style.display = 'block';
465
      }
466
   }
121 hknight 467
 
119 ghuddy 468
}
469
 
470
function CollapseAll()
471
{
129 ghuddy 472
   var elem
121 hknight 473
 
129 ghuddy 474
   if (document.all)
475
   {
476
      // Run this for IE
477
      elem = document.all;
478
   } else {
479
      // Run this for other browsers
480
      elem = document.getElementsByTagName('div');
481
   }
121 hknight 482
 
129 ghuddy 483
   for (i in elem)
484
   {
485
      if (elem[i].id)
486
      {
487
         if (elem[i].id.indexOf('SHORT_') == 0) elem[i].style.display = 'block';
488
         if (elem[i].id.indexOf('FULL_') == 0) elem[i].style.display = 'none';
489
      }
490
   }
121 hknight 491
 
119 ghuddy 492
}
493
 
494
 
495
function height()
121 hknight 496
{
129 ghuddy 497
   if( typeof( window.innerWidth ) == 'number' )
498
   {
499
      h = window.innerHeight;
500
   }
501
   else if(document.documentElement&&(document.documentElement.clientHeight ))
502
   {
503
      h = document.documentElement.clientHeight;
504
   }
505
   else if( document.body &&   ( document.body.clientWidth || document.body.clientHeight ) )
506
   {
507
      h = document.body.clientHeight;
508
   }
121 hknight 509
 
129 ghuddy 510
   var e = document.getElementById("LayerDescription");
121 hknight 511
 
129 ghuddy 512
   if (navigator.userAgent.indexOf('Internet Explorer'))
513
   {
514
      e.style.height = h - 350 + "px";
515
      e.style.overflow = "auto";
516
   }
517
   else
518
   {
519
      // This line shouldn't be run by IE; it doesn't seem to work. It gets run in Firefox, etc.
520
      e.style.minHeight= h - 350 + "px";
521
      e.style.overflow = "auto";
522
   }
119 ghuddy 523
}
524
 
121 hknight 525
//////////////////////////////////////////////////////////////////////////////////////////////////
526
//
527
// MM_ValidateVersion(pkgName, versionBase, versionExt, isAutobuild)
528
//
529
//    pkgName       eg EA_DocGen
530
//    versionBase   eg 1.2.3
129 ghuddy 531
//    versionExt   eg .cr
121 hknight 532
//    isAutobuild   true or false
133 ghuddy 533
//    isPatch       true or false
121 hknight 534
//
535
// Returns true if version is valid, else false
536
//
537
// This function can and should be used instead of MM_validateForm to validate
538
// version numbers for new or reversioned package versions.
539
//
540
// So far, this function is used in the following situations:
541
//    1) Add new version to release (_form_new_version_page.asp)
542
//    2) Reversion existing version (_wform_rename_version.asp)
543
//    3) Add package to release (Form_add_pkg_versions.asp)
544
//////////////////////////////////////////////////////////////////////////////////////////////////
133 ghuddy 545
function MM_ValidateVersion(pkgName, versionBase, versionExt, isAutobuild, isPatch)
121 hknight 546
{
133 ghuddy 547
   var errString = MM_ValidateVersionReturningErrString(pkgName, versionBase, versionExt, isAutobuild, isPatch);
129 ghuddy 548
   if (errString.length > 0)
549
   {
550
      alert(errString);
551
      return false;
552
   }
553
   return true;
121 hknight 554
}
555
 
556
//////////////////////////////////////////////////////////////////////////////////////////////////
557
//
558
// MM_ValidateVersionReturningErrString(pkgName, versionBase, versionExt, isAutobuild)
559
//
560
//    pkgName       eg buildtool
561
//    versionBase   eg 1.2.3
129 ghuddy 562
//    versionExt   eg .cr
121 hknight 563
//    isAutobuild   true or false
133 ghuddy 564
//    isPatch       true or false
121 hknight 565
//
566
// Returns a non-zero-length error string if version is NOT valid, else returns a zero-length string
567
//
568
// The MM_validateForm function should be modified to use this if possible, although I currently
569
// do not believe it has access to all the necessary parameter values needed.
570
//
571
//////////////////////////////////////////////////////////////////////////////////////////////////
133 ghuddy 572
function MM_ValidateVersionReturningErrString(pkgName, versionBase, versionExt, isAutobuild, isPatch)
121 hknight 573
{
133 ghuddy 574
   var re_std_ver_format   = /^\d+\.\d+\.\d+$/;
575
   var re_patch_ver_format = /^\d+\.\d+\.\d+\.p\d+$/;
576
   var re_cots_ver_format  = /^[\w]+[\w\.\-]*$/;   // starts with letter or digit or underscore, subsequent chars can be letters or digits or _ or . or -
129 ghuddy 577
   var re_cots_ver_format_exc1 = /[-_.]+[-_.]+/;   // look for any two adjacent special characters
578
   var re_cots_ver_format_exc2 = /[0-9A-Za-z]+/;   // look for any alphanumeric char
121 hknight 579
 
129 ghuddy 580
   var forPkgName = "";
581
   if (pkgName != null && pkgName.length > 0)
582
   {
583
      forPkgName = ", for package " + pkgName;
584
   }
121 hknight 585
 
133 ghuddy 586
   if (!isAutobuild)
129 ghuddy 587
   {
133 ghuddy 588
      if ( versionBase.length == 0 )
129 ghuddy 589
      {
590
         return "Action failed: version number is of zero length" + forPkgName;
591
      }
3621 dpurdie 592
      else if ( versionExt != ".cots" && versionExt != ".tool")
129 ghuddy 593
      {
133 ghuddy 594
         if ( isPatch )
595
         {
596
            if ( !re_patch_ver_format.test(versionBase) )
597
            {
598
               return "Action failed: patch version is not of form (integer).(integer).(integer).p(integer).(extension)" + forPkgName;
599
            }
600
         }
601
         else
602
         {
603
            if ( !re_std_ver_format.test(versionBase) )
604
            {
605
               return "Action failed: version is not of form (integer).(integer).(integer).(extension)" + forPkgName;
606
            }
607
         }
129 ghuddy 608
      }
3621 dpurdie 609
      else if ( versionExt == ".cots" || versionExt == ".tool")
129 ghuddy 610
      {
3621 dpurdie 611
         var extName = versionExt.toUpperCase().substr(1);
612
 
133 ghuddy 613
         if ( !re_cots_ver_format.test(versionBase) )
129 ghuddy 614
         {
3621 dpurdie 615
            return "Action failed: " + extName + " version must begin with letter/digit/underscore, cannot contain any whitespace, and only special characters underscore/dash/dot are allowed" + forPkgName;
129 ghuddy 616
         }
121 hknight 617
 
133 ghuddy 618
         if ( re_cots_ver_format_exc1.test(versionBase) )
129 ghuddy 619
         {
3621 dpurdie 620
            return "Action failed: " + extName + " version cannot contain two adjacent special characters (underscore/dash/dot)" + forPkgName;
129 ghuddy 621
         }
121 hknight 622
 
133 ghuddy 623
         if ( !re_cots_ver_format_exc2.test(versionBase) )
129 ghuddy 624
         {
3621 dpurdie 625
            return "Action failed: " + extName + " version must contain one or more alphanumeric characters" + forPkgName;
129 ghuddy 626
         }
627
      }
628
   }
121 hknight 629
 
129 ghuddy 630
   // everything ok - no error
631
   return "";
121 hknight 632
}
633
 
634
 
635
 
119 ghuddy 636
//-->