123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400 |
- BemsWebApplication.Drawing = function (params, viewInfo) {
- "use strict";
- //2019-11-25 변경
- var dropZone = null;
- var eq = BWA.DataUtil.constructEqualFilter;
- var and = BWA.DataUtil.andFilter;
- var drawingHistory;
- var historyViewModel = new BemsWebApplication.FmsDrawingHistoryViewModel();
- //2019-11-25 변경
- var drawingGroupDataSource = BemsWebApplication.db.createDataSource('FmsDrawingCodeGroup', true),
- drawingTypeDataSource = BemsWebApplication.db.createDataSource('FmsDrawingCodeType', true),
- drawingHistoryDataSource = BemsWebApplication.DataUtil.createDataSource({
- dataSourceOptions: {
- select: [
- 'SiteId', 'DrawingId', 'HistoryId', 'FileId', 'Description', 'RevisionNo',
- 'UpdatedDate', 'UpdatedUserId',
- 'CmFile/Name', 'CmFile/FileSize', 'CmUser/Name'
- ],
- expand: ['CmFile', 'CmUser'],
- extendOptions: {
- forceOriginalField: true
- }
- }
- }, 'FmsDrawingHistory');
- var drawingHistories = ko.observableArray(),
- drawingGroups = ko.observableArray(),
- drawingTypes = ko.observableArray(),
- drawingGroupsForSearch = ko.observableArray(),
- drawingTypesForSearch = ko.observableArray(),
- tabsVisible = ko.observable(false),
- textAreaNoteHeightInPopup = ko.observable(340),
- isVisibleHistoryInsertButton = ko.observable(false),
- uploadedFileInfo = {},
- drawingHistoryPopup,
- deferredForSearch = new $.Deferred();
- params.popupPosition = { offset: '-200 0' };
- var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'FmsDrawing', {
- popupWidth: 720,
- dataSourceOptions: {
- select: [
- 'SiteId', 'DrawingId', 'DrawingNo', 'Name', 'DrawingGroupId', 'DrawingTypeId',
- 'FmsDrawingCodeGroup/Name', 'FmsDrawingCodeType/Name'
- ],
- expand: ['FmsDrawingCodeGroup', 'FmsDrawingCodeType'],
- extendOptions: {
- forceOriginalField: true
- }
- },
- columns: [
- { dataField: 'DrawingId', caption: '번호', width: '10%', alignment: 'center', sortOrder: 'desc' },
- { dataField: 'FmsDrawingCodeGroup/Name', caption: $G('drawingGroup'), width: '15%', alignment: 'center' },
- { dataField: 'FmsDrawingCodeType/Name', caption: $G('drawingType'), width: '15%', alignment: 'center' },
- { dataField: 'DrawingNo', caption: $G('drawingNumber'), width: '25%', alignment: 'center' },
- { dataField: 'Name', caption: $G('drawingName'), width: '35%', alignment: 'center' }
- ],
- searchViewItems: [
- { id: 'DrawingGroupId', ignoreValue: 0, defaultValue: 0, dataSource: drawingGroupsForSearch },
- { id: 'DrawingTypeId', ignoreValue: 0, defaultValue: 0, dataSource: drawingTypesForSearch },
- { id: 'Name' }
- ],
- getAddedToolbarItemsInPopup: function (e) {
- var isEditModeInPopup = e.isEditModeInPopup,
- hasnotModificationPermission = e.hasnotModificationPermission;
- isEditModeInPopup.subscribe(function (isEditMode) {
- tabIndex(0); // 왼쪽 수정은 무조건 매뉴얼 hcLee 2016 03 28추가
- isVisibleHistoryInsertButton(tabIndex() === 1 && isEditMode);
- });
- return [
- {
- location: 'after',
- widget: 'button',
- options: {
- text: $G('drawingHistoryInsert'),
- icon: 'plus',
- visible: isVisibleHistoryInsertButton,
- disabled: hasnotModificationPermission,
- clickAction: function () {
- drawingHistoryPopup.handleInsertDrawingHistory();
- }
- }
- },
- ]
- },
- promiseDataInSearchView: deferredForSearch.promise(),
- handlePopupShowing: function (isNewInPopup) {
- tabIndex(0);
- tabsVisible(isNewInPopup() == false);
- },
- // hcLee 2016 03 28
- beforeInsertingDataViewModel: function (dataModel, dbModelId) {
- var dfd = $.Deferred();
- if (dataModel.DrawingGroupId() == null || dataModel.DrawingTypeId() == null || dataModel.DrawingNo() == null || dataModel.Name() == null ||
- drawingFileUpload.dropzone.files.length == 0)//2019-11-25 변경
- dfd.resolve(false, '(*) 표시 항목은 필수 입력 사항 입니다!');
- return dfd.resolve(true);
- },
- handleAfterSaveInPopup: function (responseKey, response) {
- var fileId = uploadedFileInfo.FileId;
- if (_.isUndefined(fileId)) return;
- var dataViewModel = viewModel.dataModel;//2019-11-25 변경
- drawingHistory = new BWA.FmsDrawingHistoryViewModel();
- drawingHistory.SiteId(responseKey.SiteId);
- drawingHistory.DrawingId(responseKey.DrawingId);
- drawingHistory.FileId(fileId);
- drawingHistory.RevisionNo(0); // 2016 03 10 hcLee 추가
- drawingHistory.UpdatedDate(new Date());
- drawingHistory.UpdatedUserId(BWA.UserInfo.UserId());
- //2019-11-25 변경
- if (viewModel.isNewInPopup() === false) {//추가, 변경 여부
- if (_.isNull(dropZone) === false) {
- if (drawingHistory.FileId() != null) { //변경 - 그림삭제
- var temp = {
- SiteId: BWA.UserInfo.SiteId(),
- FileId: drawingHistory.FileId()
- }
- BWA.db.CmFile.byKey(temp).done(function (data) {
- dropZone.removeFile(data);
- dropZone.processQueue();
- });
- }
- else {
- dropZone.processQueue();//변경 - 그림 삭제 필요없음
- }
- }
- }
- else {
- if (_.isNull(dropZone) === false) { //추가
- if (drawingHistory.FileId() == null) {
- dropZone.processQueue();
- }
- }
- }
- BWA.db.FmsDrawingHistory.insert(drawingHistory.toJS()).done(function (res) {
- });
- },
- //2019-11-25 변경
- handleBeforeDelete: function () {
- for (var i = 0; i < drawingHistories().length; i++) {
- var temp1 = {
- SiteId: BWA.UserInfo.SiteId(),
- FileId: drawingHistories()[i].FileId()
- }
- if (temp1.FileId != null) {
- BWA.db.CmFile.byKey(temp1).done(function (data) {
- if (_.isNull(dropZone)) {
- dropZone = BWA.DropZone.create({
- id: '#drawingFileUpload1',
- categoryId: $Code.FileCategory.DRAWING
- });
- }
- dropZone.removeFile(data);
- });
- }
- if (i == drawingHistories().length) {
- dropZone = null;
- }
- }
- },
- //2019-11-25 변경
- handlePopupShown: function (isEditModeInPopup, isNewInPopup, dataViewModel) {
- if (isNewInPopup) {
- uploadedFileInfo.FileId = null;
- textAreaNoteHeightInPopup(170);
- dropZone = BWA.DropZone.create({
- categoryId: $Code.FileCategory.DRAWING,
- id: '#drawingFileUpload',
- uploadedFileInfo: uploadedFileInfo,
- maxFiles: 1,
- handleSuccess: function (fileInfo) {
- if (uploadedFileInfo.FileId) {
- historyViewModel.FileId(fileInfo.FileId);
- drawingHistoryDataSource.filter([
- eq('SiteId', BWA.UserInfo.SiteId()),
- and,
- eq('DrawingId', drawingHistory.DrawingId())
- ]);
- drawingHistoryDataSource.load().done(function (histories) {
- drawingHistories(histories);
- if (drawingHistories()[0].HistoryId() != null) {
- return BWA.db.FmsDrawingHistory.update({ SiteId: drawingHistories()[0].SiteId(), HistoryId: drawingHistories()[0].HistoryId(), DrawingId: drawingHistories()[0].DrawingId() }, { FileId: fileInfo.FileId })
- .done(function (res) {
- $('#gridContainer').dxDataGrid('instance').refresh();
- });
- }
- });
- }
- },
- handleRemovedFile: function () {
- historyViewModel.FileId(null);
- }
- });
- }
- else {
- textAreaNoteHeightInPopup(340);
- reloadDrawingHistory(dataViewModel.DrawingId());
- }
- },
- handleViewShowing: function (that) {
- $.when(
- drawingGroupDataSource.load(),
- drawingTypeDataSource.load())
- .done(function (dbGroups, dbTypes) {
- drawingGroups(dbGroups[0]);
- drawingTypes(dbTypes[0]);
- drawingGroupsForSearch($SearchView.createDefaultArray('DrawingGroupId').concat(dbGroups[0]));
- drawingTypesForSearch($SearchView.createDefaultArray('DrawingTypeId').concat(dbTypes[0]));
- deferredForSearch.resolve();
- });
- },
- //2016 03 28 hcLee 추가
- handleCancelInPopup: function () {
- //tabIndex(1);
- tabIndex(0);
- },
- handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {
- dataGrid.clearSelection();
- var data = clickRow.data;
- var dataModel = viewModel.dataModel;
- dataModel.DrawingGroupName = $KoSet(dataModel.DrawingGroupName, data['FmsDrawingCodeGroup/Name']);
- dataModel.DrawingTypeName = $KoSet(dataModel.DrawingTypeName, data['FmsDrawingCodeType/Name']);
- popupVisible(true);
- },
- handleViewShown: function () {
- }
- });
- function reloadDrawingHistory(drawingId) {
- drawingHistoryDataSource.filter([
- eq('SiteId', BWA.UserInfo.SiteId()),
- and,
- eq('DrawingId', drawingId)
- ]);
- drawingHistoryDataSource.load().done(function (histories) {
- drawingHistories(histories);
- });
- }
- drawingHistoryPopup = BWA.Popup.DrawingHistory.create(viewModel, params, drawingHistories, reloadDrawingHistory);
- viewModel.drawingGroups = drawingGroups;
- viewModel.drawingTypes = drawingTypes;
- viewModel.drawingGroupsForSearch = drawingGroupsForSearch;
- viewModel.drawingTypesForSearch = drawingTypesForSearch;
- var tabIndex = ko.observable(0);
- viewModel.tabsOptions = {
- visible: tabsVisible,
- selectedIndex: tabIndex,
- dataSource: [
- { text: '도면정보' },
- { text: '도면이력' }
- ]
- };
- tabIndex.subscribe(function (index) {
- //isVisibleHistoryInsertButton(index === 1 && viewModel.isEditModeInPopup());
- // 왼쪽 수정은 무조건 매뉴얼 hcLee 2016 03 28추가
- //if (viewModel.isEditModeInPopup()) return;
- if (viewModel.isEditModeInPopup() == false) {
- isVisibleHistoryInsertButton(index === 1);
- viewModel.visibleEditButton(index === 0);
- viewModel.visibleDeleteButton(index === 0);
- }
- if (index == 0) drawingHistoryPopup.hide();
- //if (index == 0 && tabIndex() == 0) return;
- // hcLee 2016 03 28
- if (viewModel.isEditModeInPopup()) {
- tabIndex(0);
- return;
- }
- });
- viewModel.multiViewOptions = {
- dataSource: [
- {
- template: 'drawing',
- viewModel: viewModel,
- dataModel: viewModel.dataModel,
- },
- {
- template: 'drawingHistory',
- viewModel: viewModel,
- dataGridOptions: {
- dataSource: drawingHistories,
- columns: [
- { dataField: 'RevisionNo', caption: $G('revisionNo'), width: '13%' },
- { dataField: 'UpdatedDate', caption: $G('updatedDate'), width: '30%', dataType: 'date', format: 'yyyy-MM-dd HH:mm:ss' },
- { dataField: 'CmUser/Name', caption: $G('modifier'), width: '22%' },
- {
- dataField: 'CmFile/Name', caption: $G('fileName'), alignment: 'center', width: '45%',
- cellTemplate: function (cellElement, cellInfo) {
- var data = cellInfo.data;
- var url = [
- BWA.db._url,
- '/CmFile(SiteId={0},FileId={1})/$value'.formati(data.SiteId(), data.FileId())
- ].join('');
- $('<a>')
- .prop('href', url)
- .prop('download', cellInfo.value)
- .attr('style', 'color: {0} !important; text-decoration: underline;'.formati('purple'))
- //.style('color', '#333 !important')
- .attr('target', '_blank')
- .text(cellInfo.value)
- .appendTo(cellElement);
- }
- }
- ],
- paging: {
- pageSize: 10,
- enabled: true
- },
- pager: { visible: true },
- hoverStateEnabled: true,
- contentReadyAction: function (e) {
- drawingHistoryPopup.setDrawingHistoryGridViewInstance(e.component);
- },
- selection: { mode: 'single' },
- rowClick: function (clickRow) {
- if (drawingHistoryPopup.isNewData()) {
- utils.toast.show('도면이력추가 중 입니다.'); // hcLee 2016 03 28
- return;
- }
- drawingHistoryPopup.setSelectedDrawingHistory(clickRow.data);
- //drawingHistoryPopup.hide();
- drawingHistoryPopup.show();
- },
- height: 405
- }
- }
- ],
- swipeEnabled: false,
- selectedIndex: tabIndex,
- height: '520px'
- };
- // 왼쪽 수정은 무조건 매뉴얼 hcLee 2016 03 28추가
- viewModel.isEditModeInPopup.subscribe(function (isEditMode) {
- tabIndex(0);
- });
- viewModel.DrawingTypeName = $KoSet(viewModel.DrawingTypeName, '');
- viewModel.textAreaNoteHeightInPopup = textAreaNoteHeightInPopup;
- viewModel.drawingHistoryPopup = drawingHistoryPopup;
- return viewModel;
- };
|