Subversion Repositories DevTools

Rev

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