|
@@ -86,7 +86,7 @@ String.prototype.zeroPad = function(len) { return this.prePad(len, '0'); };
|
86
|
86
|
String.prototype.toHTML = function() { return jQuery('<div>').text(this).html(); };
|
87
|
87
|
String.prototype.regEsc = function() { return this.replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&"); }
|
88
|
88
|
String.prototype.lineCount = function() { var len = this.split(/\r?\n|\r/).length; return len > 0 ? len - 1 : 0; };
|
89
|
|
-String.prototype.toLabel = function() { return this.replace(/_/g, ' ').toTitleCase(); }
|
|
89
|
+String.prototype.toLabel = function() { return this.replace(/[\[\]]/g, '').replace(/_/g, ' ').toTitleCase(); }
|
90
|
90
|
String.prototype.toTitleCase = function() { return this.replace(/([A-Z])(\w+)/gi, function(m,p1,p2) { return p1.toUpperCase() + p2.toLowerCase(); }); }
|
91
|
91
|
Number.prototype.limit = function(m1, m2) {
|
92
|
92
|
if (m2 == null) return this > m1 ? m1 : this;
|
|
@@ -124,6 +124,10 @@ $.fn.extend({
|
124
|
124
|
.attr('unselectable', 'on')
|
125
|
125
|
.css('user-select', 'none')
|
126
|
126
|
.on('selectstart', false);
|
|
127
|
+ },
|
|
128
|
+ unblock: function(on) {
|
|
129
|
+ on ? this.removeClass('blocked') : this.addClass('blocked');
|
|
130
|
+ return this;
|
127
|
131
|
}
|
128
|
132
|
});
|
129
|
133
|
|
|
@@ -144,6 +148,7 @@ window.configuratorApp = (function(){
|
144
|
148
|
$config = $cfg.find('pre'), $config_adv = $adv.find('pre'),
|
145
|
149
|
define_info = {},
|
146
|
150
|
define_list = [[],[]],
|
|
151
|
+ define_groups = [{},{}],
|
147
|
152
|
define_section = {},
|
148
|
153
|
dependentGroups = {},
|
149
|
154
|
boards_list = {},
|
|
@@ -354,17 +359,93 @@ window.configuratorApp = (function(){
|
354
|
359
|
},
|
355
|
360
|
|
356
|
361
|
/**
|
|
362
|
+ * Find the defines in one of the configs that are just variants.
|
|
363
|
+ * Group them together for form-building and other uses.
|
|
364
|
+ */
|
|
365
|
+ refreshDefineGroups: function(index) {
|
|
366
|
+ var findDef = /^(|.*_)(([XYZE](MAX|MIN))|(E[0-3]|[XYZE01234])|MAX|MIN|(bed)?K[pid])(_.*|)$/;
|
|
367
|
+ var match_prev, patt, title, nameList, groups = {}, match_section;
|
|
368
|
+ $.each(define_list[index], function() {
|
|
369
|
+ if (match_prev) {
|
|
370
|
+ if (match_prev.exec(this) && define_section[this] == match_section) {
|
|
371
|
+ nameList.push(this);
|
|
372
|
+ }
|
|
373
|
+ else {
|
|
374
|
+ if (nameList.length > 1) {
|
|
375
|
+ $.each(nameList, function(){
|
|
376
|
+ groups[this] = {
|
|
377
|
+ pattern: patt,
|
|
378
|
+ title: title,
|
|
379
|
+ count: nameList.length
|
|
380
|
+ };
|
|
381
|
+ });
|
|
382
|
+ }
|
|
383
|
+ match_prev = null;
|
|
384
|
+ }
|
|
385
|
+ }
|
|
386
|
+ if (!match_prev) {
|
|
387
|
+ var r = findDef.exec(this);
|
|
388
|
+ if (r != null) {
|
|
389
|
+ switch(r[2]) {
|
|
390
|
+ case '0':
|
|
391
|
+ patt = '([0123])';
|
|
392
|
+ title = 'N';
|
|
393
|
+ break;
|
|
394
|
+ case 'X':
|
|
395
|
+ patt = '([XYZE])';
|
|
396
|
+ title = 'AXIS';
|
|
397
|
+ break;
|
|
398
|
+ case 'E0':
|
|
399
|
+ patt = 'E([0-3])';
|
|
400
|
+ title = 'E';
|
|
401
|
+ break;
|
|
402
|
+ case 'bedKp':
|
|
403
|
+ patt = 'bed(K[pid])';
|
|
404
|
+ title = 'BED_PID';
|
|
405
|
+ break;
|
|
406
|
+ case 'Kp':
|
|
407
|
+ patt = '(K[pid])';
|
|
408
|
+ title = 'PID';
|
|
409
|
+ break;
|
|
410
|
+ case 'MAX':
|
|
411
|
+ case 'MIN':
|
|
412
|
+ patt = '(MAX|MIN)';
|
|
413
|
+ title = '';
|
|
414
|
+ break;
|
|
415
|
+ case 'XMIN':
|
|
416
|
+ case 'XMAX':
|
|
417
|
+ patt = '([XYZ])'+r[4];
|
|
418
|
+ title = 'XYZ_'+r[4];
|
|
419
|
+ break;
|
|
420
|
+ default:
|
|
421
|
+ patt = null;
|
|
422
|
+ break;
|
|
423
|
+ }
|
|
424
|
+ if (patt) {
|
|
425
|
+ patt = '^' + r[1] + patt + r[7] + '$';
|
|
426
|
+ title = r[1] + title + r[7];
|
|
427
|
+ match_prev = new RegExp(patt);
|
|
428
|
+ match_section = define_section[this];
|
|
429
|
+ nameList = [ this ];
|
|
430
|
+ }
|
|
431
|
+ }
|
|
432
|
+ }
|
|
433
|
+ });
|
|
434
|
+ define_groups[index] = groups;
|
|
435
|
+ },
|
|
436
|
+
|
|
437
|
+ /**
|
357
|
438
|
* Get all condition blocks and their line ranges.
|
358
|
439
|
* Conditions may control multiple line-ranges
|
359
|
440
|
* across both config files.
|
360
|
441
|
*/
|
361
|
442
|
initDependentGroups: function() {
|
362
|
|
- var findDef = /^[ \t]*#(ifn?def|if|else|endif)[ \t]*(.*)([ \t]*\/\/[^\n]+)?$/gm,
|
|
443
|
+ var findBlock = /^[ \t]*#(ifn?def|if|else|endif)[ \t]*(.*)([ \t]*\/\/[^\n]+)?$/gm,
|
363
|
444
|
leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H'];
|
364
|
445
|
$.each([$config, $config_adv], function(i, $v) {
|
365
|
446
|
var ifStack = [];
|
366
|
447
|
var r, txt = $v.text();
|
367
|
|
- while((r = findDef.exec(txt)) !== null) {
|
|
448
|
+ while((r = findBlock.exec(txt)) !== null) {
|
368
|
449
|
var lineNum = txt.substr(0, r.index).lineCount();
|
369
|
450
|
var code = r[2].replace(/[ \t]*\/\/.*$/, '');
|
370
|
451
|
switch(r[1]) {
|
|
@@ -431,34 +512,67 @@ window.configuratorApp = (function(){
|
431
|
512
|
},
|
432
|
513
|
|
433
|
514
|
/**
|
434
|
|
- * Create fields for any defines that have none
|
|
515
|
+ * Create fields for defines in a config that have none
|
|
516
|
+ * Use define_groups data to group fields together
|
435
|
517
|
*/
|
436
|
|
- createFieldsForDefines: function(e) {
|
|
518
|
+ createFieldsForDefines: function(index) {
|
437
|
519
|
var n = 0, fail_list = [];
|
438
|
|
- $.each(define_list[e], function(i,name) {
|
|
520
|
+ var grouping = false, group_pattern, group_regex, subitem, group_section, group_class;
|
|
521
|
+ $.each(define_list[index], function(i,name) {
|
439
|
522
|
var section = define_section[name];
|
440
|
523
|
if (section != 'hidden' && !$('#'+name).length) {
|
441
|
524
|
var inf = define_info[name];
|
442
|
525
|
|
443
|
526
|
if (inf) {
|
444
|
527
|
|
|
528
|
+ var label_text = name, sublabel;
|
|
529
|
+
|
|
530
|
+ // Is this field in a sequence?
|
|
531
|
+ // Then see if it's the second or after
|
|
532
|
+ var group = define_groups[index];
|
|
533
|
+ if (grouping) {
|
|
534
|
+ if (name in group && group_pattern == group[name].pattern && group_section == section) {
|
|
535
|
+ subitem = true;
|
|
536
|
+ sublabel = group_regex.exec(name)[1];
|
|
537
|
+ }
|
|
538
|
+ else
|
|
539
|
+ grouping = false;
|
|
540
|
+ }
|
|
541
|
+ // Start grouping?
|
|
542
|
+ if (!grouping && name in group) {
|
|
543
|
+ grouping = true;
|
|
544
|
+ subitem = false;
|
|
545
|
+ var grp = group[name];
|
|
546
|
+ group_pattern = grp.pattern;
|
|
547
|
+ group_class = 'one_of_' + grp.count;
|
|
548
|
+ label_text = grp.title;
|
|
549
|
+ group_regex = new RegExp(group_pattern);
|
|
550
|
+ group_section = section;
|
|
551
|
+ sublabel = group_regex.exec(name)[1];
|
|
552
|
+ }
|
|
553
|
+
|
445
|
554
|
var $ff = $('#'+section), $newfield,
|
446
|
|
- avail = eval(inf.enabled),
|
447
|
|
- $newlabel = $('<label>',{for:name,class:'added'}).text(name.toLabel());
|
|
555
|
+ avail = eval(inf.enabled);
|
|
556
|
+
|
|
557
|
+ if (!(grouping && subitem)) {
|
|
558
|
+
|
|
559
|
+ var $newlabel = $('<label>',{for:name,class:'added'}).text(label_text.toLabel());
|
448
|
560
|
|
449
|
|
- if (!avail) $newlabel.addClass('blocked');
|
|
561
|
+ $newlabel.unblock(avail);
|
450
|
562
|
|
451
|
|
- // if (!(++n % 3))
|
452
|
|
- $newlabel.addClass('newline');
|
|
563
|
+ // if (!(++n % 3))
|
|
564
|
+ $newlabel.addClass('newline');
|
453
|
565
|
|
454
|
|
- $ff.append($newlabel);
|
|
566
|
+ $ff.append($newlabel);
|
|
567
|
+
|
|
568
|
+ }
|
455
|
569
|
|
456
|
570
|
// Multiple fields?
|
457
|
571
|
if (inf.type == 'list') {
|
458
|
572
|
for (var i=0; i<inf.size; i++) {
|
459
|
573
|
var fieldname = i > 0 ? name+'-'+i : name;
|
460
|
|
- $newfield = $('<input>',{type:'text',size:6,maxlength:10,id:fieldname,name:fieldname,class:'subitem added',disabled:!avail});
|
461
|
|
- if (!avail) $newfield.addClass('blocked');
|
|
574
|
+ $newfield = $('<input>',{type:'text',size:6,maxlength:10,id:fieldname,name:fieldname,class:'subitem added',disabled:!avail}).unblock(avail);
|
|
575
|
+ if (grouping) $newfield.addClass(group_class);
|
462
|
576
|
$ff.append($newfield);
|
463
|
577
|
}
|
464
|
578
|
}
|
|
@@ -478,8 +592,12 @@ window.configuratorApp = (function(){
|
478
|
592
|
else {
|
479
|
593
|
$newfield = inf.type == 'switch' ? $('<input>',{type:'checkbox'}) : $('<input>',{type:'text',size:10,maxlength:40});
|
480
|
594
|
}
|
481
|
|
- $newfield.attr({id:name,name:name,class:'added',disabled:!avail});
|
482
|
|
- if (!avail) $newfield.addClass('blocked');
|
|
595
|
+ $newfield.attr({id:name,name:name,class:'added',disabled:!avail}).unblock(avail);
|
|
596
|
+ if (grouping) {
|
|
597
|
+ $newfield.addClass(group_class);
|
|
598
|
+ if (sublabel)
|
|
599
|
+ $ff.append($('<span class="label"/>').text(sublabel.toTitleCase()).unblock(avail));
|
|
600
|
+ }
|
483
|
601
|
// Add the new field to the form
|
484
|
602
|
$ff.append($newfield);
|
485
|
603
|
}
|
|
@@ -558,7 +676,7 @@ window.configuratorApp = (function(){
|
558
|
676
|
this.initDefineList(init_index, txt);
|
559
|
677
|
// TODO: Find sequential names and group them
|
560
|
678
|
// Allows related settings to occupy one line in the form
|
561
|
|
- // this.refreshSequentialDefines();
|
|
679
|
+ this.refreshDefineGroups(init_index);
|
562
|
680
|
// Build the dependent defines list
|
563
|
681
|
this.initDependentGroups(); // all config text
|
564
|
682
|
// Get define_info for all known defines
|
|
@@ -721,15 +839,13 @@ window.configuratorApp = (function(){
|
721
|
839
|
var inf = define_info[this];
|
722
|
840
|
if (inf && inf.enabled != 'true') {
|
723
|
841
|
var $elm = $('#'+this), ena = eval(inf.enabled);
|
|
842
|
+ var isEnabled = (inf.type == 'switch') || self.defineIsEnabled(this);
|
724
|
843
|
// Make any switch toggle also
|
725
|
844
|
$('#'+this+'-switch').attr('disabled', !ena);
|
726
|
|
- var alreadyEnabled = inf.type == 'switch' || self.defineIsEnabled(this);
|
727
|
|
- $elm.attr('disabled', !(ena && alreadyEnabled));
|
728
|
|
- ena ? $elm.removeClass('blocked') : $elm.addClass('blocked');
|
|
845
|
+ $elm.attr('disabled', !(ena && isEnabled)).unblock(ena);
|
|
846
|
+ //self.log("Setting " + this + " to " + (ena && isEnabled ? 'enabled' : 'disabled'));
|
729
|
847
|
// Dim label for unavailable element
|
730
|
|
- var $lbl = $elm.prev('label');
|
731
|
|
- if ($lbl.length)
|
732
|
|
- ena ? $lbl.removeClass('blocked') : $lbl.addClass('blocked');
|
|
848
|
+ $elm.prevAll('label, span.label').filter(':first').unblock(ena);
|
733
|
849
|
}
|
734
|
850
|
});
|
735
|
851
|
});
|
|
@@ -745,7 +861,8 @@ window.configuratorApp = (function(){
|
745
|
861
|
|
746
|
862
|
// Create a tooltip on the label if there is one
|
747
|
863
|
if (inf.tooltip) {
|
748
|
|
- var $tipme = $elm.prev('label');
|
|
864
|
+ // previous label or
|
|
865
|
+ var $tipme = $elm.prevAll('label, span.label').filter(':first');
|
749
|
866
|
if ($tipme.length) {
|
750
|
867
|
$tipme.unbind('mouseenter mouseleave');
|
751
|
868
|
$tipme.hover(
|
|
@@ -972,7 +1089,7 @@ window.configuratorApp = (function(){
|
972
|
1089
|
|
973
|
1090
|
this.log('initFieldValue:' + name + ' to ' + val, 2);
|
974
|
1091
|
|
975
|
|
- // If the item has a checkbox then set enabled state too
|
|
1092
|
+ // If the item is switchable then set enabled state too
|
976
|
1093
|
var $cb = $('#'+name+'-switch'), avail = eval(inf.enabled), on = true;
|
977
|
1094
|
if ($cb.length) {
|
978
|
1095
|
on = self.defineIsEnabled(name);
|
|
@@ -983,20 +1100,17 @@ window.configuratorApp = (function(){
|
983
|
1100
|
$.each(val.split(','),function(i,v){
|
984
|
1101
|
var $e = i > 0 ? $('#'+name+'-'+i) : $elm;
|
985
|
1102
|
$e.val(v.trim());
|
986
|
|
- $e.attr('disabled', !on);
|
987
|
|
- avail ? $e.removeClass('blocked') : $e.addClass('blocked');
|
|
1103
|
+ $e.attr('disabled', !(on && avail)).unblock(avail);
|
988
|
1104
|
});
|
989
|
1105
|
}
|
990
|
1106
|
else {
|
991
|
1107
|
if (inf.type == 'toggle') val = val == inf.options[1];
|
992
|
1108
|
$elm.attr('type') == 'checkbox' ? $elm.prop('checked', val) : $elm.val(''+val);
|
993
|
|
- $elm.attr('disabled', !on); // enable/disable the form field (could also dim it)
|
994
|
|
- avail ? $elm.removeClass('blocked') : $elm.addClass('blocked');
|
|
1109
|
+ $elm.attr('disabled', !(on && avail)).unblock(avail); // enable/disable the form field (could also dim it)
|
995
|
1110
|
}
|
996
|
1111
|
|
997
|
1112
|
// set label color
|
998
|
|
- var $lbl = $elm.prev('label');
|
999
|
|
- avail ? $lbl.removeClass('blocked') : $lbl.addClass('blocked');
|
|
1113
|
+ $elm.prevAll('label, span.label').filter(':first').unblock(avail);
|
1000
|
1114
|
},
|
1001
|
1115
|
|
1002
|
1116
|
/**
|