ajaxloadsystemblock.ui.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. window.setRelease = function(target)
  2. {
  3. window.initAppPicker();
  4. const index = $(target).closest('tr').data('index');
  5. const apps = $(target).val();
  6. const $releases = $('#releases' + index).zui('picker');
  7. $releases.$.setValue('');
  8. const options = [{text: '', value: ''}];
  9. for(let id in releases)
  10. {
  11. if(releases[id].system == apps) options.push({value: id, text: releases[id].name, disabled: id == index});
  12. }
  13. $releases.render({items: options});
  14. };
  15. window.initAppPicker = function()
  16. {
  17. let selected = [];
  18. let $appList = $('#systemForm').find('.picker-box [name^=apps]');
  19. $appList.each(function()
  20. {
  21. const $apps = $(this);
  22. for(i = 0; i < $apps.length; i++)
  23. {
  24. let value = $apps.eq(i).val();
  25. if(value != '') selected.push(value);
  26. }
  27. });
  28. $appList.each(function()
  29. {
  30. const $apps = $(this);
  31. const apps = $apps.val();
  32. const $appsPicker = $apps.zui('picker');
  33. const appsItems = $appsPicker.options.items;
  34. $.each(appsItems, function(i, item)
  35. {
  36. if(item.value == '') return;
  37. appsItems[i].disabled = selected.includes(item.value) && item.value != apps;
  38. })
  39. $appsPicker.render({items: appsItems, required: true});
  40. });
  41. };
  42. window.addItem = function(obj)
  43. {
  44. let item = $('#addItem > tbody').html().replace(/_i/g, itemIndex);
  45. const $currentTr = $(obj).closest('tr');
  46. $currentTr.after(item);
  47. setTimeout(window.initAppPicker, 100);
  48. $('#systemForm tbody tr .actions-list .btn-link').eq(1).removeClass('hidden');
  49. if(itemIndex >= appLength - 1) $('#systemForm tbody tr .actions-list .add-item').addClass('hidden');
  50. itemIndex ++;
  51. };
  52. window.deleteItem = function(obj)
  53. {
  54. $(obj).closest('tr').remove();
  55. const trLen = $('#systemForm tbody tr').length;
  56. if(trLen < 2) $('#systemForm tbody tr .actions-list .btn-link').eq(1).addClass('hidden');
  57. if(trLen <= appLength) $('#systemForm tbody tr .actions-list .add-item').removeClass('hidden');
  58. setTimeout(window.initAppPicker, 100);
  59. itemIndex --;
  60. };
  61. $(function()
  62. {
  63. setTimeout(window.initAppPicker, 100);
  64. });