123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537 |
- BemsWebApplication.ExecutionScheduleCalendar = function (params, viewInfo) {
- "use strict";
- var endpointSelector;
- if (BemsWebApplication.config.mode == "production") {
- endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.production;
- } else {
- endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.local;
- }
- var eq = BWA.DataUtil.constructEqualFilter,
- and = BWA.DataUtil.andFilter,
- noteq = BWA.DataUtil.constructNotEqualFilter;
- var executionScheduleCalendarPopup = null;
- var SiteId = BWA.UserInfo.SiteId();
- var holidayDataSource = BemsWebApplication.db.createDataSource('CmHoliday', true, true);
- var holidayCustomDataSource = BemsWebApplication.db.createDataSource('CmHolidayCustom', true);
- var holidayWeekendDataSource = BemsWebApplication.db.createDataSource('CmHolidayWeekend', true);
- var checkBox_regular = true, checkBox_legal = true, checkBox_any = true;
- var useBusinessFiltering = ko.observable(false);
- var workScheduleDataSource = BWA.DataUtil.createDataSource({
- dataSourceOptions: {
- select: [
- 'SiteId', 'WorkScheduleId', 'WorkTypeId', 'BusinessFieldId', 'Title', 'FmsWorkSchedule/CycleUnitId',
- 'FmsWorkSchedule/CycleSize', 'FmsWorkSchedule/IsUse', 'FmsWorkSchedule/IsAutoOrder', 'StartWorkDate',
- 'CmUser/Name', 'CmBusinessField/Name',
- 'CmPartner/Name', 'FmsWorkSchedule/HolidayWorkTypeId'
- ],
- expand: ['FmsWorkSchedule', 'CmUser', 'CmBusinessField', 'CmPartner'],
- extendOptions: {
- forceOriginalField: true
- }
- }
- }, 'FmsWorkRequest');
- var holidaySources;
- var holidayCustomSources;
- var workScheduleSources;
- var popupWeekendSetupVisible = ko.observable(false),
- popupInsertVisible = ko.observable(false),
- hasnotModificationPermission = ko.observable(true);
- var holidayModel = {
- SiteId: ko.observable(),
- HolidayMonth: ko.observable(),
- HolidayDay: ko.observable(),
- IsLunar: ko.observable(),
- HolidayDate: ko.observable(),
- IsYearlyHoliday: ko.observable(false),
- Name: ko.observable(),
- };
- var cc = new CalendarConverter;
- var holidayWeekendDataViewModel = new BemsWebApplication.CmHolidayWeekendViewModel();
- var loadedYears = [];
- var viewDate = null;
- var currentYear = null;
- var holidays = [];
- var weekends = [];
- var isSaturday = false;
- var isSunday = false;
- var holidayCalendar = null;
- var calendarOptions = {
- selectable: true,
- editable: false,
- weekends: true,
- height: 680,
- select: handleSelectInCalendar,
- eventClick: handleEventClickInCalendar,
- changedMonth: function (view) {
- var date = view.calendar.getDate();
- viewDate = date; //hcLee 2016 03 21
- if (currentYear !== null && date.year() !== currentYear) {
- currentYear = date.year();
- check_button();
- }
- else {
- applyWeekends(date);
- }
- }
- // Tooltip 관련
- //eventMouseover: function (calEvent, jsEvent) {
- // if (!calEvent.holiday) {
- // var xOffset = 10;
- // var yOffset = 30;
- // 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;">';
- // tooltip += '신청제목: ' + calEvent.title + '<br />';
- // tooltip += '신청내용: ' + calEvent.content;
- // tooltip += '</div>';
- // $("body").append(tooltip);
- // $('.tooltipevent')
- // .css("top", (jsEvent.clientY - xOffset) + "px")
- // .css("left", (jsEvent.clientX + yOffset) + "px")
- // .fadeIn("fast");
- // }
- //},
- //eventMouseout: function (calEvent, jsEvent) {
- // $('.tooltipevent').remove();
- //}
- };
- var selectedDates = {};
- function handleSelectInCalendar(start, end) {
- //var date = start.startOf('hour');
- //var isExist = holidayCalendar.isExistEvent(date, function (i, event) {
- // utils.toast.show('이미 등록된 휴일이 있습니다.', 'error');
- //});
- //if (isExist) return;
- //selectedDates.start = start;
- //selectedDates.end = end;
- //popupInsertVisible(true);
- }
- function handleEventClickInCalendar(event) {
- if (event.holiday === true) { return; }
- event.item.CycleUnitName = $KoSet(event.item.CycleUnitName, event.item['FmsWorkCodeCycleUnit/Name']);
- event.item.BusinessFieldName = $KoSet(event.item.BusinessFieldName, event.item['CmBusinessField/Name']);
- event.item.UpdateUserName = $KoSet(event.item.UpdateUserName, event.item['CmUser/Name']);
- event.item.InspectionAgencyName = $KoSet(event.item.InspectionAgencyName, event.item['CmPartner/Name']);
- event.item.IsAutoOrder = $KoSet(event.item.IsAutoOrder, event.item['FmsWorkSchedule/IsAutoOrder']);
- if (event.item.WorkTypeId() == 1 || event.item.WorkTypeId() == 2 || event.item.WorkTypeId() == 4) {
- event.item.WorkTypevisible = true;
- var CycleSize = event.item['FmsWorkSchedule/CycleSize']();
- var CycleUnitId = event.item['FmsWorkSchedule/CycleUnitId']();
- var FmsWorkCodeCycleUnitdataSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/FmsWorkCodeCycleUnit"
- },
- requireTotalCount: true,
- pageSize: 1
- });
- FmsWorkCodeCycleUnitdataSource.filter([
- ["SiteId", "=", SiteId],
- "and",
- ["CycleUnitId", "=", CycleUnitId]
- ]);
- FmsWorkCodeCycleUnitdataSource.load()
- .done(function (result) {
- var CycleUnitName = result[0].Name;
- var dispText = CycleSize + ' ' + CycleUnitName;
- event.item.CycleSizeText = $KoSet(event.item.CycleSizeText, dispText);
- var HolidayWorkTypeId = event.item['FmsWorkSchedule/HolidayWorkTypeId']();
- var FmsWorkCodeHolidayWorkTypedataSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/FmsWorkCodeHolidayWorkType"
- },
- requireTotalCount: true,
- pageSize: 1
- });
- FmsWorkCodeHolidayWorkTypedataSource.filter([
- ["SiteId", "=", SiteId],
- "and",
- ["HolidayWorkTypeId", "=", HolidayWorkTypeId]
- ]);
- FmsWorkCodeHolidayWorkTypedataSource.load()
- .done(function (result) {
- event.item.HolidayWorkTypeName = result[0].Name;
- executionScheduleCalendarPopup.selectedWorkSchedule(event.item);
- executionScheduleCalendarPopup.show();
- })
- .fail(function (error) {
- utils.toast.show(error);
- });
- })
- .fail(function (error) {
- utils.toast.show(error);
- });
- }
- else {
- event.item.WorkTypevisible = false;
- executionScheduleCalendarPopup.selectedWorkSchedule(event.item);
- executionScheduleCalendarPopup.show();
- }
- }
- function refreshList() {
- //var date = moment();
- //loadHolidays(date);
- //hcLee 2016 03 21
- currentYear = viewDate.year();
- //loadHolidays(viewDate);
- Data_fliter(viewDate);
- }
- // hcLee 2016 10 18 추가
- var initialized = false;
- function handleViewShowing() {
- useBusinessFiltering = BWA.UserInfo.isDependBusinessField(viewInfo.viewName);
- }
- function handleViewShown() {
- $SideMenu.showSideMenuIfWill(params.view);
- if (initialized === false) { // hcLee 2016 10 18 추가
- holidayCalendar = utils.fullCalendar.create('holidayCalendar', calendarOptions);
- var date = moment();
- currentYear = date.year();
- check_button();
- }
- else
- refreshList(); // hcLee 2016 10 18 추가
- }
- function check_button() {
- $("#checkBox_regular").dxCheckBox({
- text: "정기 점검",
- value: true,
- onValueChanged: function (e) {
- switch (e.value) {
- case true:
- checkBox_regular = true;
- break;
- case false:
- checkBox_regular = false;
- break;
- }
- Data_fliter(viewDate);
- }
- });
- $("#checkBox_legal").dxCheckBox({
- text: "법정 검사",
- value: true,
- onValueChanged: function (e) {
- switch (e.value) {
- case true:
- checkBox_legal = true;
- break;
- case false:
- checkBox_legal = false;
- break;
- }
- Data_fliter(viewDate);
- }
- });
- $("#checkBox_any").dxCheckBox({
- text: "수시 점검",
- value: true,
- onValueChanged: function (e) {
- switch (e.value) {
- case true:
- checkBox_any = true;
- break;
- case false:
- checkBox_any = false;
- break;
- }
- Data_fliter(viewDate);
- }
- });
- Data_fliter(viewDate);
- }
- function Data_fliter(date) {
- workScheduleDataSource.filter([]);
- if (checkBox_regular) {//1
- if (checkBox_legal) {//2
- if (checkBox_any) {//5
- workScheduleDataSource.filter().push(["WorkTypeId", ">=", 1]);//1,2,5
- }
- else {
- workScheduleDataSource.filter().push([["WorkTypeId", "=", 1], 'or', ["WorkTypeId", "=", 2]]);//1,2
- }
- }
- else {
- if (checkBox_any) {//5
- workScheduleDataSource.filter().push([["WorkTypeId", "=", 1], 'or', ["WorkTypeId", "=", 5]]);//1,5
- }
- else {
- workScheduleDataSource.filter().push(["WorkTypeId", "=", 1]);//1
- }
- }
- }
- else {
- if (checkBox_legal) {//2
- if (checkBox_any) {//5
- workScheduleDataSource.filter().push([["WorkTypeId", "=", 2], 'or', ["WorkTypeId", "=", 5]]);//2,5
- }
- else {
- workScheduleDataSource.filter().push(["WorkTypeId", "=", 2]);//2
- }
- }
- else {
- if (checkBox_any) {//5
- workScheduleDataSource.filter().push(["WorkTypeId", "=", 5]);//5
- }
- else {
- workScheduleDataSource.filter().push(["WorkTypeId", "=", 0]);//0
- }
- }
- }
- loadHolidays(date);
- hasnotModificationPermission(!BWA.UserInfo.hasPermissionOfModification(viewInfo.viewName));
- $SearchView.setPopupVisibleObservable(null);
- initialized = true;
- }
- function refreshHolidays(date) {
- holidays = [];
- var currentYear = date.year();
- if (loadedYears.indexOf(currentYear) < 0) {
- loadedYears.push(currentYear);
- var year;
- var month;
- var day;
- var solar;
- $.each(holidaySources, function (i, item) {
- year = currentYear;
- month = item.HolidayMonth() - 1;
- day = item.HolidayDay();
- if (item.IsLunar()) {
- solar = cc.lunar2solar(new Date(year - 1, month, day));
- if (solar.sYear !== year) {
- solar = cc.lunar2solar(new Date(year, month, day));
- }
- year = solar.sYear;
- month = solar.sMonth - 1;
- day = solar.sDay;
- }
- utils.holiday.pushHolidayEventInArray(holidays, item.Name(), moment([year, month, day]), true, undefined, 0);
- });
- $.each(holidayCustomSources, function (i, item) {
- var itemDate = item.HolidayDate();
- if (itemDate.getFullYear() === currentYear) {
- utils.holiday.pushHolidayEventInArray(holidays, item.Name(), moment([itemDate.getFullYear(), itemDate.getMonth(), itemDate.getDate()]), false, undefined, 1);
- }
- });
- $.each(workScheduleSources, function (i, item) {
- var itemDate = item.StartWorkDate();//추가
- item.Name = item.Title;
- if (itemDate.getFullYear() === currentYear) {
- utils.holiday.pushWorkScheduleEventInArray(holidays, item, moment([itemDate.getFullYear(), itemDate.getMonth(), itemDate.getDate()]), false, undefined, 1);
- }
- });
- }
- applyWeekends(date);
- }
- function loadHolidays(date) {
- holidays = [];
- loadedYears = [];
- if (!useBusinessFiltering) {
- workScheduleDataSource.filter().push("and", eq("WorkProgressId", $Code.WorkProgress.WORK_PLAN), "and", eq("SiteId", SiteId));
- } else {
- workScheduleDataSource.filter().push("and", eq("WorkProgressId", $Code.WorkProgress.WORK_PLAN), "and", eq("SiteId", SiteId), "and",
- [eq('BusinessFieldId', BWA.UserInfo.BusinessFieldId()), 'or', eq('BusinessFieldId', 1)]);
- }
- $.when(
- holidayDataSource.load(),
- holidayCustomDataSource.load(),
- holidayWeekendDataSource.load(),
- workScheduleDataSource.load())//수정
- .done(function (result1, result2, result3, result4) {
- holidaySources = result1[0];
- holidayCustomSources = result2[0];
- var tempworkScheduleSources = result4[0];
- workScheduleSources = [];
- for (var i = 0; i < tempworkScheduleSources.length; i++) {
- if (tempworkScheduleSources[i].WorkTypeId() <= $Code.WorkType.LEGAL_CHECK) {
- if (tempworkScheduleSources[i]['FmsWorkSchedule/IsUse']() == true)
- workScheduleSources.push(tempworkScheduleSources[i]);
- }
- else {
- workScheduleSources.push(tempworkScheduleSources[i]);
- }
- }
- if (result3.length > 0) {
- var weekend = result3[0][0];
- isSaturday = weekend.Saturday();
- isSunday = weekend.Sunday();
- holidayWeekendDataViewModel.SiteId(weekend.SiteId());
- holidayWeekendDataViewModel.Saturday(weekend.Saturday());
- holidayWeekendDataViewModel.Sunday(weekend.Sunday());
- }
- refreshHolidays(date);
- });
- }
- function applyWeekends(date) {
- if (holidayCalendar === null) return;
- if (isSunday == false && isSaturday == false) {
- holidayCalendar.updateEvents(holidays);
- return;
- }
- weekends = utils.holiday.getWeekendHolidays(date, isSaturday, isSunday);
- //var month = date.clone().startOf( 'month' );
- //var sunday = month.clone(),
- // saturday = month.clone();
- //weekends = [];
- //if( month.day() !== 0 ) {
- // sunday.day( -7 );
- //}
- //if( month.day() !== 6 ) {
- // saturday.day( -1 );
- //}
- //for( var i = 0 ; i < 7 ; i++ ) {
- // if( isSunday ) {
- // holidayCalendar.pushEventInArray( weekends, '주말 휴일', moment( [ sunday.year(), sunday.month(), sunday.date() ], null, true, 2 ));
- // sunday.day( 7 );
- // }
- // if( isSaturday ) {
- // holidayCalendar.pushEventInArray( weekends, '주말 휴일', moment( [ saturday.year(), saturday.month(), saturday.date() ], null, true, 2 ));
- // saturday.day( 13 );
- // }
- //}
- holidayCalendar.updateEvents(holidays.concat(weekends));
- }
- function handleModification() {
- //shouldReload = true;
- }
- function handleViewHidden() {
- holidayCalendar.clearEvents(true);
- }
- function handleViewDisposing() {
- BemsWebApplication.db.CmHolidayWeekend.modified.remove(handleModification);
- }
- BemsWebApplication.db.CmHolidayWeekend.modified.add(handleModification);
- function popupInsertView() {
- popupWeekendSetupVisible(true);
- }
- function handleWeekendSetupPopupButtonSave() {
- BemsWebApplication.db.CmHolidayWeekend.update(SiteId, holidayWeekendDataViewModel.toJS()).done(function () {
- refreshList();
- utils.toast.show('데이터베이스 항목 수정 작업이 성공하였습니다.');
- popupWeekendSetupVisible(false);
- });
- }
- function handleWeekendPopupButtonClose() {
- popupWeekendSetupVisible(false);
- }
- function handleInsertPopupButtonSave() {
- var dbModelId;
- var dataViewModel;
- var selectedDate = selectedDates.start;
- if (holidayModel.IsYearlyHoliday()) {
- dbModelId = 'CmHoliday';
- dataViewModel = new BemsWebApplication.CmHolidayViewModel();
- }
- else {
- dbModelId = 'CmHolidayCustom';
- dataViewModel = new BemsWebApplication.CmHolidayCustomViewModel();
- }
- var promised = {};
- for (selectedDate = selectedDates.start ; selectedDate.isSame(selectedDates.end) === false ; selectedDate.add(1, 'days')) {
- if (holidayModel.IsYearlyHoliday()) {
- dataViewModel.IsLunar(holidayModel.IsLunar());
- var month = selectedDate.month() + 1,
- date = selectedDate.date();
- if (holidayModel.IsLunar()) {
- var lunar = cc.solar2lunar(new Date(selectedDate.year(), month - 1, date));
- month = lunar.lMonth;
- date = lunar.lDay;
- }
- console.log(month + ' ' + date);
- dataViewModel.HolidayMonth(month);
- dataViewModel.HolidayDay(date);
- }
- else {
- dataViewModel.HolidayDate(new Date(selectedDate.year(), selectedDate.month(), selectedDate.date()));
- }
- dataViewModel.SiteId(SiteId);
- dataViewModel.Name(holidayModel.Name());
- dataViewModel.IsUse(true);
- promised = BemsWebApplication.db[dbModelId].insert(dataViewModel.toJS());
- }
- promised.done(function (values, newId) {
- popupInsertVisible(false);
- refreshList();
- utils.toast.show('휴일 등록 작업이 성공하였습니다.');
- }).fail(function () {
- popupInsertVisible(false);
- refreshList();
- });
- }
- function handleInsertPopupButtonClose() {
- popupInsertVisible(false);
- }
- var holidayWeekendSetupToolbarItems = [
- { location: 'before', text: '주말 휴일 설정' },
- { location: 'after', widget: 'button', options: { text: $G('save'), icon: 'save', clickAction: handleWeekendSetupPopupButtonSave } },
- { location: 'after', widget: 'button', options: { text: $G('close'), icon: 'close', clickAction: handleWeekendPopupButtonClose } }
- ];
- var insertHolidayToolbarItems = [
- { location: 'before', text: '주말 휴일 설정' },
- { location: 'after', widget: 'button', options: { text: $G('save'), icon: 'save', clickAction: handleInsertPopupButtonSave } },
- { location: 'after', widget: 'button', options: { text: $G('close'), icon: 'close', clickAction: handleInsertPopupButtonClose } }
- ];
- var popupOptions = {
- width: '480px',
- height: 'auto',
- visible: popupWeekendSetupVisible,
- closeOnOutsideClick: false,
- //showingAction: handlePopupShowing,
- //shownAction: handlePopupShown,
- animation: utils.popup.createAnimation()
- };
- var insertPopupOptions = $.extend({}, popupOptions);
- insertPopupOptions.visible = popupInsertVisible;
- executionScheduleCalendarPopup = BWA.Popup.ExecutionScheduleCalendarPopup.create(holidayWeekendDataViewModel);
- return {
- viewShowing: handleViewShowing,
- viewShown: handleViewShown,
- viewHidden: handleViewHidden,
- viewDisposing: handleViewDisposing,
- refreshList: refreshList,
- popupInsertView: popupInsertView,
- popupOptions: popupOptions,
- insertPopupOptions: insertPopupOptions,
- holidayWeekendSetupToolbarItems: holidayWeekendSetupToolbarItems,
- insertHolidayToolbarItems: insertHolidayToolbarItems,
- dataModel: holidayWeekendDataViewModel,
- executionScheduleCalendarPopup: executionScheduleCalendarPopup,
- holidayModel: holidayModel,
- hasnotModificationPermission: hasnotModificationPermission
- };
- };
|