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