|
@@ -146,6 +146,8 @@ window.configuratorApp = (function(){
|
146
|
146
|
$tooltip = $('#tooltip'),
|
147
|
147
|
$cfg = $('#config_text'), $adv = $('#config_adv_text'),
|
148
|
148
|
$config = $cfg.find('pre'), $config_adv = $adv.find('pre'),
|
|
149
|
+ config_file_list = [ boards_file, config_file, config_adv_file ],
|
|
150
|
+ config_list = [ $config, $config_adv ],
|
149
|
151
|
define_info = {},
|
150
|
152
|
define_list = [[],[]],
|
151
|
153
|
define_groups = [{},{}],
|
|
@@ -199,10 +201,9 @@ window.configuratorApp = (function(){
|
199
|
201
|
// Read boards.h, Configuration.h, Configuration_adv.h
|
200
|
202
|
var ajax_count = 0, success_count = 0;
|
201
|
203
|
var loaded_items = {};
|
202
|
|
- var config_files = [boards_file, config_file, config_adv_file];
|
203
|
204
|
var isGithub = config.type == 'github';
|
204
|
205
|
var rateLimit = 0;
|
205
|
|
- $.each(config_files, function(i,fname){
|
|
206
|
+ $.each(config_file_list, function(i,fname){
|
206
|
207
|
var url = config_path(fname);
|
207
|
208
|
$.ajax({
|
208
|
209
|
url: url,
|
|
@@ -215,7 +216,7 @@ window.configuratorApp = (function(){
|
215
|
216
|
if (req.status == 200) {
|
216
|
217
|
if (typeof req.responseText === 'string') {
|
217
|
218
|
var txt = req.responseText;
|
218
|
|
- loaded_items[fname] = function(){ self.fileLoaded(fname, txt); };
|
|
219
|
+ loaded_items[fname] = function(){ self.fileLoaded(fname, txt, true); };
|
219
|
220
|
success_count++;
|
220
|
221
|
// self.setMessage('The request for "'+fname+'" may be malformed.', 'error');
|
221
|
222
|
}
|
|
@@ -236,13 +237,13 @@ window.configuratorApp = (function(){
|
236
|
237
|
timeLeft: Math.floor(txt.meta['X-RateLimit-Reset'] - Date.now()/1000),
|
237
|
238
|
};
|
238
|
239
|
}
|
239
|
|
- loaded_items[fname] = function(){ self.fileLoaded(fname, isGithub ? atob(txt.data.content.replace(/\s/g, '')) : txt); };
|
|
240
|
+ loaded_items[fname] = function(){ self.fileLoaded(fname, isGithub ? atob(txt.data.content.replace(/\s/g, '')) : txt, true); };
|
240
|
241
|
success_count++;
|
241
|
242
|
}
|
242
|
243
|
},
|
243
|
244
|
complete: function() {
|
244
|
245
|
ajax_count++;
|
245
|
|
- if (ajax_count >= config_files.length) {
|
|
246
|
+ if (ajax_count >= config_file_list.length) {
|
246
|
247
|
// If not all files loaded set an error
|
247
|
248
|
if (success_count < ajax_count)
|
248
|
249
|
self.setMessage('Unable to load configurations. Try the upload field.', 'error');
|
|
@@ -260,7 +261,7 @@ window.configuratorApp = (function(){
|
260
|
261
|
}
|
261
|
262
|
}
|
262
|
263
|
// Post-process all the loaded files
|
263
|
|
- $.each(config_files, function(){ if (loaded_items[this]) loaded_items[this](); });
|
|
264
|
+ $.each(config_file_list, function(){ if (loaded_items[this]) loaded_items[this](); });
|
264
|
265
|
}
|
265
|
266
|
}
|
266
|
267
|
});
|
|
@@ -270,9 +271,9 @@ window.configuratorApp = (function(){
|
270
|
271
|
/**
|
271
|
272
|
* Make a download link visible and active
|
272
|
273
|
*/
|
273
|
|
- activateDownloadLink: function(adv) {
|
274
|
|
- var $c = adv ? $config_adv : $config, txt = $c.text();
|
275
|
|
- var filename = (adv ? config_adv_file : config_file);
|
|
274
|
+ activateDownloadLink: function(cindex) {
|
|
275
|
+ var filename = config_file_list[cindex+1];
|
|
276
|
+ var $c = config_list[cindex], txt = $c.text();
|
276
|
277
|
$c.prevAll('.download:first')
|
277
|
278
|
.unbind('mouseover click')
|
278
|
279
|
.mouseover(function() {
|
|
@@ -303,8 +304,7 @@ window.configuratorApp = (function(){
|
303
|
304
|
.click(function(){
|
304
|
305
|
var $button = $(this);
|
305
|
306
|
var zip = new JSZip();
|
306
|
|
- zip.file(config_file, $config.text());
|
307
|
|
- zip.file(config_adv_file, $config_adv.text());
|
|
307
|
+ for (var e in [0,1]) zip.file(config_file_list[e+1], config_list[e].text());
|
308
|
308
|
var zipped = zip.generate({type:'blob'});
|
309
|
309
|
saveAs(zipped, $button.attr('download'));
|
310
|
310
|
return false;
|
|
@@ -341,10 +341,11 @@ window.configuratorApp = (function(){
|
341
|
341
|
/**
|
342
|
342
|
* Get all the unique define names
|
343
|
343
|
*/
|
344
|
|
- initDefineList: function(index, txt) {
|
|
344
|
+ initDefineList: function(cindex) {
|
345
|
345
|
var section = 'hidden',
|
346
|
346
|
leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H'],
|
347
|
347
|
define_sect = {},
|
|
348
|
+ txt = config_list[cindex].text(),
|
348
|
349
|
r, findDef = new RegExp('(@section|#define)[ \\t]+(\\w+)', 'gm');
|
349
|
350
|
while((r = findDef.exec(txt)) !== null) {
|
350
|
351
|
var name = r[2];
|
|
@@ -353,27 +354,27 @@ window.configuratorApp = (function(){
|
353
|
354
|
else if ($.inArray(name, leave_out_defines) < 0 && !(name in define_section) && !(name in define_sect))
|
354
|
355
|
define_sect[name] = section;
|
355
|
356
|
}
|
356
|
|
- define_list[index] = Object.keys(define_sect);
|
|
357
|
+ define_list[cindex] = Object.keys(define_sect);
|
357
|
358
|
$.extend(define_section, define_sect);
|
358
|
|
- this.log(define_list[index], 2);
|
|
359
|
+ this.log(define_list[cindex], 2);
|
359
|
360
|
},
|
360
|
361
|
|
361
|
362
|
/**
|
362
|
363
|
* Find the defines in one of the configs that are just variants.
|
363
|
364
|
* Group them together for form-building and other uses.
|
364
|
365
|
*/
|
365
|
|
- refreshDefineGroups: function(index) {
|
|
366
|
+ refreshDefineGroups: function(cindex) {
|
366
|
367
|
var findDef = /^(|.*_)(([XYZE](MAX|MIN))|(E[0-3]|[XYZE01234])|MAX|MIN|(bed)?K[pid])(_.*|)$/;
|
367
|
368
|
var match_prev, patt, title, nameList, groups = {}, match_section;
|
368
|
|
- $.each(define_list[index], function() {
|
|
369
|
+ $.each(define_list[cindex], function(i, name) {
|
369
|
370
|
if (match_prev) {
|
370
|
|
- if (match_prev.exec(this) && define_section[this] == match_section) {
|
371
|
|
- nameList.push(this);
|
|
371
|
+ if (match_prev.exec(name) && define_section[name] == match_section) {
|
|
372
|
+ nameList.push(name);
|
372
|
373
|
}
|
373
|
374
|
else {
|
374
|
375
|
if (nameList.length > 1) {
|
375
|
|
- $.each(nameList, function(){
|
376
|
|
- groups[this] = {
|
|
376
|
+ $.each(nameList, function(i,n){
|
|
377
|
+ groups[n] = {
|
377
|
378
|
pattern: patt,
|
378
|
379
|
title: title,
|
379
|
380
|
count: nameList.length
|
|
@@ -384,7 +385,7 @@ window.configuratorApp = (function(){
|
384
|
385
|
}
|
385
|
386
|
}
|
386
|
387
|
if (!match_prev) {
|
387
|
|
- var r = findDef.exec(this);
|
|
388
|
+ var r = findDef.exec(name);
|
388
|
389
|
if (r != null) {
|
389
|
390
|
switch(r[2]) {
|
390
|
391
|
case '0':
|
|
@@ -425,13 +426,13 @@ window.configuratorApp = (function(){
|
425
|
426
|
patt = '^' + r[1] + patt + r[7] + '$';
|
426
|
427
|
title = r[1] + title + r[7];
|
427
|
428
|
match_prev = new RegExp(patt);
|
428
|
|
- match_section = define_section[this];
|
429
|
|
- nameList = [ this ];
|
|
429
|
+ match_section = define_section[name];
|
|
430
|
+ nameList = [ name ];
|
430
|
431
|
}
|
431
|
432
|
}
|
432
|
433
|
}
|
433
|
434
|
});
|
434
|
|
- define_groups[index] = groups;
|
|
435
|
+ define_groups[cindex] = groups;
|
435
|
436
|
},
|
436
|
437
|
|
437
|
438
|
/**
|
|
@@ -442,7 +443,7 @@ window.configuratorApp = (function(){
|
442
|
443
|
initDependentGroups: function() {
|
443
|
444
|
var findBlock = /^[ \t]*#(ifn?def|if|else|endif)[ \t]*(.*)([ \t]*\/\/[^\n]+)?$/gm,
|
444
|
445
|
leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H'];
|
445
|
|
- $.each([$config, $config_adv], function(i, $v) {
|
|
446
|
+ $.each(config_list, function(i, $v) {
|
446
|
447
|
var ifStack = [];
|
447
|
448
|
var r, txt = $v.text();
|
448
|
449
|
while((r = findBlock.exec(txt)) !== null) {
|
|
@@ -481,7 +482,7 @@ window.configuratorApp = (function(){
|
481
|
482
|
var cond = c[0], line = c[1];
|
482
|
483
|
self.log("pop " + c[0], 4);
|
483
|
484
|
if (dependentGroups[cond] === undefined) dependentGroups[cond] = [];
|
484
|
|
- dependentGroups[cond].push({adv:i,start:line,end:lineNum});
|
|
485
|
+ dependentGroups[cond].push({cindex:i,start:line,end:lineNum});
|
485
|
486
|
if (r[1] == 'else') {
|
486
|
487
|
// Reverse the condition
|
487
|
488
|
cond = (cond.indexOf('!') === 0) ? cond.substr(1) : ('!'+cond);
|
|
@@ -504,9 +505,8 @@ window.configuratorApp = (function(){
|
504
|
505
|
*/
|
505
|
506
|
initDefineInfo: function() {
|
506
|
507
|
$.each(define_list, function(e,def_list){
|
507
|
|
- var adv = e == 1;
|
508
|
|
- $.each(def_list, function(i,name) {
|
509
|
|
- define_info[name] = self.getDefineInfo(name, adv);
|
|
508
|
+ $.each(def_list, function(i, name) {
|
|
509
|
+ define_info[name] = self.getDefineInfo(name, e);
|
510
|
510
|
});
|
511
|
511
|
});
|
512
|
512
|
},
|
|
@@ -515,10 +515,12 @@ window.configuratorApp = (function(){
|
515
|
515
|
* Create fields for defines in a config that have none
|
516
|
516
|
* Use define_groups data to group fields together
|
517
|
517
|
*/
|
518
|
|
- createFieldsForDefines: function(index) {
|
519
|
|
- var n = 0, fail_list = [];
|
520
|
|
- var grouping = false, group_pattern, group_regex, subitem, group_section, group_class;
|
521
|
|
- $.each(define_list[index], function(i,name) {
|
|
518
|
+ createFieldsForDefines: function(cindex) {
|
|
519
|
+ // var n = 0;
|
|
520
|
+ var grouping = false, group = define_groups[cindex],
|
|
521
|
+ g_pattern, g_regex, g_subitem, g_section, g_class,
|
|
522
|
+ fail_list = [];
|
|
523
|
+ $.each(define_list[cindex], function(i, name) {
|
522
|
524
|
var section = define_section[name];
|
523
|
525
|
if (section != 'hidden' && !$('#'+name).length) {
|
524
|
526
|
var inf = define_info[name];
|
|
@@ -529,11 +531,10 @@ window.configuratorApp = (function(){
|
529
|
531
|
|
530
|
532
|
// Is this field in a sequence?
|
531
|
533
|
// Then see if it's the second or after
|
532
|
|
- var group = define_groups[index];
|
533
|
534
|
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];
|
|
535
|
+ if (name in group && g_pattern == group[name].pattern && g_section == section) {
|
|
536
|
+ g_subitem = true;
|
|
537
|
+ sublabel = g_regex.exec(name)[1];
|
537
|
538
|
}
|
538
|
539
|
else
|
539
|
540
|
grouping = false;
|
|
@@ -541,20 +542,20 @@ window.configuratorApp = (function(){
|
541
|
542
|
// Start grouping?
|
542
|
543
|
if (!grouping && name in group) {
|
543
|
544
|
grouping = true;
|
544
|
|
- subitem = false;
|
|
545
|
+ g_subitem = false;
|
545
|
546
|
var grp = group[name];
|
546
|
|
- group_pattern = grp.pattern;
|
547
|
|
- group_class = 'one_of_' + grp.count;
|
|
547
|
+ g_pattern = grp.pattern;
|
|
548
|
+ g_class = 'one_of_' + grp.count;
|
548
|
549
|
label_text = grp.title;
|
549
|
|
- group_regex = new RegExp(group_pattern);
|
550
|
|
- group_section = section;
|
551
|
|
- sublabel = group_regex.exec(name)[1];
|
|
550
|
+ g_regex = new RegExp(g_pattern);
|
|
551
|
+ g_section = section;
|
|
552
|
+ sublabel = g_regex.exec(name)[1];
|
552
|
553
|
}
|
553
|
554
|
|
554
|
555
|
var $ff = $('#'+section), $newfield,
|
555
|
556
|
avail = eval(inf.enabled);
|
556
|
557
|
|
557
|
|
- if (!(grouping && subitem)) {
|
|
558
|
+ if (!(grouping && g_subitem)) {
|
558
|
559
|
|
559
|
560
|
var $newlabel = $('<label>',{for:name,class:'added'}).text(label_text.toLabel());
|
560
|
561
|
|
|
@@ -572,7 +573,7 @@ window.configuratorApp = (function(){
|
572
|
573
|
for (var i=0; i<inf.size; i++) {
|
573
|
574
|
var fieldname = i > 0 ? name+'-'+i : name;
|
574
|
575
|
$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);
|
|
576
|
+ if (grouping) $newfield.addClass(g_class);
|
576
|
577
|
$ff.append($newfield);
|
577
|
578
|
}
|
578
|
579
|
}
|
|
@@ -594,9 +595,9 @@ window.configuratorApp = (function(){
|
594
|
595
|
}
|
595
|
596
|
$newfield.attr({id:name,name:name,class:'added',disabled:!avail}).unblock(avail);
|
596
|
597
|
if (grouping) {
|
597
|
|
- $newfield.addClass(group_class);
|
|
598
|
+ $newfield.addClass(g_class);
|
598
|
599
|
if (sublabel)
|
599
|
|
- $ff.append($('<span class="label"/>').text(sublabel.toTitleCase()).unblock(avail));
|
|
600
|
+ $ff.append($('<label>',{class:'added sublabel',for:name}).text(sublabel.toTitleCase()).unblock(avail));
|
600
|
601
|
}
|
601
|
602
|
// Add the new field to the form
|
602
|
603
|
$ff.append($newfield);
|
|
@@ -606,7 +607,7 @@ window.configuratorApp = (function(){
|
606
|
607
|
fail_list.push(name);
|
607
|
608
|
}
|
608
|
609
|
});
|
609
|
|
- if (fail_list) this.log('Unable to parse:\n' + fail_list.join('\n'), 2);
|
|
610
|
+ if (fail_list.length) this.log('Unable to parse:\n' + fail_list.join('\n'), 2);
|
610
|
611
|
},
|
611
|
612
|
|
612
|
613
|
/**
|
|
@@ -615,24 +616,18 @@ window.configuratorApp = (function(){
|
615
|
616
|
handleFileLoad: function(txt, $uploader) {
|
616
|
617
|
txt += '';
|
617
|
618
|
var filename = $uploader.val().replace(/.*[\/\\](.*)$/, '$1');
|
618
|
|
- switch(filename) {
|
619
|
|
- case boards_file:
|
620
|
|
- case config_file:
|
621
|
|
- case config_adv_file:
|
622
|
|
- this.fileLoaded(filename, txt);
|
623
|
|
- break;
|
624
|
|
- default:
|
625
|
|
- this.setMessage("Can't parse '"+filename+"'!");
|
626
|
|
- break;
|
627
|
|
- }
|
|
619
|
+ if ($.inArray(filename, config_file_list))
|
|
620
|
+ this.fileLoaded(filename, txt);
|
|
621
|
+ else
|
|
622
|
+ this.setMessage("Can't parse '"+filename+"'!");
|
628
|
623
|
},
|
629
|
624
|
|
630
|
625
|
/**
|
631
|
626
|
* Process a file after it's been successfully loaded
|
632
|
627
|
*/
|
633
|
|
- fileLoaded: function(filename, txt) {
|
|
628
|
+ fileLoaded: function(filename, txt, wait) {
|
634
|
629
|
this.log("fileLoaded:"+filename,4);
|
635
|
|
- var err, init_index;
|
|
630
|
+ var err, cindex;
|
636
|
631
|
switch(filename) {
|
637
|
632
|
case boards_file:
|
638
|
633
|
this.initBoardsFromText(txt);
|
|
@@ -644,10 +639,12 @@ window.configuratorApp = (function(){
|
644
|
639
|
$config.text(txt);
|
645
|
640
|
total_config_lines = txt.lineCount();
|
646
|
641
|
// this.initThermistorList(txt);
|
647
|
|
- init_index = 0;
|
|
642
|
+ if (!wait) cindex = 0;
|
648
|
643
|
has_config = true;
|
649
|
|
- if (has_config_adv)
|
|
644
|
+ if (has_config_adv) {
|
650
|
645
|
this.activateDownloadAllLink();
|
|
646
|
+ if (wait) cindex = 2;
|
|
647
|
+ }
|
651
|
648
|
}
|
652
|
649
|
else {
|
653
|
650
|
err = boards_file;
|
|
@@ -657,10 +654,12 @@ window.configuratorApp = (function(){
|
657
|
654
|
if (has_config) {
|
658
|
655
|
$config_adv.text(txt);
|
659
|
656
|
total_config_adv_lines = txt.lineCount();
|
660
|
|
- init_index = 1;
|
|
657
|
+ if (!wait) cindex = 1;
|
661
|
658
|
has_config_adv = true;
|
662
|
|
- if (has_config)
|
|
659
|
+ if (has_config) {
|
663
|
660
|
this.activateDownloadAllLink();
|
|
661
|
+ if (wait) cindex = 2;
|
|
662
|
+ }
|
664
|
663
|
}
|
665
|
664
|
else {
|
666
|
665
|
err = config_file;
|
|
@@ -668,29 +667,36 @@ window.configuratorApp = (function(){
|
668
|
667
|
break;
|
669
|
668
|
}
|
670
|
669
|
// When a config file loads defines need update
|
671
|
|
- if (init_index != null) {
|
672
|
|
- var adv = init_index == 1;
|
|
670
|
+ if (cindex != null) this.prepareConfigData(cindex);
|
|
671
|
+
|
|
672
|
+ this.setMessage(err
|
|
673
|
+ ? 'Please upload a "' + boards_file + '" file first!'
|
|
674
|
+ : '"' + filename + '" loaded successfully.', err ? 'error' : 'message'
|
|
675
|
+ );
|
|
676
|
+ },
|
|
677
|
+
|
|
678
|
+ prepareConfigData: function(cindex) {
|
|
679
|
+ var inds = (cindex == 2) ? [ 0, 1 ] : [ cindex ];
|
|
680
|
+ $.each(inds, function(i,e){
|
673
|
681
|
// Purge old fields from the form, clear the define list
|
674
|
|
- this.purgeAddedFields(init_index);
|
|
682
|
+ self.purgeAddedFields(e);
|
675
|
683
|
// Build the define_list
|
676
|
|
- this.initDefineList(init_index, txt);
|
|
684
|
+ self.initDefineList(e);
|
677
|
685
|
// TODO: Find sequential names and group them
|
678
|
686
|
// Allows related settings to occupy one line in the form
|
679
|
|
- this.refreshDefineGroups(init_index);
|
680
|
|
- // Build the dependent defines list
|
681
|
|
- this.initDependentGroups(); // all config text
|
682
|
|
- // Get define_info for all known defines
|
683
|
|
- this.initDefineInfo(); // all config text
|
|
687
|
+ self.refreshDefineGroups(e);
|
|
688
|
+ });
|
|
689
|
+ // Build the dependent defines list
|
|
690
|
+ this.initDependentGroups(); // all config text
|
|
691
|
+ // Get define_info for all known defines
|
|
692
|
+ this.initDefineInfo(); // all config text
|
|
693
|
+ $.each(inds, function(i,e){
|
684
|
694
|
// Create new fields
|
685
|
|
- this.createFieldsForDefines(init_index); // create new fields
|
|
695
|
+ self.createFieldsForDefines(e); // create new fields
|
686
|
696
|
// Init the fields, set values, etc
|
687
|
|
- this.refreshConfigForm(init_index);
|
688
|
|
- this.activateDownloadLink(adv);
|
689
|
|
- }
|
690
|
|
- this.setMessage(err
|
691
|
|
- ? 'Please upload a "' + boards_file + '" file first!'
|
692
|
|
- : '"' + filename + '" loaded successfully.', err ? 'error' : 'message'
|
693
|
|
- );
|
|
697
|
+ self.refreshConfigForm(e);
|
|
698
|
+ self.activateDownloadLink(e);
|
|
699
|
+ });
|
694
|
700
|
},
|
695
|
701
|
|
696
|
702
|
/**
|
|
@@ -782,7 +788,7 @@ window.configuratorApp = (function(){
|
782
|
788
|
/**
|
783
|
789
|
* Update all fields on the form after loading a configuration
|
784
|
790
|
*/
|
785
|
|
- refreshConfigForm: function(init_index) {
|
|
791
|
+ refreshConfigForm: function(cindex) {
|
786
|
792
|
|
787
|
793
|
/**
|
788
|
794
|
* Any manually-created form elements will remain
|
|
@@ -803,13 +809,13 @@ window.configuratorApp = (function(){
|
803
|
809
|
|
804
|
810
|
// Init all existing fields, getting define info for those that need it
|
805
|
811
|
// refreshing the options and updating their current values
|
806
|
|
- $.each(define_list[init_index], function() {
|
807
|
|
- if ($('#'+this).length) {
|
808
|
|
- self.initField(this);
|
809
|
|
- self.initFieldValue(this);
|
|
812
|
+ $.each(define_list[cindex], function(i, name) {
|
|
813
|
+ if ($('#'+name).length) {
|
|
814
|
+ self.initField(name);
|
|
815
|
+ self.initFieldValue(name);
|
810
|
816
|
}
|
811
|
817
|
else
|
812
|
|
- self.log(this + " is not on the page yet.", 2);
|
|
818
|
+ self.log(name + " is not on the page yet.", 2);
|
813
|
819
|
});
|
814
|
820
|
|
815
|
821
|
// Set enabled state based on dependencies
|
|
@@ -835,24 +841,23 @@ window.configuratorApp = (function(){
|
835
|
841
|
// check and update enabled state for the field.
|
836
|
842
|
//
|
837
|
843
|
$.each(define_list, function(e,def_list){
|
838
|
|
- $.each(def_list, function() {
|
839
|
|
- var inf = define_info[this];
|
|
844
|
+ $.each(def_list, function(i, name) {
|
|
845
|
+ var inf = define_info[name];
|
840
|
846
|
if (inf && inf.enabled != 'true') {
|
841
|
|
- var $elm = $('#'+this), ena = eval(inf.enabled);
|
842
|
|
- var isEnabled = (inf.type == 'switch') || self.defineIsEnabled(this);
|
|
847
|
+ var $elm = $('#'+name), ena = eval(inf.enabled);
|
|
848
|
+ var isEnabled = (inf.type == 'switch') || self.defineIsEnabled(name);
|
843
|
849
|
// Make any switch toggle also
|
844
|
|
- $('#'+this+'-switch').attr('disabled', !ena);
|
|
850
|
+ $('#'+name+'-switch').attr('disabled', !ena);
|
845
|
851
|
$elm.attr('disabled', !(ena && isEnabled)).unblock(ena);
|
846
|
|
- //self.log("Setting " + this + " to " + (ena && isEnabled ? 'enabled' : 'disabled'));
|
847
|
|
- // Dim label for unavailable element
|
848
|
|
- $elm.prevAll('label, span.label').filter(':first').unblock(ena);
|
|
852
|
+ //self.log("Setting " + name + " to " + (ena && isEnabled ? 'enabled' : 'disabled'));
|
|
853
|
+ $('label[for="'+name+'"]').unblock(ena);
|
849
|
854
|
}
|
850
|
855
|
});
|
851
|
856
|
});
|
852
|
857
|
},
|
853
|
858
|
|
854
|
859
|
/**
|
855
|
|
- * Make the field responsive, add optional tooltip, enabler box
|
|
860
|
+ * Make a field responsive, tooltip its label(s), add enabler if needed
|
856
|
861
|
*/
|
857
|
862
|
initField: function(name) {
|
858
|
863
|
this.log("initField:"+name,4);
|
|
@@ -861,8 +866,8 @@ window.configuratorApp = (function(){
|
861
|
866
|
|
862
|
867
|
// Create a tooltip on the label if there is one
|
863
|
868
|
if (inf.tooltip) {
|
864
|
|
- // previous label or
|
865
|
|
- var $tipme = $elm.prevAll('label, span.label').filter(':first');
|
|
869
|
+ // label for the item
|
|
870
|
+ var $tipme = $('label[for="'+name+'"]');
|
866
|
871
|
if ($tipme.length) {
|
867
|
872
|
$tipme.unbind('mouseenter mouseleave');
|
868
|
873
|
$tipme.hover(
|
|
@@ -1071,7 +1076,7 @@ window.configuratorApp = (function(){
|
1071
|
1076
|
|
1072
|
1077
|
// Scroll to the altered text if it isn't visible
|
1073
|
1078
|
var halfHeight = $c.height()/2, scrollHeight = $c.prop('scrollHeight'),
|
1074
|
|
- lineHeight = scrollHeight/(inf.adv ? total_config_adv_lines : total_config_lines),
|
|
1079
|
+ lineHeight = scrollHeight/[total_config_lines, total_config_adv_lines][inf.cindex],
|
1075
|
1080
|
textScrollY = (inf.lineNum * lineHeight - halfHeight).limit(0, scrollHeight - 1);
|
1076
|
1081
|
|
1077
|
1082
|
if (always || Math.abs($c.prop('scrollTop') - textScrollY) > halfHeight) {
|
|
@@ -1109,18 +1114,17 @@ window.configuratorApp = (function(){
|
1109
|
1114
|
$elm.attr('disabled', !(on && avail)).unblock(avail); // enable/disable the form field (could also dim it)
|
1110
|
1115
|
}
|
1111
|
1116
|
|
1112
|
|
- // set label color
|
1113
|
|
- $elm.prevAll('label, span.label').filter(':first').unblock(avail);
|
|
1117
|
+ $('label[for="'+name+'"]').unblock(avail);
|
1114
|
1118
|
},
|
1115
|
1119
|
|
1116
|
1120
|
/**
|
1117
|
1121
|
* Purge added fields and all their define info
|
1118
|
1122
|
*/
|
1119
|
|
- purgeAddedFields: function(index) {
|
1120
|
|
- $.each(define_list[index], function(){
|
1121
|
|
- $('#'+this + ",[id^='"+this+"-'],label[for='"+this+"']").filter('.added').remove();
|
|
1123
|
+ purgeAddedFields: function(cindex) {
|
|
1124
|
+ $.each(define_list[cindex], function(i, name){
|
|
1125
|
+ $('#'+name + ",[id^='"+name+"-'],label[for='"+name+"']").filter('.added').remove();
|
1122
|
1126
|
});
|
1123
|
|
- define_list[index] = [];
|
|
1127
|
+ define_list[cindex] = [];
|
1124
|
1128
|
},
|
1125
|
1129
|
|
1126
|
1130
|
/**
|
|
@@ -1133,16 +1137,15 @@ window.configuratorApp = (function(){
|
1133
|
1137
|
* - Gather nearby comments to be used as tooltips.
|
1134
|
1138
|
* - Look for JSON in nearby comments to use as select options.
|
1135
|
1139
|
*/
|
1136
|
|
- getDefineInfo: function(name, adv) {
|
1137
|
|
- if (adv === undefined) adv = false;
|
|
1140
|
+ getDefineInfo: function(name, cindex) {
|
|
1141
|
+ if (cindex === undefined) cindex = 0;
|
1138
|
1142
|
this.log('getDefineInfo:'+name,4);
|
1139
|
|
- var $c = adv ? $config_adv : $config,
|
1140
|
|
- txt = $c.text();
|
|
1143
|
+ var $c = config_list[cindex], txt = $c.text();
|
1141
|
1144
|
|
1142
|
1145
|
// a switch line with no value
|
1143
|
1146
|
var findDef = new RegExp('^([ \\t]*//)?([ \\t]*#define[ \\t]+' + name + ')([ \\t]*/[*/].*)?$', 'm'),
|
1144
|
1147
|
result = findDef.exec(txt),
|
1145
|
|
- info = { type:0, adv:adv, field:$c[0], val_i: 2 };
|
|
1148
|
+ info = { type:0, cindex:cindex, field:$c[0], val_i: 2 };
|
1146
|
1149
|
if (result !== null) {
|
1147
|
1150
|
$.extend(info, {
|
1148
|
1151
|
val_i: 1,
|
|
@@ -1250,10 +1253,9 @@ window.configuratorApp = (function(){
|
1250
|
1253
|
|
1251
|
1254
|
// See if this define is enabled conditionally
|
1252
|
1255
|
var enable_cond = '';
|
1253
|
|
- var adv_index = adv ? 1 : 0;
|
1254
|
1256
|
$.each(dependentGroups, function(cond,dat){
|
1255
|
1257
|
$.each(dat, function(i,o){
|
1256
|
|
- if (o.adv == adv_index && lineNum > o.start && lineNum < o.end) {
|
|
1258
|
+ if (o.cindex == cindex && lineNum > o.start && lineNum < o.end) {
|
1257
|
1259
|
// self.log(name + " is in range " + o.start + "-" + o.end, 2);
|
1258
|
1260
|
// if this setting is in a range, conditions are added
|
1259
|
1261
|
if (enable_cond != '') enable_cond += ' && ';
|