blob: 933c588f34e91b6db7516e67c50c206c35751491 [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>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050044 <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>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060045 <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>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050066 <p class="help-block text-danger" style="display:none;" id="fstypes-error-message">You must select at least one image type</p>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060067 <label>Or choose from known image types:</label>
68 <input id="filter-image_fstypes" type="text" placeholder="Search image types" class="form-control">
69 <div id="all-image_fstypes" class="scrolling"></div>
70 </form>
71 </dd>
72 {% endif %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050073
Patrick Williamsc0f7c042017-02-23 20:41:17 -060074 {% if image_install_append_defined %}
75 <dt>
76 <span class="js-config-var-name js-config-var-managed-name">IMAGE_INSTALL_append</span>
77 <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>
78 </dt>
79 <dd class="variable-list">
80 <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>
81 <span class="glyphicon glyphicon-edit" id="change-image_install-icon"></span>
82 <span class="glyphicon glyphicon-trash" id="delete-image_install-icon" {% if image_install_append %}{%else%}style="display:none;"{%endif%}></span>
83 <form id="change-image_install-form" class="form-inline" style="display:none;">
84 <div class="row">
85 <div class="col-md-4">
86 <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 -050087 </div>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060088 </div>
89 <div class="form-group">
90 <input type="text" class="form-control" id="new-image_install" placeholder="Type one or more package names">
91 </div>
92 <button id="apply-change-image_install" class="btn btn-default" type="button">Save</button>
93 <button id="cancel-change-image_install" type="button" class="btn btn-link">Cancel</button>
94 </form>
95 </dd>
96 {% endif %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050097
Patrick Williamsc0f7c042017-02-23 20:41:17 -060098 {% if package_classes_defined %}
99 <dt>
100 <span class="js-config-var-name js-config-var-managed-name">PACKAGE_CLASSES</span>
101 <span class="glyphicon glyphicon-question-sign get-help" title="Specifies the package manager to use when packaging data"></span>
102 </dt>
103 <dd class="variable-list">
104 <span class="lead" id="package_classes">{{package_classes}}</span>
105 <span id="change-package_classes-icon" class="glyphicon glyphicon-edit"></span>
106 <form id="change-package_classes-form" style="display:none;">
107 <div class="form-group">
108 <label class="control-label">
109 Root file system package format
110 <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>
111 </label>
112 <select id="package_classes-select" class="form-control">
113 <option>package_deb</option>
114 <option>package_ipk</option>
115 <option>package_rpm</option>
116 </select>
117 </div>
118 <div class="form-group">
119 <label class="control-label">
120 Additional package formats
121 <span class="glyphicon glyphicon-question-sign get-help" title="Extra package formats to build"></span>
122 </label>
123 <div class="checkbox">
124 <label id="package_class_1">
125 <input type="checkbox" id="package_class_1_input"> package_deb
126 </label>
127 </div>
128 <div class="checkbox">
129 <label id="package_class_2">
130 <input type="checkbox" id="package_class_2_input"> package_ipk
131 </label>
132 </div>
133 </div>
134 <button id="apply-change-package_classes" type="button" class="btn btn-default">Save</button>
135 <button id="cancel-change-package_classes" type="button" class="btn btn-link">Cancel</button>
136 </form>
137 </dd>
138 {% endif %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500139
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600140 {% if sstate_dir_defined %}
141 <dt>
142 <span class="js-config-var-name js-config-var-managed-name">SSTATE_DIR</span>
143 <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>
144 </dt>
145 <dd class="variable-list">
146 <span id="sstate_dir" class="lead {% if not sstate_dir %} text-muted {% endif %}">{% if sstate_dir %}{{sstate_dir}}{%else%}Not set{%endif%}</span>
147 <span class="glyphicon glyphicon-edit" id="change-sstate_dir-icon"></span>
148 <form class="form-inline" id="change-sstate_dir-form" style="display:none;">
149 <div class="form-group" id="validate-sstate_dir">
150 <input type="text" class="form-control" id="new-sstate_dir" placeholder="Type an absolute path">
151 </div>
152 <button id="apply-change-sstate_dir" class="btn btn-default" type="button">Save</button>
153 <button id="cancel-change-sstate_dir" type="button" class="btn btn-link">Cancel</button>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500154 <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>
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600155 <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>
156 </form>
157 </dd>
158 {% endif %}
159 </dl>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500160
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600161 <!-- <ul class="list-unstyled configuration-list" id="configvar-list"> -->
162 <dl id="configvar-list">
163 <!-- the added configuration variables are inserted here -->
164 </dl>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500165
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600166 <!-- pass the fstypes list, black list, and externally managed variables here -->
167 {% for fstype in vars_fstypes %}
168 <input type="hidden" class="js-checkbox-fstypes-list" value="{{fstype}}">
169 {% endfor %}
170 {% for b in vars_blacklist %}
171 <input type="hidden" class="js-config-blacklist-name" value="{{b}}">
172 {% endfor %}
173 {% for b in vars_managed %}
174 <input type="hidden" class="js-config-managed-name" value="{{b}}">
175 {% endfor %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500176
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600177 <form id="variable-form">
178 <fieldset>
179 <legend>Add variable</legend>
180 <div class="row">
181 <div class="col-md-3">
182 <div id="add-configvar-name-div" class="form-group">
183 <label class="control-label">
184 Variable
185 <span class="glyphicon glyphicon-question-sign get-help"
186 title="Variable names are case sensitive,
187 cannot have spaces, and can only include letters, numbers, underscores
188 and dashes"></span>
189 </label>
190 <input type="text" class="form-control" placeholder="Type the variable name" id="variable">
191 </div>
192 <p class="help-block" id="new-variable-error-message"></p>
193 <div class="form-group">
194 <label clas="control-label">Value</label>
195 <input id="value" type="text" class="form-control" placeholder="Type the variable value">
196 </div>
197 <button id="add-configvar-button" class="btn btn-default save" type="button" disabled>Add variable</button>
198 </div>
199 <div class="col-md-5 help-block">
200 <h5>Some variables cannot be set from Toaster</h5>
201 <p>Toaster cannot set any variables that impact 1) the configuration of the build servers,
202 or 2) where artifacts produced by the build are stored. Such variables include: </p>
203 <p>
204 <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>
205 <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>
206 <code>CVS_PROXY_HOST</code>
207 <code>CVS_PROXY_PORT</code>
208 <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>
209 <code><a href="http://www.yoctoproject.org/docs/1.6.1/ref-manual/ref-manual.html#var-TMPDIR" target="_blank">TMPDIR</a></code></p>
210 <p>Plus the following standard shell environment variables:</p>
211 <p><code>http_proxy</code> <code>ftp_proxy</code> <code>https_proxy</code> <code>all_proxy</code></p>
212 </div>
213 </div>
214 </fieldset>
215 </form>
216</div>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500217
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600218</div>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500219
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600220<script>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500221
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600222// global variables
223var do_reload=false;
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500224
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600225// validate new variable name
226function validate_new_variable() {
227 var variable = $("input#variable").val();
228 var value = $("input#value").val();
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500229
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600230 // presumed innocence
231 $('#new-variable-error-message').text("");
232 var error_msg = "";
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500233
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600234 var existing_configvars = document.getElementsByClassName('js-config-var-name');
235 for (var i = 0, length = existing_configvars.length; i < length; i++) {
236 if (existing_configvars[i].innerHTML.toUpperCase() == variable.toUpperCase()) {
237 error_msg = "This variable is already set in this page. Edit its value instead";
238 }
239 }
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500240
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600241 var blacklist_configvars = document.getElementsByClassName('js-config-blacklist-name');
242 for (var i = 0, length = blacklist_configvars.length; i < length; i++) {
243 if (blacklist_configvars[i].value.toUpperCase() == variable.toUpperCase()) {
244 error_msg = "You cannot edit this variable in Toaster because it is set by the build servers";
245 }
246 }
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500247
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600248 var managed_configvars = document.getElementsByClassName('js-config-managed-name');
249 for (var i = 0, length = managed_configvars.length; i < length; i++) {
250 if (managed_configvars[i].value.toUpperCase() == variable.toUpperCase()) {
251 error_msg = "You cannot set this variable here. Please set it in the <a href=\"{% url 'project' project.id %}\">project main page</a>";
252 }
253 }
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500254
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600255 var bad_chars = /[^a-zA-Z0-9\-_/]/.test(variable);
256 var has_spaces = (0 <= variable.indexOf(" "));
257 var only_spaces = (0 < variable.length) && (0 == variable.trim().length);
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500258
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600259 if (only_spaces) {
260 error_msg = "A valid variable name cannot include spaces";
261 } else if (bad_chars && has_spaces) {
262 error_msg = "A valid variable name can only include letters, numbers and the special characters <code> _ - /</code>. Variable names cannot include spaces";
263 } else if (bad_chars) {
264 error_msg = "A valid variable name can only include letters, numbers and the special characters <code>_ - /</code>";
265 }
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500266
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600267 if ("" != error_msg) {
268 $('#new-variable-error-message').html(error_msg);
269 $(".save").attr("disabled","disabled");
270
271 // add one (and only one) error class append
272 $("#add-configvar-name-div").addClass("has-error");
273 $("#new-variable-error-message").addClass("text-danger");
274
275 return false;
276 } else if (0 == variable.length) {
277 $(".save").attr("disabled","disabled");
278 return false;
279 }
280
281 $("#add-configvar-name-div").removeClass("has-error");
282
283 // now set the "Save" enablement if 'value' also passes
284 if (value.trim().length > 0) {
285 $(".save").removeAttr("disabled");
286 } else {
287 $(".save").attr("disabled","disabled");
288 }
289
290 return true;
291}
292
293// validate distro name
294function validate_distro_name() {
295 var value = $("input#new-distro").val();
296
297 // presumed innocence
298 $('#distro-error-message').text("");
299 var error_msg = "";
300
301 var has_spaces = (0 <= value.indexOf(" "));
302
303 if (has_spaces) {
304 error_msg = "A valid distro name cannot include spaces";
305 } else if (0 == value.length) {
306 error_msg = " ";
307 }
308
309 if ("" != error_msg) {
310 $('#distro-error-message').text(error_msg);
311 $("#apply-change-distro").attr("disabled","disabled");
312
313 // add one (and only one) error class append
314 $("#change-distro-form").addClass("has-error");
315
316 return false;
317 }
318
319 $("#change-distro-form").removeClass("has-error");
320 $("#apply-change-distro").removeAttr("disabled");
321 return true;
322}
323
324// Test to insure at least one FS Type is checked
325function enableFsTypesSave() {
326 var any_checked = 0;
327 $(".fs-checkbox-fstypes:checked").each(function(){
328 any_checked = 1;
329 });
330 if ( 0 == any_checked ) {
331 $("#apply-change-image_fstypes").attr("disabled","disabled");
332 $('.scrolling').addClass('has-error');
333 $('#fstypes-error-message').show();
334 }
335 else {
336 $("#apply-change-image_fstypes").removeAttr("disabled");
337 $('.scrolling').removeClass('has-error');
338 $('#fstypes-error-message').hide();
339 }
340}
341
342// Preset or reset the Package Class checkbox labels
343function updatePackageClassCheckboxes() {
344 $('#package_class_1, #package_class_2').hide();
345 if ($('select').val() == 'package_deb') {
346 $('#package_class_1').html('<input type="checkbox" id="package_class_1_input"> package_ipk');
347 $('#package_class_2').html('<input type="checkbox" id="package_class_2_input"> package_rpm');
348 }
349 if ($('select').val() == 'package_ipk') {
350 $('#package_class_1').html('<input type="checkbox" id="package_class_1_input"> package_deb');
351 $('#package_class_2').html('<input type="checkbox" id="package_class_2_input"> package_rpm');
352 }
353 if ($('select').val() == 'package_rpm') {
354 $('#package_class_1').html('<input type="checkbox" id="package_class_1_input"> package_deb');
355 $('#package_class_2').html('<input type="checkbox" id="package_class_2_input"> package_ipk');
356 }
357 $('#package_class_1, #package_class_2').fadeIn(1500);
358}
359
360// Re-assert handlers when the page is served and/or refreshed via Ajax
361function setEventHandlersForDynamicElements() {
362
363 // change variable value
364 $('.js-icon-pencil-config_var').click(function (evt) {
365 var pk = $(this).attr("x-data");
366 var current_val = $("#config_var_value_"+pk).text();
367 $("#config_var_value_"+pk).hide();
368 $("#config_var_trash_"+pk).hide();
369 $(".js-icon-pencil-config_var[x-data="+pk+"]").hide();
370 $("#change-config_var-form_"+pk).slideDown();
371 $("#new-config_var_"+pk).val(current_val);
372 if ( $("#new-config_var_"+pk).val().length ) {
373 $("#apply-change-config_var_"+pk).removeAttr("disabled");
374 }
375 else {
376 $("#apply-change-config_var_"+pk).attr("disabled");
377 }
378 });
379
380 $('.js-cancel-change-config_var').click(function (evt) {
381 var pk = evt.target.attributes["x-data"].value;
382 $("#change-config_var-form_"+pk).slideUp(function() {
383 $("#config_var_trash_"+pk).show();
384 $('#config_var_value_'+pk).show();
385 $(".js-icon-pencil-config_var[x-data="+pk+"]").show();
386 });
387 });
388
389 $(".js-new-config_var").on('input', function(){
390 if ($(this).val().length == 0) {
391 $(this).parent("div").next(".btn-default").attr("disabled","disabled");
392 }
393 else {
394 $(this).parent("div").next(".btn-default").removeAttr("disabled");
395 }
396 });
397
398 $('.js-apply-change-config_var').click(function (evt) {
399 var xdata = evt.target.attributes["x-data"].value.split(":");
400 var pk = xdata[0];
401 var variable = xdata[1];
402 var val = $('#new-config_var_'+pk).val();
403 postEditAjaxRequest({"configvarChange" : variable+':'+val});
404 $("#change-config_var-form_"+pk).slideUp();
405 $("#config_var_trash_"+pk).fadeIn();
406 $('#config_var_value_'+pk).fadeIn();
407 $(".js-icon-pencil-config_var[x-data="+pk+"]").fadeIn();
408 });
409
410 // delete variable
411 $(".js-icon-trash-config_var").click(function (evt) {
412 var pk = $(this).attr("x-data");
413
414 // fade out the variable+value div, then refresh the variable list
415 $(this).fadeOut();
416 $(this).tooltip("hide");
417 $("config_var_entry_"+pk).fadeOut();
418 $('#config_var_value_'+pk).parent("dd").fadeOut();
419 postEditAjaxRequest({"configvarDel": evt.target.attributes["x-data"].value});
420 });
421
422}
423
424function onEditPageUpdate(data) {
425 // update targets
426 var i; var orightml = "";
427
428 var configvars_sorted = data.configvars.sort(function(a, b){return a[0] > b[0]});
429
430 var managed_configvars = document.getElementsByClassName('js-config-var-managed-name');
431
432 for (i = 0; i < configvars_sorted.length; i++) {
433 // skip if the variable name has a special context (not user defined)
434 var var_context=undefined;
435 for (var j = 0, length = managed_configvars.length; j < length; j++) {
436 if ((managed_configvars[j].innerHTML == configvars_sorted[i][0]) ||
437 (managed_configvars[j].value == configvars_sorted[i][0]) ) {
438 var_context='m';
439 }
440 }
441 if (var_context == undefined) {
442 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>'
443 orightml += '<dd class="variable-list">'
444 orightml += ' <span class="lead" id="config_var_value_'+configvars_sorted[i][2]+'"></span>'
445 orightml += ' <span class="glyphicon glyphicon-edit js-icon-pencil-config_var" x-data="'+configvars_sorted[i][2]+'"></span>'
446 orightml += ' <form class="form-inline" id="change-config_var-form_'+configvars_sorted[i][2]+'" style="display:none;">'
447 orightml += ' <div class="form-group">'
448 orightml += ' <input type="text" class="form-control js-new-config_var" id="new-config_var_'+configvars_sorted[i][2]+'" value=""></div>'
449 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>'
450 orightml += ' <button type="button" class="btn btn-link js-cancel-change-config_var" x-data="'+configvars_sorted[i][2]+'">Cancel</button>'
451 orightml += ' </form>'
452 orightml += '</dd>'
453 }
454 }
455
456 // update configvars list HTML framework
457 $("dl#configvar-list").html(orightml);
458
459 // insert the name/value pairs safely as non-HTML
460 for (i = 0; i < configvars_sorted.length; i++) {
461 $('#config_var_entry_'+configvars_sorted[i][2]).text(configvars_sorted[i][0]);
462 $('#config_var_value_'+configvars_sorted[i][2]).text(configvars_sorted[i][1]);
463 }
464
465 // Add the tooltips
466 $(".js-icon-trash-config_var").each( function(){ setDeleteTooltip($(this)); });
467 $(".js-icon-pencil-config_var").each(function(){ setChangeTooltip($(this)); });
468
469 // re-assert these event handlers
470 setEventHandlersForDynamicElements();
471}
472
473function onEditAjaxSuccess(data, textstatus) {
474 console.log("XHR returned:", data, "(" + textstatus + ")");
475 if (data.error != "ok") {
476 alert("error on request:\n" + data.error);
477 return;
478 }
479
480 // delayed page reload?
481 if (do_reload) {
482 do_reload=false;
483 location.reload(true);
484 } else {
485 onEditPageUpdate(data);
486 }
487}
488
489function onEditAjaxError(jqXHR, textstatus, error) {
490 alert("XHR errored:\n" + error + "\n(" + textstatus + ")");
491 // re-assert the event handlers
492}
493
494/* ensure cookie exists {% csrf_token %} */
495function postEditAjaxRequest(reqdata) {
496 var ajax = $.ajax({
497 type:"POST",
498 data: $.param(reqdata),
499 url:"{% url 'xhr_configvaredit' project.id%}",
500 headers: { 'X-CSRFToken': $.cookie("csrftoken")},
501 success: onEditAjaxSuccess,
502 error: onEditAjaxError,
503 })
504}
505
506function setDeleteTooltip(object) {
507 object.tooltip({ container: 'body', html: true, delay: {show: 400}, title: "Delete" });
508}
509function setChangeTooltip(object) {
510 object.tooltip({ container: 'body', html: true, delay: {show: 400}, title: "Change" });
511}
512
513$(document).ready(function() {
514
515 //
516 // Register handlers for static elements
517 //
518
519 {% if distro_defined %}
520 // change distro variable
521 $('#change-distro-icon').click(function() {
522 $('#change-distro-icon, #distro').hide();
523 $("#change-distro-form").slideDown();
524 $("#new-distro").val( $('#distro').text() );
525 $("#apply-change-distro").removeAttr("disabled");
526 });
527
528 $('#cancel-change-distro').click(function(){
529 $("#change-distro-form").slideUp(function() {
530 $('#distro, #change-distro-icon').show();
531
532 // reset any dangling error state
533 $('#distro-error-message').text("");
534 $("#change-distro-form").removeClass("has-error");
535 });
536 });
537
538 // validate new distro name
539 $("input#new-distro").on('input', function (evt) {
540 validate_distro_name();
541 });
542
543 $('#apply-change-distro').click(function(){
544 //$('#repo').parent().removeClass('highlight-go');
545 var name = $('#new-distro').val();
546 postEditAjaxRequest({"configvarChange" : 'DISTRO:'+name});
547 $('#distro').text(name);
548 $("#change-distro-form").slideUp(function () {
549 $('#distro, #change-distro-icon').show();
550 });
551 });
552 {% endif %}
553
554 {% if dl_dir_defined %}
555
556 // change DL_DIR variable
557 $('#change-dl_dir-icon').click(function() {
558 $('#change-dl_dir-form').removeClass('has-error');
559 // preset the edit value
560 var current_val = $("#dl_dir").text().trim();
561 if (current_val == "Not set") {
562 current_val="";
563 $("#apply-change-dl_dir").attr("disabled","disabled");
564 }
565 $("input#new-dl_dir").val(current_val);
566 // enable / disable the save button based on the input value
567 if ( current_val.length ) {
568 $("#apply-change-dl_dir").removeAttr("disabled");
569 }
570 else {
571 $("#apply-change-dl_dir").attr("disabled","disabled");
572 }
573
574 $('#change-dl_dir-icon, #dl_dir').hide();
575 $("#change-dl_dir-form").slideDown();
576 });
577
578 $('#cancel-change-dl_dir').click(function(){
579 $("#hintError-dl_dir").hide();
580 $("#hintError-initialChar-dl_dir").hide();
581 $("#change-dl_dir-form").slideUp(function() {
582 $('#dl_dir, #change-dl_dir-icon').show();
583 });
584 });
585
586 $("#new-dl_dir").on('input', function(){
587 if ($(this).val().trim().length == 0) {
588 $("#apply-change-dl_dir").attr("disabled","disabled");
589 $('#change-dl_dir-form').addClass('has-error');
590 $('#hintError-dl_dir').hide();
591 $('#hintError-initialChar-dl_dir').hide();
592 }
593 else {
594 var input = $(this);
595 var reBeginWithSlash = /^\//;
596 var reCheckVariable = /^\$/;
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500597 var re = /([ <>\\|":%\?\*]+)/;
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600598 var invalidDir = re.test(input.val());
599 var invalidSlash = reBeginWithSlash.test(input.val());
600 var invalidVar = reCheckVariable.test(input.val());
601 if (!invalidSlash && !invalidVar) {
602 $('#change-dl_dir-form').addClass('has-error');
603 $("#apply-change-dl_dir").attr("disabled","disabled");
604 $('#hintError-initialChar-dl_dir').show();
605 } else if (invalidDir) {
606 $('#change-dl_dir-form').addClass('has-error');
607 $("#apply-change-dl_dir").attr("disabled","disabled");
608 $('#hintError-dl_dir').show();
609 } else {
610 $('#change-dl_dir-form').removeClass('has-error');
611 $("#apply-change-dl_dir").removeAttr("disabled");
612 $('#hintError-dl_dir').hide();
613 $('#hintError-initialChar-dl_dir').hide();
614 }
615 }
616 });
617
618 $('#apply-change-dl_dir').click(function(){
619 var value = $('#new-dl_dir').val().trim();
620 postEditAjaxRequest({"configvarChange" : 'DL_DIR:'+value});
621 $('#dl_dir').text(value);
622 $('#dl_dir').removeClass('muted');
623 $("#change-dl_dir-form").slideUp(function () {
624 $('#dl_dir, #change-dl_dir-icon').show();
625 });
626 });
627
628 {% endif %}
629
630 {% if fstypes_defined %}
631 // change IMAGE_FSTYPES variable
632
633 // get value of fstypes and add to the textbox
634 $("#new-imagefs_types").val("{{fstypes}}");
635
636 // If value of new-imagefs_types is empty disable save button
637 $("#new-imagefs_types").on("input", function() {
638 $(this).val($(this).val().replace(/\s+/g,' '));
639 if ($(this).val().length === 0) {
640 //$('#apply-change-image_fstypes').prop('disabled', true);
641 $('#apply-change-image_fstypes').attr("disabled", "disabled");
642 } else {
643 //$('#apply-change-image_fstypes').prop('disabled', false);
644 $('#apply-change-image_fstypes').removeAttr("disabled");
645 }
646
647 /*If user types imagefs do the action on checkboxes.
648 Lets say if an imagefstype typed by user and the same
649 imagefs is unchecked in the checkbox, then checkbox needs
650 to get checked. Similarly when user deletes imagefs from
651 textbox the checkbox which is checked gets unchecked.
652 */
653 $('#all-image_fstypes input').each(function(){
654 var imagefs_userval = $('#new-imagefs_types').val();
655 if( imagefs_userval.indexOf($(this).val()) > -1) {
656 $(this).prop('checked', true);
657 } else {
658 $(this).prop('checked', false);
659 }
660 });
661
662 // Validate underscore in image fs types
663 if ($(this).val().indexOf('_') > -1) {
664 $('#validate-image_fstypes').addClass('has-error');
665 $('#hintError-image-fs_type').show();
666 $("#apply-change-image_fstypes").prop("disabled", true);
667 } else {
668 $('#validate-image_fstypes').removeClass('has-error');
669 $('#hintError-image-fs_type').hide();
670 }
671 });
672
673 $('#change-image_fstypes-icon').click(function() {
674 $('#change-image_fstypes-icon, #image_fstypes').hide();
675 $("#change-image_fstypes-form").slideDown();
676 // avoid false substring matches by including space separators
677 var html = "";
678 var fstypes = " " + document.getElementById("image_fstypes").innerHTML + " ";
679 var fstypes_list = document.getElementsByClassName('js-checkbox-fstypes-list');
680 // Add the checked boxes first
681 if (" " != fstypes) {
682 for (var i = 0, length = fstypes_list.length; i < length; i++) {
683 if (0 <= fstypes.indexOf(" "+fstypes_list[i].value+" ")) {
684 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 -0500685 }
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600686 }
687 }
688 // Add the un-checked boxes second
689 for (var i = 0, length = fstypes_list.length; i < length; i++) {
690 if (0 > fstypes.indexOf(" "+fstypes_list[i].value+" ")) {
691 html += '<div class="checkbox"><label><input type="checkbox" class="fs-checkbox-fstypes" value="'+fstypes_list[i].value+'">'+fstypes_list[i].value+'</label></div>';
692 }
693 }
694 // Add the 'no search matches' line last
695 html += '<label id="no-match-fstypes" class="text-muted">No image types found</label>\n';
696 // Display the list
697 document.getElementById("all-image_fstypes").innerHTML = html;
698 $('#no-match-fstypes').hide();
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500699
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600700 // clear the previous filter values and warning messages
701 $("input#filter-image_fstypes").val("");
702 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500703
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600704 // When checkbox is checked/unchecked kindly update the text
705 $(document).on("change", "#all-image_fstypes :checkbox", function() {
706 var imagefs = $(this);
707 var imagefs_obj = $('#new-imagefs_types');
708 var imagefs_userval = imagefs_obj.val();
709 if ($(this).is(':checked')) {
710 if (imagefs_userval.indexOf($(imagefs).val()) === -1) {
711 imagefs_obj.val(imagefs_userval + " " + $(imagefs).val());
712 }
713 } else {
714 if (imagefs_userval.indexOf($(imagefs).val()) > -1) {
715 imagefs_obj.val(imagefs_userval.replace($(imagefs).val(), '').trim());
716 }
717 }
718 if ($('#new-imagefs_types').val().length === 0) {
719 $("#apply-change-image_fstypes").prop("disabled", true);
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500720 $('#fstypes-error-message').show();
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600721 } else {
722 $("#apply-change-image_fstypes").prop("disabled", false);
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500723 $('#fstypes-error-message').hide();
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600724 }
725 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500726
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600727 $('#cancel-change-image_fstypes').click(function(){
728 $("#new-imagefs_types").val("{{fstypes}}");
729 $("#change-image_fstypes-form").slideUp(function() {
730 $('#image_fstypes, #change-image_fstypes-icon').show();
731 });
732 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500733
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600734 $('#filter-image_fstypes').on('input', function(){
735 var valThis = $(this).val().toLowerCase();
736 var matchCount=0;
737 $('#all-image_fstypes label').each(function(){
738 var text = $(this).text().toLowerCase();
739 var match = text.indexOf(valThis);
740 if (match >= 0) {
741 $(this).show();
742 matchCount += 1;
743 }
744 else {
745 $(this).hide();
746 }
747 });
748 if (matchCount === 0) {
749 $('#no-match-fstypes').show();
750 } else {
751 $('#no-match-fstypes').hide();
752 }
753 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500754
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600755 $('#apply-change-image_fstypes').click(function(){
756 var fstypes = $('#new-imagefs_types').val();
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500757
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600758 postEditAjaxRequest({"configvarChange" : 'IMAGE_FSTYPES:'+fstypes});
759 $('#image_fstypes').text(fstypes);
760 $('#image_fstypes').parent().removeClass('muted');
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500761
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600762 $("#change-image_fstypes-form").slideUp(function() {
763 $('#image_fstypes, #change-image_fstypes-icon').show();
764 });
765 });
766 {% endif %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500767
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500768
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600769 {% if image_install_append_defined %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500770
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600771 // init IMAGE_INSTALL_append trash icon
772 setDeleteTooltip($('#delete-image_install-icon'));
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500773
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600774 // change IMAGE_INSTALL_append variable
775 $('#change-image_install-icon').click(function() {
776 // preset the edit value
777 var current_val = $("span#image_install").text().trim();
778 if (current_val == "Not set") {
779 current_val="";
780 $("#apply-change-image_install").attr("disabled","disabled");
781 } else {
782 // insure these non-empty values have single space prefix
783 current_val=" " + current_val;
784 $("#apply-change-image_install").removeAttr("disabled");
785 }
786 $("input#new-image_install").val(current_val);
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500787
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600788 $('#change-image_install-icon, #delete-image_install-icon, #image_install').hide();
789 $("#change-image_install-form").slideDown();
790 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500791
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600792 $('#cancel-change-image_install').click(function(){
793 $("#change-image_install-form").slideUp(function() {
794 $('#image_install, #change-image_install-icon').show();
795 if ($("span#image_install").text() != "Not set") {
796 $('#delete-image_install-icon').show();
797 setDeleteTooltip($('#delete-image_install-icon'));
798 }
799 });
800 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500801
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600802 $("#new-image_install").on('input', function(){
803 if ($(this).val().trim().length == 0) {
804 $("#apply-change-image_install").attr("disabled","disabled");
805 }
806 else {
807 $("#apply-change-image_install").removeAttr("disabled");
808 }
809 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500810
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600811 $('#apply-change-image_install').click(function(){
812 // insure these non-empty values have single space prefix
813 var value = " " + $('#new-image_install').val().trim();
814 postEditAjaxRequest({"configvarChange" : 'IMAGE_INSTALL_append:'+value});
815 $('#image_install').text(value);
816 $('#image_install').removeClass('text-muted');
817 $("#change-image_install-form").slideUp(function () {
818 $('#image_install, #change-image_install-icon').show();
819 if (value.length > -1) {
820 $('#delete-image_install-icon').show();
821 setDeleteTooltip($('#delete-image_install-icon'));
822 }
823 });
824 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500825
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600826 // delete IMAGE_INSTALL_append variable value
827 $('#delete-image_install-icon').click(function(){
828 $(this).tooltip('hide');
829 postEditAjaxRequest({"configvarChange" : 'IMAGE_INSTALL_append:'+''});
830 $('#image_install').parent().fadeOut(1000, function(){
831 $('#image_install').addClass('text-muted');
832 $('#image_install').text('Not set');
833 $('#delete-image_install-icon').hide();
834 $('#image_install').parent().fadeIn(1000);
835 });
836 });
837 {% endif %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500838
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500839
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600840 {% if package_classes_defined %}
841 // change PACKAGE_CLASSES variable
842 $('#change-package_classes-icon').click(function() {
843 $('#change-package_classes-icon, #package_classes').hide();
844 $("#change-package_classes-form").slideDown();
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500845
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600846 // initialize the pulldown and checkboxes
847 var value = $("#package_classes").text();
848 if ( value.indexOf("package_deb") == 0 ) {
849 $("#package_classes-select").prop('selectedIndex', 0);
850 updatePackageClassCheckboxes();
851 if ( value.indexOf("_ipk") > 0 ) {
852 $("#package_class_1_input").attr("checked",true);
853 }
854 if ( value.indexOf("_rpm") > 0 ) {
855 $("#package_class_2_input").attr("checked",true);
856 }
857 }
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500858
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600859 if ( value.indexOf("package_ipk") == 0 ) {
860 $("#package_classes-select").prop('selectedIndex', 1);
861 updatePackageClassCheckboxes();
862 if ( value.indexOf("_deb") > 0 ) {
863 $("#package_class_1_input").attr("checked",true);
864 }
865 if ( value.indexOf("_rpm") > 0 ) {
866 $("#package_class_2_input").attr("checked",true);
867 }
868 }
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500869
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600870 if ( value.indexOf("package_rpm") == 0 ) {
871 $("#package_classes-select").prop('selectedIndex', 2);
872 updatePackageClassCheckboxes();
873 if ( value.indexOf("_deb") > 0 ) {
874 $("#package_class_1_input").attr("checked",true);
875 }
876 if ( value.indexOf("_ipk") > 0 ) {
877 $("#package_class_2_input").attr("checked",true);
878 }
879 }
880 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500881
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600882 $('#cancel-change-package_classes').click(function(){
883 $("#change-package_classes-form").slideUp(function() {
884 $('#package_classes, #change-package_classes-icon').show();
885 });
886 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500887
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600888 $('select').change(function() {
889 updatePackageClassCheckboxes();
890 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500891
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600892 $('#apply-change-package_classes').click(function(){
893 var e = document.getElementById("package_classes-select");
894 var val = e.options[e.selectedIndex].text;
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500895
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600896 pc1_checked = document.getElementById("package_class_1_input").checked;
897 pc2_checked = document.getElementById("package_class_2_input").checked;
898 if (val == "package_deb") {
899 if (pc1_checked) val = val + " package_ipk";
900 if (pc2_checked) val = val + " package_rpm";
901 }
902 if (val == "package_ipk") {
903 if (pc1_checked) val = val + " package_deb";
904 if (pc2_checked) val = val + " package_rpm";
905 }
906 if (val == "package_rpm") {
907 if (pc1_checked) val = val + " package_deb";
908 if (pc2_checked) val = val + " package_ipk";
909 }
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500910
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600911 $('#package_classes').text(val);
912 //$('#package_classes').parent().removeClass('muted');
913 postEditAjaxRequest({"configvarChange" : 'PACKAGE_CLASSES:'+val});
914 $("#change-package_classes-form").slideUp(function() {
915 $('#package_classes, #change-package_classes-icon').show();
916 });
917 });
918 {% endif %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500919
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600920 {% if sstate_dir_defined %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500921
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600922 // change SSTATE_DIR variable
923 $('#change-sstate_dir-icon').click(function() {
924 $('#change-sstate_dir-form').removeClass('has-error');
925 // preset the edit value
926 var current_val = $("span#sstate_dir").text().trim();
927 if (current_val == "Not set") {
928 current_val="";
929 $("#apply-change-sstate_dir").attr("disabled","disabled");
930 }
931 $("input#new-sstate_dir").val(current_val);
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500932
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600933 // enable / disable the save button based on the input value
934 if ( current_val.length ) {
935 $("#apply-change-sstate_dir").removeAttr("disabled");
936 }
937 else {
938 $("#apply-change-sstate_dir").attr("disabled","disabled");
939 }
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500940
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600941 $('#change-sstate_dir-icon, #sstate_dir').hide();
942 $("#change-sstate_dir-form").slideDown();
943 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500944
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600945 $('#cancel-change-sstate_dir').click(function(){
946 $("#hintError-sstate_dir").hide();
947 $("#hintError-initialChar-sstate_dir").hide();
948 $("#change-sstate_dir-form").slideUp(function() {
949 $('#sstate_dir, #change-sstate_dir-icon').show();
950 });
951 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500952
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600953 $("#new-sstate_dir").on('input', function(){
954 if ($(this).val().trim().length == 0) {
955 $("#apply-change-sstate_dir").attr("disabled","disabled");
956 $('#change-sstate_dir-form').addClass('has-error');
957 $('#hintError-sstate_dir').hide();
958 $('#hintError-initialChar-sstate_dir').hide();
959 }
960 else {
961 var input = $(this);
962 var reBeginWithSlash = /^\//;
963 var reCheckVariable = /^\$/;
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500964 var re = /([ <>\\|":%\?\*]+)/;
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600965 var invalidDir = re.test(input.val());
966 var invalidSlash = reBeginWithSlash.test(input.val());
967 var invalidVar = reCheckVariable.test(input.val());
968 if (!invalidSlash && !invalidVar) {
969 $('#change-sstate_dir-form').addClass('has-error');
970 $("#apply-change-sstate_dir").attr("disabled","disabled");
971 $('#hintError-initialChar-sstate_dir').show();
972 } else if (invalidDir) {
973 $('#change-sstate_dir-form').addClass('has-error');
974 $("#apply-change-sstate_dir").attr("disabled","disabled");
975 $('#hintError-sstate_dir').show();
976 } else {
977 $('#change-sstate_dir-form').removeClass('has-error');
978 $("#apply-change-sstate_dir").removeAttr("disabled");
979 $('#hintError-sstate_dir').hide();
980 $('#hintError-initialChar-sstate_dir').hide();
981 }
982 }
983 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500984
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600985 $('#apply-change-sstate_dir').click(function(){
986 var value = $('#new-sstate_dir').val().trim();
987 postEditAjaxRequest({"configvarChange" : 'SSTATE_DIR:'+value});
988 $('#sstate_dir').text(value);
989 $('#sstate_dir').removeClass('text-muted');
990 $("#change-sstate_dir-form").slideUp(function () {
991 $('#sstate_dir, #change-sstate_dir-icon').show();
992 });
993 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500994
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600995 {% endif %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500996
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600997 // add new variable
998 $("button#add-configvar-button").click( function (evt) {
999 var variable = $("input#variable").val();
1000 var value = $("input#value").val();
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001001
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001002 postEditAjaxRequest({"configvarAdd" : variable+':'+value});
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001003
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001004 // clear the previous values
1005 $("input#variable").val("");
1006 $("input#value").val("");
1007 // Disable add button
1008 $(".save").attr("disabled","disabled");
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001009
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001010 // Reload page if admin-removed core managed value is manually added back in
1011 if (0 <= " DISTRO DL_DIR IMAGE_FSTYPES IMAGE_INSTALL_append PACKAGE_CLASSES SSTATE_DIR ".indexOf( " "+variable+" " )) {
1012 // delayed reload to avoid race condition with postEditAjaxRequest
1013 do_reload=true;
1014 }
1015 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001016
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001017 // validate new variable name and value
1018 $("#variable, #value").on('input', function() {
1019 validate_new_variable();
1020 });
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001021
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001022 //
1023 // draw and register the dynamic configuration variables and handlers
1024 //
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001025
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001026 var data = {
1027 configvars : []
1028 };
1029 {% for c in configvars %}
1030 data.configvars.push([ "{{c.name}}","{{c.value}}","{{c.pk}}" ]);
1031 {% if '' != vars_context|get_dict_value:c.name %}
1032 data.vars_context[ "{{c.name}}" ] = "{{vars_context|get_dict_value:c.name }}";
1033 {% endif %}
1034 {% endfor %}
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001035
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001036 // draw these elements and assert their event handlers
1037 onEditPageUpdate(data);
1038});
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001039
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001040</script>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001041
1042{% endblock %}