projectconf.html 41 KB

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