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.

160 lines
6.0 KiB

2 years ago
  1. 'use strict';
  2. var fnPageInit = function () {
  3. var canDo = new CanDo({
  4. /**
  5. * 當前程式所有ID名稱集合
  6. */
  7. idKeys: ['OrgID', 'TemplID'],
  8. /**
  9. * 當前程式所有參數名稱集合
  10. */
  11. paramKeys: ['TemplID'],
  12. /**
  13. * 當前程式所有參數名稱集合
  14. */
  15. jsonStrKeys: ['TemplKeys'],
  16. /**
  17. * 處理新增資料參數
  18. * @param {Object} pargs CanDo 對象
  19. * @param {Object} data 當前表單資料
  20. */
  21. getInsertParams: function (pargs, data) {
  22. data.FileID = pargs.data.FileID;
  23. data.TemplKeys = JSON.stringify(pargs.data.TemplKeys);
  24. return data;
  25. },
  26. /**
  27. * 處理修改資料參數
  28. * @param {Object} pargs CanDo 對象
  29. * @param {Object} data 當前表單資料
  30. */
  31. getUpdateParams: function (pargs, data) {
  32. return pargs.options.getInsertParams(pargs, data);
  33. },
  34. /**
  35. * 客製化驗證規則
  36. * @param {Object} pargs CanDo 對象
  37. */
  38. validRulesCus: function (pargs) {
  39. $.validator.addMethod("templidrule", function (value) {
  40. var bRetn = true;
  41. if (value) {
  42. g_api.ConnectLite(pargs.ProgramId, pargs._api.getcout,
  43. {
  44. TemplID: value,
  45. },
  46. function (res) {
  47. if (res.RESULT && res.DATA.rel > 0) {
  48. bRetn = false;
  49. }
  50. }, null, false);
  51. }
  52. return bRetn;
  53. });
  54. },
  55. /**
  56. * 驗證規則
  57. */
  58. validRules: function (pargs) {
  59. return {
  60. onfocusout: false,
  61. rules: {
  62. TemplID: { templidrule: pargs.action === 'add' ? true : false },
  63. },
  64. messages: {
  65. TemplID: { templidrule: i18next.t("message.Data_Repeat") }// ╠message.Data_Repeat⇒此筆資料已建檔╣
  66. }
  67. };
  68. },
  69. /**
  70. * 頁面初始化
  71. * @param {Object} pargs CanDo 對象
  72. */
  73. pageInit: function (pargs) {
  74. if (pargs.action === 'upd') {
  75. $('#TemplID').prop('disabled', true);
  76. pargs._getOne().done(function (res) {
  77. pargs.data.FileID = pargs.data.FileID || guid();
  78. fnBindKeys();
  79. fnGetUploadFiles(pargs.data.FileID, fnUpload);
  80. });
  81. }
  82. else {
  83. pargs.data.FileID = guid();
  84. pargs.data.TemplKeys = [];
  85. fnUpload();
  86. }
  87. $('.plustemplkey').on('click', function () {
  88. var oNewKey = {};
  89. oNewKey.guid = guid();
  90. oNewKey.TemplKey = '';
  91. oNewKey.TemplKeyValue = '';
  92. oNewKey.TemplName = '';
  93. oNewKey.Memo = '';
  94. canDo.data.TemplKeys.push(oNewKey);
  95. fnBindKeys();
  96. });
  97. }
  98. }),
  99. /**
  100. * 綁定模版參數
  101. * @param {Array} files 上傳的文件
  102. */
  103. fnBindKeys = function () {
  104. var sKeysHtml = '';
  105. $.each(canDo.data.TemplKeys, function (idx, item) {
  106. sKeysHtml += '<tr data-id="' + item.guid + '">\
  107. <td class="wcenter">' + (idx + 1) + '</td>\
  108. <td class="wcenter"><input type="text" data-input="TemplKey" class="form-control w100p" value="' + item.TemplKey + '"></td>\
  109. <td><input type="text" data-input="TemplKeyValue" class="form-control w100p" value="' + item.TemplKeyValue + '"></td>\
  110. <td><input type="text" data-input="TemplName" class="form-control w100p" value="' + item.TemplName + '"></td>\
  111. <td><input type="text" data-input="Memo" class="form-control w100p" value="' + item.Memo + '"></td>\
  112. <td class="wcenter">\
  113. <i class="glyphicon glyphicon-trash" data-value="' + item.guid + '" title="刪除"></i>\
  114. </td>\
  115. </tr>';
  116. });
  117. $('#table_box').html(sKeysHtml).find('.glyphicon-trash').on('click', function () {
  118. var sId = $(this).attr('data-value'),
  119. saNewList = [];
  120. $.each(canDo.data.TemplKeys, function (idx, item) {
  121. if (sId !== item.guid) {
  122. saNewList.push(item);
  123. }
  124. });
  125. $(this).parents('tr').remove();
  126. canDo.data.TemplKeys = saNewList;
  127. });
  128. $('#table_box').find('[data-input]').on('change', function () {
  129. var sKey = $(this).attr('data-input'),
  130. sId = $(this).parents('tr').attr('data-id'),
  131. sVal = this.value;
  132. $.each(canDo.data.TemplKeys, function (idx, item) {
  133. if (sId === item.guid) {
  134. item[sKey] = sVal;
  135. return false;
  136. }
  137. });
  138. });
  139. },
  140. /**
  141. * 上傳附件
  142. * @param {Array} files 上傳的文件
  143. */
  144. fnUpload = function (files) {
  145. var option = {};
  146. option.input = $('#fileInput');
  147. option.theme = 'dragdropbox';
  148. option.folder = 'OfficeTemplate';
  149. option.type = 'one';
  150. option.limit = 1;
  151. option.parentid = canDo.data.FileID;
  152. if (files) {
  153. option.files = files;
  154. }
  155. fnUploadRegister(option);
  156. };
  157. };
  158. require(['base', 'filer', 'cando'], fnPageInit);