ajaxcustom.ui.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. function handleEditColsSubmit()
  2. {
  3. const formData = [];
  4. let index = 0;
  5. const types = ['left', 'no', 'right'];
  6. const getSelector = (value) => `[data-zin-gid="${formGID}"] ul.${value}-cols`;
  7. const colsList = types.map(x => document.querySelector(getSelector(x)));
  8. for(let i = 0; i < colsList.length; i++)
  9. {
  10. const cols = colsList[i];
  11. if(!cols) continue;
  12. const children = Array.from(cols.children);
  13. for(let j = 0; j < children.length; j++)
  14. {
  15. const li = children[j];
  16. const checkbox = li.querySelector('input[type="checkbox"]');
  17. if(!checkbox) continue;
  18. const input = li.querySelector('input[type="text"]');
  19. const unit = li.querySelector('select');
  20. formData.push({
  21. id: li.dataset.key,
  22. order: ++ index,
  23. show: checkbox.checked,
  24. width: unit.value === '%' ? String(input.value / 100) : input.value,
  25. fixed: types[i],
  26. });
  27. }
  28. }
  29. $.ajaxSubmit(
  30. {
  31. url: ajaxSaveUrl,
  32. data: {fields: JSON.stringify(formData)},
  33. closeModal: true,
  34. onSuccess: function()
  35. {
  36. let $table = $(`#table-${config.currentModule}-${config.currentMethod}`).closest('[z-use-dtable]');
  37. if(!$table.length) $table = $('#main [z-use-dtable]');
  38. $table.attr('zui-create-dtable', '');
  39. },
  40. });
  41. }