blob: fcf6df2bf856a0a78a710b6531d6ea00f053bd78 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001{% extends "baseprojectpage.html" %}
2{% load projecttags %}
3{% load humanize %}
4
Patrick Williamsf1e5d692016-03-30 15:21:19 -05005{% block title %} BitBake variables - {{project.name}} - Toaster {% endblock %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006{% block projectinfomain %}
7
8<h2>Bitbake variables</h2>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06009<div>
10 <dl>
11 {% if distro_defined %}
12 <dt>
13 <span class="js-config-var-name js-config-var-managed-name">DISTRO</span>
14 <span class="glyphicon glyphicon-question-sign get-help" title="The short name of the distribution. If the variable is blank, meta/conf/distro/defaultsetup.conf will be used"></span>
15 </dt>
16 <dd class="variable-list">
17 <span class="lead" id="distro">{{distro}}</span>
18 <span class="glyphicon glyphicon-edit" id="change-distro-icon"></span>
19 <form id="change-distro-form" class="form-inline" style="display:none;">
20 <div id="edit-distro-name-div" class="form-group">
21 <input type="text" class="form-control" id="new-distro" value="{{distro}}">
22 </div>
23 <button id="apply-change-distro" class="btn btn-default" type="button">Save</button>
24 <button id="cancel-change-distro" type="button" class="btn btn-link">Cancel</button>
25 <span class="help-block" id="distro-error-message"></span>
26 </form>
27 </dd>
28 {% endif %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050029
Patrick Williamsc0f7c042017-02-23 20:41:17 -060030 {% if dl_dir_defined %}
31 <dt>
32 <span class="js-config-var-name js-config-var-managed-name">DL_DIR</span>
33 <span class="glyphicon glyphicon-question-sign get-help" title="Absolute path to the directory used to store downloads required for your builds. By default, Toaster projects share the same downloads directory"></span>
34 </dt>
35 <dd class="variable-list">
36 <span id="dl_dir" class="lead {% if not dl_dir %} text-muted {% endif %}">{% if dl_dir %}{{dl_dir}}{%else%}Not set{%endif%}</span>
37 <span class="glyphicon glyphicon-edit" id="change-dl_dir-icon"></span>
38 <form id="change-dl_dir-form" class="form-inline" style="display:none;">
39 <div class="form-group" id="validate-dl_dir">
40 <input type="text" class="form-control" id="new-dl_dir" placeholder="Type an absolute path">
41 </div>
42 <button id="apply-change-dl_dir" class="btn btn-default" type="button">Save</button>
43 <button id="cancel-change-dl_dir" type="button" class="btn btn-link">Cancel</button>
44 <p class="help-block" id="hintError-dl_dir" style="display:none;">The directory path cannot include spaces or any of these characters: . \ ? % * : | " " &lt; &gt;</p>
45 <p class="help-block" id="hintError-initialChar-dl_dir" style="display:none;">The directory path should either start with a /, e.g. /home/toaster/downloads; or with a variable, e.g. ${TOPDIR}/downloads.</p>
46 </form>
47 </dd>
48 {% endif %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050049
Patrick Williamsc0f7c042017-02-23 20:41:17 -060050 {% if fstypes_defined %}
51 <dt>
52 <span class="js-config-var-name js-config-var-managed-name">IMAGE_FSTYPES</span>
53 <span class="glyphicon glyphicon-question-sign get-help" title="Formats of root file system images that you want to create"></span>
54 </dt>
55 <dd class="variable-list">
56 <span class="lead" id="image_fstypes">{{fstypes}}</span>
57 <span class="glyphicon glyphicon-edit" id="change-image_fstypes-icon"></span>
58 <form id="change-image_fstypes-form" style="display:none;">
59 <label>Type the image types you want to build:</label>
60 <div class="form-group form-inline" id="validate-image_fstypes">
61 <input type="text" class="form-control "id="new-imagefs_types">
62 <button id="apply-change-image_fstypes" type="button" class="btn btn-default">Save</button>
63 <button id="cancel-change-image_fstypes" type="button" class="btn btn-link">Cancel</button>
64 </div>
65 <p class="help-block text-danger" style="display:none;" id="hintError-image-fs_type">A valid image type cannot include underscores</p>
66 <label>Or choose from known image types:</label>
67 <input id="filter-image_fstypes" type="text" placeholder="Search image types" class="form-control">
68 <div id="all-image_fstypes" class="scrolling"></div>
69 </form>
70 </dd>
71 {% endif %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050072
Patrick Williamsc0f7c042017-02-23 20:41:17 -060073 {% if image_install_append_defined %}
74 <dt>
75 <span class="js-config-var-name js-config-var-managed-name">IMAGE_INSTALL_append</span>
76 <span class="glyphicon glyphicon-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 all of them"></span>
77 </dt>
78 <dd class="variable-list">
79 <span id="image_install" class="lead {% if not image_install_append %} text-muted {%endif%}">{% if image_install_append %}{{image_install_append}}{%else%}Not set{%endif%}</span>
80 <span class="glyphicon glyphicon-edit" id="change-image_install-icon"></span>
81 <span class="glyphicon glyphicon-trash" id="delete-image_install-icon" {% if image_install_append %}{%else%}style="display:none;"{%endif%}></span>
82 <form id="change-image_install-form" class="form-inline" style="display:none;">
83 <div class="row">
84 <div class="col-md-4">
85 <span class="help-block">To set IMAGE_INSTALL_append to more than one package, type the package names separated by a space.</span>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050086 </div>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060087 </div>
88 <div class="form-group">
89 <input type="text" class="form-control" id="new-image_install" placeholder="Type one or more package names">
90 </div>
91 <button id="apply-change-image_install" class="btn btn-default" type="button">Save</button>
92 <button id="cancel-change-image_install" type="button" class="btn btn-link">Cancel</button>
93 </form>
94 </dd>
95 {% endif %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050096
Patrick Williamsc0f7c042017-02-23 20:41:17 -060097 {% if package_classes_defined %}
98 <dt>
99 <span class="js-config-var-name js-config-var-managed-name">PACKAGE_CLASSES</span>
100 <span class="glyphicon glyphicon-question-sign get-help" title="Specifies the package manager to use when packaging data"></span>
101 </dt>
102 <dd class="variable-list">
103 <span class="lead" id="package_classes">{{package_classes}}</span>
104 <span id="change-package_classes-icon" class="glyphicon glyphicon-edit"></span>
105 <form id="change-package_classes-form" style="display:none;">
106 <div class="form-group">
107 <label class="control-label">
108 Root file system package format
109 <span class="glyphicon glyphicon-question-sign get-help" title="The package format used to generate the root file system. Options are <code>deb</code>, <code>ipk</code> and <code>rpm</code>"></i>
110 </label>
111 <select id="package_classes-select" class="form-control">
112 <option>package_deb</option>
113 <option>package_ipk</option>
114 <option>package_rpm</option>
115 </select>
116 </div>
117 <div class="form-group">
118 <label class="control-label">
119 Additional package formats
120 <span class="glyphicon glyphicon-question-sign get-help" title="Extra package formats to build"></span>
121 </label>
122 <div class="checkbox">
123 <label id="package_class_1">
124 <input type="checkbox" id="package_class_1_input"> package_deb
125 </label>
126 </div>
127 <div class="checkbox">
128 <label id="package_class_2">
129 <input type="checkbox" id="package_class_2_input"> package_ipk
130 </label>
131 </div>
132 </div>
133 <button id="apply-change-package_classes" type="button" class="btn btn-default">Save</button>
134 <button id="cancel-change-package_classes" type="button" class="btn btn-link">Cancel</button>
135 </form>
136 </dd>
137 {% endif %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500138
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600139 {% if sstate_dir_defined %}
140 <dt>
141 <span class="js-config-var-name js-config-var-managed-name">SSTATE_DIR</span>
142 <span class="glyphicon glyphicon-question-sign get-help" title="Absolute path to the directory used to store shared state cache files. These files are reused across the builds, which makes the builds faster. By default, Toaster projects share the same cache directory"></span>
143 </dt>
144 <dd class="variable-list">
145 <span id="sstate_dir" class="lead {% if not sstate_dir %} text-muted {% endif %}">{% if sstate_dir %}{{sstate_dir}}{%else%}Not set{%endif%}</span>
146 <span class="glyphicon glyphicon-edit" id="change-sstate_dir-icon"></span>
147 <form class="form-inline" id="change-sstate_dir-form" style="display:none;">
148 <div class="form-group" id="validate-sstate_dir">
149 <input type="text" class="form-control" id="new-sstate_dir" placeholder="Type an absolute path">
150 </div>
151 <button id="apply-change-sstate_dir" class="btn btn-default" type="button">Save</button>
152 <button id="cancel-change-sstate_dir" type="button" class="btn btn-link">Cancel</button>
153 <p class="help-block" id="hintError-sstate_dir" style="display:none;">The directory path cannot include spaces or any of these characters: . \ ? % * : | " " &lt; &gt;</p>
154 <p class="help-block" id="hintError-initialChar-sstate_dir" style="display:none;">The directory path should either start with a /, e.g. /home/toaster/sstate-cache; or with a variable, e.g. ${TOPDIR}/sstate-cache.</p>
155 </form>
156 </dd>
157 {% endif %}
158 </dl>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500159
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600160 <!-- <ul class="list-unstyled configuration-list" id="configvar-list"> -->
161 <dl id="configvar-list">
162 <!-- the added configuration variables are inserted here -->
163 </dl>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500164
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600165 <!-- pass the fstypes list, black list, and externally managed variables here -->
166 {% for fstype in vars_fstypes %}
167 <input type="hidden" class="js-checkbox-fstypes-list" value="{{fstype}}">
168 {% endfor %}
169 {% for b in vars_blacklist %}
170 <input type="hidden" class="js-config-blacklist-name" value="{{b}}">
171 {% endfor %}
172 {% for b in vars_managed %}
173 <input type="hidden" class="js-config-managed-name" value="{{b}}">
174 {% endfor %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500175
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600176 <form id="variable-form">
177 <fieldset>
178 <legend>Add variable</legend>
179 <div class="row">
180 <div class="col-md-3">
181 <div id="add-configvar-name-div" class="form-group">
182 <label class="control-label">
183 Variable
184 <span class="glyphicon glyphicon-question-sign get-help"
185 title="Variable names are case sensitive,
186 cannot have spaces, and can only include letters, numbers, underscores
187 and dashes"></span>
188 </label>
189 <input type="text" class="form-control" placeholder="Type the variable name" id="variable">
190 </div>
191 <p class="help-block" id="new-variable-error-message"></p>
192 <div class="form-group">
193 <label clas="control-label">Value</label>
194 <input id="value" type="text" class="form-control" placeholder="Type the variable value">
195 </div>
196 <button id="add-configvar-button" class="btn btn-default save" type="button" disabled>Add variable</button>
197 </div>
198 <div class="col-md-5 help-block">
199 <h5>Some variables cannot be set from Toaster</h5>
200 <p>Toaster cannot set any variables that impact 1) the configuration of the build servers,
201 or 2) where artifacts produced by the build are stored. Such variables include: </p>
202 <p>
203 <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>
204 <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>
205 <code>CVS_PROXY_HOST</code>
206 <code>CVS_PROXY_PORT</code>
207 <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>
208 <code><a href="http://www.yoctoproject.org/docs/1.6.1/ref-manual/ref-manual.html#var-TMPDIR" target="_blank">TMPDIR</a></code></p>
209 <p>Plus the following standard shell environment variables:</p>
210 <p><code>http_proxy</code> <code>ftp_proxy</code> <code>https_proxy</code> <code>all_proxy</code></p>
211 </div>
212 </div>
213 </fieldset>
214 </form>
215</div>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500216
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600217</div>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500218
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600219<script>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500220
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600221// global variables
222var do_reload=false;
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500223
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600224// validate new variable name
225function validate_new_variable() {
226 var variable = $("input#variable").val();
227 var value = $("input#value").val();
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500228
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600229 // presumed innocence
230 $('#new-variable-error-message').text("");
231 var error_msg = "";
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500232
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600233 var existing_configvars = document.getElementsByClassName('js-config-var-name');
234 for (var i = 0, length = existing_configvars.length; i < length; i++) {
235 if (existing_configvars[i].innerHTML.toUpperCase() == variable.toUpperCase()) {
236 error_msg = "This variable is already set in this page. Edit its value instead";
237 }
238 }
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500239
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600240 var blacklist_configvars = document.getElementsByClassName('js-config-blacklist-name');
241 for (var i = 0, length = blacklist_configvars.length; i < length; i++) {
242 if (blacklist_configvars[i].value.toUpperCase() == variable.toUpperCase()) {
243 error_msg = "You cannot edit this variable in Toaster because it is set by the build servers";
244 }
245 }
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500246
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600247 var managed_configvars = document.getElementsByClassName('js-config-managed-name');
248 for (var i = 0, length = managed_configvars.length; i < length; i++) {
249 if (managed_configvars[i].value.toUpperCase() == variable.toUpperCase()) {
250 error_msg = "You cannot set this variable here. Please set it in the <a href=\"{% url 'project' project.id %}\">project main page</a>";
251 }
252 }
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500253
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600254 var bad_chars = /[^a-zA-Z0-9\-_/]/.test(variable);
255 var has_spaces = (0 <= variable.indexOf(" "));
256 var only_spaces = (0 < variable.length) && (0 == variable.trim().length);
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500257
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600258 if (only_spaces) {
259 error_msg = "A valid variable name cannot include spaces";
260 } else if (bad_chars && has_spaces) {
261 error_msg = "A valid variable name can only include letters, numbers and the special characters <code> _ - /</code>. Variable names cannot include spaces";
262 } else if (bad_chars) {
263 error_msg = "A valid variable name can only include letters, numbers and the special characters <code>_ - /</code>";
264 }
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500265
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600266 if ("" != error_msg) {
267 $('#new-variable-error-message').html(error_msg);
268 $(".save").attr("disabled","disabled");
269
270 // add one (and only one) error class append
271 $("#add-configvar-name-div").addClass("has-error");
272 $("#new-variable-error-message").addClass("text-danger");
273
274 return false;
275 } else if (0 == variable.length) {
276 $(".save").attr("disabled","disabled");
277 return false;
278 }
279
280 $("#add-configvar-name-div").removeClass("has-error");
281
282 // now set the "Save" enablement if 'value' also passes
283 if (value.trim().length > 0) {
284 $(".save").removeAttr("disabled");
285 } else {
286 $(".save").attr("disabled","disabled");
287 }
288
289 return true;
290}
291
292// validate distro name
293function validate_distro_name() {
294 var value = $("input#new-distro").val();
295
296 // presumed innocence
297 $('#distro-error-message').text("");
298 var error_msg = "";
299
300 var has_spaces = (0 <= value.indexOf(" "));
301
302 if (has_spaces) {
303 error_msg = "A valid distro name cannot include spaces";
304 } else if (0 == value.length) {
305 error_msg = " ";
306 }
307
308 if ("" != error_msg) {
309 $('#distro-error-message').text(error_msg);
310 $("#apply-change-distro").attr("disabled","disabled");
311
312 // add one (and only one) error class append
313 $("#change-distro-form").addClass("has-error");
314
315 return false;
316 }
317
318 $("#change-distro-form").removeClass("has-error");
319 $("#apply-change-distro").removeAttr("disabled");
320 return true;
321}
322
323// Test to insure at least one FS Type is checked
324function enableFsTypesSave() {
325 var any_checked = 0;
326 $(".fs-checkbox-fstypes:checked").each(function(){
327 any_checked = 1;
328 });
329 if ( 0 == any_checked ) {
330 $("#apply-change-image_fstypes").attr("disabled","disabled");
331 $('.scrolling').addClass('has-error');
332 $('#fstypes-error-message').show();
333 }
334 else {
335 $("#apply-change-image_fstypes").removeAttr("disabled");
336 $('.scrolling').removeClass('has-error');
337 $('#fstypes-error-message').hide();
338 }
339}
340
341// Preset or reset the Package Class checkbox labels
342function updatePackageClassCheckboxes() {
343 $('#package_class_1, #package_class_2').hide();
344 if ($('select').val() == 'package_deb') {
345 $('#package_class_1').html('<input type="checkbox" id="package_class_1_input"> package_ipk');
346 $('#package_class_2').html('<input type="checkbox" id="package_class_2_input"> package_rpm');
347 }
348 if ($('select').val() == 'package_ipk') {
349 $('#package_class_1').html('<input type="checkbox" id="package_class_1_input"> package_deb');
350 $('#package_class_2').html('<input type="checkbox" id="package_class_2_input"> package_rpm');
351 }
352 if ($('select').val() == 'package_rpm') {
353 $('#package_class_1').html('<input type="checkbox" id="package_class_1_input"> package_deb');
354 $('#package_class_2').html('<input type="checkbox" id="package_class_2_input"> package_ipk');
355 }
356 $('#package_class_1, #package_class_2').fadeIn(1500);
357}
358
359// Re-assert handlers when the page is served and/or refreshed via Ajax
360function setEventHandlersForDynamicElements() {
361
362 // change variable value
363 $('.js-icon-pencil-config_var').click(function (evt) {
364 var pk = $(this).attr("x-data");
365 var current_val = $("#config_var_value_"+pk).text();
366 $("#config_var_value_"+pk).hide();
367 $("#config_var_trash_"+pk).hide();
368 $(".js-icon-pencil-config_var[x-data="+pk+"]").hide();
369 $("#change-config_var-form_"+pk).slideDown();
370 $("#new-config_var_"+pk).val(current_val);
371 if ( $("#new-config_var_"+pk).val().length ) {
372 $("#apply-change-config_var_"+pk).removeAttr("disabled");
373 }
374 else {
375 $("#apply-change-config_var_"+pk).attr("disabled");
376 }
377 });
378
379 $('.js-cancel-change-config_var').click(function (evt) {
380 var pk = evt.target.attributes["x-data"].value;
381 $("#change-config_var-form_"+pk).slideUp(function() {
382 $("#config_var_trash_"+pk).show();
383 $('#config_var_value_'+pk).show();
384 $(".js-icon-pencil-config_var[x-data="+pk+"]").show();
385 });
386 });
387
388 $(".js-new-config_var").on('input', function(){
389 if ($(this).val().length == 0) {
390 $(this).parent("div").next(".btn-default").attr("disabled","disabled");
391 }
392 else {
393 $(this).parent("div").next(".btn-default").removeAttr("disabled");
394 }
395 });
396
397 $('.js-apply-change-config_var').click(function (evt) {
398 var xdata = evt.target.attributes["x-data"].value.split(":");
399 var pk = xdata[0];
400 var variable = xdata[1];
401 var val = $('#new-config_var_'+pk).val();
402 postEditAjaxRequest({"configvarChange" : variable+':'+val});
403 $("#change-config_var-form_"+pk).slideUp();
404 $("#config_var_trash_"+pk).fadeIn();
405 $('#config_var_value_'+pk).fadeIn();
406 $(".js-icon-pencil-config_var[x-data="+pk+"]").fadeIn();
407 });
408
409 // delete variable
410 $(".js-icon-trash-config_var").click(function (evt) {
411 var pk = $(this).attr("x-data");
412
413 // fade out the variable+value div, then refresh the variable list
414 $(this).fadeOut();
415 $(this).tooltip("hide");
416 $("config_var_entry_"+pk).fadeOut();
417 $('#config_var_value_'+pk).parent("dd").fadeOut();
418 postEditAjaxRequest({"configvarDel": evt.target.attributes["x-data"].value});
419 });
420
421}
422
423function onEditPageUpdate(data) {
424 // update targets
425 var i; var orightml = "";
426
427 var configvars_sorted = data.configvars.sort(function(a, b){return a[0] > b[0]});
428
429 var managed_configvars = document.getElementsByClassName('js-config-var-managed-name');
430
431 for (i = 0; i < configvars_sorted.length; i++) {
432 // skip if the variable name has a special context (not user defined)
433 var var_context=undefined;
434 for (var j = 0, length = managed_configvars.length; j < length; j++) {
435 if ((managed_configvars[j].innerHTML == configvars_sorted[i][0]) ||
436 (managed_configvars[j].value == configvars_sorted[i][0]) ) {
437 var_context='m';
438 }
439 }
440 if (var_context == undefined) {
441 orightml += '<dt><span id="config_var_entry_'+configvars_sorted[i][2]+'" class="js-config-var-name"></span><span class="glyphicon glyphicon-trash js-icon-trash-config_var" id="config_var_trash_'+configvars_sorted[i][2]+'" x-data="'+configvars_sorted[i][2]+'"></span> </dt>'
442 orightml += '<dd class="variable-list">'
443 orightml += ' <span class="lead" id="config_var_value_'+configvars_sorted[i][2]+'"></span>'
444 orightml += ' <span class="glyphicon glyphicon-edit js-icon-pencil-config_var" x-data="'+configvars_sorted[i][2]+'"></span>'
445 orightml += ' <form class="form-inline" id="change-config_var-form_'+configvars_sorted[i][2]+'" style="display:none;">'
446 orightml += ' <div class="form-group">'
447 orightml += ' <input type="text" class="form-control js-new-config_var" id="new-config_var_'+configvars_sorted[i][2]+'" value=""></div>'
448 orightml += ' <button id="apply-change-config_var_'+configvars_sorted[i][2]+'" class="btn btn-default js-apply-change-config_var" type="button" x-data="'+configvars_sorted[i][2]+':'+configvars_sorted[i][0]+'" disabled>Save</button>'
449 orightml += ' <button type="button" class="btn btn-link js-cancel-change-config_var" x-data="'+configvars_sorted[i][2]+'">Cancel</button>'
450 orightml += ' </form>'
451 orightml += '</dd>'
452 }
453 }
454
455 // update configvars list HTML framework
456 $("dl#configvar-list").html(orightml);
457
458 // insert the name/value pairs safely as non-HTML
459 for (i = 0; i < configvars_sorted.length; i++) {
460 $('#config_var_entry_'+configvars_sorted[i][2]).text(configvars_sorted[i][0]);
461 $('#config_var_value_'+configvars_sorted[i][2]).text(configvars_sorted[i][1]);
462 }
463
464 // Add the tooltips
465 $(".js-icon-trash-config_var").each( function(){ setDeleteTooltip($(this)); });
466 $(".js-icon-pencil-config_var").each(function(){ setChangeTooltip($(this)); });
467
468 // re-assert these event handlers
469 setEventHandlersForDynamicElements();
470}
471
472function onEditAjaxSuccess(data, textstatus) {
473 console.log("XHR returned:", data, "(" + textstatus + ")");
474 if (data.error != "ok") {
475 alert("error on request:\n" + data.error);
476 return;
477 }
478
479 // delayed page reload?
480 if (do_reload) {
481 do_reload=false;
482 location.reload(true);
483 } else {
484 onEditPageUpdate(data);
485 }
486}
487
488function onEditAjaxError(jqXHR, textstatus, error) {
489 alert("XHR errored:\n" + error + "\n(" + textstatus + ")");
490 // re-assert the event handlers
491}
492
493/* ensure cookie exists {% csrf_token %} */
494function postEditAjaxRequest(reqdata) {
495 var ajax = $.ajax({
496 type:"POST",
497 data: $.param(reqdata),
498 url:"{% url 'xhr_configvaredit' project.id%}",
499 headers: { 'X-CSRFToken': $.cookie("csrftoken")},
500 success: onEditAjaxSuccess,
501 error: onEditAjaxError,
502 })
503}
504
505function setDeleteTooltip(object) {
506 object.tooltip({ container: 'body', html: true, delay: {show: 400}, title: "Delete" });
507}
508function setChangeTooltip(object) {
509 object.tooltip({ container: 'body', html: true, delay: {show: 400}, title: "Change" });
510}
511
512$(document).ready(function() {
513
514 //
515 // Register handlers for static elements
516 //
517
518 {% if distro_defined %}
519 // change distro variable
520 $('#change-distro-icon').click(function() {
521 $('#change-distro-icon, #distro').hide();
522 $("#change-distro-form").slideDown();
523 $("#new-distro").val( $('#distro').text() );
524 $("#apply-change-distro").removeAttr("disabled");
525 });
526
527 $('#cancel-change-distro').click(function(){
528 $("#change-distro-form").slideUp(function() {
529 $('#distro, #change-distro-icon').show();
530
531 // reset any dangling error state
532 $('#distro-error-message').text("");
533 $("#change-distro-form").removeClass("has-error");
534 });
535 });
536
537 // validate new distro name
538 $("input#new-distro").on('input', function (evt) {
539 validate_distro_name();
540 });
541
542 $('#apply-change-distro').click(function(){
543 //$('#repo').parent().removeClass('highlight-go');
544 var name = $('#new-distro').val();
545 postEditAjaxRequest({"configvarChange" : 'DISTRO:'+name});
546 $('#distro').text(name);
547 $("#change-distro-form").slideUp(function () {
548 $('#distro, #change-distro-icon').show();
549 });
550 });
551 {% endif %}
552
553 {% if dl_dir_defined %}
554
555 // change DL_DIR variable
556 $('#change-dl_dir-icon').click(function() {
557 $('#change-dl_dir-form').removeClass('has-error');
558 // preset the edit value
559 var current_val = $("#dl_dir").text().trim();
560 if (current_val == "Not set") {
561 current_val="";
562 $("#apply-change-dl_dir").attr("disabled","disabled");
563 }
564 $("input#new-dl_dir").val(current_val);
565 // enable / disable the save button based on the input value
566 if ( current_val.length ) {
567 $("#apply-change-dl_dir").removeAttr("disabled");
568 }
569 else {
570 $("#apply-change-dl_dir").attr("disabled","disabled");
571 }
572
573 $('#change-dl_dir-icon, #dl_dir').hide();
574 $("#change-dl_dir-form").slideDown();
575 });
576
577 $('#cancel-change-dl_dir').click(function(){
578 $("#hintError-dl_dir").hide();
579 $("#hintError-initialChar-dl_dir").hide();
580 $("#change-dl_dir-form").slideUp(function() {
581 $('#dl_dir, #change-dl_dir-icon').show();
582 });
583 });
584
585 $("#new-dl_dir").on('input', function(){
586 if ($(this).val().trim().length == 0) {
587 $("#apply-change-dl_dir").attr("disabled","disabled");
588 $('#change-dl_dir-form').addClass('has-error');
589 $('#hintError-dl_dir').hide();
590 $('#hintError-initialChar-dl_dir').hide();
591 }
592 else {
593 var input = $(this);
594 var reBeginWithSlash = /^\//;
595 var reCheckVariable = /^\$/;
596 var re = /([ <>\\|":\.%\?\*]+)/;
597 var invalidDir = re.test(input.val());
598 var invalidSlash = reBeginWithSlash.test(input.val());
599 var invalidVar = reCheckVariable.test(input.val());
600 if (!invalidSlash && !invalidVar) {
601 $('#change-dl_dir-form').addClass('has-error');
602 $("#apply-change-dl_dir").attr("disabled","disabled");
603 $('#hintError-initialChar-dl_dir').show();
604 } else if (invalidDir) {
605 $('#change-dl_dir-form').addClass('has-error');
606 $("#apply-change-dl_dir").attr("disabled","disabled");
607 $('#hintError-dl_dir').show();
608 } else {
609 $('#change-dl_dir-form').removeClass('has-error');
610 $("#apply-change-dl_dir").removeAttr("disabled");
611 $('#hintError-dl_dir').hide();
612 $('#hintError-initialChar-dl_dir').hide();
613 }
614 }
615 });
616
617 $('#apply-change-dl_dir').click(function(){
618 var value = $('#new-dl_dir').val().trim();
619 postEditAjaxRequest({"configvarChange" : 'DL_DIR:'+value});
620 $('#dl_dir').text(value);
621 $('#dl_dir').removeClass('muted');
622 $("#change-dl_dir-form").slideUp(function () {
623 $('#dl_dir, #change-dl_dir-icon').show();
624 });
625 });
626
627 {% endif %}
628
629 {% if fstypes_defined %}
630 // change IMAGE_FSTYPES variable
631
632 // get value of fstypes and add to the textbox
633 $("#new-imagefs_types").val("{{fstypes}}");
634
635 // If value of new-imagefs_types is empty disable save button
636 $("#new-imagefs_types").on("input", function() {
637 $(this).val($(this).val().replace(/\s+/g,' '));
638 if ($(this).val().length === 0) {
639 //$('#apply-change-image_fstypes').prop('disabled', true);
640 $('#apply-change-image_fstypes').attr("disabled", "disabled");
641 } else {
642 //$('#apply-change-image_fstypes').prop('disabled', false);
643 $('#apply-change-image_fstypes').removeAttr("disabled");
644 }
645
646 /*If user types imagefs do the action on checkboxes.
647 Lets say if an imagefstype typed by user and the same
648 imagefs is unchecked in the checkbox, then checkbox needs
649 to get checked. Similarly when user deletes imagefs from
650 textbox the checkbox which is checked gets unchecked.
651 */
652 $('#all-image_fstypes input').each(function(){
653 var imagefs_userval = $('#new-imagefs_types').val();
654 if( imagefs_userval.indexOf($(this).val()) > -1) {
655 $(this).prop('checked', true);
656 } else {
657 $(this).prop('checked', false);
658 }
659 });
660
661 // Validate underscore in image fs types
662 if ($(this).val().indexOf('_') > -1) {
663 $('#validate-image_fstypes').addClass('has-error');
664 $('#hintError-image-fs_type').show();
665 $("#apply-change-image_fstypes").prop("disabled", true);
666 } else {
667 $('#validate-image_fstypes').removeClass('has-error');
668 $('#hintError-image-fs_type').hide();
669 }
670 });
671
672 $('#change-image_fstypes-icon').click(function() {
673 $('#change-image_fstypes-icon, #image_fstypes').hide();
674 $("#change-image_fstypes-form").slideDown();
675 // avoid false substring matches by including space separators
676 var html = "";
677 var fstypes = " " + document.getElementById("image_fstypes").innerHTML + " ";
678 var fstypes_list = document.getElementsByClassName('js-checkbox-fstypes-list');
679 // Add the checked boxes first
680 if (" " != fstypes) {
681 for (var i = 0, length = fstypes_list.length; i < length; i++) {
682 if (0 <= fstypes.indexOf(" "+fstypes_list[i].value+" ")) {
683 html += '<div class="checkbox"><label><input type="checkbox" class="fs-checkbox-fstypes" value="'+fstypes_list[i].value+'" checked="checked">'+fstypes_list[i].value+'</label></div>';
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500684 }
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600685 }
686 }
687 // Add the un-checked boxes second
688 for (var i = 0, length = fstypes_list.length; i < length; i++) {
689 if (0 > fstypes.indexOf(" "+fstypes_list[i].value+" ")) {
690 html += '<div class="checkbox"><label><input type="checkbox" class="fs-checkbox-fstypes" value="'+fstypes_list[i].value+'">'+fstypes_list[i].value+'</label></div>';
691 }
692 }
693 // Add the 'no search matches' line last
694 html += '<label id="no-match-fstypes" class="text-muted">No image types found</label>\n';
695 // Display the list
696 document.getElementById("all-image_fstypes").innerHTML = html;
697 $('#no-match-fstypes').hide();
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500698
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600699 // clear the previous filter values and warning messages
700 $("input#filter-image_fstypes").val("");
701 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500702
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600703 // When checkbox is checked/unchecked kindly update the text
704 $(document).on("change", "#all-image_fstypes :checkbox", function() {
705 var imagefs = $(this);
706 var imagefs_obj = $('#new-imagefs_types');
707 var imagefs_userval = imagefs_obj.val();
708 if ($(this).is(':checked')) {
709 if (imagefs_userval.indexOf($(imagefs).val()) === -1) {
710 imagefs_obj.val(imagefs_userval + " " + $(imagefs).val());
711 }
712 } else {
713 if (imagefs_userval.indexOf($(imagefs).val()) > -1) {
714 imagefs_obj.val(imagefs_userval.replace($(imagefs).val(), '').trim());
715 }
716 }
717 if ($('#new-imagefs_types').val().length === 0) {
718 $("#apply-change-image_fstypes").prop("disabled", true);
719 } else {
720 $("#apply-change-image_fstypes").prop("disabled", false);
721 }
722 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500723
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600724 $('#cancel-change-image_fstypes').click(function(){
725 $("#new-imagefs_types").val("{{fstypes}}");
726 $("#change-image_fstypes-form").slideUp(function() {
727 $('#image_fstypes, #change-image_fstypes-icon').show();
728 });
729 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500730
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600731 $('#filter-image_fstypes').on('input', function(){
732 var valThis = $(this).val().toLowerCase();
733 var matchCount=0;
734 $('#all-image_fstypes label').each(function(){
735 var text = $(this).text().toLowerCase();
736 var match = text.indexOf(valThis);
737 if (match >= 0) {
738 $(this).show();
739 matchCount += 1;
740 }
741 else {
742 $(this).hide();
743 }
744 });
745 if (matchCount === 0) {
746 $('#no-match-fstypes').show();
747 } else {
748 $('#no-match-fstypes').hide();
749 }
750 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500751
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600752 $('#apply-change-image_fstypes').click(function(){
753 var fstypes = $('#new-imagefs_types').val();
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500754
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600755 postEditAjaxRequest({"configvarChange" : 'IMAGE_FSTYPES:'+fstypes});
756 $('#image_fstypes').text(fstypes);
757 $('#image_fstypes').parent().removeClass('muted');
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500758
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600759 $("#change-image_fstypes-form").slideUp(function() {
760 $('#image_fstypes, #change-image_fstypes-icon').show();
761 });
762 });
763 {% endif %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500764
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500765
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600766 {% if image_install_append_defined %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500767
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600768 // init IMAGE_INSTALL_append trash icon
769 setDeleteTooltip($('#delete-image_install-icon'));
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500770
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600771 // change IMAGE_INSTALL_append variable
772 $('#change-image_install-icon').click(function() {
773 // preset the edit value
774 var current_val = $("span#image_install").text().trim();
775 if (current_val == "Not set") {
776 current_val="";
777 $("#apply-change-image_install").attr("disabled","disabled");
778 } else {
779 // insure these non-empty values have single space prefix
780 current_val=" " + current_val;
781 $("#apply-change-image_install").removeAttr("disabled");
782 }
783 $("input#new-image_install").val(current_val);
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500784
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600785 $('#change-image_install-icon, #delete-image_install-icon, #image_install').hide();
786 $("#change-image_install-form").slideDown();
787 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500788
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600789 $('#cancel-change-image_install').click(function(){
790 $("#change-image_install-form").slideUp(function() {
791 $('#image_install, #change-image_install-icon').show();
792 if ($("span#image_install").text() != "Not set") {
793 $('#delete-image_install-icon').show();
794 setDeleteTooltip($('#delete-image_install-icon'));
795 }
796 });
797 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500798
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600799 $("#new-image_install").on('input', function(){
800 if ($(this).val().trim().length == 0) {
801 $("#apply-change-image_install").attr("disabled","disabled");
802 }
803 else {
804 $("#apply-change-image_install").removeAttr("disabled");
805 }
806 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500807
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600808 $('#apply-change-image_install').click(function(){
809 // insure these non-empty values have single space prefix
810 var value = " " + $('#new-image_install').val().trim();
811 postEditAjaxRequest({"configvarChange" : 'IMAGE_INSTALL_append:'+value});
812 $('#image_install').text(value);
813 $('#image_install').removeClass('text-muted');
814 $("#change-image_install-form").slideUp(function () {
815 $('#image_install, #change-image_install-icon').show();
816 if (value.length > -1) {
817 $('#delete-image_install-icon').show();
818 setDeleteTooltip($('#delete-image_install-icon'));
819 }
820 });
821 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500822
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600823 // delete IMAGE_INSTALL_append variable value
824 $('#delete-image_install-icon').click(function(){
825 $(this).tooltip('hide');
826 postEditAjaxRequest({"configvarChange" : 'IMAGE_INSTALL_append:'+''});
827 $('#image_install').parent().fadeOut(1000, function(){
828 $('#image_install').addClass('text-muted');
829 $('#image_install').text('Not set');
830 $('#delete-image_install-icon').hide();
831 $('#image_install').parent().fadeIn(1000);
832 });
833 });
834 {% endif %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500835
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500836
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600837 {% if package_classes_defined %}
838 // change PACKAGE_CLASSES variable
839 $('#change-package_classes-icon').click(function() {
840 $('#change-package_classes-icon, #package_classes').hide();
841 $("#change-package_classes-form").slideDown();
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500842
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600843 // initialize the pulldown and checkboxes
844 var value = $("#package_classes").text();
845 if ( value.indexOf("package_deb") == 0 ) {
846 $("#package_classes-select").prop('selectedIndex', 0);
847 updatePackageClassCheckboxes();
848 if ( value.indexOf("_ipk") > 0 ) {
849 $("#package_class_1_input").attr("checked",true);
850 }
851 if ( value.indexOf("_rpm") > 0 ) {
852 $("#package_class_2_input").attr("checked",true);
853 }
854 }
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500855
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600856 if ( value.indexOf("package_ipk") == 0 ) {
857 $("#package_classes-select").prop('selectedIndex', 1);
858 updatePackageClassCheckboxes();
859 if ( value.indexOf("_deb") > 0 ) {
860 $("#package_class_1_input").attr("checked",true);
861 }
862 if ( value.indexOf("_rpm") > 0 ) {
863 $("#package_class_2_input").attr("checked",true);
864 }
865 }
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500866
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600867 if ( value.indexOf("package_rpm") == 0 ) {
868 $("#package_classes-select").prop('selectedIndex', 2);
869 updatePackageClassCheckboxes();
870 if ( value.indexOf("_deb") > 0 ) {
871 $("#package_class_1_input").attr("checked",true);
872 }
873 if ( value.indexOf("_ipk") > 0 ) {
874 $("#package_class_2_input").attr("checked",true);
875 }
876 }
877 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500878
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600879 $('#cancel-change-package_classes').click(function(){
880 $("#change-package_classes-form").slideUp(function() {
881 $('#package_classes, #change-package_classes-icon').show();
882 });
883 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500884
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600885 $('select').change(function() {
886 updatePackageClassCheckboxes();
887 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500888
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600889 $('#apply-change-package_classes').click(function(){
890 var e = document.getElementById("package_classes-select");
891 var val = e.options[e.selectedIndex].text;
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500892
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600893 pc1_checked = document.getElementById("package_class_1_input").checked;
894 pc2_checked = document.getElementById("package_class_2_input").checked;
895 if (val == "package_deb") {
896 if (pc1_checked) val = val + " package_ipk";
897 if (pc2_checked) val = val + " package_rpm";
898 }
899 if (val == "package_ipk") {
900 if (pc1_checked) val = val + " package_deb";
901 if (pc2_checked) val = val + " package_rpm";
902 }
903 if (val == "package_rpm") {
904 if (pc1_checked) val = val + " package_deb";
905 if (pc2_checked) val = val + " package_ipk";
906 }
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500907
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600908 $('#package_classes').text(val);
909 //$('#package_classes').parent().removeClass('muted');
910 postEditAjaxRequest({"configvarChange" : 'PACKAGE_CLASSES:'+val});
911 $("#change-package_classes-form").slideUp(function() {
912 $('#package_classes, #change-package_classes-icon').show();
913 });
914 });
915 {% endif %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500916
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600917 {% if sstate_dir_defined %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500918
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600919 // change SSTATE_DIR variable
920 $('#change-sstate_dir-icon').click(function() {
921 $('#change-sstate_dir-form').removeClass('has-error');
922 // preset the edit value
923 var current_val = $("span#sstate_dir").text().trim();
924 if (current_val == "Not set") {
925 current_val="";
926 $("#apply-change-sstate_dir").attr("disabled","disabled");
927 }
928 $("input#new-sstate_dir").val(current_val);
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500929
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600930 // enable / disable the save button based on the input value
931 if ( current_val.length ) {
932 $("#apply-change-sstate_dir").removeAttr("disabled");
933 }
934 else {
935 $("#apply-change-sstate_dir").attr("disabled","disabled");
936 }
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500937
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600938 $('#change-sstate_dir-icon, #sstate_dir').hide();
939 $("#change-sstate_dir-form").slideDown();
940 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500941
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600942 $('#cancel-change-sstate_dir').click(function(){
943 $("#hintError-sstate_dir").hide();
944 $("#hintError-initialChar-sstate_dir").hide();
945 $("#change-sstate_dir-form").slideUp(function() {
946 $('#sstate_dir, #change-sstate_dir-icon').show();
947 });
948 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500949
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600950 $("#new-sstate_dir").on('input', function(){
951 if ($(this).val().trim().length == 0) {
952 $("#apply-change-sstate_dir").attr("disabled","disabled");
953 $('#change-sstate_dir-form').addClass('has-error');
954 $('#hintError-sstate_dir').hide();
955 $('#hintError-initialChar-sstate_dir').hide();
956 }
957 else {
958 var input = $(this);
959 var reBeginWithSlash = /^\//;
960 var reCheckVariable = /^\$/;
961 var re = /([ <>\\|":\.%\?\*]+)/;
962 var invalidDir = re.test(input.val());
963 var invalidSlash = reBeginWithSlash.test(input.val());
964 var invalidVar = reCheckVariable.test(input.val());
965 if (!invalidSlash && !invalidVar) {
966 $('#change-sstate_dir-form').addClass('has-error');
967 $("#apply-change-sstate_dir").attr("disabled","disabled");
968 $('#hintError-initialChar-sstate_dir').show();
969 } else if (invalidDir) {
970 $('#change-sstate_dir-form').addClass('has-error');
971 $("#apply-change-sstate_dir").attr("disabled","disabled");
972 $('#hintError-sstate_dir').show();
973 } else {
974 $('#change-sstate_dir-form').removeClass('has-error');
975 $("#apply-change-sstate_dir").removeAttr("disabled");
976 $('#hintError-sstate_dir').hide();
977 $('#hintError-initialChar-sstate_dir').hide();
978 }
979 }
980 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500981
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600982 $('#apply-change-sstate_dir').click(function(){
983 var value = $('#new-sstate_dir').val().trim();
984 postEditAjaxRequest({"configvarChange" : 'SSTATE_DIR:'+value});
985 $('#sstate_dir').text(value);
986 $('#sstate_dir').removeClass('text-muted');
987 $("#change-sstate_dir-form").slideUp(function () {
988 $('#sstate_dir, #change-sstate_dir-icon').show();
989 });
990 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500991
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600992 {% endif %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500993
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600994 // add new variable
995 $("button#add-configvar-button").click( function (evt) {
996 var variable = $("input#variable").val();
997 var value = $("input#value").val();
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500998
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600999 postEditAjaxRequest({"configvarAdd" : variable+':'+value});
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001000
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001001 // clear the previous values
1002 $("input#variable").val("");
1003 $("input#value").val("");
1004 // Disable add button
1005 $(".save").attr("disabled","disabled");
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001006
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001007 // Reload page if admin-removed core managed value is manually added back in
1008 if (0 <= " DISTRO DL_DIR IMAGE_FSTYPES IMAGE_INSTALL_append PACKAGE_CLASSES SSTATE_DIR ".indexOf( " "+variable+" " )) {
1009 // delayed reload to avoid race condition with postEditAjaxRequest
1010 do_reload=true;
1011 }
1012 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001013
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001014 // validate new variable name and value
1015 $("#variable, #value").on('input', function() {
1016 validate_new_variable();
1017 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001018
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001019 //
1020 // draw and register the dynamic configuration variables and handlers
1021 //
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001022
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001023 var data = {
1024 configvars : []
1025 };
1026 {% for c in configvars %}
1027 data.configvars.push([ "{{c.name}}","{{c.value}}","{{c.pk}}" ]);
1028 {% if '' != vars_context|get_dict_value:c.name %}
1029 data.vars_context[ "{{c.name}}" ] = "{{vars_context|get_dict_value:c.name }}";
1030 {% endif %}
1031 {% endfor %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001032
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001033 // draw these elements and assert their event handlers
1034 onEditPageUpdate(data);
1035});
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001036
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001037</script>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001038
1039{% endblock %}