Subversion Repositories DevTools

Rev

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