123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556 |
- BemsWebApplication.ConstructionPlan = function (params, viewInfo) {
- "use strict";
- var imagefileUrl1 = ko.observable(),
- imagefileUrl2 = ko.observable(),
- uploadedFileInfo = {},
- //hcLee 2016 03 23
- uploadedFileInfo2 = {},
- dropZone1 = null,
- dropZone2 = null;
- var FmsConstructionDataSource = BemsWebApplication.db.createDataSource('FmsConstruction');
- var ConstructionInfo = ko.observableArray();
- var RowName;
- var eq = BWA.DataUtil.constructEqualFilter,
- and = BWA.DataUtil.andFilter,
- noteq = BWA.DataUtil.constructNotEqualFilter;
- var isEditModeInPopup = ko.observable(false);
- // 공사업체 데이터 소스...
- var partnerDataSource = BemsWebApplication.db.createDataSource('CmPartner', true, false, true),
- constructionTypeDataSource = BemsWebApplication.db.createDataSource('FmsConstructionCodeType', true, false, true),
- progressDataSource = BemsWebApplication.db.createDataSource('FmsConstructionCodeProgress');
- var partners = ko.observableArray(),
- constructionTypes = ko.observableArray(),
- dbProgresses = ko.observableArray();
- var constructionTypesForSearch = ko.observableArray(),
- partnerTypesForSearch = ko.observableArray();
- var deferredForSearch = new $.Deferred();
- var dataSourceOptions = {
- select: [
- 'SiteId',
- 'ConstructionId',
- 'ConstructionTypeId',
- 'Name',
- 'StartDate',
- 'EndDate',
- 'PartnerId',
- 'ConstructLocation',
- 'OwnerShipName',
- 'CommitmentMan',
- 'OwnerShipPhoneNo',
- 'WeldWorkStartTime',
- 'WeldWorkEndTime',
- 'GasWorkStartTime',
- 'GasWorkEndTime',
- 'PaintWorkStartTime',
- 'PaintWorkEndTime',
- 'Comment',
- 'ProgressId',
- 'AddDate',
- 'UpdateDate',
- 'FmsConstructionCodeProgress/Name',
- 'CmPartner/Name',
- 'CmPartner/PhoneNo',
- 'FmsConstructionCodeType/Name',
- 'ConstructionDetail',
- 'InOutStockName',
- 'FileId1',
- 'FileId2',
- 'FileId3',
- 'CmFile/Name',
- 'CmFile1/Name',
- 'CmFile2/Name'
- ],
- expand: [
- 'FmsConstructionCodeProgress',
- 'CmPartner',
- 'FmsConstructionEstimation',
- 'FmsConstructionCodeType',
- 'CmFile',
- 'CmFile1',
- 'CmFile2'
- ],
- extendOptions: {
- forceOriginalField: true
- },
- filter: [
- eq('SiteId', BWA.UserInfo.SiteId()),
- 'and',
- ['ProgressId', '<', 3] // 공사진행단계 항목 까지만 가져옴
- ]
- };
- function setupDropZone(isEditModeInPopup, dataViewModel) {//2019-11-18 변경
- var timer = null;
- isEditModeInPopup.subscribe(function (value) {
- if (value) {
- if (timer) { clearInterval(timer); }
- timer = setInterval(function () {
- if ($('#constructionDropZone1').length) {
- if (_.isNull(dropZone1)) {
- dropZone1 = BWA.DropZone.create({
- id: '#constructionDropZone1',
- categoryId: $Code.FileCategory.CONSTRUCTION,
- uploadedFileInfo: uploadedFileInfo,
- handleRemoveBeforePromise: function () {
- var keys = BWA.db.extractKeysObject('FmsConstruction', dataViewModel);
- return BWA.db.FmsConstruction.update(keys, { FileId1: null });
- },
- handleSuccess: function (fileInfo) {
- if (uploadedFileInfo.FileId) {
- dataViewModel.FileId1(fileInfo.FileId);
- var keys = BWA.db.extractKeysObject('FmsConstruction', dataViewModel);
- if (keys.ConstructionId != null) {
- return BWA.db.FmsConstruction.update(keys, { FileId1: fileInfo.FileId })
- .done(function (res) {
- $('#gridContainer').dxDataGrid('instance').refresh();
- });
- }
- }
- },
- handleRemovedFile: function () {
- dataViewModel.FileId1(null);
- },
- });
- }
- }
- if ($('#constructionDropZone2').length) {
- if (_.isNull(dropZone2)) {
- dropZone2 = BWA.DropZone.create({
- id: '#constructionDropZone2',
- categoryId: $Code.FileCategory.CONSTRUCTION,
- uploadedFileInfo: uploadedFileInfo2,
- handleRemoveBeforePromise: function () {
- var keys = BWA.db.extractKeysObject('FmsConstruction', dataViewModel);
- return BWA.db.FmsConstruction.update(keys, { FileId2: null });
- },
- handleSuccess: function (fileInfo) {
- if (uploadedFileInfo2.FileId) {
- dataViewModel.FileId2(fileInfo.FileId);
- var keys = BWA.db.extractKeysObject('FmsConstruction', dataViewModel);
- if (keys.ConstructionId != null) {
- return BWA.db.FmsConstruction.update(keys, { FileId2: fileInfo.FileId })
- .done(function (res) {
- $('#gridContainer').dxDataGrid('instance').refresh();
- });
- }
- }
- },
- handleRemovedFile: function () {
- dataViewModel.FileId2(null);
- },
- });
- }
- }
- }, 100);
- }
- else {
- if (timer) {
- clearInterval(timer);
- timer = null;
- }
- dropZone1 = null;
- dropZone2 = null;
- }
- });
- }
- var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'FmsConstruction', {
- dataSourceOptions: dataSourceOptions,
- columns: [
- { dataField: 'Number', caption: $G('number'), width: '10%', alignment: 'center' },
- { dataField: 'FmsConstructionCodeType/Name', caption: '공사구분', width: '20%', alignment: 'center' },
- { dataField: 'Name', caption: '공사명', width: '80%', alignment: 'center' },
- { dataField: 'ConstructLocation', caption: '공사위치', width: '30%', alignment: 'center' },
- { dataField: 'CmPartner/Name', caption: '공사업체', width: '20%', alignment: 'center' },
- { dataField: 'OwnerShipName', caption: '공사책임자', width: '20%', alignment: 'center' },
- {
- dataField: 'StartDate', caption: '시작일', width: '20%', alignment: 'center',
- customizeText: function (cellInfo) { return $G.date(cellInfo.value); }
- },
- {
- dataField: 'EndDate', caption: '종료일', width: '20%', alignment: 'center',
- customizeText: function (cellInfo) { return $G.date(cellInfo.value); }
- },
- ],
- popupWidth: '900px',
- // jks-2015-12-30 팝업넓이조절
- //popupWidth: '740px',
- promiseDataInSearchView: deferredForSearch.promise(),
- searchViewItems: [
- { id: 'Name' },
- { id: 'ConstructionTypeId', ignoreValue: 0, defaultValue: 0, dataSource: constructionTypesForSearch },
- { id: 'PartnerId', ignoreValue: 0, defaultValue: 0, dataSource: partnerTypesForSearch },
- { id: 'StartDate', type: 'dateRange', isOnlyDate: true },
- { id: 'EndDate', type: 'dateRange', isOnlyDate: true }
- ],
- beforeInsertingDataViewModel: function (dataModel, dbModelId) {
- var dfd = $.Deferred();
- if (dataModel.StartDate() > dataModel.EndDate()) {
- return dfd.resolve(false, '시작일은 종료일 이전으로 선택해야 합니다.');
- }
- if (dataModel.WeldWorkStartTime() > dataModel.WeldWorkEndTime()) {
- return dfd.resolve(false, '용접작업시작시간은 용접작업종료시간 이전으로 선택해야 합니다.');
- }
- if (dataModel.GasWorkStartTime() > dataModel.GasWorkEndTime()) {
- return dfd.resolve(false, '가스공사시작시간은 가스공사종료시간 이전으로 선택해야 합니다.');
- }
- if (dataModel.PaintWorkStartTime() > dataModel.PaintWorkEndTime()) {
- return dfd.resolve(false, '도장작업시작시간은 도장작업종료시간 이전으로 선택해야 합니다.');
- } else {
- var isDuplicated = false;
- for (var i = 0; i < ConstructionInfo().length; i++) {
- if (dataModel.Name() == ConstructionInfo()[i].Name()) {
- isDuplicated = true;
- }
- }
-
- if (isDuplicated)
- return dfd.resolve(false, '이미 동일 이름이 존재합니다.');
- else
- return dfd.resolve(true);
- }
- },
- beforeUpdateDataViewModel: function () {
- var dataModel = viewModel.dataModel;
- if (dataModel.StartDate() > dataModel.EndDate()) {
- utils.toast.show('시작일은 종료일 이전으로 선택해야 합니다.', 'error');
- return 0;
- }
- if (dataModel.WeldWorkStartTime() > dataModel.WeldWorkEndTime()) {
- utils.toast.show('용접작업시작시간은 용접작업종료시간 이전으로 선택해야 합니다.', 'error');
- return 0;
- }
- if (dataModel.GasWorkStartTime() > dataModel.GasWorkEndTime()) {
- utils.toast.show('가스공사시작시간은 가스공사종료시간 이전으로 선택해야 합니다.', 'error');
- return 0;
- }
- if (dataModel.PaintWorkStartTime() > dataModel.PaintWorkEndTime()) {
- utils.toast.show('도장작업시작시간은 도장작업종료시간 이전으로 선택해야 합니다.', 'error');
- return 0;
- } else {
- if (dataModel.WeldWorkStartTime() != null) {
- dataModel.WeldWorkStartTime().setSeconds(0);
- }
- if (dataModel.WeldWorkEndTime() != null) {
- dataModel.WeldWorkEndTime().setSeconds(0);
- }
- if (dataModel.GasWorkStartTime() != null) {
- dataModel.GasWorkStartTime().setSeconds(0);
- }
- if (dataModel.GasWorkEndTime() != null) {
- dataModel.GasWorkEndTime().setSeconds(0);
- }
- if (dataModel.PaintWorkStartTime() != null) {
- dataModel.PaintWorkStartTime().setSeconds(0);
- }
- if (dataModel.PaintWorkEndTime() != null) {
- dataModel.PaintWorkEndTime().setSeconds(0);
- }
- }
- var isDuplicated = false;
- for (var i = 0; i < ConstructionInfo().length; i++) {
- if (viewModel.dataModel.Name() == ConstructionInfo()[i].Name() && RowName() != ConstructionInfo()[i].Name()) {
- isDuplicated = true;
- }
- }
- if (!BWA.DataUtil.isValidInputValue(viewModel.dataModel.Name())) {
- utils.toast.show('저장 혹은 수정 반드시 필수 입력 정보를 모두 입력하셔야 합니다 (앞뒤공백 허용안함)', 'error');
- return 0;
- }
- else {
- if (isDuplicated) {
- utils.toast.show('이미 동일 이름이 존재합니다.', 'error');
- return 0;
- }
- else
- return 2;
- }
- },
- handleAfterSaveInPopup: function (responseKey, response) {//2019-11-18 변경
- viewModel.dataModel.ConstructionId(responseKey.ConstructionId);
- },
- handleSaveButtonInPopup: function (isInsert) {//2019-11-18 변경
- if (isInsert === false) {//추가, 변경 여부
- if (_.isNull(dropZone1) === false) {
- if (viewModel.dataModel.FileId1() != null) { //변경 - 그림삭제
- var temp1 = {
- SiteId: BWA.UserInfo.SiteId(),
- FileId: viewModel.dataModel.FileId1()
- }
- BWA.db.CmFile.byKey(temp1).done(function (data) {
- dropZone1.removeFile(data);
- dropZone1.processQueue();
- });
- }
- else {
- dropZone1.processQueue();//변경 - 그림 삭제 필요없음
- }
- }
- }
- else {
- if (_.isNull(dropZone1) === false) { //추가
- if (viewModel.dataModel.FileId1() == null) {
- dropZone1.processQueue();
- }
- }
- }
- if (isInsert === false) {//추가, 변경 여부
- if (_.isNull(dropZone2) === false) {
- if (viewModel.dataModel.FileId2() != null) { //변경 - 그림삭제
- var temp2 = {
- SiteId: BWA.UserInfo.SiteId(),
- FileId: viewModel.dataModel.FileId2()
- }
- BWA.db.CmFile.byKey(temp2).done(function (data) {
- dropZone2.removeFile(data);
- dropZone2.processQueue();
- });
- }
- else {
- dropZone2.processQueue();//변경 - 그림 삭제 필요없음
- }
- }
- }
- else {
- if (_.isNull(dropZone2) === false) { //추가
- if (viewModel.dataModel.FileId2() == null) {
- dropZone2.processQueue();
- }
- }
- }
- },
- handleBeforeDelete: function () {//2019-11-18 변경
- var temp1 = {
- SiteId: BWA.UserInfo.SiteId(),
- FileId: viewModel.dataModel.FileId1()
- }
- if (temp1.FileId != null) {
- BWA.db.CmFile.byKey(temp1).done(function (data) {
- if ($('#constructionDropZone3').length) {
- if (_.isNull(dropZone1)) {
- dropZone1 = BWA.DropZone.create({
- id: '#constructionDropZone3',
- categoryId: $Code.FileCategory.CONSTRUCTION
- });
- dropZone1.removeFile(data);
- dropZone1 = null;
- }
- }
- });
- }
- var temp2 = {
- SiteId: BWA.UserInfo.SiteId(),
- FileId: viewModel.dataModel.FileId2()
- }
- if (temp2.FileId != null) {
- BWA.db.CmFile.byKey(temp2).done(function (data) {
- if ($('#constructionDropZone4').length) {
- if (_.isNull(dropZone2)) {
- dropZone2 = BWA.DropZone.create({
- id: '#constructionDropZone4',
- categoryId: $Code.FileCategory.CONSTRUCTION
- });
- dropZone2.removeFile(data);
- dropZone2 = null;
- }
- }
- });
- }
- },
- handleAfterLoadingModelByKey: function (data, dataViewModel, isNewInPopup) {
- if (isNewInPopup() == false) {
- if (_.isNull(dataViewModel.FileId1()) === false) {
- imagefileUrl1('{0}/CmFile(SiteId={1},FileId={2})/$value'.formati(BWA.db._url, dataViewModel.SiteId(), dataViewModel.FileId1()));
- }
- else {
- imagefileUrl1(undefined);
- }
- if (_.isNull(dataViewModel.FileId2()) === false) {
- imagefileUrl2('{0}/CmFile(SiteId={1},FileId={2})/$value'.formati(BWA.db._url, dataViewModel.SiteId(), dataViewModel.FileId2()));
- }
- else {
- imagefileUrl2(undefined);
- }
- //var keys = BWA.db.extractKeysObject('FmsConstruction', dataViewModel);
- //BWA.db.FmsConstruction.update(keys, dataViewModel.toJS());
- }
- },
-
- handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {
- dataGrid.clearSelection();
- var data = clickRow.data;
- var dataModel = viewModel.dataModel;
-
- RowName = data.Name;
- //dataModel.PartnerName = data['CmPartner/Name']();
- //dataModel.PartnerPhoneNo = data['CmPartner/PhoneNo']();
- dataModel.PartnerName = $KoSet(dataModel.PartnerName, data['CmPartner/Name']());
- //dataModel.PartnerPhoneNo = $KoSet(dataModel.PartnerPhoneNo, data['CmPartner/PhoneNo']());
- dataModel.ConstructionTypeName = $KoSet(dataModel.ConstructionTypeName, data['FmsConstructionCodeType/Name']());
- dataModel.ProgressName = $KoSet(dataModel.ProgressName, data['FmsConstructionCodeProgress/Name']());
- if (data['FileId1']() != null)
- dataModel.AttachmentFileName1(data['CmFile/Name']());
- else dataModel.AttachmentFileName1('');
- if (data['FileId2']() != null)
- dataModel.AttachmentFileName2(data['CmFile1/Name']());
- else dataModel.AttachmentFileName2('');
- popupVisible(true);
- },
- // hcLee 2016 02 01
- handlePopupButtonEdit: function (dataModel) {
- isEditModeInPopup(true);
- },
- handleViewShowing: function (dataModel) {
- partnerDataSource.filter([
- eq('SiteId', BWA.UserInfo.SiteId()), // 공사업체 유형 필터링
- 'and',
- eq('PartnerTypeId', 1)]);
- constructionTypeDataSource.filter([
- eq('SiteId', BWA.UserInfo.SiteId()) // 공사업체 유형 필터링
- ]);
- progressDataSource.filter([
- eq('ProgressId', 2),
- 'or',
- eq('ProgressId', 3),
- ]);
- $.when(
- partnerDataSource.load(),
- constructionTypeDataSource.load(),
- progressDataSource.load()
- )
- .done(function (dbPartners, dbConstructions, dbProgress) {
- partners(dbPartners[0]);
- constructionTypes(dbConstructions[0]);
- dbProgresses(dbProgress[0]);
- constructionTypesForSearch($SearchView.createArrayOfSelectBox('ConstructionTypeId', constructionTypes()));
- partnerTypesForSearch($SearchView.createArrayOfSelectBox('PartnerId', partners()));
- deferredForSearch.resolve();
- });
- },
- handleViewShown: function (dataViewModel, isEditModeInPopup) {
- setupDropZone(isEditModeInPopup, dataViewModel);
- },
- handleCancelInPopup: function () {
- isEditModeInPopup(false);
- },
- handlePopupButtonClose: function () {
- isEditModeInPopup(false);
- },
- handleSaveSuccess: function () {
- if (_.isNull(dropZone1) === false) {
- dropZone1.resetUploadedFileInfo();
- }
- if (_.isNull(dropZone2) === false) {
- dropZone2.resetUploadedFileInfo();
- }
- isEditModeInPopup(false);
- },
- // hcLee 2016 03 23
- handlePopupShowing: function (isEditMode, isNew, dataViewModel) {
- imagefileUrl1(undefined);
- imagefileUrl2(undefined);
- if (_.isNull(dropZone1) === false) dropZone1.resetUploadedFileInfo();
- if (_.isNull(dropZone2) === false) dropZone2.resetUploadedFileInfo();
- if (isNew) { // 신규등록인 경우
- dropZone1 = null;
- dropZone2 = null;
- }
-
- // 이름 중복 방지
- FmsConstructionDataSource.filter([
- ['SiteId', '=', BWA.UserInfo.SiteId()],
- 'and',
- [ 'ProgressId', '<', 3]
- ]);
- FmsConstructionDataSource.load().done(function (result) {
- ConstructionInfo(result);
- });
- },
- handlePopupShown: function (isEditMode, isNew, dataViewModel) {
- //handlePopupShowing: function (isEditMode, isNew, dataViewModel) {
- var partners = viewModel.partners();
- var constructionTypes = viewModel.constructionTypes();
- /*
- imagefileUrl1(undefined);
- imagefileUrl2(undefined);
- if (_.isNull(dropZone1) === false) dropZone1.resetUploadedFileInfo();
- if (_.isNull(dropZone2) === false) dropZone2.resetUploadedFileInfo();
- */
- isEditModeInPopup(false);
- if (isNew) { // 신규등록인 경우
- isEditModeInPopup(true);
- dataViewModel.ProgressId(2); // 공사계획 상태를 '진행' 단계로 초기화
- dataViewModel.AddDate($G.date(new Date()));
- dataViewModel.UpdateDate($G.date(new Date()));
- if (!_.isEmpty(partners)) {
- dataViewModel.PartnerId(partners[0].PartnerId());
- }
- if (!_.isEmpty(constructionTypes)) {
- dataViewModel.ConstructionTypeId(constructionTypes[0].ConstructionTypeId());
- }
- }
- }
- });
- viewModel.imagefileUrl1 = imagefileUrl1;
- viewModel.imagefileUrl2 = imagefileUrl2;
- viewModel.isEditModeInPopup = isEditModeInPopup;
- viewModel.constructionTypes = constructionTypes;
- viewModel.partners = partners;
- viewModel.dbProgresses = dbProgresses;
- viewModel.dataModel.ConstructionTypeName = ko.observable();
- viewModel.dataModel.PartnerName = ko.observable();
- //viewModel.dataModel.PartnerPhoneNo = ko.observable();
- viewModel.dataModel.ProgressName = ko.observable();
- viewModel.dataModel.AttachmentFileName1 = ko.observable();
- viewModel.dataModel.AttachmentFileName2 = ko.observable();
- viewModel.dataModel.AttachmentFileName3 = ko.observable();
- viewModel.dataModel.ProgressId.subscribe(function () {
- if (viewModel.dataModel.ProgressId() == 3) {
- viewModel.dataModel.EndDate(new Date());
- }
- });
- return viewModel;
- };
|