browse.ui.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. function syncModule()
  2. {
  3. productID = $('[name=allProduct]').val();
  4. moduleID = $('[name=productModule]').val();
  5. $.getJSON($.createLink('tree', 'ajaxGetSonModules', 'moduleID=' + moduleID + '&rootID=' + productID + '&type=story'), function(modules)
  6. {
  7. if(modules.length == 0)
  8. {
  9. zui.Modal.alert(noSubmodule);
  10. return false;
  11. }
  12. let $lastFormRow = $('.form-row .row-module').last().closest('.form-row');
  13. let $lastBranch = $lastFormRow.find('.picker-box [name^=branch]');
  14. let $cloneFormRow = $lastFormRow.clone().addClass('copy');
  15. let $branchPicker = null;
  16. if($lastBranch.length > 0)
  17. {
  18. $branchPicker = $lastBranch.zui('picker');
  19. $cloneFormRow.find('.picker-box').removeAttr('id').removeAttr('data-zui-picker').empty();
  20. }
  21. $.each(modules, function(key, module)
  22. {
  23. $('.form-row:not(.copyBox) .row-module').each(function()
  24. {
  25. moduleName = $(this).find('input[id^=modules]').val();
  26. if(moduleName == module.name) modules[key] = null;
  27. })
  28. });
  29. $.each(modules, function(key, module)
  30. {
  31. if(module)
  32. {
  33. $('.form-row:not(.copyBox):not(.sonModule):not(.copy)').first().before($cloneFormRow.prop('outerHTML'));
  34. let $copy = $('.form-row.copy').last();
  35. let $branch = $copy.find('.picker-box');
  36. $copy.find('input[id^=modules]').attr('id', 'modules[]').attr('name', 'modules[]').val(module.name);
  37. $copy.find('input[id^=shorts]').attr('id', 'shorts[]').attr('name', 'shorts[]').val(module.short);
  38. $copy.find('.add-btn').on('click', addItem);
  39. $copy.find('.del-btn').on('click', removeItem);
  40. if($branch.length > 0) new zui.Picker($branch, $.extend({'name': 'branch[]'}, $branchPicker.options));
  41. }
  42. });
  43. });
  44. }
  45. function syncProduct(obj)
  46. {
  47. link = $.createLink('tree', 'ajaxGetOptionMenu', 'rootID=' + obj.value + "&viewType=" + viewType + "&branch=all&rootModuleID=0&returnType=json");
  48. $.getJSON(link, function(modules)
  49. {
  50. let $picker = $('[name=productModule]').zui('picker');
  51. let items = [];
  52. if(obj.value)
  53. {
  54. $.each(modules, function(key, value){ items.push({'value': key, 'text': value}); });
  55. }
  56. $picker.render({items: items})
  57. $picker.$.setValue('');
  58. });
  59. }
  60. window.addItem = function(e)
  61. {
  62. const obj = e.target
  63. const thisRow = $(obj).closest('.form-row');
  64. const newItem = thisRow.clone();
  65. newItem.find('.add-btn').on('click', addItem);
  66. newItem.find('.del-btn').on('click', removeItem);
  67. $newBranch = newItem.find('.picker-box [name^=branch]');
  68. $pickerBox = null;
  69. if($newBranch.length > 0)
  70. {
  71. $pickerBox = $newBranch.closest('.picker-box');
  72. $pickerBox.removeAttr('id').removeAttr('data-zui-picker').empty();
  73. }
  74. $(obj).closest('.form-row').after(newItem);
  75. newItem.find('input[id^=modules]').attr('id', 'modules[]').attr('name', 'modules[]').val('');
  76. newItem.find('input[id^=shorts]').attr('id', 'shorts[]').attr('name', 'shorts[]').val('');
  77. if($pickerBox)
  78. {
  79. options = thisRow.find('.picker-box [name^=branch]').zui('picker').options;
  80. $pickerBox.picker($.extend({'name': 'branch[]'}, options));
  81. }
  82. }
  83. window.toggleCopy = function()
  84. {
  85. $('.form-row.copyBox').toggleClass('hidden');
  86. }