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.

806 lines
40 KiB

2 years ago
  1. 'use strict';
  2. var sProgramId = getProgramId(),
  3. isAdmin = parent.UserInfo.roles.toLowerCase().indexOf('admin') > -1,
  4. AddedTip = false,
  5. oCalendar = null,
  6. fnPageInit = function() {
  7. var saCalType = [],
  8. saOpenMent = ['P', 'G', 'D', 'C'],
  9. /**
  10. * 表單驗證
  11. * @param {Object}iframe form表單
  12. */
  13. fnValidate = function(iframe) {
  14. iframe.find('[name=OpenMent]').click(function() {
  15. var sVal = this.value;
  16. if (sVal === 'G') {
  17. iframe.find('#trGroupMembers').show();
  18. } else {
  19. iframe.find('#trGroupMembers').hide();
  20. iframe.find('#GroupMembers').val('').data('value', '');
  21. }
  22. });
  23. $.validator.addMethod("compardatetime", function(value, element, parms) {
  24. if (new Date(value) <= new Date(iframe.find('#StartDate').val())) {
  25. return false;
  26. }
  27. return true;
  28. });
  29. $.validator.addMethod("groupmember", function(value, element, parms) {
  30. if (iframe.find('[name=OpenMent]:checked').val() === 'G' && !$(element).data('value')) {
  31. return false;
  32. }
  33. return true;
  34. });
  35. return iframe.find("#form_calendar").validate({
  36. showErrors: function() {
  37. this.defaultShowErrors();
  38. transLang(iframe);
  39. }
  40. }); // //表單欄位驗證
  41. },
  42. /**
  43. * 修改資料
  44. * @param {Object} event 事件
  45. * @param {Object} newevent 最新的事件
  46. */
  47. fnUpdData = function(event, newevent) {
  48. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  49. Params: {
  50. calendar: {
  51. values: newevent,
  52. keys: { NO: event.id }
  53. }
  54. }
  55. }, function(res) {
  56. if (res.d > 0) {
  57. showMsg(i18next.t("message.Modify_Success"), 'success'); //╠message.Modify_Success⇒修改成功╣
  58. } else {
  59. showMsg(i18next.t("message.Modify_Failed"), 'error'); //╠message.Modify_Failed⇒修改失敗╣
  60. }
  61. oCalendar.fullCalendar('refetchEvents');
  62. if (parent.Outklook) {
  63. outlookAPI(outlook.Calendar_Upd, { NO: event.id })
  64. }
  65. }, function() {
  66. showMsg(i18next.t("message.Modify_Failed"), 'error'); //╠message.Modify_Failed⇒修改失敗╣
  67. });
  68. },
  69. /**
  70. * pop視窗
  71. * @param {Object} iframe 表單
  72. */
  73. fnRegisterEvent = function(iframe, action) {
  74. iframe.find('.add-on').click(function() {
  75. fnGetSetUserGroups({
  76. Action: action,
  77. Callback: function(data) {
  78. if (data.length > 0) {
  79. var saId = [],
  80. saName = [];
  81. $.each(data, function(idx, item) {
  82. saId.push(item.UserID);
  83. saName.push(item.UserName);
  84. });
  85. iframe.find('#GroupMembers').data('value', saId.join(',')).val(saName.join(','));
  86. }
  87. }
  88. });
  89. });
  90. },
  91. /**
  92. * pop資料新增
  93. * @param {Object} start 開始時間
  94. * @param {Object} end 結束時間
  95. */
  96. fnAdd = function(start, end) {
  97. var oValidator = null;
  98. layer.open({
  99. type: 2,
  100. title: '新增行程',
  101. shade: 0.75,
  102. maxmin: true, //开启最大化最小化按钮
  103. area: ['800px', '580px'],
  104. content: '/Page/Pop/CalanderPop.html',
  105. success: function(layero, index) {
  106. var iframe = $('iframe').contents();
  107. fnSetArgDrop([{
  108. ArgClassID: 'CalType',
  109. Select: iframe.find('#CalType'),
  110. ShowId: true,
  111. CallBack: function(data) {
  112. var bAllDay = true;
  113. iframe.find('#CurrentDate').val(start);
  114. iframe.find('#AllDay')[0].checked = bAllDay = typeof start._i === 'string';
  115. iframe.find('#StartDate').val(bAllDay ? start._d.formate('yyyy/MM/dd 00:00') : newDate(start));
  116. iframe.find('#EndDate').val(bAllDay ? end._d.formate('yyyy/MM/dd 00:00') : newDate(end));
  117. oValidator = fnValidate(iframe);
  118. fnRegisterEvent(iframe, 'add');
  119. }
  120. }]);
  121. },
  122. btn: [i18next.t('common.Confirm'), i18next.t('common.Cancel')], //╠common.Confirm⇒確定╣╠common.Cancel⇒取消╣
  123. yes: function(index, layero) {
  124. var iframe = $('iframe').contents();
  125. iframe.find('#GroupMembers').removeAttr('readonly');
  126. if (!iframe.find("#form_calendar").valid()) {
  127. oValidator.focusInvalid();
  128. iframe.find('#GroupMembers').attr('readonly', 'readonly');
  129. return false;
  130. }
  131. var data = getFormSerialize(iframe.find('#form_calendar'));
  132. data = packParams(data);
  133. data.OrgID = parent.OrgID;
  134. data.UserID = parent.UserID;
  135. data.Color = parent.UserInfo.CalColor;
  136. data.AllDay = data.AllDay || '0';
  137. g_api.ConnectLite(sProgramId, ComFn.GetAdd, data,
  138. function(res) {
  139. if (res.RESULT) {
  140. var sNo = res.DATA.rel;
  141. showMsg(i18next.t("message.Save_Success"), 'success'); // ╠message.Save_Success⇒新增成功╣
  142. oCalendar.fullCalendar('refetchEvents');
  143. if (parent.Outklook) {
  144. outlookAPI(outlook.Calendar_Add, {
  145. NO: sNo,
  146. ResponseRequested: true
  147. });
  148. }
  149. } else {
  150. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  151. }
  152. });
  153. layer.close(index);
  154. }
  155. });
  156. },
  157. /**
  158. * 資料修改
  159. * @param {Object} event 事件
  160. */
  161. fnUpd = function(event) {
  162. var oValidator = null,
  163. bEdit = (event.UserID === parent.UserID && event.Memo !== 'outlook'),
  164. saBtns = [],
  165. layerOption = {
  166. type: 2,
  167. title: '修改日程',
  168. shade: 0.75,
  169. maxmin: true, //开启最大化最小化按钮
  170. area: ['800px', '580px'],
  171. content: '/Page/Pop/CalanderPop.html',
  172. success: function(layero, index) {
  173. var iframe = $('iframe').contents();
  174. fnSetArgDrop([{
  175. ArgClassID: 'CalType',
  176. Select: iframe.find('#CalType'),
  177. ShowId: true,
  178. CallBack: function(data) {
  179. oValidator = fnValidate(iframe);
  180. iframe.find('#CalType').val(event.CalType);
  181. iframe.find('#Title').val(event.title);
  182. iframe.find('#Description').val(event.content);
  183. iframe.find('#GroupMembers').data('value', event.GroupMembers);
  184. iframe.find('[name=OpenMent][value=' + event.OpenMent + ']').click();
  185. iframe.find('[name=Importment][value=' + event.Importment + ']').click();
  186. iframe.find('#AllDay')[0].checked = event.AllDay;
  187. iframe.find('#CurrentDate').val(newDate(event.start, 1));
  188. iframe.find('#StartDate').val(newDate(event.StartDate));
  189. iframe.find('#EndDate').val(newDate(event.EndDate));
  190. if (event.GroupMembers) {
  191. fnSetUserDrop([{
  192. UserIDs: event.GroupMembers,
  193. CallBack: function(data) {
  194. var saList = data,
  195. saName = [];
  196. $.each(saList, function(idx, item) {
  197. saName.push(item.MemberName);
  198. });
  199. iframe.find('#GroupMembers').val(saName);
  200. }
  201. }]);
  202. }
  203. if (bEdit) {
  204. fnRegisterEvent(iframe, 'upd');
  205. } else {
  206. disableInput(iframe);
  207. }
  208. }
  209. }]);
  210. layero.find('.layui-layer-btn1').css({ 'border-color': 'red', 'background-color': 'red', 'color': '#fff' });
  211. }
  212. };
  213. if (bEdit) {
  214. saBtns = [i18next.t('common.Confirm'), i18next.t('common.Toolbar_Del'), i18next.t('common.Cancel')]; //╠common.Confirm⇒確定╣ ╠common.Toolbar_Del⇒刪除╣ ╠common.Cancel⇒取消╣
  215. layerOption.yes = function(index, layero) {
  216. var iframe = $('iframe').contents();
  217. iframe.find('#GroupMembers').removeAttr('readonly');
  218. if (!iframe.find("#form_calendar").valid()) {
  219. oValidator.focusInvalid();
  220. iframe.find('#GroupMembers').attr('readonly', 'readonly');
  221. return false;
  222. }
  223. var data = getFormSerialize(iframe.find('#form_calendar'));
  224. data = packParams(data, 'upd');
  225. data.UserID = parent.UserInfo.MemberID;
  226. data.Description = data.Description || '';
  227. data.Color = parent.UserInfo.CalColor;
  228. data.AllDay = data.AllDay || '0';
  229. fnUpdData(event, data);
  230. layer.close(index);
  231. };
  232. layerOption.btn2 = function() {
  233. CallAjax(ComFn.W_Com, ComFn.GetDel, {
  234. Params: {
  235. calendar: {
  236. NO: event.id
  237. }
  238. }
  239. }, function(res) {
  240. if (res.d > 0) {
  241. showMsg(i18next.t("message.Delete_Success"), 'success'); // ╠message.Delete_Success⇒刪除成功╣
  242. oCalendar.fullCalendar('removeEvents', event.id);
  243. if (parent.Outklook) {
  244. outlookAPI(outlook.Calendar_Del, {
  245. OutlookEventId: event.OutlookEventId
  246. });
  247. }
  248. } else {
  249. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  250. }
  251. });
  252. };
  253. } else {
  254. saBtns = [i18next.t('common.Cancel')];
  255. }
  256. layerOption.btn = saBtns;
  257. layer.open(layerOption);
  258. },
  259. /**
  260. * 選擇分組成員
  261. * @param {Object} option 配置
  262. */
  263. fnGetSetUserGroups = function(option) {
  264. option = option || {};
  265. var oGrid = null,
  266. saItems = [],
  267. saProfileGets = [],
  268. fnGetSetlectOptions = function(el) {
  269. var saSetlectOptions = [];
  270. el.find('#lstRight option').each(function() {
  271. var sId = this.value,
  272. oItems = {},
  273. sEmail = $(this).attr('data-email');
  274. if (sEmail) {
  275. oItems = {
  276. UserID: sId,
  277. UserName: $(this).text(),
  278. OutlookEmail: sEmail
  279. };
  280. } else {
  281. oItems = $.map(saItems, function(item) {
  282. if (sId === item.MemberID) {
  283. return {
  284. UserID: item.MemberID,
  285. UserName: item.MemberName,
  286. OutlookEmail: item.OutlookAccount
  287. };
  288. }
  289. })[0];
  290. }
  291. saSetlectOptions.push(oItems);
  292. });
  293. return saSetlectOptions;
  294. },
  295. fnSetProfileDrop = function(handle) {
  296. return CallAjax(ComFn.W_Com, ComFn.GetList, {
  297. Type: '',
  298. Params: {
  299. profiles: {
  300. ProfileType: 'UserGroups',
  301. OrgID: parent.OrgID,
  302. UserID: parent.UserID
  303. },
  304. sort: { SN: 'asc' }
  305. }
  306. }, function(res) {
  307. if (res.d) {
  308. saProfileGets = JSON.parse(res.d);
  309. handle.html(createOptions(saProfileGets, 'SN', 'ProfileName'));
  310. }
  311. });
  312. },
  313. fnAddProfile = function(layero) {
  314. var oAddPm = {};
  315. oAddPm.OrgID = parent.OrgID;
  316. oAddPm.UserID = parent.UserID;
  317. oAddPm.ProfileType = 'UserGroups';
  318. oAddPm.ProfileName = layero.find('#ProfileName').val();
  319. oAddPm.ProfileSet = fnGetSetlectOptions(layero);
  320. oAddPm.ProfileSet = JSON.stringify(oAddPm.ProfileSet);
  321. oAddPm = packParams(oAddPm);
  322. if (!oAddPm.ProfileName) {
  323. showMsg(i18next.t("message.ProfileFeesClassName_Required")); //╠message.ProfileFeesClassName_Required⇒請填寫個人化費用類別名稱╣
  324. return false;
  325. }
  326. CallAjax(ComFn.W_Com, ComFn.GetAdd, {
  327. Params: {
  328. profiles: oAddPm
  329. }
  330. }, function(res) {
  331. if (res.d > 0) {
  332. fnSetProfileDrop(layero.find('#ProfileClass')).done(function() {
  333. layero.find('#ProfileClass option').each(function() {
  334. if ($(this).text() === oAddPm.ProfileName) {
  335. layero.find('#ProfileClass').val(this.value);
  336. return false;
  337. }
  338. });
  339. });
  340. showMsg(i18next.t("message.Save_Success"), 'success'); // ╠message.Save_Success⇒新增成功╣
  341. } else {
  342. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  343. }
  344. }, function() {
  345. showMsg(i18next.t("message.Save_Failed"), 'error'); // ╠message.Save_Failed⇒新增失敗╣
  346. });
  347. },
  348. fnUpdProfile = function(layero) {
  349. var oUpdPm = {},
  350. sId = layero.find('#ProfileClass').val();
  351. oUpdPm.ProfileName = layero.find('#ProfileName').val();
  352. oUpdPm.ProfileSet = [];
  353. oUpdPm.ProfileSet = fnGetSetlectOptions(layero);
  354. oUpdPm.ProfileSet = JSON.stringify(oUpdPm.ProfileSet);
  355. oUpdPm = packParams(oUpdPm, 'upd');
  356. if (!oUpdPm.ProfileName) {
  357. showMsg(i18next.t("message.ProfileFeesClassName_Required")); // 請填寫個人化費用類別名稱
  358. return false;
  359. }
  360. CallAjax(ComFn.W_Com, ComFn.GetUpd, {
  361. Params: {
  362. profiles: {
  363. values: oUpdPm,
  364. keys: { SN: sId }
  365. }
  366. }
  367. }, function(res) {
  368. if (res.d > 0) {
  369. fnSetProfileDrop(layero.find('#ProfileClass')).done(function() {
  370. layero.find('#ProfileClass').val(sId);
  371. });
  372. showMsg(i18next.t("message.Modify_Success"), 'success'); //╠message.Modify_Success⇒修改成功╣
  373. } else {
  374. showMsg(i18next.t("message.Modify_Failed"), 'error'); //╠message.Modify_Failed⇒修改失敗╣
  375. }
  376. }, function() {
  377. showMsg(i18next.t("message.Modify_Failed"), 'error'); //╠message.Modify_Failed⇒修改失敗╣
  378. });
  379. },
  380. fnDelProfile = function(layero) {
  381. var sId = layero.find('#ProfileClass').val();
  382. if (!sId) {
  383. showMsg(i18next.t("message.DeleteItem_Required")); //╠message.DeleteItem_Required⇒請選擇要刪除的項目╣
  384. return false;
  385. }
  386. CallAjax(ComFn.W_Com, ComFn.GetDel, {
  387. Params: {
  388. profiles: {
  389. SN: sId
  390. }
  391. }
  392. }, function(res) {
  393. if (res.d > 0) {
  394. fnSetProfileDrop(layero.find('#ProfileClass'));
  395. layero.find('#ProfileName').val('');
  396. layero.find('#lstRight').html('');
  397. layero.find('#lstLeft').html(createOptions(saItems, 'MemberID', 'MemberName', true));
  398. layero.find('#lstLeft').find('option:first').remove();
  399. showMsg(i18next.t("message.Delete_Success"), 'success'); // ╠message.Delete_Success⇒刪除成功╣
  400. } else {
  401. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  402. }
  403. }, function() {
  404. showMsg(i18next.t("message.Delete_Failed"), 'error'); // ╠message.Delete_Failed⇒刪除失敗╣
  405. });
  406. };
  407. getHtmlTmp('/Page/Pop/UserGroups.html').done(function(html) {
  408. layer.open({
  409. type: 1,
  410. title: i18next.t('common.ProfileFees'), // ╠common.ProfileFees⇒個人化費用項目╣
  411. shadeClose: false,
  412. shade: 0.1,
  413. maxmin: true, //开启最大化最小化按钮
  414. area: ['600px', '590px'],
  415. content: html,
  416. success: function(layero, index) {
  417. var elIistLeft = layero.find('#lstLeft'),
  418. elListRight = layero.find('#lstRight');
  419. fnSetProfileDrop(layero.find('#ProfileClass'));
  420. fnSetUserDrop([{
  421. Select: elIistLeft,
  422. ShowId: true,
  423. Action: option.Action, //傳入action來判斷是新增或是修改
  424. CallBack: function(data) {
  425. saItems = data;
  426. }
  427. }]).done(function() {
  428. elIistLeft.find('option:first').remove();
  429. optionListSearch(elIistLeft, elListRight, layero.find('#ProfileFilter'));
  430. });
  431. layero.find('#ProfileClass').on('change', function() {
  432. var sProfile = this.value,
  433. saProfileSet = [];
  434. if (sProfile) {
  435. var oProfileGet = $.grep(saProfileGets, function(e) { return e.SN.toString() == sProfile; })[0];
  436. saProfileSet = JSON.parse(oProfileGet.ProfileSet || '[]');
  437. layero.find('#ProfileName').val(oProfileGet.ProfileName);
  438. } else {
  439. layero.find('#ProfileName').val('');
  440. }
  441. elListRight.html('');
  442. elIistLeft.html(createOptions(saItems, 'MemberID', 'MemberName', true)).find('option:first').remove();
  443. elIistLeft.find('option').each(function() {
  444. var _option = this,
  445. sId = $(_option).val();
  446. $.each(saProfileSet, function(index, item) {
  447. if (sId === item.UserID) {
  448. $(_option).appendTo(elListRight);
  449. item.IsMove = true;
  450. return false;
  451. }
  452. });
  453. });
  454. $.each(saProfileSet, function(index, item) {
  455. if (!item.IsMove) {
  456. $('<option/>', {
  457. value: item.UserID,
  458. text: item.UserName,
  459. 'data-email': item.OutlookEmail,
  460. class: 'outer'
  461. }).appendTo(elListRight);
  462. }
  463. });
  464. });
  465. layero.find('#AddOutGroupUser').on('click', function() {
  466. var sOutUserName = $('#OutUserName').val(),
  467. sOutEmail = $('#OutEmail').val(),
  468. sGuid = guid();
  469. if (!sOutUserName || !OutEmail) {
  470. showMsg(i18next.t("message.OutUserNameAndOutEmail_Required")); // ╠message.OutUserNameAndOutEmail_Required⇒請填寫姓名和郵箱地址╣
  471. return false;
  472. }
  473. if (!isEmail(sOutEmail)) {
  474. showMsg(i18next.t("message.IncorrectEmail")); // ╠message.IncorrectEmail⇒郵箱格式不正確╣
  475. return false;
  476. }
  477. $('<option/>', {
  478. value: sGuid,
  479. text: sOutUserName,
  480. 'data-email': sOutEmail,
  481. class: 'outer'
  482. }).appendTo(elListRight);
  483. var oAddPm = {
  484. Guid: sGuid,
  485. UserName: sOutUserName,
  486. Email: sOutEmail
  487. };
  488. oAddPm = packParams(oAddPm);
  489. CallAjax(ComFn.W_Com, ComFn.GetAdd, {
  490. Params: {
  491. outerusers: oAddPm
  492. }
  493. });
  494. });
  495. layero.find('.cusclass-add').on('click', function() {
  496. fnAddProfile(layero);
  497. });
  498. layero.find('.cusclass-upd').on('click', function() {
  499. fnUpdProfile(layero);
  500. });
  501. layero.find('.cusclass-del').on('click', function() {
  502. fnDelProfile(layero);
  503. });
  504. layero.find('#btnToRight').on('click', function() {
  505. optionListMove(elIistLeft, elListRight);
  506. });
  507. layero.find('#btnToLeft').on('click', function() {
  508. optionListMove(elListRight, elIistLeft);
  509. });
  510. layero.find('#btnToUp').on('click', function() {
  511. optionListOrder(elListRight, true);
  512. });
  513. layero.find('#btnToDown').on('click', function() {
  514. optionListOrder(elListRight, false);
  515. });
  516. transLang(layero);
  517. },
  518. btn: [i18next.t('common.Confirm'), i18next.t('common.Cancel')], //╠common.Confirm⇒確定╣╠common.Cancel⇒取消╣
  519. yes: function(index, layero) {
  520. var saRetn = fnGetSetlectOptions(layero);
  521. if (typeof option.Callback === 'function') option.Callback(saRetn);
  522. layer.close(index);
  523. },
  524. cancel: function() {
  525. if (typeof option.CancelCallback === 'function') option.CancelCallback();
  526. }
  527. });
  528. });
  529. },
  530. /**
  531. * ToolBar 按鈕事件 function
  532. * @param {Object} inst 按鈕物件對象
  533. * @param {Object} e 事件對象
  534. */
  535. fnButtonHandler = function(inst, e) {
  536. var sId = inst.id;
  537. switch (sId) {
  538. case "Toolbar_Qry":
  539. break;
  540. case "Toolbar_Save":
  541. break;
  542. case "Toolbar_ReAdd":
  543. break;
  544. case "Toolbar_Clear":
  545. break;
  546. case "Toolbar_Leave":
  547. break;
  548. case "Toolbar_Add":
  549. break;
  550. case "Toolbar_Upd":
  551. break;
  552. case "Toolbar_Copy":
  553. break;
  554. case "Toolbar_Del":
  555. break;
  556. case "Toolbar_Exp":
  557. break;
  558. case "Toolbar_SynChronousOutlook":
  559. {
  560. var index = layer.load(0, { time: 10 * 1000 }); ////同步開啟loading,并且设定最长等待10秒
  561. outlookAPI(outlook.SynChronous, { flag: "once", memo: index });
  562. }
  563. break;
  564. default:
  565. alert("No handle '" + sId + "'");
  566. break;
  567. }
  568. },
  569. saCusBtns = [];
  570. if (parent.Outklook) {
  571. saCusBtns.push({
  572. id: 'Toolbar_SynChronousOutlook',
  573. value: 'common.SynChronousOutlook' // ╠common.SynChronousOutlook⇒同步Outlook╣
  574. });
  575. }
  576. commonInit({
  577. PrgId: sProgramId,
  578. ButtonHandler: fnButtonHandler,
  579. Buttons: saCusBtns,
  580. GoTop: true
  581. });
  582. fnSetArgDrop([{
  583. ArgClassID: 'CalType',
  584. CallBack: function(data) {
  585. var saHeaderShow = [],
  586. oCustomButtons = {
  587. addevent: {
  588. text: '新增日程',
  589. click: function() {
  590. fnAdd(new Date(), new Date().dateAdd('h', 1));
  591. }
  592. }
  593. },
  594. elCalType = $('<div class="fc-button-group" />');
  595. $.grep(data, function(item, index) {
  596. var sBtnId = 'cusbtn_' + item.id,
  597. sCalType = '<label for="CalType_' + index + '">\
  598. <input id="CalType_' + index + '" name="CalType[]" type="checkbox" value="' + item.id + '" checked="checked"><span class="openment-text">' + item.text + '</span>\
  599. </label>';
  600. saHeaderShow.push(sBtnId);
  601. oCustomButtons[sBtnId] = {
  602. text: item.text,
  603. click: function(el) {
  604. var sId = $(this).attr('data-id').replace('cusbtn_', '');
  605. if ($(this).hasClass('selected')) {
  606. $(this).removeClass('selected');
  607. saCalType.remove(sId);
  608. } else {
  609. $(this).addClass('selected');
  610. saCalType.push(sId);
  611. }
  612. oCalendar.fullCalendar('refetchEvents');
  613. }
  614. };
  615. saCalType.push(item.id);
  616. elCalType.append(sCalType);
  617. });
  618. oCalendar = $('#calendar').fullCalendar({
  619. locale: 'zh-tw',
  620. timezone: 'local',
  621. schedulerLicenseKey: 'GPL-My-Project-Is-Open-Source',
  622. theme: true,
  623. weekends: true, // will hide Saturdays and Sundays
  624. firstDay: 0,
  625. isRTL: false,
  626. defaultView: 'month',
  627. defaultDate: new Date().formate("yyyy-MM-dd"),
  628. navLinks: true, // can click iDay/week names to navigate views
  629. editable: true,
  630. droppable: true, // this allows things to be dropped onto the calendar(允許將事件拖動到日曆上)
  631. eventLimit: true, // allow "more" link when too many events(允許出現更多圖標)
  632. selectable: true,
  633. selectHelper: true,
  634. weekNumbers: true,
  635. weekNumbersWithinDays: true,
  636. weekNumberCalculation: 'ISO',
  637. nowIndicator: true,
  638. displayEventTime: true,
  639. fixedWeekCount: false,
  640. header: {
  641. left: 'prev,next today addevent ', //saHeaderShow.join(' ')
  642. center: 'title',
  643. right: 'month1,month2,month,agendaWeek,agendaDay,listMonth'
  644. },
  645. buttonIcons: {
  646. prev: 'left-single-arrow',
  647. next: 'right-single-arrow',
  648. prevYear: 'left-double-arrow',
  649. nextYear: 'right-double-arrow'
  650. },
  651. themeButtonIcons: {
  652. prev: 'circle-triangle-w',
  653. next: 'circle-triangle-e',
  654. prevYear: 'seek-prev',
  655. nextYear: 'seek-next'
  656. },
  657. businessHours: [ // specify an array instead
  658. {
  659. dow: [1, 2, 3, 4, 5], // Monday, Tuesday, Wednesday
  660. start: '09:00', // 8am
  661. end: '18:30' // 6pm
  662. }
  663. ],
  664. customButtons: oCustomButtons,
  665. select: function(start, end) {
  666. fnAdd(start, end);
  667. },
  668. eventClick: function (calEvent) {
  669. if (!!calEvent.show && calEvent.show) {
  670. fnUpd(calEvent);
  671. }
  672. },
  673. eventDrop: function(event) {
  674. var data = {};
  675. data.StartDate = newDate(event.start);
  676. data.EndDate = newDate(event.end);
  677. fnUpdData(event, data);
  678. },
  679. eventResize: function(event) {
  680. var data = {};
  681. data.StartDate = newDate(event.start);
  682. data.EndDate = newDate(event.end);
  683. fnUpdData(event, data);
  684. },
  685. eventMouseover: function (event, jsEvent, view) {
  686. addTips($('[tooltips]'));
  687. },
  688. events: function(start, end, timezone, callback) {
  689. g_api.ConnectLite(sProgramId, 'GetList', {
  690. StartDate: newDate(start),
  691. EndDate: newDate(end),
  692. CalType: saCalType.join(','),
  693. OpenMent: saOpenMent.join(',')
  694. },
  695. function(res) {
  696. if (res.RESULT) {
  697. var saEvents = res.DATA.rel;
  698. $.each(saEvents, function (idx, item) {
  699. if (item.CalType === '07') {
  700. var Owner = item.CreateUser === parent.UserID;
  701. if (Owner || isAdmin)
  702. item.show = true;
  703. else {
  704. item.show = false;
  705. item.Description = "";
  706. }
  707. }
  708. else {
  709. item.show = true;
  710. }
  711. });
  712. callback(saEvents);
  713. }
  714. });
  715. },
  716. /**
  717. * 處理資料轉換成日曆資料格式
  718. */
  719. eventDataTransform: function(event) {
  720. event.id = event.NO;
  721. event.title = event.Title;
  722. event.content = event.Description;
  723. event.allDay = event.AllDay;
  724. if (event.StartDate) event.start = event.StartDate;
  725. if (event.EndDate) event.end = event.EndDate;
  726. event.color = event.Importment === 'H' ? 'red' : event.Color;
  727. event.className = 'calendar-event';
  728. return event;
  729. }
  730. });
  731. var elOpenMent = '<div class="fc-button-group" >\
  732. <label for="OpenMent_0">\
  733. <input id="OpenMent_0" name="OpenMent[]" type="checkbox" value="P" checked="checked"><span class="openment-text" data-i18n="CalanderPop.Individual">個人</span>\
  734. </label>\
  735. <label for="OpenMent_1">\
  736. <input id="OpenMent_1" name="OpenMent[]" type="checkbox" value="G" checked="checked"><span class="openment-text" data-i18n="CalanderPop.Group">群組</span>\
  737. </label>\
  738. <label for="OpenMent_3">\
  739. <input id="OpenMent_3" name="OpenMent[]" type="checkbox" value="C" checked="checked"><span class="openment-text" data-i18n="CalanderPop.Company">公司</span>\
  740. </label>\
  741. </div>';
  742. //<label for="OpenMent_2">\
  743. // <input id="OpenMent_2" name="OpenMent[]" type="checkbox" value="D" checked="checked"><span class="openment-text" data-i18n="CalanderPop.Department">部門</span>\
  744. //</label>\
  745. $('.fc-toolbar .fc-left').append(elCalType[0].outerHTML);
  746. $('.fc-toolbar .fc-right').prepend(elOpenMent);
  747. $('[name="CalType[]"]').click(function() {
  748. saCalType = [];
  749. $('[name="CalType[]"]').each(function() {
  750. if (this.checked) {
  751. saCalType.push(this.value);
  752. }
  753. });
  754. oCalendar.fullCalendar('refetchEvents');
  755. });
  756. $('[name="OpenMent[]"]').click(function() {
  757. saOpenMent = [];
  758. $('[name="OpenMent[]"]').each(function() {
  759. if (this.checked) {
  760. saOpenMent.push(this.value);
  761. }
  762. });
  763. oCalendar.fullCalendar('refetchEvents');
  764. });
  765. }
  766. }]);
  767. },
  768. closeTips = function(index) {
  769. layer.close(index); //同步完成后關閉loading
  770. oCalendar.fullCalendar('refetchEvents');
  771. };
  772. require(['base', 'jsgrid', 'jbox', 'util'], fnPageInit);