82994ccebd5631b411c0720a21f898a0e7df3dcb.svn-base 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. BemsWebApplication.WorkHistoryScheduleCalendar = function (params, viewInfo) {
  2. "use strict";
  3. var endpointSelector;
  4. var useBusinessFiltering = BWA.UserInfo.isDependBusinessField(viewInfo.viewName);
  5. if (BemsWebApplication.config.mode == "production") {
  6. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.production;
  7. } else {
  8. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.local;
  9. }
  10. var eq = BWA.DataUtil.constructEqualFilter,
  11. and = BWA.DataUtil.andFilter,
  12. noteq = BWA.DataUtil.constructNotEqualFilter;
  13. var workHistoryScheduleCalendarPopup = null;
  14. var SiteId = BWA.UserInfo.SiteId();
  15. var holidayDataSource = BemsWebApplication.db.createDataSource('CmHoliday', true, true);
  16. var holidayCustomDataSource = BemsWebApplication.db.createDataSource('CmHolidayCustom', true);
  17. var holidayWeekendDataSource = BemsWebApplication.db.createDataSource('CmHolidayWeekend', true);
  18. var checkBox_regular = true, checkBox_legal = true, checkBox_any = true;
  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', 'FmsWorkResult/EndDate', 'FmsWorkResult/IsConfirmed',
  25. 'CmPartner/Name', 'FmsWorkSchedule/HolidayWorkTypeId'
  26. ],
  27. expand: ['FmsWorkSchedule', 'CmUser', 'CmBusinessField', 'CmPartner', 'FmsWorkResult'],
  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. event.item.EndDate = $KoSet(event.item.EndDate, event.item['FmsWorkResult/EndDate']);
  115. if (event.item.WorkTypeId() == 1 || event.item.WorkTypeId() == 2 || event.item.WorkTypeId() == 4) {
  116. event.item.WorkTypevisible = true;
  117. var CycleSize = event.item['FmsWorkSchedule/CycleSize']();
  118. var CycleUnitId = event.item['FmsWorkSchedule/CycleUnitId']();
  119. var FmsWorkCodeCycleUnitdataSource = new DevExpress.data.DataSource({
  120. store: {
  121. type: "odata",
  122. url: endpointSelector + "/FmsWorkCodeCycleUnit"
  123. },
  124. requireTotalCount: true,
  125. pageSize: 1
  126. });
  127. FmsWorkCodeCycleUnitdataSource.filter([
  128. ["SiteId", "=", SiteId],
  129. "and",
  130. ["CycleUnitId", "=", CycleUnitId]
  131. ]);
  132. FmsWorkCodeCycleUnitdataSource.load()
  133. .done(function (result) {
  134. var CycleUnitName = result[0].Name;
  135. var dispText = CycleSize + ' ' + CycleUnitName;
  136. event.item.CycleSizeText = $KoSet(event.item.CycleSizeText, dispText);
  137. var HolidayWorkTypeId = event.item['FmsWorkSchedule/HolidayWorkTypeId']();
  138. var FmsWorkCodeHolidayWorkTypedataSource = new DevExpress.data.DataSource({
  139. store: {
  140. type: "odata",
  141. url: endpointSelector + "/FmsWorkCodeHolidayWorkType"
  142. },
  143. requireTotalCount: true,
  144. pageSize: 1
  145. });
  146. FmsWorkCodeHolidayWorkTypedataSource.filter([
  147. ["SiteId", "=", SiteId],
  148. "and",
  149. ["HolidayWorkTypeId", "=", HolidayWorkTypeId]
  150. ]);
  151. FmsWorkCodeHolidayWorkTypedataSource.load()
  152. .done(function (result) {
  153. event.item.HolidayWorkTypeName = result[0].Name;
  154. workHistoryScheduleCalendarPopup.selectedWorkSchedule(event.item);
  155. workHistoryScheduleCalendarPopup.show();
  156. })
  157. .fail(function (error) {
  158. utils.toast.show(error);
  159. });
  160. })
  161. .fail(function (error) {
  162. utils.toast.show(error);
  163. });
  164. }
  165. else {
  166. event.item.WorkTypevisible = false;
  167. workHistoryScheduleCalendarPopup.selectedWorkSchedule(event.item);
  168. workHistoryScheduleCalendarPopup.show();
  169. }
  170. }
  171. function refreshList() {
  172. //var date = moment();
  173. //loadHolidays(date);
  174. //hcLee 2016 03 21
  175. currentYear = viewDate.year();
  176. //loadHolidays(viewDate);
  177. Data_fliter(viewDate);
  178. }
  179. // hcLee 2016 10 18 추가
  180. var initialized = false;
  181. function handleViewShown() {
  182. $SideMenu.showSideMenuIfWill(params.view);
  183. if (initialized === false) { // hcLee 2016 10 18 추가
  184. holidayCalendar = utils.fullCalendar.create('holidayCalendar', calendarOptions);
  185. var date = moment();
  186. currentYear = date.year();
  187. check_button();
  188. }
  189. else
  190. refreshList(); // hcLee 2016 10 18 추가
  191. }
  192. function check_button() {
  193. $("#checkBox_regular").dxCheckBox({
  194. text: "정기 점검",
  195. value: true,
  196. onValueChanged: function (e) {
  197. switch (e.value) {
  198. case true:
  199. checkBox_regular = true;
  200. break;
  201. case false:
  202. checkBox_regular = false;
  203. break;
  204. }
  205. Data_fliter(viewDate);
  206. }
  207. });
  208. $("#checkBox_legal").dxCheckBox({
  209. text: "법정 검사",
  210. value: true,
  211. onValueChanged: function (e) {
  212. switch (e.value) {
  213. case true:
  214. checkBox_legal = true;
  215. break;
  216. case false:
  217. checkBox_legal = false;
  218. break;
  219. }
  220. Data_fliter(viewDate);
  221. }
  222. });
  223. $("#checkBox_any").dxCheckBox({
  224. text: "수시 점검",
  225. value: true,
  226. onValueChanged: function (e) {
  227. switch (e.value) {
  228. case true:
  229. checkBox_any = true;
  230. break;
  231. case false:
  232. checkBox_any = false;
  233. break;
  234. }
  235. Data_fliter(viewDate);
  236. }
  237. });
  238. Data_fliter(viewDate);
  239. }
  240. function Data_fliter(date) {
  241. workScheduleDataSource.filter([]);
  242. if (checkBox_regular) {//1
  243. if (checkBox_legal) {//2
  244. if (checkBox_any) {//5
  245. workScheduleDataSource.filter().push(["WorkTypeId", ">=", 1]);//1,2,5
  246. }
  247. else {
  248. workScheduleDataSource.filter().push([["WorkTypeId", "=", 1], 'or', ["WorkTypeId", "=", 2]]);//1,2
  249. }
  250. }
  251. else {
  252. if (checkBox_any) {//5
  253. workScheduleDataSource.filter().push([["WorkTypeId", "=", 1], 'or', ["WorkTypeId", "=", 5]]);//1,5
  254. }
  255. else {
  256. workScheduleDataSource.filter().push(["WorkTypeId", "=", 1]);//1
  257. }
  258. }
  259. }
  260. else {
  261. if (checkBox_legal) {//2
  262. if (checkBox_any) {//5
  263. workScheduleDataSource.filter().push([["WorkTypeId", "=", 2], 'or', ["WorkTypeId", "=", 5]]);//2,5
  264. }
  265. else {
  266. workScheduleDataSource.filter().push(["WorkTypeId", "=", 2]);//2
  267. }
  268. }
  269. else {
  270. if (checkBox_any) {//5
  271. workScheduleDataSource.filter().push(["WorkTypeId", "=", 5]);//5
  272. }
  273. else {
  274. workScheduleDataSource.filter().push(["WorkTypeId", "=", 0]);//0
  275. }
  276. }
  277. }
  278. loadHolidays(date);
  279. hasnotModificationPermission(!BWA.UserInfo.hasPermissionOfModification(viewInfo.viewName));
  280. $SearchView.setPopupVisibleObservable(null);
  281. initialized = true;
  282. }
  283. function refreshHolidays(date) {
  284. holidays = [];
  285. var currentYear = date.year();
  286. if (loadedYears.indexOf(currentYear) < 0) {
  287. loadedYears.push(currentYear);
  288. var year;
  289. var month;
  290. var day;
  291. var solar;
  292. $.each(holidaySources, function (i, item) {
  293. year = currentYear;
  294. month = item.HolidayMonth() - 1;
  295. day = item.HolidayDay();
  296. if (item.IsLunar()) {
  297. solar = cc.lunar2solar(new Date(year - 1, month, day));
  298. if (solar.sYear !== year) {
  299. solar = cc.lunar2solar(new Date(year, month, day));
  300. }
  301. year = solar.sYear;
  302. month = solar.sMonth - 1;
  303. day = solar.sDay;
  304. }
  305. utils.holiday.pushHolidayEventInArray(holidays, item.Name(), moment([year, month, day]), true, undefined, 0);
  306. });
  307. $.each(holidayCustomSources, function (i, item) {
  308. var itemDate = item.HolidayDate();
  309. if (itemDate.getFullYear() === currentYear) {
  310. utils.holiday.pushHolidayEventInArray(holidays, item.Name(), moment([itemDate.getFullYear(), itemDate.getMonth(), itemDate.getDate()]), false, undefined, 1);
  311. }
  312. });
  313. $.each(workScheduleSources, function (i, item) {
  314. var itemDate = item['FmsWorkResult/EndDate']();//추가
  315. item.Name = item.Title;
  316. if (itemDate.getFullYear() === currentYear) {
  317. utils.holiday.pushWorkScheduleEventInArray(holidays, item, moment([itemDate.getFullYear(), itemDate.getMonth(), itemDate.getDate()]), false, undefined, 1);
  318. }
  319. });
  320. }
  321. applyWeekends(date);
  322. }
  323. function loadHolidays(date) {
  324. holidays = [];
  325. loadedYears = [];
  326. workScheduleDataSource.filter().push('and', eq("SiteId", SiteId));
  327. if (useBusinessFiltering)
  328. workScheduleDataSource.filter().push('and', [eq('BusinessFieldId', BWA.UserInfo.BusinessFieldId()), 'or', eq('BusinessFieldId', 1)]);
  329. $.when(
  330. holidayDataSource.load(),
  331. holidayCustomDataSource.load(),
  332. holidayWeekendDataSource.load(),
  333. workScheduleDataSource.load())//수정
  334. .done(function (result1, result2, result3, result4) {
  335. holidaySources = result1[0];
  336. holidayCustomSources = result2[0];
  337. var tempworkScheduleSources = result4[0];
  338. workScheduleSources = [];
  339. for (var i = 0; i < tempworkScheduleSources.length; i++) {
  340. //if (tempworkScheduleSources[i].WorkTypeId() <= $Code.WorkType.LEGAL_CHECK) {
  341. // if (tempworkScheduleSources[i]['FmsWorkSchedule/IsUse']() == true)
  342. // workScheduleSources.push(tempworkScheduleSources[i]);
  343. //}
  344. //else {
  345. // workScheduleSources.push(tempworkScheduleSources[i]);
  346. //}
  347. if (tempworkScheduleSources[i]['FmsWorkResult/IsConfirmed'] != null) {
  348. if (tempworkScheduleSources[i]['FmsWorkResult/IsConfirmed']() == true) {
  349. workScheduleSources.push(tempworkScheduleSources[i]);
  350. }
  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. workHistoryScheduleCalendarPopup = BWA.Popup.WorkHistoryScheduleCalendarPopup.create(holidayWeekendDataViewModel);
  485. return {
  486. viewShown: handleViewShown,
  487. viewHidden: handleViewHidden,
  488. viewDisposing: handleViewDisposing,
  489. refreshList: refreshList,
  490. popupInsertView: popupInsertView,
  491. popupOptions: popupOptions,
  492. insertPopupOptions: insertPopupOptions,
  493. holidayWeekendSetupToolbarItems: holidayWeekendSetupToolbarItems,
  494. insertHolidayToolbarItems: insertHolidayToolbarItems,
  495. dataModel: holidayWeekendDataViewModel,
  496. workHistoryScheduleCalendarPopup: workHistoryScheduleCalendarPopup,
  497. holidayModel: holidayModel,
  498. hasnotModificationPermission: hasnotModificationPermission
  499. };
  500. };