1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
|
{% extends "baseprojectpage.html" %}
{% load projecttags %}
{% load humanize %}
{% block localbreadcrumb %}
<li>Configuration variables</li>
{% endblock %}
{% block projectinfomain %}
<div class="page-header">
<h1>Configuration variables</h1>
</div>
<div style="padding-left:19px;">
<dl class="dl-vertical">
{% if distro_defined %}
<dt>
<span class="js-config-var-name js-config-var-managed-name">DISTRO</span>
<i class="icon-question-sign get-help" title="The short name of the distribution. If the variable is blank, meta/conf/distro/defaultsetup.conf will be used. <br /><a href='http://www.yoctoproject.org/docs/1.6.1/ref-manual/ref-manual.html#var-DISTRO' target='_blank'>Read more in the manual</a>"></i>
</dt>
<dd class="lead">
<span id="distro">{{distro}}</span>
<i class="icon-pencil" id="change-distro-icon"></i>
<form id="change-distro-form" style="display:none;">
<div class="input-append">
<span id="edit-distro-name-div" class="control-group">
<input type="text" id="new-distro" value="{{distro}}">
<button id="apply-change-distro" class="btn" type="button">Save</button>
<button id="cancel-change-distro" type="button" class="btn btn-link">Cancel</button>
</span>
<span class="help-block error" id="distro-error-message"></span>
</div>
</form>
</dd>
{% endif %}
{% if fstypes_defined %}
<dt>
<span class="js-config-var-name js-config-var-managed-name">IMAGE_FSTYPES</span>
<i class="icon-question-sign get-help" title="Formats of root file system images that you want to have created <br /><a href='http://www.yoctoproject.org/docs/1.6.1/ref-manual/ref-manual.html#var-IMAGE_FSTYPES' target='_blank'>Read more in the manual</a>"></i>
</dt>
<dd class="lead">
<span id="image_fstypes">{{fstypes}}</span>
<i class="icon-pencil" id="change-image_fstypes-icon"></i>
<form id="change-image_fstypes-form" style="display:none;">
<input id="filter-image_fstypes" type="text" placeholder="Search image types" class="span4">
<div id="all-image_fstypes" class="scrolling">
</div>
<button id="apply-change-image_fstypes" type="button" class="btn">Save</button>
<button id="cancel-change-image_fstypes" type="button" class="btn btn-link">Cancel</button>
</form>
</dd>
{% endif %}
{% if image_install_append_defined %}
<dt>
<span class="js-config-var-name js-config-var-managed-name">IMAGE_INSTALL_append</span>
<i class="icon-question-sign get-help" title="Specifies additional packages to install into an image. If your build creates more than one image, the packages will be installed in <strong>all of them</strong> <br /><a href='http://www.yoctoproject.org/docs/1.6.1/ref-manual/ref-manual.html#var-IMAGE_INSTALL' target='_blank'>Read more in the manual</a>"></i>
</dt>
<dd class="lead">
<span id="image_install"{% if image_install_append %}{%else%} class="muted"{%endif%}>{% if image_install_append %}{{image_install_append}}{%else%}Not set{%endif%}</span>
<i class="icon-pencil" id="change-image_install-icon"></i>
<i class="icon-trash" id="delete-image_install-icon" {% if image_install_append %}{%else%}style="display:none;"{%endif%}></i>
<form id="change-image_install-form" style="display:none;">
<div class="row-fluid">
<span class="help-block span4">To set IMAGE_INSTALL_append to more than one package, type the package names separated by a space.</span>
</div>
<div class="input-append">
<input type="text" class="input-xlarge" id="new-image_install" placeholder="Type one or more package names">
<button id="apply-change-image_install" class="btn" type="button">Save</button>
<button id="cancel-change-image_install" type="button" class="btn btn-link">Cancel</button>
</div>
</form>
</dd>
{% endif %}
{% if package_classes_defined %}
<dt>
<span class="js-config-var-name js-config-var-managed-name">PACKAGE_CLASSES</span>
<i class="icon-question-sign get-help" title="Specifies the package manager to use when packaging data <br /><a href='http://www.yoctoproject.org/docs/1.6.1/ref-manual/ref-manual.html#var-PACKAGE_CLASSES' target='_blank'>Read more in the manual</a>"></i>
</dt>
<dd class="lead">
<span id="package_classes">{{package_classes}}</span>
<i id="change-package_classes-icon" class="icon-pencil"></i>
<form id="change-package_classes-form" style="display:none;">
<label>
Root file system package format
<i class="icon-question-sign get-help" title="The package format used to generate the root file system. Options are <code>dev</code>, <code>ipk</code> and <code>rpm</code>"></i>
</label>
<select id="package_classes-select">
<option>package_deb</option>
<option>package_ipk</option>
<option>package_rpm</option>
</select>
<label>
Additional package formats
<i class="icon-question-sign get-help" title="Extra package formats to build"></i>
</label>
<label class="checkbox" id="package_class_1">
<input type="checkbox" id="package_class_1_input"> package_deb
</label>
<label class="checkbox" id="package_class_2">
<input type="checkbox" id="package_class_2_input"> package_ipk
</label>
<div style="padding-top:10px;">
<button id="apply-change-package_classes" type="button" class="btn">Save</button>
<button id="cancel-change-package_classes" type="button" class="btn btn-link">Cancel</button>
</div>
</form>
</dd>
{% endif %}
{% if sdk_machine_defined %}
<dt>
<span class="js-config-var-name js-config-var-managed-name">SDKMACHINE</span>
<i class="icon-question-sign get-help" title="Specifies the architecture (i.e. i686 or x86_64) for which to build SDK and ADT items <br /><a href='http://www.yoctoproject.org/docs/1.6.1/ref-manual/ref-manual.html#var-SDKMACHINE' target='_blank'>Read more in the manual</a>"></i>
</dt>
<dd class="lead">
<span id="sdkmachine">{{sdk_machine}}</span>
<i id="change-sdkmachine-icon" class="icon-pencil"></i>
<form id="change-sdkmachine-form" style="display:none;">
<label class="radio">
<input type="radio" name="sdkmachine" value="i686">
i686
</label>
<label class="radio">
<input type="radio" name="sdkmachine" value="x86_64">
x86_64
</label>
<div style="padding-top:10px;">
<button id="apply-change-sdkmachine" type="button" class="btn">Save</button>
<button id="cancel-change-sdkmachine" type="button" class="btn btn-link">Cancel</button>
</div>
</form>
</dd>
{% endif %}
</dl>
<!-- <ul class="unstyled configuration-list" id="configvar-list"> -->
<dl id="configvar-list">
<!-- the added configuration variables are inserted here -->
</dl>
<!-- pass the fstypes list, black list, and externally managed variables here -->
{% for fstype in vars_fstypes %}
<input type="hidden" class="js-checkbox-fstypes-list" value="{{fstype}}">
{% endfor %}
{% for b in vars_blacklist %}
<input type="hidden" class="js-config-blacklist-name" value="{{b}}">
{% endfor %}
{% for b in vars_managed %}
<input type="hidden" class="js-config-managed-name" value="{{b}}">
{% endfor %}
<div class="row-fluid">
<form id="variable-form">
<fieldset style="padding-left:0px;">
<legend>Add variable</legend>
<div class="span3" style="margin-left:0px;">
<span id="add-configvar-name-div" class="control-group">
<label>
Variable
<i title="" class="icon-question-sign get-help"
data-original-title="Variable names are case sensitive,
cannot have spaces, and can only include letters, numbers, underscores
and dashes"></i>
</label>
<input type="text" placeholder="Type variable name" id="variable">
<span class="help-block error" id="new-variable-error-message"></span>
</span>
<label>Value</label>
<input id="value" type="text" placeholder="Type variable value"><p>
<div>
<button id="add-configvar-button" class="btn save" type="button" disabled>Add variable</button>
</div>
</div>
<div class="span5 help-block">
<h5>Some variables are reserved from Toaster</h5>
<p>Toaster cannot set any variables that impact 1) the configuration of the build servers,
or 2) where artifacts produced by the build are stored. Such variables include: </p>
<p>
<code><a href="http://www.yoctoproject.org/docs/1.6.1/ref-manual/ref-manual.html#var-BB_DISKMON_DIRS" target="_blank">BB_DISKMON_DIRS</a></code>
<code><a href="http://www.yoctoproject.org/docs/1.6.1/ref-manual/ref-manual.html#var-BB_NUMBER_THREADS" target="_blank">BB_NUMBER_THREADS</a></code>
<code>CVS_PROXY_HOST</code>
<code>CVS_PROXY_PORT</code>
<code><a href="http://www.yoctoproject.org/docs/1.6.1/ref-manual/ref-manual.html#var-DL_DIR" target="_blank">DL_DIR</a></code>
<code><a href="http://www.yoctoproject.org/docs/1.6.1/ref-manual/ref-manual.html#var-PARALLEL_MAKE" target="_blank">PARALLEL_MAKE</a></code>
<code><a href="http://www.yoctoproject.org/docs/1.6.1/ref-manual/ref-manual.html#var-SSTATE_DIR" target="_blank">SSTATE_DIR</a></code>
<code><a href="http://www.yoctoproject.org/docs/1.6.1/ref-manual/ref-manual.html#var-SSTATE_MIRRORS" target="_blank">SSTATE_MIRRORS</a></code>
<code><a href="http://www.yoctoproject.org/docs/1.6.1/ref-manual/ref-manual.html#var-TMPDIR" target="_blank">TMPDIR</a></code></p>
<p>Plus the following standard shell environment variables:</p>
<p><code>http_proxy</code> <code>ftp_proxy</code> <code>https_proxy</code> <code>all_proxy</code></p>
</div>
</fieldset>
</form>
</div>
</div>
<script>
// global variables
var do_reload=false;
// validate new variable name
function validate_new_variable() {
var variable = $("input#variable").val();
var value = $("input#value").val();
// presumed innocence
$('#new-variable-error-message').text("");
var error_msg = "";
var existing_configvars = document.getElementsByClassName('js-config-var-name');
for (var i = 0, length = existing_configvars.length; i < length; i++) {
if (existing_configvars[i].innerHTML.toUpperCase() == variable.toUpperCase()) {
error_msg = "This variable is already set in this page, edit its value instead";
}
}
var blacklist_configvars = document.getElementsByClassName('js-config-blacklist-name');
for (var i = 0, length = blacklist_configvars.length; i < length; i++) {
if (blacklist_configvars[i].value.toUpperCase() == variable.toUpperCase()) {
error_msg = "You cannot edit this variable in Toaster because it is set by the build servers";
}
}
var managed_configvars = document.getElementsByClassName('js-config-managed-name');
for (var i = 0, length = managed_configvars.length; i < length; i++) {
if (managed_configvars[i].value.toUpperCase() == variable.toUpperCase()) {
error_msg = "You cannot set this variable here. Please set it in the <a href=\"{% url 'project' project.id %}\">project main page</a>";
}
}
var bad_chars = /[^a-zA-Z0-9\-_]/.test(variable);
var has_spaces = (0 <= variable.indexOf(" "));
var only_spaces = (0 < variable.length) && (0 == variable.trim().length);
if (only_spaces) {
error_msg = "A valid variable name cannot include spaces";
} else if (bad_chars && has_spaces) {
error_msg = "A valid variable name can only include letters, numbers, underscores, dashes, and cannot include spaces";
} else if (bad_chars) {
error_msg = "A valid variable name can only include letters, numbers, underscores, and dashes";
}
if ("" != error_msg) {
$('#new-variable-error-message').html(error_msg);
$(".save").attr("disabled","disabled");
// add one (and only one) error class append
var d = document.getElementById("add-configvar-name-div");
d.className = d.className.replace(" error","");
d.className = d.className + " error";
return false;
} else if (0 == variable.length) {
$(".save").attr("disabled","disabled");
return false;
}
var d = document.getElementById("add-configvar-name-div");
d.className = d.className.replace(" error","");
// now set the "Save" enablement if 'value' also passes
if (value.trim().length > 0) {
$(".save").removeAttr("disabled");
} else {
$(".save").attr("disabled","disabled");
}
return true;
}
// validate distro name
function validate_distro_name() {
var value = $("input#new-distro").val();
// presumed innocence
$('#distro-error-message').text("");
var error_msg = "";
var has_spaces = (0 <= value.indexOf(" "));
if (has_spaces) {
error_msg = "A valid distro name cannot include spaces";
} else if (0 == value.length) {
error_msg = " ";
}
if ("" != error_msg) {
$('#distro-error-message').text(error_msg);
$("#apply-change-distro").attr("disabled","disabled");
// add one (and only one) error class append
var d = document.getElementById("edit-distro-name-div");
d.className = d.className.replace(" error","");
d.className = d.className + " error";
return false;
}
var d = document.getElementById("edit-distro-name-div");
d.className = d.className.replace(" error","");
$("#apply-change-distro").removeAttr("disabled");
return true;
}
// Test to insure at least one FS Type is checked
function enableFsTypesSave() {
var any_checked = 0;
$(".fs-checkbox-fstypes:checked").each(function(){
any_checked = 1;
});
if ( 0 == any_checked ) {
$("#apply-change-image_fstypes").attr("disabled","disabled");
}
else {
$("#apply-change-image_fstypes").removeAttr("disabled");
}
}
// Preset or reset the Package Class checkbox labels
function updatePackageClassCheckboxes() {
$('#package_class_1, #package_class_2').hide();
if ($('select').val() == 'package_deb') {
$('#package_class_1').html('<input type="checkbox" id="package_class_1_input"> package_ipk');
$('#package_class_2').html('<input type="checkbox" id="package_class_2_input"> package_rpm');
}
if ($('select').val() == 'package_ipk') {
$('#package_class_1').html('<input type="checkbox" id="package_class_1_input"> package_deb');
$('#package_class_2').html('<input type="checkbox" id="package_class_2_input"> package_rpm');
}
if ($('select').val() == 'package_rpm') {
$('#package_class_1').html('<input type="checkbox" id="package_class_1_input"> package_deb');
$('#package_class_2').html('<input type="checkbox" id="package_class_2_input"> package_ipk');
}
$('#package_class_1, #package_class_2').fadeIn(1500);
}
// Re-assert handlers when the page is served and/or refreshed via Ajax
function setEventHandlersForDynamicElements() {
// change variable value
$('.js-icon-pencil-config_var').click(function (evt) {
var pk = evt.target.attributes["x-data"].value;
var current_val = $("span#config_var_value_"+pk).text();
$('.js-icon-pencil-config_var, .js-icon-trash-config_var, #config_var_value_'+pk).hide();
$("#change-config_var-form_"+pk).slideDown();
$("input#new-config_var_"+pk).val(current_val);
});
$('.js-cancel-change-config_var').click(function (evt) {
var pk = evt.target.attributes["x-data"].value;
$("#change-config_var-form_"+pk).slideUp(function() {
$('.js-icon-pencil-config_var, .js-icon-trash-config_var, #config_var_value_'+pk).show();
});
});
$(".js-new-config_var").on('input', function(){
if ($(this).val().length == 0) {
$(".js-apply-change-config_var").attr("disabled","disabled");
}
else {
$(".js-apply-change-config_var").removeAttr("disabled");
}
});
$('.js-apply-change-config_var').click(function (evt) {
var xdata = evt.target.attributes["x-data"].value.split(":");
var pk = xdata[0];
var variable = xdata[1];
var val = $('#new-config_var_'+pk).val();
postEditAjaxRequest({"configvarChange" : variable+':'+val});
$('#config_var_value_'+pk).parent().removeClass('muted');
$("#change-config_var-form_"+pk).slideUp(function() {
$('.js-icon-pencil-config_var, .js-icon-trash-config_var, #config_var_value_'+pk).show();
});
});
// delete variable
$(".js-icon-trash-config_var").click(function (evt) {
var xdata = evt.target.attributes["x-data"].value.split(":");
var pk = xdata[0];
// hide the dangling trash tooltip
$('#config_var_trash_'+pk).hide();
// fade out the variable+value div, then refresh the variable list
$('#config_var_entry_'+pk).parent().parent().fadeOut(1000, function(){
postEditAjaxRequest({"configvarDel": evt.target.attributes["x-data"].value});
});
});
}
function onEditPageUpdate(data) {
// update targets
var i; var orightml = "";
var configvars_sorted = data.configvars.sort(function(a, b){return a[0] > b[0]});
var managed_configvars = document.getElementsByClassName('js-config-var-managed-name');
for (i = 0; i < configvars_sorted.length; i++) {
// skip if the variable name has a special context (not user defined)
var var_context=undefined;
for (var j = 0, length = managed_configvars.length; j < length; j++) {
if ((managed_configvars[j].innerHTML == configvars_sorted[i][0]) ||
(managed_configvars[j].value == configvars_sorted[i][0]) ) {
var_context='m';
}
}
if (var_context == undefined) {
orightml += '<div> <dt><span id="config_var_entry_'+configvars_sorted[i][2]+'" class="js-config-var-name"></span><i class="icon-trash js-icon-trash-config_var" id="config_var_trash_'+configvars_sorted[i][2]+'" x-data="'+configvars_sorted[i][2]+'"></i> </dt>'
orightml += '<dd class="lead">'
orightml += ' <span id="config_var_value_'+configvars_sorted[i][2]+'"></span>'
orightml += ' <i class="icon-pencil js-icon-pencil-config_var" x-data="'+configvars_sorted[i][2]+'"></i>'
orightml += ' <form id="change-config_var-form_'+configvars_sorted[i][2]+'" style="display:none;">'
orightml += ' <div class="input-append">'
orightml += ' <input type="text" class="input-xlarge js-new-config_var" id="new-config_var_'+configvars_sorted[i][2]+'" value="">'
orightml += ' <button class="btn js-apply-change-config_var" type="button" x-data="'+configvars_sorted[i][2]+':'+configvars_sorted[i][0]+'" disabled>Save</button>'
orightml += ' <button type="button" class="btn btn-link js-cancel-change-config_var" x-data="'+configvars_sorted[i][2]+'">Cancel</button>'
orightml += ' </div>'
orightml += ' </form>'
orightml += '</dd> </div>'
}
}
// update configvars list HTML framework
$("dl#configvar-list").html(orightml);
// insert the name/value pairs safely as non-HTML
for (i = 0; i < configvars_sorted.length; i++) {
$('#config_var_entry_'+configvars_sorted[i][2]).text(configvars_sorted[i][0]);
$('#config_var_value_'+configvars_sorted[i][2]).text(configvars_sorted[i][1]);
}
// Add the tooltips
$(".js-icon-trash-config_var").each( function(){ setDeleteTooltip($(this)); });
$(".js-icon-pencil-config_var").each(function(){ setChangeTooltip($(this)); });
// re-assert these event handlers
setEventHandlersForDynamicElements();
}
function onEditAjaxSuccess(data, textstatus) {
// console.log("XHR returned:", data, "(" + textstatus + ")");
if (data.error != "ok") {
alert("error on request:\n" + data.error);
return;
}
// delayed page reload?
if (do_reload) {
do_reload=false;
location.reload(true);
} else {
onEditPageUpdate(data);
}
}
function onEditAjaxError(jqXHR, textstatus, error) {
alert("XHR errored:\n" + error + "\n(" + textstatus + ")");
// re-assert the event handlers
}
/* ensure cookie exists {% csrf_token %} */
function postEditAjaxRequest(reqdata) {
var ajax = $.ajax({
type:"POST",
data: $.param(reqdata),
url:"{% url 'xhr_configvaredit' project.id%}",
headers: { 'X-CSRFToken': $.cookie("csrftoken")},
success: onEditAjaxSuccess,
error: onEditAjaxError,
})
}
function setDeleteTooltip(object) {
object.tooltip({ container: 'body', html: true, delay: {show: 400}, title: "Delete" });
}
function setChangeTooltip(object) {
object.tooltip({ container: 'body', html: true, delay: {show: 400}, title: "Change" });
}
$(document).ready(function() {
//
// Register handlers for static elements
//
{% if distro_defined %}
// change distro variable
$('#change-distro-icon').click(function() {
$('#change-distro-icon, #distro').hide();
$("#change-distro-form").slideDown();
$("#new-distro").val( $('#distro').text() );
});
$('#cancel-change-distro').click(function(){
$("#change-distro-form").slideUp(function() {
$('#distro, #change-distro-icon').show();
// reset any dangling error state
$('#distro-error-message').text("");
var d = document.getElementById("edit-distro-name-div");
d.className = d.className.replace(" error","");
});
});
// validate new distro name
$("input#new-distro").on('input', function (evt) {
validate_distro_name();
});
$('#apply-change-distro').click(function(){
//$('#repo').parent().removeClass('highlight-go');
var name = $('#new-distro').val();
postEditAjaxRequest({"configvarChange" : 'DISTRO:'+name});
$('#distro').text(name);
$("#change-distro-form").slideUp(function () {
$('#distro, #change-distro-icon').show();
});
});
{% endif %}
{% if fstypes_defined %}
// change IMAGE_FSTYPES variable
$('#change-image_fstypes-icon').click(function() {
$('#change-image_fstypes-icon, #image_fstypes').hide();
$("#change-image_fstypes-form").slideDown();
// avoid false substring matches by including space separators
var html = "";
var fstypes = " " + document.getElementById("image_fstypes").innerHTML + " ";
var fstypes_list = document.getElementsByClassName('js-checkbox-fstypes-list');
// Add the checked boxes first
if (" " != fstypes) {
for (var i = 0, length = fstypes_list.length; i < length; i++) {
if (0 <= fstypes.indexOf(" "+fstypes_list[i].value+" ")) {
html += '<label class="checkbox"><input type="checkbox" class="fs-checkbox-fstypes" value="'+fstypes_list[i].value+'" checked="checked">'+fstypes_list[i].value+'</label>\n';
}
}
}
// Add the un-checked boxes second
for (var i = 0, length = fstypes_list.length; i < length; i++) {
if (0 > fstypes.indexOf(" "+fstypes_list[i].value+" ")) {
html += '<label class="checkbox"><input type="checkbox" class="fs-checkbox-fstypes" value="'+fstypes_list[i].value+'">'+fstypes_list[i].value+'</label>\n';
}
}
document.getElementById("all-image_fstypes").innerHTML = html;
// Watch elements to disable Save when none are checked
$(".fs-checkbox-fstypes").each(function(){
$(this).click(function() {
enableFsTypesSave();
});
});
// clear the previous filter values
$("input#filter-image_fstypes").val("");
});
$('#cancel-change-image_fstypes').click(function(){
$("#change-image_fstypes-form").slideUp(function() {
$('#image_fstypes, #change-image_fstypes-icon').show();
});
});
$('#filter-image_fstypes').on('input', function(){
var valThis = $(this).val().toLowerCase();
$('#all-image_fstypes label').each(function(){
var text = $(this).text().toLowerCase();
var match = text.indexOf(valThis);
if (match >= 0) {
$(this).show();
}
else {
$(this).hide();
}
});
});
$('#apply-change-image_fstypes').click(function(){
// extract the selected fstypes and sort them
var fstypes_array = [];
var checkboxes = document.getElementsByClassName('fs-checkbox-fstypes');
$(".fs-checkbox-fstypes:checked").each(function(){
fstypes_array.push($(this).val());
});
fstypes_array.sort();
// now make a string of them
var fstypes = '';
for (var i = 0, length = fstypes_array.length; i < length; i++) {
fstypes += fstypes_array[i] + ' ';
}
fstypes = fstypes.trim();
postEditAjaxRequest({"configvarChange" : 'IMAGE_FSTYPES:'+fstypes});
$('#image_fstypes').text(fstypes);
$('#image_fstypes').parent().removeClass('muted');
$("#change-image_fstypes-form").slideUp(function() {
$('#image_fstypes, #change-image_fstypes-icon').show();
});
});
{% endif %}
{% if image_install_append_defined %}
// init IMAGE_INSTALL_append trash icon
setDeleteTooltip($('#delete-image_install-icon'));
// change IMAGE_INSTALL_append variable
$('#change-image_install-icon').click(function() {
// preset the edit value
var current_val = $("span#image_install").text().trim();
if (current_val == "Not set") {
current_val="";
$("#apply-change-image_install").attr("disabled","disabled");
} else {
// insure these non-empty values have single space prefix
current_val=" " + current_val;
}
$("input#new-image_install").val(current_val);
$('#change-image_install-icon, #delete-image_install-icon, #image_install').hide();
$("#change-image_install-form").slideDown();
});
$('#cancel-change-image_install').click(function(){
$("#change-image_install-form").slideUp(function() {
$('#image_install, #change-image_install-icon').show();
if ($("span#image_install").text() != "Not set") {
$('#delete-image_install-icon').show();
setDeleteTooltip($('#delete-image_install-icon'));
}
});
});
$("#new-image_install").on('input', function(){
if ($(this).val().trim().length == 0) {
$("#apply-change-image_install").attr("disabled","disabled");
}
else {
$("#apply-change-image_install").removeAttr("disabled");
}
});
$('#apply-change-image_install').click(function(){
// insure these non-empty values have single space prefix
var value = " " + $('#new-image_install').val().trim();
postEditAjaxRequest({"configvarChange" : 'IMAGE_INSTALL_append:'+value});
$('#image_install').text(value);
$('#image_install').removeClass('muted');
$("#change-image_install-form").slideUp(function () {
$('#image_install, #change-image_install-icon').show();
if (value.length > -1) {
$('#delete-image_install-icon').show();
setDeleteTooltip($('#delete-image_install-icon'));
}
});
});
// delete IMAGE_INSTALL_append variable value
$('#delete-image_install-icon').click(function(){
$(this).tooltip('hide');
postEditAjaxRequest({"configvarChange" : 'IMAGE_INSTALL_append:'+''});
$('#image_install').parent().fadeOut(1000, function(){
$('#image_install').addClass('muted');
$('#image_install').text('Not set');
$('#delete-image_install-icon').hide();
$('#image_install').parent().fadeIn(1000);
});
});
{% endif %}
{% if package_classes_defined %}
// change PACKAGE_CLASSES variable
$('#change-package_classes-icon').click(function() {
$('#change-package_classes-icon, #package_classes').hide();
$("#change-package_classes-form").slideDown();
// initialize the pulldown and checkboxes
var value = $("#package_classes").text();
if ( value.indexOf("package_deb") == 0 ) {
$("#package_classes-select").prop('selectedIndex', 0);
updatePackageClassCheckboxes();
if ( value.indexOf("_ipk") > 0 ) {
$("#package_class_1_input").attr("checked",true);
}
if ( value.indexOf("_rpm") > 0 ) {
$("#package_class_2_input").attr("checked",true);
}
}
if ( value.indexOf("package_ipk") == 0 ) {
$("#package_classes-select").prop('selectedIndex', 1);
updatePackageClassCheckboxes();
if ( value.indexOf("_deb") > 0 ) {
$("#package_class_1_input").attr("checked",true);
}
if ( value.indexOf("_rpm") > 0 ) {
$("#package_class_2_input").attr("checked",true);
}
}
if ( value.indexOf("package_rpm") == 0 ) {
$("#package_classes-select").prop('selectedIndex', 2);
updatePackageClassCheckboxes();
if ( value.indexOf("_deb") > 0 ) {
$("#package_class_1_input").attr("checked",true);
}
if ( value.indexOf("_ipk") > 0 ) {
$("#package_class_2_input").attr("checked",true);
}
}
});
$('#cancel-change-package_classes').click(function(){
$("#change-package_classes-form").slideUp(function() {
$('#package_classes, #change-package_classes-icon').show();
});
});
$('select').change(function() {
updatePackageClassCheckboxes();
});
$('#apply-change-package_classes').click(function(){
var e = document.getElementById("package_classes-select");
var val = e.options[e.selectedIndex].text;
pc1_checked = document.getElementById("package_class_1_input").checked;
pc2_checked = document.getElementById("package_class_2_input").checked;
if (val == "package_deb") {
if (pc1_checked) val = val + " package_ipk";
if (pc2_checked) val = val + " package_rpm";
}
if (val == "package_ipk") {
if (pc1_checked) val = val + " package_deb";
if (pc2_checked) val = val + " package_rpm";
}
if (val == "package_rpm") {
if (pc1_checked) val = val + " package_deb";
if (pc2_checked) val = val + " package_ipk";
}
$('#package_classes').text(val);
//$('#package_classes').parent().removeClass('muted');
postEditAjaxRequest({"configvarChange" : 'PACKAGE_CLASSES:'+val});
$("#change-package_classes-form").slideUp(function() {
$('#package_classes, #change-package_classes-icon').show();
});
});
{% endif %}
{% if sdk_machine_defined %}
// change SDKMACHINE variable
$('#change-sdkmachine-icon').click(function() {
var current_value = document.getElementById("sdkmachine").innerHTML;
var radios = document.getElementsByName('sdkmachine');
for (var i = 0, length = radios.length; i < length; i++) {
radios[i].checked = false;
if (radios[i].value == current_value) {
radios[i].checked = true;
}
}
$('#change-sdkmachine-icon, #sdkmachine').hide();
$("#change-sdkmachine-form").slideDown();
});
$('#cancel-change-sdkmachine').click(function(){
$("#change-sdkmachine-form").slideUp(function() {
$('#sdkmachine, #change-sdkmachine-icon').show();
});
});
$('#apply-change-sdkmachine').click(function(){
var value="";
var radios = document.getElementsByName('sdkmachine');
for (var i = 0, length = radios.length; i < length; i++) {
if (radios[i].checked) {
// do whatever you want with the checked radio
value=radios[i].value;
break;
}
}
postEditAjaxRequest({"configvarChange" : 'SDKMACHINE:'+value});
$('#sdkmachine').text(value);
$("#change-sdkmachine-form").slideUp(function() {
$('#sdkmachine, #change-sdkmachine-icon').show();
});
});
{% endif %}
// add new variable
$("button#add-configvar-button").click( function (evt) {
var variable = $("input#variable").val();
var value = $("input#value").val();
postEditAjaxRequest({"configvarAdd" : variable+':'+value});
// clear the previous values
$("input#variable").val("");
$("input#value").val("");
// Disable add button
$(".save").attr("disabled","disabled");
// Reload page if admin-removed core managed value is manually added back in
if (0 <= " DISTRO IMAGE_FSTYPES IMAGE_INSTALL_append PACKAGE_CLASSES SDKMACHINE ".indexOf( " "+variable+" " )) {
// delayed reload to avoid race condition with postEditAjaxRequest
do_reload=true;
}
});
// validate new variable name and value
$("#variable, #value").on('input', function() {
validate_new_variable();
});
//
// draw and register the dynamic configuration variables and handlers
//
var data = {
configvars : []
};
{% for c in configvars %}
data.configvars.push([ "{{c.name}}","{{c.value}}","{{c.pk}}" ]);
{% if '' != vars_context|get_dict_value:c.name %}
data.vars_context[ "{{c.name}}" ] = "{{vars_context|get_dict_value:c.name }}";
{% endif %}
{% endfor %}
// draw these elements and assert their event handlers
onEditPageUpdate(data);
});
</script>
{% endblock %}
|