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.

1051 lines
58 KiB

2 years ago
  1. 'use strict';
  2. var sProgramId = getProgramId(),
  3. sQueryPrgId = getQueryPrgId(),
  4. sViewPrgId = sProgramId.replace('_Upd', '_View'),
  5. sAction = getUrlParam('Action') || 'Add',
  6. sDataId = getUrlParam('Guid'),
  7. sCheckId = sDataId,
  8. fnPageInit = function () {
  9. var oCurData = { CheckOrder: [], OverTimes: [] },
  10. oForm = $('#form_main'),
  11. oGrid = null,
  12. oValidator = null,
  13. sOptionHtml_Users = '',
  14. sOptionHtml_OverTime = '',
  15. sOptionHtml_PrjCode = '',
  16. oAddItem = {},
  17. saUsers = [],
  18. /**
  19. * 獲取資料
  20. */
  21. fnGet = function () {
  22. if (sDataId) {
  23. return g_api.ConnectLite(sQueryPrgId, ComFn.GetOne,
  24. {
  25. Guid: sDataId
  26. },
  27. function (res) {
  28. if (res.RESULT) {
  29. var oRes = res.DATA.rel;
  30. oCurData = oRes;
  31. oCurData.OverTimes = $.parseJSON(oCurData.OverTimes);
  32. oCurData.CheckOrder = $.parseJSON(oCurData.CheckOrder);
  33. setFormVal(oForm, oRes);
  34. $('.AskTheDummy').text(oCurData.AskTheDummyName + '(' + oCurData.AskTheDummy + ') ' + oCurData.DeptName);
  35. fnGetUploadFiles(oCurData.Guid, fnUpload);
  36. if (oCurData.Handle_DeptID) {
  37. fnSetUserDrop([
  38. {
  39. Select: $('#Handle_Person'),
  40. DepartmentID: oCurData.Handle_DeptID,
  41. ShowId: true,
  42. Select2: true,
  43. Action: sAction,
  44. DefultVal: oCurData.Handle_Person
  45. }
  46. ]);
  47. }
  48. if (oCurData.Flows_Lock === 'Y') {
  49. $(".checkordertoolbox").hide();
  50. }
  51. else {
  52. $(".checkordertoolbox").show();
  53. }
  54. if (oCurData.Handle_Lock === 'Y') {
  55. $("#Handle_DeptID,#Handle_Person").attr('disabled', true);
  56. }
  57. else {
  58. $("#Handle_DeptID,#Handle_Person").removeAttr('disabled');
  59. }
  60. $("#jsGrid").jsGrid("loadData");
  61. $("#jsGrid1").jsGrid("loadData");
  62. setNameById().done(function () {
  63. getPageVal();//緩存頁面值,用於清除
  64. });
  65. }
  66. });
  67. }
  68. else {
  69. $('.AskTheDummy').text(parent.UserInfo.MemberName + '(' + parent.UserInfo.MemberID + ') ' + parent.UserInfo.DepartmentName);
  70. $('#AskTheDummy').val(parent.UserInfo.MemberID);
  71. oCurData.OverTimes = [];
  72. oCurData.CheckOrder = [];
  73. oCurData.Guid = guid();
  74. fnUpload();
  75. return $.Deferred().resolve().promise();
  76. }
  77. },
  78. /**
  79. * 新增資料
  80. * @param {String} sFlag 新增或儲存後新增
  81. */
  82. fnAdd = function (flag) {
  83. var data = getFormSerialize(oForm);
  84. data = packParams(data);
  85. data.OrgID = parent.OrgID;
  86. data.Guid = oCurData.Guid;
  87. data.SignedNumber = 'SerialNumber|' + parent.UserInfo.OrgID + '|OT|MinYear|3|' + parent.UserInfo.ServiceCode + '|' + parent.UserInfo.ServiceCode;
  88. data.CheckFlows = fnCheckFlows(oCurData, false, true, saUsers);
  89. data.HandleFlows = fnHandleFlows(oCurData, saUsers);
  90. data.OverTimes = JSON.stringify(oCurData.OverTimes);
  91. data.CheckOrder = JSON.stringify(oCurData.CheckOrder);
  92. data.Status = 'A';
  93. data.IsHandled = 'N';
  94. data.Inspectors = '';
  95. data.Reminders = '';
  96. data.Flows_Lock = oCurData.Flows_Lock;
  97. data.Handle_Lock = oCurData.Handle_Lock;
  98. CallAjax(ComFn.W_Com, ComFn.GetAdd, {
  99. Params: {
  100. overtime: data
  101. }
  102. }, function (res) {
  103. if (res.d > 0) {
  104. bRequestStorage = false;
  105. if (flag == 'add') {
  106. showMsgAndGo(i18next.t("message.Save_Success"), sProgramId, '?Action=Upd&Guid=' + data.Guid); // ╠message.Save_Success⇒新增成功╣
  107. }
  108. else {
  109. showMsgAndGo(i18next.t("message.Save_Success"), sProgramId, '?Action=Add'); // ╠message.Save_Success⇒新增成功╣
  110. }
  111. }
  112. else {
  113. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  114. }
  115. }, function () {
  116. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  117. });
  118. },
  119. /**
  120. * 修改資料
  121. * @param {Boolean} balert 是否提示
  122. */
  123. fnUpd = function (balert) {
  124. var data = getFormSerialize(oForm);
  125. data = packParams(data, 'upd');
  126. data.CheckFlows = fnCheckFlows(oCurData, false, true, saUsers);
  127. data.HandleFlows = fnHandleFlows(oCurData, saUsers);
  128. data.OverTimes = JSON.stringify(oCurData.OverTimes);
  129. data.CheckOrder = JSON.stringify(oCurData.CheckOrder);
  130. data.Flows_Lock = oCurData.Flows_Lock;
  131. data.Handle_Lock = oCurData.Handle_Lock;
  132. return CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  133. Params: {
  134. overtime: {
  135. values: data,
  136. keys: { Guid: sDataId }
  137. }
  138. }
  139. }, function (res) {
  140. if (res.d > 0) {
  141. if (!balert) {
  142. bRequestStorage = false;
  143. showMsg(i18next.t("message.Modify_Success"), 'success'); //╠message.Modify_Success⇒修改成功╣
  144. if (window.bLeavePage) {
  145. setTimeout(function () {
  146. pageLeave();
  147. }, 1000);
  148. }
  149. }
  150. }
  151. else {
  152. showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣
  153. }
  154. }, function () {
  155. showMsg(i18next.t("message.Modify_Failed"), 'error');//╠message.Modify_Failed⇒修改失敗╣
  156. });
  157. },
  158. /**
  159. * 資料刪除
  160. */
  161. fnDel = function () {
  162. CallAjax(ComFn.W_Com, ComFn.GetDel, {
  163. Params: {
  164. overtime: {
  165. Guid: sDataId
  166. }
  167. }
  168. }, function (res) {
  169. if (res.d > 0) {
  170. DelTask(sDataId);
  171. showMsgAndGo(i18next.t("message.Delete_Success"), sQueryPrgId); // ╠message.Delete_Success⇒刪除成功╣
  172. }
  173. else {
  174. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  175. }
  176. }, function () {
  177. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  178. });
  179. },
  180. /**
  181. * 上傳附件
  182. * @param {Array} files 上傳的文件
  183. */
  184. fnUpload = function (files) {
  185. var option = {};
  186. option.input = $('#fileInput');
  187. option.theme = 'dragdropbox';
  188. option.folder = 'OverTime';
  189. option.type = 'list';
  190. option.parentid = oCurData.Guid;
  191. if (files) {
  192. option.files = files;
  193. }
  194. fnUploadRegister(option);
  195. },
  196. /**
  197. * 提交簽呈
  198. */
  199. fnSubmitPetition = function () {
  200. g_api.ConnectLite(sProgramId, 'OverTimeToAudit', {
  201. guid: oCurData.Guid
  202. }, function (res) {
  203. if (res.RESULT) {
  204. showMsgAndGo(i18next.t("message.ToAudit_Success"), sViewPrgId, '?Action=Upd&Guid=' + oCurData.Guid);// ╠message.ToAudit_Success⇒提交審核成功╣
  205. parent.msgs.server.pushTips(parent.fnReleaseUsers(res.DATA.rel));
  206. }
  207. else {
  208. showMsg(i18next.t('message.ToAudit_Failed') + '<br>' + res.MSG, 'error'); // ╠message.ToAudit_Failed⇒提交審核失敗╣
  209. }
  210. }, function () {
  211. showMsg(i18next.t('message.ToAudit_Failed'), 'error'); // ╠message.ToAudit_Failed⇒提交審核失敗╣
  212. });
  213. },
  214. /**
  215. * ToolBar 按鈕事件 function
  216. * @param {Object}inst 按鈕物件對象
  217. * @param {Object} e 事件對象
  218. */
  219. fnButtonHandler = function (inst, e) {
  220. var sId = inst.id;
  221. switch (sId) {
  222. case "Toolbar_Qry":
  223. break;
  224. case "Toolbar_Save":
  225. if (!$("#form_main").valid()) {
  226. oValidator.focusInvalid();
  227. return false;
  228. }
  229. if (sAction === 'Add') {
  230. fnAdd('add');
  231. }
  232. else {
  233. fnUpd();
  234. }
  235. break;
  236. case "Toolbar_ReAdd":
  237. if (!$("#form_main").valid()) {
  238. oValidator.focusInvalid();
  239. return false;
  240. }
  241. fnAdd('readd');
  242. break;
  243. case "Toolbar_Clear":
  244. clearPageVal();
  245. break;
  246. case "Toolbar_Leave":
  247. pageLeave();
  248. break;
  249. case "Toolbar_Add":
  250. break;
  251. case "Toolbar_Upd":
  252. break;
  253. case "Toolbar_Copy":
  254. break;
  255. case "Toolbar_Petition":
  256. if (!$("#form_main").valid()) {
  257. oValidator.focusInvalid();
  258. return false;
  259. }
  260. fnUpd(true).done(function () {
  261. fnSubmitPetition();
  262. });
  263. break;
  264. case "Toolbar_Del": // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
  265. layer.confirm(i18next.t("message.ConfirmToDelete"), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
  266. fnDel();
  267. layer.close(index);
  268. });
  269. break;
  270. default:
  271. alert("No handle '" + sId + "'");
  272. break;
  273. }
  274. },
  275. /**
  276. * 初始化 function
  277. */
  278. init = function () {
  279. var saCusBtns = null;
  280. if (sAction === 'Upd') {
  281. saCusBtns = [{
  282. id: 'Toolbar_Petition',
  283. value: 'common.SubmitPetition'// ╠common.SubmitPetition⇒提交簽呈╣
  284. }];
  285. }
  286. commonInit({
  287. PrgId: sProgramId,
  288. ButtonHandler: fnButtonHandler,
  289. Buttons: saCusBtns,
  290. GoTop: true
  291. });
  292. oValidator = $("#form_main").validate();
  293. $.whenArray([
  294. fnSetDeptDrop($('#Handle_DeptID')),
  295. fnSetFlowDrop({
  296. Flow_Type: parent.SysSet.Eip_007,
  297. ShareTo: parent.UserID,
  298. CallBack: function (data) {
  299. $.each(data, function (idx, item) {
  300. var saFlows = $.parseJSON(item.Flows),
  301. saFlowsText = [],
  302. sFlowsText = '';
  303. $.each(saFlows, function (idx, flow) {
  304. var sFlowType = i18next.t('common.' + flow.SignedWay);
  305. if (flow.SignedWay !== 'flow1') {
  306. saFlowsText.push(sFlowType + '(' + Enumerable.From(flow.SignedMember).ToString(",", "$.name") + ')');
  307. }
  308. else {
  309. saFlowsText.push(Enumerable.From(flow.SignedMember).ToString(",", "$.name"));
  310. }
  311. });
  312. sFlowsText = saFlowsText.join(' → ');
  313. item.text = item.Flow_Name + ' - ' + (sFlowsText.length > 60 ? sFlowsText.substr(0, 60) + '...' : sFlowsText);
  314. });
  315. $('#FlowId').html(createOptions(data, 'Guid', 'text')).on('change', function () {
  316. var sFlowId = this.value;
  317. if (sFlowId) {
  318. CallAjax(ComFn.W_Com, ComFn.GetOne, {
  319. Type: '',
  320. Params: {
  321. checkflow: {
  322. Guid: sFlowId
  323. }
  324. }
  325. }, function (res) {
  326. if (res.d) {
  327. var oRes = $.parseJSON(res.d);
  328. oRes.Flows = $.parseJSON(oRes.Flows);
  329. oCurData.CheckOrder = oRes.Flows;
  330. oCurData.Flows_Lock = oRes.Flows_Lock;
  331. oCurData.Handle_Lock = oRes.Handle_Lock;
  332. $("#Handle_DeptID").val(oRes.Handle_DeptID);
  333. $("#Handle_Person").val(oRes.Handle_Person).trigger('change');
  334. if (oRes.Flows_Lock === 'Y') {
  335. $(".checkordertoolbox").hide();
  336. }
  337. else {
  338. $(".checkordertoolbox").show();
  339. }
  340. if (oRes.Handle_Lock === 'Y') {
  341. $("#Handle_DeptID,#Handle_Person").attr('disabled', true);
  342. }
  343. else {
  344. $("#Handle_DeptID,#Handle_Person").removeAttr('disabled');
  345. }
  346. $("#jsGrid").jsGrid("loadData");
  347. }
  348. });
  349. }
  350. else {
  351. oCurData.CheckOrder = [];
  352. $(".checkordertoolbox").hide();
  353. $("#jsGrid").jsGrid("loadData");
  354. $("#Handle_DeptID,#Handle_Person").removeAttr('disabled');
  355. }
  356. });
  357. }
  358. }),
  359. fnSetEpoDrop({
  360. CallBack: function (data) {
  361. sOptionHtml_PrjCode = createOptions(data, 'ExhibitionCode', 'ExhibitioShotName_TW');
  362. }
  363. }),
  364. fnSetUserDrop([
  365. {
  366. Select: $('#Handle_Person'),
  367. Select2: true,
  368. ShowId: true,
  369. Action: sAction,
  370. CallBack: function (data) {
  371. saUsers = data;
  372. sOptionHtml_Users = createOptions(data, 'MemberID', 'MemberName');
  373. }
  374. }
  375. ]),
  376. fnSetArgDrop([
  377. {
  378. ArgClassID: 'OverTime',
  379. CallBack: function (data) {
  380. sOptionHtml_OverTime = createOptions(data, 'id', 'text', true);
  381. }
  382. }
  383. ])])
  384. .done(function () {
  385. fnGet();
  386. $("#jsGrid1").jsGrid({
  387. width: "100%",
  388. height: "auto",
  389. autoload: true,
  390. filtering: false,
  391. inserting: true,
  392. editing: true,
  393. pageLoading: true,
  394. confirmDeleting: true,
  395. invalidMessage: i18next.t('common.InvalidData'),// ╠common.InvalidData⇒输入的数据无效!╣
  396. deleteConfirm: i18next.t('message.ConfirmToDelete'),// ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣
  397. pageIndex: 1,
  398. pageSize: 10000,
  399. fields: [
  400. {
  401. name: "Index", title: '#', width: 30, align: "center"
  402. },
  403. {// ╠common.EmployeeCode⇒員工代號╣
  404. name: "EmployeeCode", title: 'common.EmployeeCode', width: 70, type: "text",
  405. insertTemplate: function (val, item) {
  406. var oControl = $('<input />', {
  407. class: "form-control w100p",
  408. disabled: true
  409. });
  410. return this.insertControl = oControl;
  411. },
  412. insertValue: function () {
  413. return this.insertControl.val();
  414. },
  415. editTemplate: function (val, item) {
  416. var oControl = $('<input />', {
  417. class: "form-control w100p",
  418. disabled: true,
  419. value: val
  420. });
  421. return this.editControl = oControl;
  422. },
  423. editValue: function () {
  424. return this.editControl.val();
  425. }
  426. },
  427. {// ╠common.EmployeeName⇒員工姓名╣
  428. name: "EmployeeName", title: 'common.EmployeeName', width: 70, type: "text", validate: { validator: 'required', message: i18next.t('common.Employee_required') },// ╠common.Employee_required⇒請選擇員工╣
  429. insertTemplate: function (val, item) {
  430. var oControl = $('<select />', {
  431. class: "form-control w100p",
  432. html: sOptionHtml_Users,
  433. change: function () {
  434. oControl.parent().prev().find('input').val(this.value);
  435. }
  436. });
  437. return this.insertControl = oControl;
  438. },
  439. insertValue: function () {
  440. if (this.insertControl.val()) {
  441. return this.insertControl.find('option:selected').text();
  442. }
  443. else {
  444. return '';
  445. }
  446. },
  447. editTemplate: function (val, item) {
  448. var oControl = $('<select />', {
  449. class: "form-control w100p",
  450. html: sOptionHtml_Users,
  451. change: function () {
  452. oControl.parent().prev().find('input').val(this.value);
  453. }
  454. });
  455. return this.editControl = oControl.val(item.EmployeeCode);
  456. },
  457. editValue: function () {
  458. if (this.editControl.val()) {
  459. return this.editControl.find('option:selected').text();
  460. }
  461. else {
  462. return '';
  463. }
  464. }
  465. },
  466. {// ╠common.OvertimeClass⇒加班類別╣
  467. name: "OvertimeClass", title: 'common.OvertimeClass', width: 70, type: "text", validate: { validator: 'required', message: i18next.t('common.OvertimeClass_required') },// ╠common.OvertimeClass_required⇒請選擇加班類別╣
  468. itemTemplate: function (val, item) {
  469. return item.OvertimeClassName;
  470. },
  471. insertTemplate: function (val, item) {
  472. var oControl = $('<select />', {
  473. class: "form-control w100p",
  474. html: sOptionHtml_OverTime
  475. });
  476. return this.insertControl = oControl;
  477. },
  478. insertValue: function () {
  479. if (this.insertControl.val()) {
  480. oAddItem.OvertimeClassName = this.insertControl.find('option:selected').text();
  481. }
  482. return this.insertControl.val();
  483. },
  484. editTemplate: function (val, item) {
  485. var oControl = $('<select />', {
  486. class: "form-control w100p",
  487. html: sOptionHtml_OverTime,
  488. change: function () {
  489. item.OvertimeClassName = $(this).find('option:selected').text();
  490. }
  491. });
  492. return this.editControl = oControl.val(item.OvertimeClass);
  493. },
  494. editValue: function () {
  495. return this.editControl.val();
  496. }
  497. },
  498. {// ╠common.AttendanceDate⇒出勤日期╣
  499. name: "AttendanceDate", title: 'common.AttendanceDate', width: 80, align: "center", type: "text", validate: { validator: 'required', message: i18next.t('common.AttendanceDate_required') },// ╠common.AttendanceDate_required⇒請選擇出勤日期╣
  500. insertTemplate: function (val, item) {
  501. var oControl = $('<input />', {
  502. class: "form-control w100p date-picker"
  503. });
  504. oControl.datepicker({
  505. changeYear: true,
  506. changeMonth: true,
  507. altFormat: 'yyyy/MM/dd'
  508. });
  509. return this.insertControl = oControl;
  510. },
  511. insertValue: function () {
  512. return this.insertControl.val();
  513. },
  514. editTemplate: function (val, item) {
  515. var oControl = $('<input />', {
  516. class: "form-control w100p date-picker",
  517. value: val
  518. });
  519. oControl.datepicker({
  520. changeYear: true,
  521. changeMonth: true,
  522. altFormat: 'yyyy/MM/dd'
  523. });
  524. return this.editControl = oControl;
  525. },
  526. editValue: function () {
  527. return this.editControl.val();
  528. }
  529. },
  530. {// ╠common.StartDate⇒开始日期╣
  531. name: "StartDate", title: 'common.StartDate', width: 80, type: "text", align: "center", validate: { validator: 'required', message: i18next.t('common.StartDate_required') },// ╠common.StartDate_required⇒請選擇開始日期╣
  532. insertTemplate: function (val, item) {
  533. var oControl = $('<input />', {
  534. class: "form-control w100p date-picker"
  535. });
  536. oControl.datepicker({
  537. changeYear: true,
  538. changeMonth: true,
  539. altFormat: 'yyyy/MM/dd'
  540. });
  541. return this.insertControl = oControl;
  542. },
  543. insertValue: function () {
  544. return this.insertControl.val();
  545. },
  546. editTemplate: function (val, item) {
  547. var oControl = $('<input />', {
  548. class: "form-control w100p date-picker",
  549. value: val
  550. });
  551. oControl.datepicker({
  552. changeYear: true,
  553. changeMonth: true,
  554. altFormat: 'yyyy/MM/dd'
  555. });
  556. return this.editControl = oControl;
  557. },
  558. editValue: function () {
  559. return this.editControl.val();
  560. }
  561. },
  562. {// ╠common.StartTime⇒开始時間╣
  563. name: "StartTime", title: 'common.StartTime', width: 60, type: "text", align: "center", validate: { validator: 'required', message: i18next.t('common.StartTime_required') },// ╠common.StartTime_required⇒請選擇開始時間╣
  564. insertTemplate: function (val, item) {
  565. var oControl = $('<input />', {
  566. class: "form-control w100p date-picker"
  567. });
  568. return this.insertControl = oControl.timepicker(
  569. {
  570. timeFormat: 'HH:mm',
  571. hour: 9,
  572. hourGrid: 6,
  573. minuteGrid: 30,
  574. stepMinute: 30
  575. }
  576. );
  577. },
  578. insertValue: function () {
  579. return this.insertControl.val();
  580. },
  581. editTemplate: function (val, item) {
  582. var oControl = $('<input />', {
  583. class: "form-control w100p date-picker",
  584. value: val
  585. });
  586. return this.editControl = oControl.timepicker(
  587. {
  588. timeFormat: 'HH:mm',
  589. hour: 9,
  590. hourGrid: 6,
  591. minuteGrid: 30,
  592. stepMinute: 30
  593. }
  594. );
  595. },
  596. editValue: function () {
  597. return this.editControl.val();
  598. }
  599. },
  600. {// ╠common.EndDate⇒結束日期╣
  601. name: "EndDate", title: 'common.EndDate', width: 80, type: "text", align: "center", validate: { validator: 'required', message: i18next.t('common.EndDate_required') },// ╠common.EndDate_required⇒請選擇結束日期╣
  602. insertTemplate: function (val, item) {
  603. var oControl = $('<input />', {
  604. class: "form-control w100p date-picker"
  605. });
  606. oControl.datepicker({
  607. changeYear: true,
  608. changeMonth: true,
  609. altFormat: 'yyyy/MM/dd'
  610. });
  611. return this.insertControl = oControl;
  612. },
  613. insertValue: function () {
  614. return this.insertControl.val();
  615. },
  616. editTemplate: function (val, item) {
  617. var oControl = $('<input />', {
  618. class: "form-control w100p date-picker",
  619. value: val
  620. });
  621. oControl.datepicker({
  622. changeYear: true,
  623. changeMonth: true,
  624. altFormat: 'yyyy/MM/dd'
  625. });
  626. return this.editControl = oControl;
  627. },
  628. editValue: function () {
  629. return this.editControl.val();
  630. }
  631. },
  632. {// ╠common.EndTime⇒結束時間╣
  633. name: "EndTime", title: 'common.EndTime', width: 60, type: "text", align: "center", validate: { validator: 'required', message: i18next.t('common.EndTime_required') },// ╠common.EndTime_required⇒請選擇結束時間╣
  634. insertTemplate: function (val, item) {
  635. var oControl = $('<input />', {
  636. class: "form-control w100p date-picker"
  637. });
  638. return this.insertControl = oControl.timepicker(
  639. {
  640. timeFormat: 'HH:mm',
  641. hour: 17,
  642. minute: 30,
  643. hourGrid: 6,
  644. minuteGrid: 30,
  645. stepMinute: 30
  646. }
  647. );
  648. },
  649. insertValue: function () {
  650. return this.insertControl.val();
  651. },
  652. editTemplate: function (val, item) {
  653. var oControl = $('<input />', {
  654. class: "form-control w100p date-picker",
  655. value: val
  656. });
  657. return this.editControl = oControl.timepicker(
  658. {
  659. timeFormat: 'HH:mm',
  660. hour: 17,
  661. minute: 30,
  662. hourGrid: 6,
  663. minuteGrid: 30,
  664. stepMinute: 30
  665. }
  666. );
  667. },
  668. editValue: function () {
  669. return this.editControl.val();
  670. }
  671. },
  672. {// ╠common.OvertimeHours⇒加班時數╣
  673. name: "OvertimeHours", title: 'common.OvertimeHours', width: 50, align: "center", type: "text", validate: { validator: 'required', message: i18next.t('common.OvertimeHours_required') }// ╠common.OvertimeHours_required⇒請輸入加班時數╣
  674. },
  675. {// ╠common.TakeTimeOffHours⇒補休時數╣
  676. name: "TakeTimeOffHours", title: 'common.TakeTimeOffHours', width: 50, align: "center", type: "text", validate: { validator: 'required', message: i18next.t('common.TakeTimeOffHours_required') }// ╠common.TakeTimeOffHours_required⇒請輸入補休時數╣
  677. },
  678. {// ╠common.PrjCode⇒專案代號╣
  679. name: "PrjCode", title: 'common.PrjCode', width: 80, type: "text",
  680. itemTemplate: function (val, item) {
  681. return item.PrjCode + '(' + item.PrjName + ')';
  682. },
  683. insertTemplate: function (val, item) {
  684. var oControl = $('<select />', {
  685. class: "form-control w100p",
  686. html: sOptionHtml_PrjCode
  687. });
  688. setTimeout(function () {
  689. oControl.select2({ width: '100px' });
  690. }, 1000);
  691. return this.insertControl = oControl;
  692. },
  693. insertValue: function () {
  694. if (this.insertControl.val()) {
  695. oAddItem.PrjName = this.insertControl.find('option:selected').text();
  696. }
  697. return this.insertControl.val();
  698. },
  699. editTemplate: function (val, item) {
  700. var oControl = $('<select />', {
  701. class: "form-control w100p",
  702. html: sOptionHtml_PrjCode,
  703. change: function () {
  704. item.PrjName = $(this).find('option:selected').text();
  705. }
  706. });
  707. setTimeout(function () {
  708. oControl.select2({ width: '100px' });
  709. }, 1000);
  710. return this.editControl = oControl.val(item.PrjCode);
  711. },
  712. editValue: function () {
  713. return this.editControl.val();
  714. }
  715. },
  716. {// ╠common.LeaveReason⇒事由說明╣
  717. name: "Reason", title: 'common.LeaveReason', width: 70, type: "text",
  718. insertTemplate: function (val, item) {
  719. var oControl = $('<textarea rows="2" cols="20" />', {
  720. class: "form-control w100p"
  721. });
  722. return this.insertControl = oControl;
  723. },
  724. insertValue: function () {
  725. return this.insertControl.val();
  726. },
  727. editTemplate: function (val, item) {
  728. var oControl = $('<textarea rows="2" cols="20" />', {
  729. class: "form-control w100p"
  730. });
  731. return this.editControl = oControl.val(val);
  732. },
  733. editValue: function () {
  734. return this.editControl.val();
  735. }
  736. },
  737. {
  738. type: "control", width: 50
  739. }
  740. ],
  741. controller: {
  742. loadData: function (args) {
  743. return {
  744. data: oCurData.OverTimes,
  745. itemsCount: oCurData.OverTimes.length //data.length
  746. };
  747. },
  748. insertItem: function (args) {
  749. args.guid = guid();
  750. args.Index = oCurData.OverTimes.length + 1;
  751. args.OvertimeClassName = oAddItem.OvertimeClassName;
  752. args.PrjName = oAddItem.PrjName;
  753. oCurData.OverTimes.push(args);
  754. },
  755. updateItem: function (args) {
  756. },
  757. deleteItem: function (args) {
  758. var saNewOverTimes = [];
  759. $.each(oCurData.OverTimes, function (idx, _data) {
  760. if (_data.guid !== args.guid) {
  761. saNewOverTimes.push(_data);
  762. }
  763. });
  764. $.each(saNewOverTimes, function (idx, _data) {
  765. _data.Index = idx + 1;
  766. });
  767. oCurData.OverTimes = saNewOverTimes;
  768. }
  769. },
  770. onInit: function (args) {
  771. oGrid = args.grid;
  772. }
  773. });
  774. });
  775. $('#Handle_DeptID').on('change', function () {
  776. fnSetUserDrop([
  777. {
  778. Select: $('#Handle_Person'),
  779. DepartmentID: this.value,
  780. ShowId: true,
  781. Select2: true,
  782. Action: sAction
  783. }
  784. ]);
  785. });
  786. $('#Agent_Person').on('change', function () {
  787. oCurData.Agent_Person = this.value;
  788. });
  789. $('.flowlink').on('click', function () {
  790. var oOption = {};
  791. oOption.SignedWay = this.id;
  792. oOption.Callback = function (data) {
  793. if (data.Users.length > 0) {
  794. var oFlow = {};
  795. if (data.FlowType === 'flow1') {
  796. $.each(data.Users, function (idx, user) {
  797. oFlow = {};
  798. oFlow.id = guid();
  799. oFlow.Order = oCurData.CheckOrder.length + 1;
  800. oFlow.SignedWay = data.FlowType;
  801. oFlow.SignedMember = [{
  802. id: user.id,
  803. name: user.name,
  804. deptname: user.deptname,
  805. jobname: user.jobname
  806. }];
  807. oCurData.CheckOrder.push(oFlow);
  808. });
  809. }
  810. else {
  811. var saSignedMember = [];
  812. $.each(data.Users, function (idx, user) {
  813. saSignedMember.push({
  814. id: user.id,
  815. name: user.name,
  816. deptname: user.deptname,
  817. jobname: user.jobname
  818. });
  819. });
  820. oFlow.id = guid();
  821. oFlow.Order = oCurData.CheckOrder.length + 1;
  822. oFlow.SignedWay = data.FlowType;
  823. oFlow.SignedMember = saSignedMember;
  824. oCurData.CheckOrder.push(oFlow);
  825. }
  826. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  827. $("#jsGrid").jsGrid("loadData");
  828. }
  829. };
  830. oPenUserListPop(oOption);
  831. });
  832. $("#jsGrid").jsGrid({
  833. width: "100%",
  834. height: "auto",
  835. autoload: true,
  836. filtering: false,
  837. pageLoading: true,
  838. pageIndex: 1,
  839. pageSize: 10000,
  840. fields: [
  841. {
  842. name: "Order", title: 'common.Order', width: 50, align: "center",
  843. itemTemplate: function (val, item) {
  844. return val < 10 ? '0' + val : val;
  845. }
  846. },
  847. {
  848. name: "SignedWay", title: 'common.SignedWay', width: 120, align: "center",
  849. itemTemplate: function (val, item) {
  850. return i18next.t('common.' + val);
  851. }
  852. },
  853. {
  854. type: "Icon", width: 50, align: "center",
  855. itemTemplate: function (val, item) {
  856. var oIcon = {
  857. flow1: '<img src="../../images/flow_check.gif">',
  858. flow2: '<img src="../../images/flow_check.gif"><img src="../../images/flow_check.gif">',
  859. flow3: '<img src="../../images/flow_check.gif"><img src="../../images/flow_nocheck.gif">',
  860. flow4: '<img src="../../images/flow4.gif">'
  861. },
  862. sIcon = oIcon[item.SignedWay];
  863. if (item.Order !== oCurData.CheckOrder.length) {
  864. sIcon += '<br><img src="../../images/flow_arrow.gif" style="vertical-align:top;">'
  865. }
  866. return sIcon;
  867. }
  868. },
  869. {
  870. name: "SignedMember", title: 'common.SignedMember', width: 500,
  871. itemTemplate: function (val, item) {
  872. return Enumerable.From(val).ToString(",", "$.name");
  873. }
  874. },
  875. {
  876. type: "control", title: 'common.Action', width: 200,
  877. itemTemplate: function (val, item) {
  878. var oBtns = [$('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  879. class: 'glyphicon glyphicon-pencil' + (oCurData.Flows_Lock === 'Y' ? ' disabled' : ''),
  880. title: i18next.t('common.Edit'),// ╠common.Edit⇒編輯╣
  881. click: function () {
  882. if ($(this).hasClass('disabled')) { return false; }
  883. var oOption = {};
  884. oOption.SignedWay = item.SignedWay;
  885. oOption.SignedMember = item.SignedMember;
  886. oOption.Callback = function (data) {
  887. if (data.Users.length > 0) {
  888. var oFlow = {};
  889. if (data.FlowType === 'flow1') {
  890. $.each(data.Users, function (idx, user) {
  891. var oFlow = {};
  892. oFlow.id = guid();
  893. oFlow.Order = item.Order + idx;
  894. oFlow.SignedWay = data.FlowType;
  895. oFlow.SignedMember = [{
  896. id: user.id,
  897. name: user.name,
  898. deptname: user.deptname,
  899. jobname: user.jobname
  900. }];
  901. oCurData.CheckOrder.insert(item.Order + idx, oFlow);
  902. });
  903. }
  904. else {
  905. var saSignedMember = [];
  906. $.each(data.Users, function (idx, user) {
  907. saSignedMember.push({
  908. id: user.id,
  909. name: user.name,
  910. deptname: user.deptname,
  911. jobname: user.jobname
  912. });
  913. });
  914. oFlow.id = guid();
  915. oFlow.Order = item.Order;
  916. oFlow.SignedWay = data.FlowType;
  917. oFlow.SignedMember = saSignedMember;
  918. oCurData.CheckOrder.insert(item.Order, oFlow);
  919. }
  920. var iOrder = 1;
  921. $.each(oCurData.CheckOrder, function (idx, _data) {
  922. if (item.id !== _data.id) {
  923. _data.Order = iOrder;
  924. iOrder++;
  925. }
  926. });
  927. oCurData.CheckOrder = Enumerable.From(oCurData.CheckOrder).Where(function (e) { return e.id !== item.id; }).ToArray();
  928. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  929. $("#jsGrid").jsGrid("loadData");
  930. }
  931. };
  932. oPenUserListPop(oOption);
  933. }
  934. })),
  935. $('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  936. class: 'glyphicon glyphicon-trash' + (oCurData.Flows_Lock === 'Y' ? ' disabled' : ''),
  937. title: i18next.t('common.Toolbar_Del'),// ╠common.Toolbar_Del⇒刪除╣
  938. click: function () {
  939. if ($(this).hasClass('disabled')) { return false; }
  940. var saNewList = Enumerable.From(oCurData.CheckOrder).Where(function (e) { return e.id !== item.id; }).ToArray();
  941. oCurData.CheckOrder = saNewList;
  942. $.each(oCurData.CheckOrder, function (idx, _data) {
  943. _data.Order = idx + 1;
  944. });
  945. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  946. $("#jsGrid").jsGrid("loadData");
  947. }
  948. }))];
  949. if (oCurData.CheckOrder.length !== item.Order) {
  950. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  951. class: 'glyphicon glyphicon-arrow-down' + (oCurData.Flows_Lock === 'Y' ? ' disabled' : ''),
  952. title: i18next.t('common.Down'),// ╠common.Down⇒下移╣
  953. click: function () {
  954. if ($(this).hasClass('disabled')) { return false; }
  955. var sOrder = Enumerable.From(oCurData.CheckOrder).Where(function (e) { return e.id === item.id; }).ToString('', '$.Order'),
  956. iOrder = sOrder * 1;
  957. $.each(oCurData.CheckOrder, function (idx, _data) {
  958. if (iOrder === _data.Order) {
  959. _data.Order++;
  960. }
  961. else if ((iOrder + 1) === _data.Order) {
  962. _data.Order--;
  963. }
  964. });
  965. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  966. $("#jsGrid").jsGrid("loadData");
  967. }
  968. })));
  969. }
  970. else {
  971. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }));
  972. }
  973. if (1 !== item.Order) {
  974. oBtns.push($('<div>', { class: 'fa-item col-sm-3' }).append($('<i>', {
  975. class: 'glyphicon glyphicon-arrow-up' + (oCurData.Flows_Lock === 'Y' ? ' disabled' : ''),
  976. title: i18next.t('common.Up'),// ╠common.Up⇒上移╣
  977. click: function () {
  978. if ($(this).hasClass('disabled')) { return false; }
  979. var sOrder = Enumerable.From(oCurData.CheckOrder).Where(function (e) { return e.id === item.id; }).ToString('', '$.Order'),
  980. iOrder = sOrder * 1;
  981. $.each(oCurData.CheckOrder, function (idx, _data) {
  982. if (iOrder === _data.Order) {
  983. _data.Order--;
  984. }
  985. else if ((iOrder - 1) === _data.Order) {
  986. _data.Order++;
  987. }
  988. });
  989. oCurData.CheckOrder = releaseGridList(oCurData.CheckOrder);
  990. $("#jsGrid").jsGrid("loadData");
  991. }
  992. })));
  993. }
  994. return oBtns;
  995. }
  996. }
  997. ],
  998. controller: {
  999. loadData: function (args) {
  1000. return {
  1001. data: oCurData.CheckOrder,
  1002. itemsCount: oCurData.CheckOrder.length //data.length
  1003. };
  1004. },
  1005. insertItem: function (args) {
  1006. },
  1007. updateItem: function (args) {
  1008. },
  1009. deleteItem: function (args) {
  1010. }
  1011. }
  1012. });
  1013. };
  1014. init();
  1015. };
  1016. require(['base', 'select2', 'jsgrid', 'timepicker', 'filer', 'common_eip', 'util'], fnPageInit, 'timepicker');