manageprojectadmin.ui.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. function addItem(e)
  2. {
  3. let maxNum = 0;
  4. $(e.target).closest('table').find("tr[class^='line']").each(function()
  5. {
  6. let trname = $(this).attr('class');
  7. let index = trname.match(/\d+/g);
  8. index = parseInt(index);
  9. maxNum = index > maxNum ? index : maxNum;
  10. })
  11. maxNum = parseInt(maxNum);
  12. maxNum += 1;
  13. let className = $(e.target).closest('tr').attr('class');
  14. let lastTr = $('table tr.' + className).last();
  15. $($('table tr.' + className).get().reverse()).each(function()
  16. {
  17. let $newRow = $(this).clone();
  18. $newRow.attr('class', className.replace(/\d+/g, maxNum));
  19. $newRow.find("input[type='checkbox']").each(function()
  20. {
  21. let name = $(this).attr('name');
  22. let id = $(this).attr('id');
  23. let label = $(this).next().attr('for');
  24. $(this).prop('name', name.replace(/\d+/g, maxNum));
  25. $(this).prop('id', id.replace(/\d+/g, maxNum));
  26. $(this).prop('checked', false);
  27. $(this).next().prop('for', label.replace(/\d+/g, maxNum));
  28. })
  29. let optionArr = [];
  30. $newRow.find('select').each(function()
  31. {
  32. let name = $(this).attr('name');
  33. let options = zui.Picker.query(`[name='${name}']`).options;
  34. let newName = name.replace(/\d+/g, maxNum);
  35. let newID = newName.replace(/\[|\]/g, '');
  36. options.name = newName;
  37. options.defaultValue = '';
  38. optionArr[newID] = options;
  39. $(this).closest('td').find('div[data-zui-picker]').parent().append(`<div id='${newID}' style='width: 100%'></div>`);
  40. $(this).closest('td').find('div[data-zui-picker]').remove();
  41. });
  42. /* Append btn-delete. */
  43. $newRow.find('.btn-group .btn').length == 1 ? $newRow.find('.btn-group').append('<button class="btn ghost btn-delete square" type="button"><i class="icon icon-trash"></i></button>') : '';
  44. $(lastTr).after($newRow);
  45. for(let key in optionArr)
  46. {
  47. let options = optionArr[key];
  48. let newID = key;
  49. new zui.Picker(`#${newID}`, options);
  50. $(`#${newID}`).zui('picker').render({disabled: false});
  51. }
  52. })
  53. }
  54. function deleteItem(e)
  55. {
  56. if($("table tr").length == 5) return false;
  57. let currentClass = $(e.target).closest('tr').attr('class');
  58. $(e.target).closest('table').find('tr.' + currentClass).remove();
  59. }
  60. function toggleDisabled(e)
  61. {
  62. let name = e.target.name;
  63. let checked = e.target.checked;
  64. let $picker = $(e.target).closest('tr').find('.input-group select').zui('picker');
  65. if(checked)
  66. {
  67. $picker.render({disabled: true});
  68. }
  69. else
  70. {
  71. $picker.render({disabled: false});
  72. }
  73. }