Subversion Repositories DevTools

Rev

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