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.

207 lines
11 KiB

2 years ago
  1. 'use strict';
  2. var sProgramId = getProgramId(),
  3. oGrid = null,
  4. fnPageInit = function () {
  5. var saLangTypes = [],
  6. saLangCountries = [],
  7. canDo = new CanDo({
  8. sortField: 'LangId',
  9. sortOrder: 'asc',
  10. inserting: true,
  11. /**
  12. * 當前程式所有ID名稱集合
  13. */
  14. idKeys: ['OrgID', 'ArgumentClassID', 'ArgumentID'],
  15. /**
  16. * Grid欄位設置可以是 function
  17. */
  18. gridFields: function () {
  19. return [
  20. { name: "RowIndex", title: 'common.RowNumber', editing: false, inserting: false, type: "text", width: 50, align: "center", sorting: false },
  21. { name: "Type", title: 'Language_Set.LanguageType', editing: false, align: "left", type: "select", items: saLangTypes, valueField: "id", textField: "name", width: 200 },
  22. { name: "Country", title: 'Language_Set.Language', editing: false, align: "left", type: "select", items: saLangCountries, valueField: "id", textField: "label", width: 100 },
  23. { name: "LangId", title: 'Language_Set.languageId_required', editing: false, type: "text", width: 200, validate: { validator: 'required', message: i18next.t("Language_Set.languageId_required") } },// ╠Language_Set.languageId_required⇒語系ID不能為空╣
  24. { name: "LangName", title: 'Language_Set.LanguageName', type: "text", width: 200 },
  25. { name: "Memo", title: 'common.Memo', type: "text", width: 200 },
  26. { type: "control" }
  27. ];
  28. },
  29. /**
  30. * 客製化按鈕
  31. * @param {Object} pargs CanDo 對象
  32. */
  33. cusBtns: function (pargs) {
  34. var saCusBtns = [{
  35. id: 'CreateLangFile',
  36. value: 'common.Toolbar_CreateLangFile',// ╠common.Toolbar_CreateLangFile⇒產生檔案╣
  37. action: function (_pargs) {
  38. fnCreateLangFile();
  39. }
  40. },
  41. {
  42. id: 'CopyLanguage',
  43. value: 'common.Toolbar_CopyLanguage',// ╠common.Toolbar_CopyLanguage⇒語系複製╣
  44. action: function (_pargs) {
  45. fnCopyLanguageFile();
  46. }
  47. },
  48. {
  49. id: 'InitializeLanguage',
  50. value: 'common.Toolbar_InitializeLanguage',// ╠common.Toolbar_InitializeLanguage⇒語系初始化╣
  51. action: function (_pargs) {
  52. fnInitializeLanguage();
  53. }
  54. }];
  55. return saCusBtns;
  56. },
  57. /**
  58. * 頁面初始化
  59. * @param {Object} pargs CanDo 對象
  60. */
  61. pageInit: function (pargs) {
  62. $.when(fnSetLanguageTypeDrop(),
  63. fnSetArgDrop([
  64. {
  65. ArgClassID: 'LanCountry',
  66. Select: $('#Country'),
  67. ShowId: true,
  68. CallBack: function (data) {
  69. saLangCountries = data;
  70. }
  71. }
  72. ])).done(function () {
  73. pargs._reSetQueryPm();
  74. pargs._initGrid();
  75. });
  76. }
  77. }),
  78. /**
  79. * 設置語言類別下拉單
  80. * @return {Object} Ajax 物件
  81. */
  82. fnSetLanguageTypeDrop = function () {
  83. return g_api.ConnectLite(canDo.ProgramId, 'GetSysHtmlPath', {
  84. filepath: ''
  85. }, function (res) {
  86. if (res.RESULT) {
  87. var saList = res.DATA.rel;
  88. $.each(saList, function (idx, data) {
  89. data.id = getProgramId(data.id);
  90. data.name = data.name.split("/").slice(-1)[0].match(/^[a-zA-Z0-9_]*/g);
  91. //data.name = data.name.split("/").slice(-1)[0].match(/^[a-zA-Z0-9_]*/g);
  92. });
  93. saList.unshift({ id: 'other', name: '其他' });
  94. saList.unshift({ id: 'message', name: '提示消息' });
  95. saList.unshift({ id: 'common', name: '公用' });
  96. saLangTypes = saList;
  97. var sOptionHtml = createOptions(saList, 'id', 'name');
  98. $('#LanguageType').html(sOptionHtml);
  99. }
  100. else {
  101. showMsg(res.MSG, 'error'); //更新失敗
  102. }
  103. });
  104. },
  105. /**
  106. * 初始化多語系
  107. */
  108. fnInitializeLanguage = function () {
  109. g_api.ConnectLite('Language', 'InitializeLanguage', {}, function (res) {
  110. if (res.RESULT) {
  111. showMsg(i18next.t("message.Initialize_Success"), 'success'); // ╠message.Initialize_Success⇒初始化成功╣
  112. }
  113. else {
  114. showMsg(i18next.t('message.Initialize_Failed') + '<br>' + res.MSG, 'error'); // ╠message.Initialize_Failed⇒初始化失敗╣
  115. }
  116. }, function () {
  117. showMsg(i18next.t("message.Initialize_Failed"), 'error');// ╠message.Initialize_Failed⇒初始化失敗╣
  118. });
  119. },
  120. /**
  121. * 更新語系檔案
  122. */
  123. fnCreateLangFile = function () {
  124. g_api.ConnectLite('Language', 'CreateLangJson', {}, function (res) {
  125. if (res.RESULT) {
  126. showMsg(i18next.t("message.Createlanguage_Success"), 'success'); // ╠message.Createlanguage_Success⇒語系檔產生成功╣
  127. }
  128. else {
  129. showMsg(i18next.t('message.Createlanguage_Failed') + '<br>' + res.MSG, 'error'); // ╠message.Createlanguage_Failed⇒語系檔產生失敗╣
  130. }
  131. }, function () {
  132. showMsg(i18next.t("message.Createlanguage_Failed"), 'error'); // ╠message.Createlanguage_Failed⇒語系檔產生失敗╣
  133. });
  134. },
  135. /**
  136. * 複製語系
  137. */
  138. fnCopyLanguageFile = function () {
  139. var oValidator = null;
  140. layer.open({
  141. type: 2,
  142. title: i18next.t('common.CopyLanguage'),// ╠common.CopyLanguage⇒語言複製╣
  143. shade: 0.75,
  144. maxmin: true, //开启最大化最小化按钮
  145. area: ['600px', '240px'],
  146. content: '/Page/Pop/CopyLanguage.html',
  147. success: function (layero, index) {
  148. var iframe = $('iframe').contents(),
  149. sOptions = $('#Country').html();
  150. iframe.find('#lang_from').html(sOptions);
  151. iframe.find('#lang_to').html(sOptions);
  152. $.validator.addMethod("comparlang_to", function (value, element, parms) {
  153. if (value === iframe.find(parms).val()) {
  154. return false;
  155. }
  156. return true;
  157. });
  158. oValidator = iframe.find("#CopyLanguage_form").validate({ //表單欄位驗證
  159. rules: {
  160. lang_from: 'required',
  161. lang_to: { required: true, comparlang_to: '#lang_from' }
  162. },
  163. messages: {
  164. lang_from: i18next.t('CopyLanguage.LangFrom_required'),// ╠CopyLanguage.LangFrom_required⇒請選擇來源語系╣
  165. lang_to: { required: i18next.t('CopyLanguage.LangTo_required'), comparlang_to: i18next.t('CopyLanguage.LangTo_equalTo') }//╠CopyLanguage.LangTo_required⇒請選擇目的語系╣ ╠CopyLanguage.LangTo_equalTo⇒目的語系不能與來源語系一致╣
  166. }
  167. });
  168. transLang(layero);
  169. },
  170. btn: [i18next.t('common.Confirm'), i18next.t('common.Cancel')],//╠common.Confirm⇒確定╣╠common.Cancel⇒取消╣
  171. yes: function (index, layero) {
  172. var iframe = $('iframe').contents();
  173. if (!iframe.find("#CopyLanguage_form").valid()) {
  174. oValidator.focusInvalid();
  175. return false;
  176. }
  177. var sLang_from = iframe.find('#lang_from').val(),
  178. sLang_to = iframe.find('#lang_to').val(),
  179. data = { LangFrom: sLang_from, LangTo: sLang_to, UserId: parent.UserInfo.MemberID };
  180. g_api.ConnectLite(canDo.ProgramId, 'CopyLanguage', data, function (res) {
  181. if (res.RESULT) {
  182. showMsg(i18next.t("message.CopyLanguage_Success")); //╠message.CopyLanguage_Success⇒語系複製成功╣
  183. layer.close(index);
  184. }
  185. else {
  186. if (res.MSG == "0") {
  187. showMsg(i18next.t("message.CopyLanguage_Failed"), 'error'); //╠message.CopyLanguage_Failed⇒語言複製失敗╣
  188. }
  189. else if (res.MSG == "1") {
  190. showMsg(i18next.t("message.Lang_From_NotFond"), 'error'); //╠message.Lang_From_NotFond⇒來源語系為空╣
  191. }
  192. else {
  193. showMsg(res.MSG, 'error');
  194. }
  195. }
  196. }, function () {
  197. showMsg(i18next.t("message.CopyLanguage_Failed"), 'error');//╠message.CopyLanguage_Failed⇒語言複製失敗╣
  198. });
  199. }
  200. });
  201. };
  202. };
  203. require(['base', 'jsgrid', 'cando'], fnPageInit);