99f3bec6b097f0f804c668c96a6fdbb270f844eb.svn-base 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  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. weekNumbers: true,
  63. height: 680,
  64. select: handleSelectInCalendar,
  65. eventClick: handleEventClickInCalendar,
  66. changedMonth: function (view) {
  67. var date = view.calendar.getDate();
  68. viewDate = date; //hcLee 2016 03 21
  69. if (currentYear !== null && date.year() !== currentYear) {
  70. currentYear = date.year();
  71. check_button();
  72. }
  73. else {
  74. applyWeekends(date);
  75. }
  76. }
  77. // Tooltip 관련
  78. //eventMouseover: function (calEvent, jsEvent) {
  79. // if (!calEvent.holiday) {
  80. // var xOffset = 10;
  81. // var yOffset = 30;
  82. // 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;">';
  83. // tooltip += '신청제목: ' + calEvent.title + '<br />';
  84. // tooltip += '신청내용: ' + calEvent.content;
  85. // tooltip += '</div>';
  86. // $("body").append(tooltip);
  87. // $('.tooltipevent')
  88. // .css("top", (jsEvent.clientY - xOffset) + "px")
  89. // .css("left", (jsEvent.clientX + yOffset) + "px")
  90. // .fadeIn("fast");
  91. // }
  92. //},
  93. //eventMouseout: function (calEvent, jsEvent) {
  94. // $('.tooltipevent').remove();
  95. //}
  96. };
  97. var selectedDates = {};
  98. function handleSelectInCalendar(start, end) {
  99. //var date = start.startOf('hour');
  100. //var isExist = holidayCalendar.isExistEvent(date, function (i, event) {
  101. // utils.toast.show('이미 등록된 휴일이 있습니다.', 'error');
  102. //});
  103. //if (isExist) return;
  104. //selectedDates.start = start;
  105. //selectedDates.end = end;
  106. //popupInsertVisible(true);
  107. }
  108. function handleEventClickInCalendar(event) {
  109. if (event.holiday === true) { return; }
  110. event.item.CycleUnitName = $KoSet(event.item.CycleUnitName, event.item['FmsWorkCodeCycleUnit/Name']);
  111. event.item.BusinessFieldName = $KoSet(event.item.BusinessFieldName, event.item['CmBusinessField/Name']);
  112. event.item.UpdateUserName = $KoSet(event.item.UpdateUserName, event.item['CmUser/Name']);
  113. event.item.InspectionAgencyName = $KoSet(event.item.InspectionAgencyName, event.item['CmPartner/Name']);
  114. event.item.IsAutoOrder = $KoSet(event.item.IsAutoOrder, event.item['FmsWorkSchedule/IsAutoOrder']);
  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. executionScheduleCalendarPopup.selectedWorkSchedule(event.item);
  155. executionScheduleCalendarPopup.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. executionScheduleCalendarPopup.selectedWorkSchedule(event.item);
  168. executionScheduleCalendarPopup.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 handleViewShowing() {
  182. useBusinessFiltering = BWA.UserInfo.isDependBusinessField(viewInfo.viewName);
  183. }
  184. function handleViewShown() {
  185. $SideMenu.showSideMenuIfWill(params.view);
  186. if (initialized === false) { // hcLee 2016 10 18 추가
  187. holidayCalendar = utils.fullCalendar.create('holidayCalendar', calendarOptions);
  188. var date = moment();
  189. currentYear = date.year();
  190. check_button();
  191. }
  192. else
  193. refreshList(); // hcLee 2016 10 18 추가
  194. }
  195. function check_button() {
  196. $("#checkBox_regular").dxCheckBox({
  197. text: "정기 점검",
  198. value: true,
  199. onValueChanged: function (e) {
  200. switch (e.value) {
  201. case true:
  202. checkBox_regular = true;
  203. break;
  204. case false:
  205. checkBox_regular = false;
  206. break;
  207. }
  208. Data_fliter(viewDate);
  209. }
  210. });
  211. $("#checkBox_legal").dxCheckBox({
  212. text: "법정 검사",
  213. value: true,
  214. onValueChanged: function (e) {
  215. switch (e.value) {
  216. case true:
  217. checkBox_legal = true;
  218. break;
  219. case false:
  220. checkBox_legal = false;
  221. break;
  222. }
  223. Data_fliter(viewDate);
  224. }
  225. });
  226. $("#checkBox_any").dxCheckBox({
  227. text: "수시 점검",
  228. value: true,
  229. onValueChanged: function (e) {
  230. switch (e.value) {
  231. case true:
  232. checkBox_any = true;
  233. break;
  234. case false:
  235. checkBox_any = false;
  236. break;
  237. }
  238. Data_fliter(viewDate);
  239. }
  240. });
  241. Data_fliter(viewDate);
  242. }
  243. function Data_fliter(date) {
  244. workScheduleDataSource.filter([]);
  245. if (checkBox_regular) {//1
  246. if (checkBox_legal) {//2
  247. if (checkBox_any) {//5
  248. workScheduleDataSource.filter().push(["WorkTypeId", ">=", 1]);//1,2,5
  249. }
  250. else {
  251. workScheduleDataSource.filter().push([["WorkTypeId", "=", 1], 'or', ["WorkTypeId", "=", 2]]);//1,2
  252. }
  253. }
  254. else {
  255. if (checkBox_any) {//5
  256. workScheduleDataSource.filter().push([["WorkTypeId", "=", 1], 'or', ["WorkTypeId", "=", 5]]);//1,5
  257. }
  258. else {
  259. workScheduleDataSource.filter().push(["WorkTypeId", "=", 1]);//1
  260. }
  261. }
  262. }
  263. else {
  264. if (checkBox_legal) {//2
  265. if (checkBox_any) {//5
  266. workScheduleDataSource.filter().push([["WorkTypeId", "=", 2], 'or', ["WorkTypeId", "=", 5]]);//2,5
  267. }
  268. else {
  269. workScheduleDataSource.filter().push(["WorkTypeId", "=", 2]);//2
  270. }
  271. }
  272. else {
  273. if (checkBox_any) {//5
  274. workScheduleDataSource.filter().push(["WorkTypeId", "=", 5]);//5
  275. }
  276. else {
  277. workScheduleDataSource.filter().push(["WorkTypeId", "=", 0]);//0
  278. }
  279. }
  280. }
  281. loadHolidays(date);
  282. hasnotModificationPermission(!BWA.UserInfo.hasPermissionOfModification(viewInfo.viewName));
  283. $SearchView.setPopupVisibleObservable(null);
  284. initialized = true;
  285. }
  286. function refreshHolidays(date) {
  287. holidays = [];
  288. var currentYear = date.year();
  289. if (loadedYears.indexOf(currentYear) < 0) {
  290. loadedYears.push(currentYear);
  291. var year;
  292. var month;
  293. var day;
  294. var solar;
  295. $.each(holidaySources, function (i, item) {
  296. year = currentYear;
  297. month = item.HolidayMonth() - 1;
  298. day = item.HolidayDay();
  299. if (item.IsLunar()) {
  300. solar = cc.lunar2solar(new Date(year - 1, month, day));
  301. if (solar.sYear !== year) {
  302. solar = cc.lunar2solar(new Date(year, month, day));
  303. }
  304. year = solar.sYear;
  305. month = solar.sMonth - 1;
  306. day = solar.sDay;
  307. }
  308. utils.holiday.pushHolidayEventInArray(holidays, item.Name(), moment([year, month, day]), true, undefined, 0);
  309. });
  310. $.each(holidayCustomSources, function (i, item) {
  311. var itemDate = item.HolidayDate();
  312. if (itemDate.getFullYear() === currentYear) {
  313. utils.holiday.pushHolidayEventInArray(holidays, item.Name(), moment([itemDate.getFullYear(), itemDate.getMonth(), itemDate.getDate()]), false, undefined, 1);
  314. }
  315. });
  316. $.each(workScheduleSources, function (i, item) {
  317. var itemDate = item.StartWorkDate();//추가
  318. item.Name = item.Title;
  319. if (itemDate.getFullYear() === currentYear) {
  320. utils.holiday.pushWorkScheduleEventInArray(holidays, item, moment([itemDate.getFullYear(), itemDate.getMonth(), itemDate.getDate()]), false, undefined, item.WorkTypeId());
  321. }
  322. });
  323. }
  324. applyWeekends(date);
  325. }
  326. function loadHolidays(date) {
  327. holidays = [];
  328. loadedYears = [];
  329. if (!useBusinessFiltering) {
  330. workScheduleDataSource.filter().push("and", eq("WorkProgressId", $Code.WorkProgress.WORK_PLAN), "and", eq("SiteId", SiteId));
  331. } else {
  332. workScheduleDataSource.filter().push("and", eq("WorkProgressId", $Code.WorkProgress.WORK_PLAN), "and", eq("SiteId", SiteId), "and",
  333. [eq('BusinessFieldId', BWA.UserInfo.BusinessFieldId()), 'or', eq('BusinessFieldId', 1)]);
  334. }
  335. $.when(
  336. holidayDataSource.load(),
  337. holidayCustomDataSource.load(),
  338. holidayWeekendDataSource.load(),
  339. workScheduleDataSource.load())//수정
  340. .done(function (result1, result2, result3, result4) {
  341. holidaySources = result1[0];
  342. holidayCustomSources = result2[0];
  343. var tempworkScheduleSources = result4[0];
  344. workScheduleSources = [];
  345. for (var i = 0; i < tempworkScheduleSources.length; i++) {
  346. if (tempworkScheduleSources[i].WorkTypeId() <= $Code.WorkType.LEGAL_CHECK) {
  347. if (tempworkScheduleSources[i]['FmsWorkSchedule/IsUse']() == true)
  348. workScheduleSources.push(tempworkScheduleSources[i]);
  349. }
  350. else {
  351. workScheduleSources.push(tempworkScheduleSources[i]);
  352. }
  353. }
  354. if (result3.length > 0) {
  355. var weekend = result3[0][0];
  356. isSaturday = weekend.Saturday();
  357. isSunday = weekend.Sunday();
  358. holidayWeekendDataViewModel.SiteId(weekend.SiteId());
  359. holidayWeekendDataViewModel.Saturday(weekend.Saturday());
  360. holidayWeekendDataViewModel.Sunday(weekend.Sunday());
  361. }
  362. refreshHolidays(date);
  363. });
  364. }
  365. function applyWeekends(date) {
  366. if (holidayCalendar === null) return;
  367. if (isSunday == false && isSaturday == false) {
  368. holidayCalendar.updateEvents(holidays);
  369. return;
  370. }
  371. weekends = utils.holiday.getWeekendHolidays(date, isSaturday, isSunday);
  372. //var month = date.clone().startOf( 'month' );
  373. //var sunday = month.clone(),
  374. // saturday = month.clone();
  375. //weekends = [];
  376. //if( month.day() !== 0 ) {
  377. // sunday.day( -7 );
  378. //}
  379. //if( month.day() !== 6 ) {
  380. // saturday.day( -1 );
  381. //}
  382. //for( var i = 0 ; i < 7 ; i++ ) {
  383. // if( isSunday ) {
  384. // holidayCalendar.pushEventInArray( weekends, '주말 휴일', moment( [ sunday.year(), sunday.month(), sunday.date() ], null, true, 2 ));
  385. // sunday.day( 7 );
  386. // }
  387. // if( isSaturday ) {
  388. // holidayCalendar.pushEventInArray( weekends, '주말 휴일', moment( [ saturday.year(), saturday.month(), saturday.date() ], null, true, 2 ));
  389. // saturday.day( 13 );
  390. // }
  391. //}
  392. holidayCalendar.updateEvents(holidays.concat(weekends));
  393. }
  394. function handleModification() {
  395. //shouldReload = true;
  396. }
  397. function handleViewHidden() {
  398. holidayCalendar.clearEvents(true);
  399. }
  400. function handleViewDisposing() {
  401. BemsWebApplication.db.CmHolidayWeekend.modified.remove(handleModification);
  402. }
  403. BemsWebApplication.db.CmHolidayWeekend.modified.add(handleModification);
  404. function popupInsertView() {
  405. popupWeekendSetupVisible(true);
  406. }
  407. function handleWeekendSetupPopupButtonSave() {
  408. BemsWebApplication.db.CmHolidayWeekend.update(SiteId, holidayWeekendDataViewModel.toJS()).done(function () {
  409. refreshList();
  410. utils.toast.show('데이터베이스 항목 수정 작업이 성공하였습니다.');
  411. popupWeekendSetupVisible(false);
  412. });
  413. }
  414. function handleWeekendPopupButtonClose() {
  415. popupWeekendSetupVisible(false);
  416. }
  417. function handleInsertPopupButtonSave() {
  418. var dbModelId;
  419. var dataViewModel;
  420. var selectedDate = selectedDates.start;
  421. if (holidayModel.IsYearlyHoliday()) {
  422. dbModelId = 'CmHoliday';
  423. dataViewModel = new BemsWebApplication.CmHolidayViewModel();
  424. }
  425. else {
  426. dbModelId = 'CmHolidayCustom';
  427. dataViewModel = new BemsWebApplication.CmHolidayCustomViewModel();
  428. }
  429. var promised = {};
  430. for (selectedDate = selectedDates.start ; selectedDate.isSame(selectedDates.end) === false ; selectedDate.add(1, 'days')) {
  431. if (holidayModel.IsYearlyHoliday()) {
  432. dataViewModel.IsLunar(holidayModel.IsLunar());
  433. var month = selectedDate.month() + 1,
  434. date = selectedDate.date();
  435. if (holidayModel.IsLunar()) {
  436. var lunar = cc.solar2lunar(new Date(selectedDate.year(), month - 1, date));
  437. month = lunar.lMonth;
  438. date = lunar.lDay;
  439. }
  440. console.log(month + ' ' + date);
  441. dataViewModel.HolidayMonth(month);
  442. dataViewModel.HolidayDay(date);
  443. }
  444. else {
  445. dataViewModel.HolidayDate(new Date(selectedDate.year(), selectedDate.month(), selectedDate.date()));
  446. }
  447. dataViewModel.SiteId(SiteId);
  448. dataViewModel.Name(holidayModel.Name());
  449. dataViewModel.IsUse(true);
  450. promised = BemsWebApplication.db[dbModelId].insert(dataViewModel.toJS());
  451. }
  452. promised.done(function (values, newId) {
  453. popupInsertVisible(false);
  454. refreshList();
  455. utils.toast.show('휴일 등록 작업이 성공하였습니다.');
  456. }).fail(function () {
  457. popupInsertVisible(false);
  458. refreshList();
  459. });
  460. }
  461. function handleInsertPopupButtonClose() {
  462. popupInsertVisible(false);
  463. }
  464. var holidayWeekendSetupToolbarItems = [
  465. { location: 'before', text: '주말 휴일 설정' },
  466. { location: 'after', widget: 'button', options: { text: $G('save'), icon: 'save', clickAction: handleWeekendSetupPopupButtonSave } },
  467. { location: 'after', widget: 'button', options: { text: $G('close'), icon: 'close', clickAction: handleWeekendPopupButtonClose } }
  468. ];
  469. var insertHolidayToolbarItems = [
  470. { location: 'before', text: '주말 휴일 설정' },
  471. { location: 'after', widget: 'button', options: { text: $G('save'), icon: 'save', clickAction: handleInsertPopupButtonSave } },
  472. { location: 'after', widget: 'button', options: { text: $G('close'), icon: 'close', clickAction: handleInsertPopupButtonClose } }
  473. ];
  474. var popupOptions = {
  475. width: '480px',
  476. height: 'auto',
  477. visible: popupWeekendSetupVisible,
  478. closeOnOutsideClick: false,
  479. //showingAction: handlePopupShowing,
  480. //shownAction: handlePopupShown,
  481. animation: utils.popup.createAnimation()
  482. };
  483. var insertPopupOptions = $.extend({}, popupOptions);
  484. insertPopupOptions.visible = popupInsertVisible;
  485. executionScheduleCalendarPopup = BWA.Popup.ExecutionScheduleCalendarPopup.create(holidayWeekendDataViewModel);
  486. return {
  487. viewShowing: handleViewShowing,
  488. viewShown: handleViewShown,
  489. viewHidden: handleViewHidden,
  490. viewDisposing: handleViewDisposing,
  491. refreshList: refreshList,
  492. popupInsertView: popupInsertView,
  493. popupOptions: popupOptions,
  494. insertPopupOptions: insertPopupOptions,
  495. holidayWeekendSetupToolbarItems: holidayWeekendSetupToolbarItems,
  496. insertHolidayToolbarItems: insertHolidayToolbarItems,
  497. dataModel: holidayWeekendDataViewModel,
  498. executionScheduleCalendarPopup: executionScheduleCalendarPopup,
  499. holidayModel: holidayModel,
  500. hasnotModificationPermission: hasnotModificationPermission
  501. };
  502. };