You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

255 lines
9.2 KiB

2 years ago
  1. 'use strict';
  2. var sProgramId = getProgramId(),
  3. sQueryPrgId = getQueryPrgId(),
  4. sAction = getUrlParam('Action') || 'Add',
  5. sDataId = getUrlParam('FileID'),
  6. sCheckId = sDataId,
  7. fnPageInit = function () {
  8. var oCurData = {},
  9. oForm = $('#form_main'),
  10. oValidator = null,
  11. /**
  12. * 獲取資料
  13. * @return {Object} Ajax 物件
  14. */
  15. fnGet = function () {
  16. if (sDataId) {
  17. return CallAjax(ComFn.W_Com, ComFn.GetOne, {
  18. Type: '',
  19. Params: {
  20. websitefiles: {
  21. FileID: sDataId,
  22. OrgID: parent.OrgID
  23. }
  24. }
  25. }, function (res) {
  26. if (res.d) {
  27. var oRes = $.parseJSON(res.d);
  28. oCurData = oRes;
  29. setFormVal(oForm, oRes);
  30. fnGetUploadFiles(oCurData.FileID, fnUpload);
  31. setNameById().done(function () {
  32. getPageVal();//緩存頁面值,用於清除
  33. });
  34. $('#UniqueID').attr('disabled', 'disabled');
  35. }
  36. });
  37. }
  38. else {
  39. oCurData.FileID = guid();
  40. fnUpload();
  41. return $.Deferred().resolve().promise();
  42. }
  43. },
  44. /**
  45. * 新增資料
  46. * @param {String} sFlag 新增或儲存後新增
  47. */
  48. fnAdd = function (sFlag) {
  49. var data = getFormSerialize(oForm);
  50. data = packParams(data);
  51. data.OrgID = parent.OrgID;
  52. data.FileID = oCurData.FileID;
  53. CallAjax(ComFn.W_Com, ComFn.GetAdd, {
  54. Params: {
  55. websitefiles: data
  56. }
  57. }, function (res) {
  58. if (res.d > 0) {
  59. bRequestStorage = false;
  60. if (sFlag == 'add') {
  61. showMsgAndGo(i18next.t("message.Save_Success"), sQueryPrgId); // ╠message.Save_Success⇒新增成功╣
  62. }
  63. else {
  64. showMsgAndGo(i18next.t("message.Save_Success"), sProgramId, '?Action=Add'); // ╠message.Save_Success⇒新增成功╣
  65. }
  66. parent.msgs.server.broadcast(data);
  67. }
  68. else {
  69. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  70. }
  71. });
  72. },
  73. /**
  74. * 修改資料
  75. */
  76. fnUpd = function () {
  77. var data = getFormSerialize(oForm);
  78. data = packParams(data, 'upd');
  79. data.FileID = oCurData.FileID;
  80. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  81. Params: {
  82. websitefiles: {
  83. values: data,
  84. keys: {
  85. FileID: sDataId,
  86. OrgID: parent.OrgID
  87. }
  88. }
  89. }
  90. }, function (res) {
  91. if (res.d > 0) {
  92. bRequestStorage = false;
  93. showMsgAndGo(i18next.t("message.Modify_Success"), sQueryPrgId);//╠message.Modify_Success⇒修改成功╣
  94. }
  95. else {
  96. showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣
  97. }
  98. }, function () {
  99. showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣
  100. });
  101. },
  102. /**
  103. * 資料刪除
  104. */
  105. fnDel = function () {
  106. CallAjax(ComFn.W_Com, ComFn.GetDel, {
  107. Params: {
  108. websitefiles: {
  109. FileID: sDataId,
  110. OrgID: parent.OrgID
  111. }
  112. }
  113. }, function (res) {
  114. if (res.d > 0) {
  115. showMsgAndGo(i18next.t("message.Delete_Success"), sQueryPrgId); // ╠message.Delete_Success⇒刪除成功╣
  116. }
  117. else {
  118. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  119. }
  120. }, function () {
  121. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  122. });
  123. },
  124. /**
  125. * 上傳附件
  126. * @param {Array} files 上傳的文件
  127. */
  128. fnUpload = function (files) {
  129. var option = {};
  130. option.input = $('#fileInput');
  131. option.theme = 'dragdropbox';
  132. option.folder = 'WebSiteFiles';
  133. option.type = 'list';
  134. option.parentid = oCurData.FileID;
  135. if (files) {
  136. option.files = files;
  137. }
  138. fnUploadRegister(option);
  139. },
  140. /**
  141. * ToolBar 按鈕事件 function
  142. * @param {Object}inst 按鈕物件對象
  143. * @param {Object} e 事件對象
  144. */
  145. fnButtonHandler = function (inst, e) {
  146. var sId = inst.id;
  147. switch (sId) {
  148. case "Toolbar_Qry":
  149. break;
  150. case "Toolbar_Save":
  151. if (!$("#form_main").valid()) {
  152. oValidator.focusInvalid();
  153. return false;
  154. }
  155. if (sAction == 'Add') {
  156. fnAdd('add');
  157. }
  158. else {
  159. fnUpd();
  160. }
  161. break;
  162. case "Toolbar_ReAdd":
  163. if (!$("#form_main").valid()) {
  164. oValidator.focusInvalid();
  165. return false;
  166. }
  167. fnAdd('readd');
  168. break;
  169. case "Toolbar_Clear":
  170. clearPageVal();
  171. break;
  172. case "Toolbar_Leave":
  173. pageLeave();
  174. break;
  175. case "Toolbar_Add":
  176. break;
  177. case "Toolbar_Upd":
  178. break;
  179. case "Toolbar_Copy":
  180. break;
  181. case "Toolbar_Del": // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
  182. layer.confirm(i18next.t("message.ConfirmToDelete"), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  183. fnDel();
  184. layer.close(index);
  185. });
  186. break;
  187. default:
  188. alert("No handle '" + sId + "'");
  189. break;
  190. }
  191. },
  192. /**
  193. * 初始化 function
  194. */
  195. init = function () {
  196. commonInit({
  197. PrgId: sProgramId,
  198. ButtonHandler: fnButtonHandler,
  199. GoTop: true
  200. });
  201. $.validator.addMethod("uniqueidrule", function (value) {
  202. var bRetn = true;
  203. if (value) {
  204. CallAjax(ComFn.W_Com, ComFn.GetCount, {
  205. Params: {
  206. websitefiles: {
  207. UniqueID: value,
  208. OrgID: parent.OrgID
  209. }
  210. }
  211. }, function (rq) {
  212. if (rq.d > 0) {
  213. bRetn = false;
  214. }
  215. }, null, true, false);
  216. }
  217. return bRetn;
  218. });
  219. oValidator = $("#form_main").validate({
  220. onfocusout: false,
  221. rules: {
  222. UniqueID: { uniqueidrule: sAction === 'Add' ? true : false },
  223. },
  224. messages: {
  225. UniqueID: { uniqueidrule: i18next.t("message.Data_Repeat") }// ╠message.Data_Repeat⇒此筆資料已建檔╣
  226. }
  227. });
  228. fnGet();
  229. };
  230. init();
  231. };
  232. require(['base', 'jsgrid', 'filer', 'util'], fnPageInit);