Subversion Repositories DevTools

Rev

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