b10e7550adbac5cee1a6f70f9bbb7c2dd33940fb.svn-base 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. BemsWebApplication.ExecutionScheduleCalendar = function (params, viewInfo) {
  2. "use strict";
  3. var endpointSelector;
  4. if (BemsWebApplication.config.mode == "production") {
  5. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.production;
  6. } else {
  7. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.local;
  8. }
  9. var eq = BWA.DataUtil.constructEqualFilter,
  10. and = BWA.DataUtil.andFilter,
  11. noteq = BWA.DataUtil.constructNotEqualFilter;
  12. var executionScheduleCalendarPopup = null;
  13. var SiteId = BWA.UserInfo.SiteId();
  14. var holidayDataSource = BemsWebApplication.db.createDataSource('CmHoliday', true, true);
  15. var holidayCustomDataSource = BemsWebApplication.db.createDataSource('CmHolidayCustom', true);
  16. var holidayWeekendDataSource = BemsWebApplication.db.createDataSource('CmHolidayWeekend', true);
  17. var checkBox_regular = true, checkBox_legal = true, checkBox_any = true;
  18. var useBusinessFiltering = ko.observable(false);
  19. var workScheduleDataSource = BWA.DataUtil.createDataSource({
  20. dataSourceOptions: {
  21. select: [
  22. 'SiteId', 'WorkScheduleId', 'WorkTypeId', 'BusinessFieldId', 'Title', 'FmsWorkSchedule/CycleUnitId',
  23. 'FmsWorkSchedule/CycleSize', 'FmsWorkSchedule/IsUse', 'FmsWorkSchedule/IsAutoOrder', 'StartWorkDate',
  24. 'CmUser/Name', 'CmBusinessField/Name',
  25. 'CmPartner/Name', 'FmsWorkSchedule/HolidayWorkTypeId'
  26. ],
  27. expand: ['FmsWorkSchedule', 'CmUser', 'CmBusinessField', 'CmPartner'],
  28. extendOptions: {
  29. forceOriginalField: true
  30. }
  31. }
  32. }, 'FmsWorkRequest');
  33. var holidaySources;
  34. var holidayCustomSources;
  35. var workScheduleSources;
  36. var popupWeekendSetupVisible = ko.observable(false),
  37. popupInsertVisible = ko.observable(false),
  38. hasnotModificationPermission = ko.observable(true);
  39. var holidayModel = {
  40. SiteId: ko.observable(),
  41. HolidayMonth: ko.observable(),
  42. HolidayDay: ko.observable(),
  43. IsLunar: ko.observable(),
  44. HolidayDate: ko.observable(),
  45. IsYearlyHoliday: ko.observable(false),
  46. Name: ko.observable(),
  47. };
  48. var cc = new CalendarConverter;
  49. var holidayWeekendDataViewModel = new BemsWebApplication.CmHolidayWeekendViewModel();
  50. var loadedYears = [];
  51. var viewDate = null;
  52. var currentYear = null;
  53. var holidays = [];
  54. var weekends = [];
  55. var isSaturday = false;
  56. var isSunday = false;
  57. var holidayCalendar = null;
  58. var calendarOptions = {
  59. selectable: true,
  60. editable: false,
  61. weekends: true,
  62. height: 680,
  63. select: handleSelectInCalendar,
  64. eventClick: handleEventClickInCalendar,
  65. changedMonth: function (view) {
  66. var date = view.calendar.getDate();
  67. viewDate = date; //hcLee 2016 03 21
  68. if (currentYear !== null && date.year() !== currentYear) {
  69. currentYear = date.year();
  70. check_button();
  71. }
  72. else {
  73. applyWeekends(date);
  74. }
  75. }
  76. // Tooltip 관련
  77. //eventMouseover: function (calEvent, jsEvent) {
  78. // if (!calEvent.holiday) {
  79. // var xOffset = 10;
  80. // var yOffset = 30;
  81. // var tooltip = '<div class="tooltipevent" style="background: #333; background: rgba(0,0,0,.8); border-radius: 5px; color: #fff;padding: 5px 15px;position:absolute;z-index:10001;">';
  82. // tooltip += '신청제목: ' + calEvent.title + '<br />';
  83. // tooltip += '신청내용: ' + calEvent.content;
  84. // tooltip += '</div>';
  85. // $("body").append(tooltip);
  86. // $('.tooltipevent')
  87. // .css("top", (jsEvent.clientY - xOffset) + "px")
  88. // .css("left", (jsEvent.clientX + yOffset) + "px")
  89. // .fadeIn("fast");
  90. // }
  91. //},
  92. //eventMouseout: function (calEvent, jsEvent) {
  93. // $('.tooltipevent').remove();
  94. //}
  95. };
  96. var selectedDates = {};
  97. function handleSelectInCalendar(start, end) {
  98. //var date = start.startOf('hour');
  99. //var isExist = holidayCalendar.isExistEvent(date, function (i, event) {
  100. // utils.toast.show('이미 등록된 휴일이 있습니다.', 'error');
  101. //});
  102. //if (isExist) return;
  103. //selectedDates.start = start;
  104. //selectedDates.end = end;
  105. //popupInsertVisible(true);
  106. }
  107. function handleEventClickInCalendar(event) {
  108. if (event.holiday === true) { return; }
  109. event.item.CycleUnitName = $KoSet(event.item.CycleUnitName, event.item['FmsWorkCodeCycleUnit/Name']);
  110. event.item.BusinessFieldName = $KoSet(event.item.BusinessFieldName, event.item['CmBusinessField/Name']);
  111. event.item.UpdateUserName = $KoSet(event.item.UpdateUserName, event.item['CmUser/Name']);
  112. event.item.InspectionAgencyName = $KoSet(event.item.InspectionAgencyName, event.item['CmPartner/Name']);
  113. event.item.IsAutoOrder = $KoSet(event.item.IsAutoOrder, event.item['FmsWorkSchedule/IsAutoOrder']);
  114. if (event.item.WorkTypeId() == 1 || event.item.WorkTypeId() == 2 || event.item.WorkTypeId() == 4) {
  115. event.item.WorkTypevisible = true;
  116. var CycleSize = event.item['FmsWorkSchedule/CycleSize']();
  117. var CycleUnitId = event.item['FmsWorkSchedule/CycleUnitId']();
  118. var FmsWorkCodeCycleUnitdataSource = new DevExpress.data.DataSource({
  119. store: {
  120. type: "odata",
  121. url: endpointSelector + "/FmsWorkCodeCycleUnit"
  122. },
  123. requireTotalCount: true,
  124. pageSize: 1
  125. });
  126. FmsWorkCodeCycleUnitdataSource.filter([
  127. ["SiteId", "=", SiteId],
  128. "and",
  129. ["CycleUnitId", "=", CycleUnitId]
  130. ]);
  131. FmsWorkCodeCycleUnitdataSource.load()
  132. .done(function (result) {
  133. var CycleUnitName = result[0].Name;
  134. var dispText = CycleSize + ' ' + CycleUnitName;
  135. event.item.CycleSizeText = $KoSet(event.item.CycleSizeText, dispText);
  136. var HolidayWorkTypeId = event.item['FmsWorkSchedule/HolidayWorkTypeId']();
  137. var FmsWorkCodeHolidayWorkTypedataSource = new DevExpress.data.DataSource({
  138. store: {
  139. type: "odata",
  140. url: endpointSelector + "/FmsWorkCodeHolidayWorkType"
  141. },
  142. requireTotalCount: true,
  143. pageSize: 1
  144. });
  145. FmsWorkCodeHolidayWorkTypedataSource.filter([
  146. ["SiteId", "=", SiteId],
  147. "and",
  148. ["HolidayWorkTypeId", "=", HolidayWorkTypeId]
  149. ]);
  150. FmsWorkCodeHolidayWorkTypedataSource.load()
  151. .done(function (result) {
  152. event.item.HolidayWorkTypeName = result[0].Name;
  153. executionScheduleCalendarPopup.selectedWorkSchedule(event.item);
  154. executionScheduleCalendarPopup.show();
  155. })
  156. .fail(function (error) {
  157. utils.toast.show(error);
  158. });
  159. })
  160. .fail(function (error) {
  161. utils.toast.show(error);
  162. });
  163. }
  164. else {
  165. event.item.WorkTypevisible = false;
  166. executionScheduleCalendarPopup.selectedWorkSchedule(event.item);
  167. executionScheduleCalendarPopup.show();
  168. }
  169. }
  170. function refreshList() {
  171. //var date = moment();
  172. //loadHolidays(date);
  173. //hcLee 2016 03 21
  174. currentYear = viewDate.year();
  175. //loadHolidays(viewDate);
  176. Data_fliter(viewDate);
  177. }
  178. // hcLee 2016 10 18 추가
  179. var initialized = false;
  180. function handleViewShowing() {
  181. useBusinessFiltering = BWA.UserInfo.isDependBusinessField(viewInfo.viewName);
  182. }
  183. function handleViewShown() {
  184. $SideMenu.showSideMenuIfWill(params.view);
  185. if (initialized === false) { // hcLee 2016 10 18 추가
  186. holidayCalendar = utils.fullCalendar.create('holidayCalendar', calendarOptions);
  187. var date = moment();
  188. currentYear = date.year();
  189. check_button();
  190. }
  191. else
  192. refreshList(); // hcLee 2016 10 18 추가
  193. }
  194. function check_button() {
  195. $("#checkBox_regular").dxCheckBox({
  196. text: "정기 점검",
  197. value: true,
  198. onValueChanged: function (e) {
  199. switch (e.value) {
  200. case true:
  201. checkBox_regular = true;
  202. break;
  203. case false:
  204. checkBox_regular = false;
  205. break;
  206. }
  207. Data_fliter(viewDate);
  208. }
  209. });
  210. $("#checkBox_legal").dxCheckBox({
  211. text: "법정 검사",
  212. value: true,
  213. onValueChanged: function (e) {
  214. switch (e.value) {
  215. case true:
  216. checkBox_legal = true;
  217. break;
  218. case false:
  219. checkBox_legal = false;
  220. break;
  221. }
  222. Data_fliter(viewDate);
  223. }
  224. });
  225. $("#checkBox_any").dxCheckBox({
  226. text: "수시 점검",
  227. value: true,
  228. onValueChanged: function (e) {
  229. switch (e.value) {
  230. case true:
  231. checkBox_any = true;
  232. break;
  233. case false:
  234. checkBox_any = false;
  235. break;
  236. }
  237. Data_fliter(viewDate);
  238. }
  239. });
  240. Data_fliter(viewDate);
  241. }
  242. function Data_fliter(date) {
  243. workScheduleDataSource.filter([]);
  244. if (checkBox_regular) {//1
  245. if (checkBox_legal) {//2
  246. if (checkBox_any) {//5
  247. workScheduleDataSource.filter().push(["WorkTypeId", ">=", 1]);//1,2,5
  248. }
  249. else {
  250. workScheduleDataSource.filter().push([["WorkTypeId", "=", 1], 'or', ["WorkTypeId", "=", 2]]);//1,2
  251. }
  252. }
  253. else {
  254. if (checkBox_any) {//5
  255. workScheduleDataSource.filter().push([["WorkTypeId", "=", 1], 'or', ["WorkTypeId", "=", 5]]);//1,5
  256. }
  257. else {
  258. workScheduleDataSource.filter().push(["WorkTypeId", "=", 1]);//1
  259. }
  260. }
  261. }
  262. else {
  263. if (checkBox_legal) {//2
  264. if (checkBox_any) {//5
  265. workScheduleDataSource.filter().push([["WorkTypeId", "=", 2], 'or', ["WorkTypeId", "=", 5]]);//2,5
  266. }
  267. else {
  268. workScheduleDataSource.filter().push(["WorkTypeId", "=", 2]);//2
  269. }
  270. }
  271. else {
  272. if (checkBox_any) {//5
  273. workScheduleDataSource.filter().push(["WorkTypeId", "=", 5]);//5
  274. }
  275. else {
  276. workScheduleDataSource.filter().push(["WorkTypeId", "=", 0]);//0
  277. }
  278. }
  279. }
  280. loadHolidays(date);
  281. hasnotModificationPermission(!BWA.UserInfo.hasPermissionOfModification(viewInfo.viewName));
  282. $SearchView.setPopupVisibleObservable(null);
  283. initialized = true;
  284. }
  285. function refreshHolidays(date) {
  286. holidays = [];
  287. var currentYear = date.year();
  288. if (loadedYears.indexOf(currentYear) < 0) {
  289. loadedYears.push(currentYear);
  290. var year;
  291. var month;
  292. var day;
  293. var solar;
  294. $.each(holidaySources, function (i, item) {
  295. year = currentYear;
  296. month = item.HolidayMonth() - 1;
  297. day = item.HolidayDay();
  298. if (item.IsLunar()) {
  299. solar = cc.lunar2solar(new Date(year - 1, month, day));
  300. if (solar.sYear !== year) {
  301. solar = cc.lunar2solar(new Date(year, month, day));
  302. }
  303. year = solar.sYear;
  304. month = solar.sMonth - 1;
  305. day = solar.sDay;
  306. }
  307. utils.holiday.pushHolidayEventInArray(holidays, item.Name(), moment([year, month, day]), true, undefined, 0);
  308. });
  309. $.each(holidayCustomSources, function (i, item) {
  310. var itemDate = item.HolidayDate();
  311. if (itemDate.getFullYear() === currentYear) {
  312. utils.holiday.pushHolidayEventInArray(holidays, item.Name(), moment([itemDate.getFullYear(), itemDate.getMonth(), itemDate.getDate()]), false, undefined, 1);
  313. }
  314. });
  315. $.each(workScheduleSources, function (i, item) {
  316. var itemDate = item.StartWorkDate();//추가
  317. item.Name = item.Title;
  318. if (itemDate.getFullYear() === currentYear) {
  319. utils.holiday.pushWorkScheduleEventInArray(holidays, item, moment([itemDate.getFullYear(), itemDate.getMonth(), itemDate.getDate()]), false, undefined, 1);
  320. }
  321. });
  322. }
  323. applyWeekends(date);
  324. }
  325. function loadHolidays(date) {
  326. holidays = [];
  327. loadedYears = [];
  328. if (!useBusinessFiltering) {
  329. workScheduleDataSource.filter().push("and", eq("WorkProgressId", $Code.WorkProgress.WORK_PLAN), "and", eq("SiteId", SiteId));
  330. } else {
  331. workScheduleDataSource.filter().push("and", eq("WorkProgressId", $Code.WorkProgress.WORK_PLAN), "and", eq("SiteId", SiteId), "and",
  332. [eq('BusinessFieldId', BWA.UserInfo.BusinessFieldId()), 'or', eq('BusinessFieldId', 1)]);
  333. }
  334. $.when(
  335. holidayDataSource.load(),
  336. holidayCustomDataSource.load(),
  337. holidayWeekendDataSource.load(),
  338. workScheduleDataSource.load())//수정
  339. .done(function (result1, result2, result3, result4) {
  340. holidaySources = result1[0];
  341. holidayCustomSources = result2[0];
  342. var tempworkScheduleSources = result4[0];
  343. workScheduleSources = [];
  344. for (var i = 0; i < tempworkScheduleSources.length; i++) {
  345. if (tempworkScheduleSources[i].WorkTypeId() <= $Code.WorkType.LEGAL_CHECK) {
  346. if (tempworkScheduleSources[i]['FmsWorkSchedule/IsUse']() == true)
  347. workScheduleSources.push(tempworkScheduleSources[i]);
  348. }
  349. else {
  350. workScheduleSources.push(tempworkScheduleSources[i]);
  351. }
  352. }
  353. if (result3.length > 0) {
  354. var weekend = result3[0][0];
  355. isSaturday = weekend.Saturday();
  356. isSunday = weekend.Sunday();
  357. holidayWeekendDataViewModel.SiteId(weekend.SiteId());
  358. holidayWeekendDataViewModel.Saturday(weekend.Saturday());
  359. holidayWeekendDataViewModel.Sunday(weekend.Sunday());
  360. }
  361. refreshHolidays(date);
  362. });
  363. }
  364. function applyWeekends(date) {
  365. if (holidayCalendar === null) return;
  366. if (isSunday == false && isSaturday == false) {
  367. holidayCalendar.updateEvents(holidays);
  368. return;
  369. }
  370. weekends = utils.holiday.getWeekendHolidays(date, isSaturday, isSunday);
  371. //var month = date.clone().startOf( 'month' );
  372. //var sunday = month.clone(),
  373. // saturday = month.clone();
  374. //weekends = [];
  375. //if( month.day() !== 0 ) {
  376. // sunday.day( -7 );
  377. //}
  378. //if( month.day() !== 6 ) {
  379. // saturday.day( -1 );
  380. //}
  381. //for( var i = 0 ; i < 7 ; i++ ) {
  382. // if( isSunday ) {
  383. // holidayCalendar.pushEventInArray( weekends, '주말 휴일', moment( [ sunday.year(), sunday.month(), sunday.date() ], null, true, 2 ));
  384. // sunday.day( 7 );
  385. // }
  386. // if( isSaturday ) {
  387. // holidayCalendar.pushEventInArray( weekends, '주말 휴일', moment( [ saturday.year(), saturday.month(), saturday.date() ], null, true, 2 ));
  388. // saturday.day( 13 );
  389. // }
  390. //}
  391. holidayCalendar.updateEvents(holidays.concat(weekends));
  392. }
  393. function handleModification() {
  394. //shouldReload = true;
  395. }
  396. function handleViewHidden() {
  397. holidayCalendar.clearEvents(true);
  398. }
  399. function handleViewDisposing() {
  400. BemsWebApplication.db.CmHolidayWeekend.modified.remove(handleModification);
  401. }
  402. BemsWebApplication.db.CmHolidayWeekend.modified.add(handleModification);
  403. function popupInsertView() {
  404. popupWeekendSetupVisible(true);
  405. }
  406. function handleWeekendSetupPopupButtonSave() {
  407. BemsWebApplication.db.CmHolidayWeekend.update(SiteId, holidayWeekendDataViewModel.toJS()).done(function () {
  408. refreshList();
  409. utils.toast.show('데이터베이스 항목 수정 작업이 성공하였습니다.');
  410. popupWeekendSetupVisible(false);
  411. });
  412. }
  413. function handleWeekendPopupButtonClose() {
  414. popupWeekendSetupVisible(false);
  415. }
  416. function handleInsertPopupButtonSave() {
  417. var dbModelId;
  418. var dataViewModel;
  419. var selectedDate = selectedDates.start;
  420. if (holidayModel.IsYearlyHoliday()) {
  421. dbModelId = 'CmHoliday';
  422. dataViewModel = new BemsWebApplication.CmHolidayViewModel();
  423. }
  424. else {
  425. dbModelId = 'CmHolidayCustom';
  426. dataViewModel = new BemsWebApplication.CmHolidayCustomViewModel();
  427. }
  428. var promised = {};
  429. for (selectedDate = selectedDates.start ; selectedDate.isSame(selectedDates.end) === false ; selectedDate.add(1, 'days')) {
  430. if (holidayModel.IsYearlyHoliday()) {
  431. dataViewModel.IsLunar(holidayModel.IsLunar());
  432. var month = selectedDate.month() + 1,
  433. date = selectedDate.date();
  434. if (holidayModel.IsLunar()) {
  435. var lunar = cc.solar2lunar(new Date(selectedDate.year(), month - 1, date));
  436. month = lunar.lMonth;
  437. date = lunar.lDay;
  438. }
  439. console.log(month + ' ' + date);
  440. dataViewModel.HolidayMonth(month);
  441. dataViewModel.HolidayDay(date);
  442. }
  443. else {
  444. dataViewModel.HolidayDate(new Date(selectedDate.year(), selectedDate.month(), selectedDate.date()));
  445. }
  446. dataViewModel.SiteId(SiteId);
  447. dataViewModel.Name(holidayModel.Name());
  448. dataViewModel.IsUse(true);
  449. promised = BemsWebApplication.db[dbModelId].insert(dataViewModel.toJS());
  450. }
  451. promised.done(function (values, newId) {
  452. popupInsertVisible(false);
  453. refreshList();
  454. utils.toast.show('휴일 등록 작업이 성공하였습니다.');
  455. }).fail(function () {
  456. popupInsertVisible(false);
  457. refreshList();
  458. });
  459. }
  460. function handleInsertPopupButtonClose() {
  461. popupInsertVisible(false);
  462. }
  463. var holidayWeekendSetupToolbarItems = [
  464. { location: 'before', text: '주말 휴일 설정' },
  465. { location: 'after', widget: 'button', options: { text: $G('save'), icon: 'save', clickAction: handleWeekendSetupPopupButtonSave } },
  466. { location: 'after', widget: 'button', options: { text: $G('close'), icon: 'close', clickAction: handleWeekendPopupButtonClose } }
  467. ];
  468. var insertHolidayToolbarItems = [
  469. { location: 'before', text: '주말 휴일 설정' },
  470. { location: 'after', widget: 'button', options: { text: $G('save'), icon: 'save', clickAction: handleInsertPopupButtonSave } },
  471. { location: 'after', widget: 'button', options: { text: $G('close'), icon: 'close', clickAction: handleInsertPopupButtonClose } }
  472. ];
  473. var popupOptions = {
  474. width: '480px',
  475. height: 'auto',
  476. visible: popupWeekendSetupVisible,
  477. closeOnOutsideClick: false,
  478. //showingAction: handlePopupShowing,
  479. //shownAction: handlePopupShown,
  480. animation: utils.popup.createAnimation()
  481. };
  482. var insertPopupOptions = $.extend({}, popupOptions);
  483. insertPopupOptions.visible = popupInsertVisible;
  484. executionScheduleCalendarPopup = BWA.Popup.ExecutionScheduleCalendarPopup.create(holidayWeekendDataViewModel);
  485. return {
  486. viewShowing: handleViewShowing,
  487. viewShown: handleViewShown,
  488. viewHidden: handleViewHidden,
  489. viewDisposing: handleViewDisposing,
  490. refreshList: refreshList,
  491. popupInsertView: popupInsertView,
  492. popupOptions: popupOptions,
  493. insertPopupOptions: insertPopupOptions,
  494. holidayWeekendSetupToolbarItems: holidayWeekendSetupToolbarItems,
  495. insertHolidayToolbarItems: insertHolidayToolbarItems,
  496. dataModel: holidayWeekendDataViewModel,
  497. executionScheduleCalendarPopup: executionScheduleCalendarPopup,
  498. holidayModel: holidayModel,
  499. hasnotModificationPermission: hasnotModificationPermission
  500. };
  501. };