edit.ui.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * 父阶段更改值操作。
  3. * Change parent stage.
  4. *
  5. * @param stageID stageID
  6. * @return void
  7. */
  8. function changeParentStage(event)
  9. {
  10. const stageID = parseInt($(event.target).val());
  11. $('#acl').attr('disabled', stageID != 0);
  12. $.get($.createLink('programplan', 'ajaxGetStageAttr', 'stageID=' + stageID), function(attribute)
  13. {
  14. var isPicker = $('#attributeType').find('.picker-box').length > 0;
  15. if((attribute.length == 0 || attribute == 'mix') && !isPicker)
  16. {
  17. $('#attributeType').empty().append('<div class="form-group-wrapper picker-box" id="attribute"></div>');
  18. $('#attribute').picker({name: 'attribute', items: stageTypeItems, defaultValue: attribute});
  19. }
  20. if(isPicker && attribute != 'mix' && attribute.length > 0)
  21. {
  22. $('#attributeType').find('[name=attribute]').zui('picker').destroy();
  23. $('#attributeType').find('.picker-box').remove();
  24. $('#attributeType').append('<span>' + stageTypeList[attribute] + '</span>');
  25. }
  26. });
  27. }
  28. /**
  29. * 编辑阶段提交操作。
  30. * Submit form for edit stage.
  31. *
  32. * @return void
  33. */
  34. window.editStage = function()
  35. {
  36. let result = true;
  37. let currentParent = $('[name=parent]').val();
  38. if(plan.parent != currentParent && currentParent != 0)
  39. {
  40. result = false;
  41. $.get($.createLink('programplan', 'ajaxGetStageAttr', 'stageID=' + currentParent), function(attribute)
  42. {
  43. if(attribute != 'mix' && plan.attribute != attribute)
  44. {
  45. zui.Modal.confirm(changeAttrLang.replace('%s', stageTypeList[attribute])).then((res) =>
  46. {
  47. if(res) formSubmit();
  48. });
  49. }
  50. else
  51. {
  52. formSubmit();
  53. }
  54. });
  55. }
  56. var currentAttribute = $('[name=attribute]').val();
  57. var hasChangedAttribute = (currentAttribute && currentAttribute != 'mix' && plan.attribute != currentAttribute);
  58. var hasChangedParent = ((isTopStage && currentParent != 0) || (!isTopStage && plan.parent != currentParent));
  59. if(hasChangedAttribute && !hasChangedParent && !isLeafStage)
  60. {
  61. result = false;
  62. zui.Modal.confirm(changeAttrLang.replace('%s', stageTypeList[currentAttribute])).then((res) =>
  63. {
  64. if(res) formSubmit();
  65. });
  66. }
  67. return result;
  68. }
  69. /**
  70. * 提交表单操作。
  71. * Submit form.
  72. *
  73. * @access public
  74. * @return void
  75. */
  76. function formSubmit()
  77. {
  78. let $form = $('#editForm form');
  79. let formUrl = $form.attr('action');
  80. let formData = new FormData($form[0]);
  81. $.ajaxSubmit({
  82. url: formUrl,
  83. data: formData,
  84. onFail: (error) => {
  85. if(error?.message) showValidateMessage(error.message);
  86. }
  87. });
  88. }