123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654 |
- BemsWebApplication.FloorPlan = function (params, viewInfo) {
- "use strict";
- var FloorInPopUpForSearch = ko.observableArray(),
- FloorInPopUp = ko.observableArray();
- var imagefileUrl = ko.observable(), uploadedFileInfo = {}, dropZone = null;
- var deferredForSearch = new $.Deferred();
- var floorplan = ko.observableArray();
- var isImageUpload = ko.observableArray();
- var enableDataBoxInPopup = ko.observable(false);
- var visibleEditButton = ko.observable(false); // 수정 버튼 활성화 여부 플래그
- var hasnotModificationPermission = ko.observable(true); // 수정버튼 비활성화 플래그
- var visibleDeleteButton = ko.observable(false); // 삭제버튼 활성화 플래그
- var visibleCancelButton = ko.observable(false); // 취소버튼 활성화 플래그
- var isEditModeInPopup = ko.observable(); // 저장버튼 활성화 플래그
- var isNotModifyMode = ko.observable(false); // 저장버튼 비활성화 플래그
- var backupDataViewModel = new BemsWebApplication.BemsFloorPlanViewModel();
- var backup_data;
- var floorAll;
- 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 floorplanPopupToolbarItems = [
- { location: 'before', text: '평면도 등록' },
- { location: 'after', widget: 'button', options: { text: $G('edit'), icon: 'edit', visible: visibleEditButton, disabled: hasnotModificationPermission, clickAction: handlePopupButtonEdit } },
- { location: 'after', widget: 'button', options: { text: $G('delete'), type: 'danger', icon: 'remove', visible: visibleDeleteButton, disabled: hasnotModificationPermission, clickAction: handlePopupButtonDelete } },
- { location: 'after', widget: 'button', options: { text: $G('cancel'), icon: 'cancel', visible: visibleCancelButton, clickAction: handlePopupButtonCancel } },
- { location: 'after', widget: 'button', options: { text: $G('save'), icon: 'save', visible: isEditModeInPopup, disabled: isNotModifyMode, clickAction: handlePopupButtonSave } },
- { location: 'after', widget: 'button', options: { text: $G('close'), icon: 'close', clickAction: PopupButtonClose } }
- ];
- function setupDropZone(dataViewModel) {
- var timer = null;
- viewModel.isEditModeInPopup.subscribe(function (value) {
- if (value) {
- if (timer) {
- clearInterval(timer);
- }
- timer = setInterval(function () {
- if ($('#FloorPlanDropZone').length) {
- if (_.isNull(dropZone)) {
- dropZone = BWA.DropZone.create({
- id: '#FloorPlanDropZone',
- categoryId: $Code.FileCategory.FLOOR,
- uploadedFileInfo: uploadedFileInfo,
- handleRemoveBeforePromise: function () {
- var keys = BWA.db.extractKeysObject('BemsFloorPlan', dataViewModel);
- utils.toast.show($G('successDatabaseInsertionMsg'));
- PopupButtonClose();
- return BWA.db.BemsFloorPlan.update(keys, { ImageFileId: null });
- },
- handleSuccess: function (fileInfo) {
- if (uploadedFileInfo.FileId) {
- dataViewModel.ImageFileId(uploadedFileInfo.FileId);
- var keys = BWA.db.extractKeysObject('BemsFloorPlan', dataViewModel);
- var insert_data = {
- SiteId: BWA.UserInfo.SiteId(),
- FloorId: backup_data.FloorId,
- Name: dataViewModel.Name(),
- ImageFileId: uploadedFileInfo.FileId
- };
- if (keys.Name != null) {
- //update(insert_data, tmp_data);
- BemsWebApplication.db['BemsFloorPlan'].remove(backup_data).done(function () {
- var store = new DevExpress.data.ODataStore({
- url: endpointSelector + "/BemsFloorPlan",
- key: ["SiteId", "Name"],
- keyType: {
- SiteId: "Int32", Name: "String"
- }
- });
- store.insert(insert_data).done(function (key, result) {
- utils.toast.show($G('successDatabaseInsertionMsg'));
- PopupButtonClose();
- })
- .fail(function (error) {
- utils.toast.show(error);
- });
- viewModel.refreshList();
- setTimeout(function () {
- GetGridData();
- }, 500);
- });
- }
- }
- },
- handleRemovedFile: function () {
- dataViewModel.ImageFileId(null);
- }
- });
- }
- }
- }, 100);
- }
- else {
- if (timer) {
- clearInterval(timer);
- timer = null;
- }
- dropZone = null;
- }
- });
- }
- function update(postData, backupData) {
- var floorplanDataModel = new BemsWebApplication.BemsFloorPlanViewModel();
- if (FloorPlanDropZone.dropzone.files.length == 0) {
- utils.toast.show("첨부 파일을 업로드하여 주십시오.", 'error');
- return;
- }
- else if (_.isNull(dropZone) === false
- && (dropZone.files[0].type == 'image/jpeg'
- || dropZone.files[0].type == 'image/jpg'
- || dropZone.files[0].type == 'image/gif'
- || dropZone.files[0].type == 'image/png'
- || dropZone.files[0].type == 'image/bmp')) {
- dropZone.processQueue();
- }
- else {
- utils.toast.show("그림파일(jpeg, jpg, gif, png, bmp)만 등록 가능합니다.", 'error');
- return;
- }
- backup_data = {
- SiteId: BWA.UserInfo.SiteId(),
- FloorId: backupData.FloorId,
- Name: backupData.Name,
- ImageFileId: backupData.ImageFileId
- };
- var temp = {
- SiteId: BWA.UserInfo.SiteId(),
- FileId: backupData.ImageFileId
- }
- if (backupData.ImageFileId != null) {
- BWA.db.CmFile.byKey(temp).done(function (data) {
- dropZone.removeFile(data);
- });
- }
- dropZone.processQueue();
- }
- function insert(postData) {
- if (postData.Name == null || postData.FloorId == null) {
- utils.toast.show("층 정보가 입력되지 않았습니다.", 'error');
- return;
- }
- else if (FloorPlanDropZone.dropzone.files.length == 0) {
- utils.toast.show("첨부 파일을 업로드하여 주십시오.", 'error');
- return;
- }
- else if (_.isNull(dropZone) === false
- && viewModel.dataModel.ImageFileId() == null
- && (dropZone.files[0].type == 'image/jpeg'
- || dropZone.files[0].type == 'image/jpg'
- || dropZone.files[0].type == 'image/gif'
- || dropZone.files[0].type == 'image/png'
- || dropZone.files[0].type == 'image/bmp')) {
- dropZone.processQueue();
- }
- else {
- utils.toast.show("그림파일(jpeg, jpg, gif, png, bmp)만 등록 가능합니다.", 'error');
- return;
- }
- backup_data = {
- SiteId: BWA.UserInfo.SiteId(),
- FloorId: viewModel.dataModel.FloorId(),
- Name: viewModel.dataModel.Name(),
- ImageFileId: null
- };
- var store = new DevExpress.data.ODataStore({
- url: endpointSelector + "/BemsFloorPlan",
- key: ["SiteId", "Name"],
- keyType: {
- SiteId: "Int32", Name: "String"
- }
- });
- store.insert(postData).done(function (key, result) {
- utils.toast.show($G('successDatabaseInsertionMsg'));
- PopupButtonClose();
- })
- .fail(function (error) {
- utils.toast.show(error);
- });
- }
- //저장버튼
- function handlePopupButtonSave() {
- var dataViewModel = viewModel.dataModel;
- var postViewModel = new BemsWebApplication.BemsFloorPlanViewModel();
- postViewModel.SiteId(dataViewModel.SiteId());
- postViewModel.FloorId(dataViewModel.FloorId());
- postViewModel.Name(dataViewModel.Name());
- postViewModel.ImageFileId(dataViewModel.ImageFileId());
- var postData = postViewModel.toJS();
- if (viewModel.isNewInPopup())
- insert(postData);
- else
- update(postData, backupDataViewModel);
-
- //예외 처리(ImageFileId가 기존과 수정버전 모두 null인 경우)
- if (dataViewModel.ImageFileId() == null && backupDataViewModel.ImageFileId == null) {
- utils.toast.show($G('successDatabaseInsertionMsg'));
- PopupButtonClose();
- }
- //DB 저장에 시간이 걸리기때문에 딜레이 후 데이터 로드
- setTimeout(function () {
- UpdateSelectBoxInPopUp();
- GetGridData();
- }, 500);
- }
- function getBackupDataViewModel(model) {
- var object = {};
- $.each(model, function (name, value) {
- if (ko.isObservable(value)) {
- object[name] = value();
- }
- });
- return object;
- }
- function restoreDataViewModelFromBackup(model, backupModel) {
- $.each(backupModel, function (name, value) {
- model[name](value);
- });
- }
- // 수정버튼 클릭
- function handlePopupButtonEdit() {
- viewModel.isNewInPopup(false);
- viewModel.visibleEditButton(false);
- viewModel.visibleDeleteButton(false);
- viewModel.visibleCancelButton(true);
- viewModel.isEditModeInPopup(true);
- viewModel.isNotModifyMode(false);
- viewModel.enableDataBoxInPopup(false);
- viewModel.isImageUpload(true);
- backupDataViewModel = getBackupDataViewModel(viewModel.dataModel);
- dropZone = null;
- }
- //////
- // 삭제버튼 클릭
- function handlePopupButtonDelete() {
- DevExpress.ui.dialog.confirm($G('deleteConfirmMsg'), "삭제").then(function (result) {
- if (result) {
- var temp = {
- SiteId: BWA.UserInfo.SiteId(),
- FileId: viewModel.dataModel.ImageFileId()
- }
- if (viewModel.dataModel.ImageFileId() != null) {
- BWA.db.CmFile.byKey(temp).done(function (data) {
- if ($('#FloorPlanDropZone1').length) {
- if (_.isNull(dropZone)) {
- dropZone = BWA.DropZone.create({
- id: '#FloorPlanDropZone1',
- categoryId: $Code.FileCategory.FLOOR
- });
- dropZone.removeFile(data);
- dropZone = null;
- }
- }
- });
- }
- var selectedId = {};
- selectedId.SiteId = viewModel.dataModel.SiteId();
- selectedId.FloorId = viewModel.dataModel.FloorId();
- selectedId.Name = viewModel.dataModel.Name();
- selectedId.ImageFileId = viewModel.dataModel.ImageFileId();
- BemsWebApplication.db['BemsFloorPlan'].remove(selectedId).done(function () {
- viewModel.refreshList();
- setTimeout(function () {
- GetGridData();
- UpdateSelectBoxInPopUp();
- }, 500);
- PopupButtonClose();
- utils.toast.show('데이터베이스 항목 삭제 작업이 성공하였습니다.');
- }).fail(function () {
- utils.toast.show('데이터베이스 항목 삭제 작업이 실패하였습니다.', 'error');
- });
- //층별 관제점도 같이 지워준다
- var dataSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/BemsFloorStatus",
- },
- requireTotalCount: true
- });
- dataSource.filter([
- ["SiteId", "=", BWA.UserInfo.SiteId()],
- "and",
- ["FloorId", "=", viewModel.dataModel.FloorId()]
- ]);
- dataSource.load()
- .done(function (result) {
- for (var i = 0; i < result.length; i++) {
- var num = 0;
- var removeData = {
- SiteId: result[i].SiteId,
- FloorId: result[i].FloorId,
- FloorName: result[i].FloorName,
- ImageFileId: result[i].ImageFileId,
- Xvalue: result[i].Xvalue,
- Yvalue: result[i].Yvalue,
- ZoneId: result[i].ZoneId,
- FacilityTypeId: result[i].FacilityTypeId,
- FacilityCode: result[i].FacilityCode,
- PropertyId: result[i].PropertyId,
- FacilityName: result[i].FacilityName,
- };
- BemsWebApplication.db['BemsFloorStatus'].remove(removeData);
- }
- })
- }
- });
- }
- // 취소버튼
- function handlePopupButtonCancel() {
- viewModel.visibleEditButton(true);
- viewModel.visibleDeleteButton(true);
- viewModel.visibleCancelButton(false);
- viewModel.isEditModeInPopup(false);
- viewModel.isNotModifyMode(true);
- viewModel.isImageUpload(false);
- restoreDataViewModelFromBackup(viewModel.dataModel, backupDataViewModel);
- }
- // 닫기버튼
- function PopupButtonClose() {
- viewModel.isNewInPopup(false);
- viewModel.visibleEditButton(false);
- viewModel.visibleDeleteButton(false);
- viewModel.visibleCancelButton(false);
- viewModel.isEditModeInPopup(false);
- viewModel.isNotModifyMode(false);
- viewModel.dataModel.ImageFileId(null);
- viewModel.imagefileUrl(undefined);
- viewModel.popupVisible(false);
- dropZone = null;
- }
- function GetGridData() {
- var gridData = new Array();
- var dataSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/BemsFloorPlan",
- },
- requireTotalCount: true,
- pageSize: 9999,
- });
- dataSource.filter([
- ["SiteId", "=", BWA.UserInfo.SiteId()]
- ]);
- dataSource.sort({ getter: "Name", asc: true });
- dataSource.load()
- .done(function (result) {
- for (var i = 0; i < result.length; i++) {
- gridData[i] = {
- "SiteId": 0,
- "FloorId": 0,
- "Name": "",
- "ImageFileId": null
- };
- gridData[i].SiteId = result[i].SiteId;
- gridData[i].FloorId = result[i].FloorId;
- gridData[i].Name = result[i].Name;
- gridData[i].ImageFileId = result[i].ImageFileId;
- }
- $("#gridContainer").dxDataGrid("instance").option('dataSource', gridData);
- //$("#gridContainer").dxDataGrid("instance").refresh();
- })
- .fail(function (error) {
- utils.toast.show(error);
- });
- }
- function UpdateSelectBoxInPopUp() {
- var dataSource_GridData = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/BemsFloorPlan",
- },
- requireTotalCount: true,
- pageSize: 100
- });
- dataSource_GridData.filter([
- ["SiteId", "=", BWA.UserInfo.SiteId()]
- ]);
- dataSource_GridData.load()
- .done(function (gridData) {
- var tmp = new Array(floorAll.length);
- for (var i = 0; i < floorAll.length; i++) {
- tmp[i] = 0;
- for (var j = 0; j < gridData.length; j++) {
- if (floorAll[i].FloorId == gridData[j].FloorId) {
- tmp[i] = 1;
- break;
- }
- }
- }
- var dbfloor = new Array();
- var idx = 0;
- for (var i = 0; i < floorAll.length; i++) {
- if (tmp[i] == 0)
- dbfloor.push(floorAll[i]);
- }
- FloorInPopUp(dbfloor);
- FloorInPopUpForSearch($SearchView.createArrayOfSelectBox('FloorId', FloorInPopUp));
- });
- }
- function getImageSize(width, height) {
- var viewIndoor = $('#viewIndoor');
- var maxWidth = parseFloat(viewIndoor.css('width')), maxHeight = parseFloat(viewIndoor.css('height'));
- var widthRatio = width / maxWidth;
- var heightRatio = height / maxHeight;
- var maxRatio = max(widthRatio, heightRatio);
- if (maxRatio > 1) {
- return { width: width / maxRatio, height: height / maxRatio }
- }
- return { width: width, height: height }
- }
- function max(x, y) {
- if (x > y) return x;
- return y;
- }
- function loadImage(imageUrl) {
- $('#imageContext').find('text').remove();
- //var imageUrl = url;//'/Images/Blueprint/' + viewModel.dataModel.FloorId() + '.jpg';
- var image = document.getElementById("image");
- var newImage = new Image();
- newImage.onload = function () {
- var imageSize = getImageSize(newImage.width, newImage.height);
- $('#imageContext').css('width', imageSize.width).css('height', imageSize.height);
- $('#image').attr('width', imageSize.width).attr('height', imageSize.height); // 2016 05 30 추가, IE 문제해결, 종화
- }
- newImage.src = imageUrl;
- image.setAttributeNS('http://www.w3.org/1999/xlink', 'href', imageUrl);
- }
- var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'BemsFloorPlan', {
- dataSourceOptions: {
- select: [
- 'SiteId',
- 'FloorId',
- 'Name',
- 'ImageFileId'
- ],
- filter: [
- ['SiteId', '=', BWA.UserInfo.SiteId()]
- ],
- extendOptions: {
- forceOriginalField: true
- },
- },
- columns: [
- { dataField: 'SiteId', caption: '번호', width: '30%', alignment: 'center' },
- { dataField: 'Name', caption: '층 명칭', width: '70%', alignment: 'center' },
- { dataField: 'FloorId', caption: '', width: '30%', alignment: 'center', visible: false },
- { dataField: 'ImageFileId', caption: '', width: '70%', alignment: 'center', visible: false }
- ],
- NoSearchView: true, // 2019.07.25 kgpark 검색버튼 삭제
- paging: {
- pageSize: 20,
- enabled: true
- },
- pager: {
- },
- handlePopupShowing: function (isNewInPopup, dataViewModel) {
- // 저장 버튼
- if (isNewInPopup() == false) {
- imagefileUrl(undefined);
- dropZone = null; // 신규등록인 경우
- } else {
- dataViewModel.Name('');
- dataViewModel.ImageFileId(null);
- viewModel.imagefileUrl(undefined);
- viewModel.isNewInPopup(true);
- viewModel.isEditModeInPopup(true);
- imagefileUrl('');
- loadImage(imagefileUrl());
- }
- // 탭으로 표시하지 않음
- isImageUpload(false);
- enableDataBoxInPopup(true);
- // tabsVisible(isNewInPopup() == false);
- $("#Floor_Info").dxSelectBox({
- onValueChanged: function () {
- if (isNewInPopup() == false) {
- // 이전 이미지 잔상 문제로 인한 방어코드
- // 이미지 경로 강제 초기화
- imagefileUrl(undefined);
- }
- isImageUpload(true);
- enableDataBoxInPopup(true);
- var floor = $("#Floor_Info").dxSelectBox('instance').option('value');
- var dataSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/CmFloor",
- },
- requireTotalCount: true
- });
- dataSource.filter([
- ["SiteId", "=", BWA.UserInfo.SiteId()]
- ]);
- dataSource.load()
- .done(function (result) {
- for (var i = 0; i < result.length; i++) {
- if (result[i].FloorId == floor) {
- viewModel.dataModel.Name(result[i].Name);
- break;
- }
- }
- });
- }
- });
- },
- handleViewShowing: function () {
- //권한설정
- hasnotModificationPermission(!BWA.UserInfo.hasPermissionOfModification(viewInfo.viewName));
- var dataSource_FloorInfo = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/CmFloor",
- },
- requireTotalCount: true
- });
- dataSource_FloorInfo.filter([
- ["SiteId", "=", BWA.UserInfo.SiteId()]
- ]);
- dataSource_FloorInfo.load()
- .done(function (floorInfo) {
- floorAll = floorInfo;
- });
- UpdateSelectBoxInPopUp();
- GetGridData();
- enableDataBoxInPopup(true);
- },
- handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {
- dataGrid.clearSelection();
- viewModel.visibleEditButton(true);
- viewModel.visibleDeleteButton(true);
- viewModel.isNotModifyMode(true);
- viewModel.enableDataBoxInPopup(false);
- viewModel.isImageUpload(false);
- viewModel.isNewInPopup(false);
- var data = clickRow.data;
- viewModel.dataModel.Name(data.Name);
- viewModel.dataModel.FloorId(data.FloorId);
- viewModel.dataModel.ImageFileId(data.ImageFileId);
- viewModel.dataModel.SiteId(data.SiteId);
- popupVisible(true);
- imagefileUrl('{0}/CmFile(SiteId={1},FileId={2})/$value'.formati(BWA.db._url, BWA.UserInfo.SiteId(), viewModel.dataModel.ImageFileId()));
- loadImage(imagefileUrl());
- },
- handleViewShown: function (dataViewModel, isEditModeInPopup) {
- setupDropZone(dataViewModel);
- },
- handleSaveSuccess: function () {
- if (_.isNull(dropZone) === false) {
- dropZone.resetUploadedFileInfo();
- }
- },
- handleAfterLoadingModelByKey: function (data, dataViewModel, isNewInPopup) {
- if (isNewInPopup() == false) {
- if (_.isNull(dataViewModel.ImageFileId()) === false) {
- imagefileUrl('{0}/CmFile(SiteId={1},FileId={2})/$value'.formati(BWA.db._url, dataViewModel.SiteId(), dataViewModel.ImageFileId()));
- }
- else {
- imagefileUrl("images/default.png");
- }
- }
- },
- });
- viewModel.floorplanPopupToolbarItems = floorplanPopupToolbarItems;
- viewModel.imagefileUrl = imagefileUrl;
- viewModel.FloorInPopUp = FloorInPopUp;
- viewModel.dataModel.FloorId = ko.observable();
- viewModel.isImageUpload = isImageUpload;
- viewModel.backupDataViewModel = backupDataViewModel;
- viewModel.enableDataBoxInPopup = enableDataBoxInPopup;
- viewModel.visibleEditButton = visibleEditButton;
- viewModel.hasnotModificationPermission = hasnotModificationPermission;
- viewModel.visibleDeleteButton = visibleDeleteButton;
- viewModel.visibleCancelButton = visibleCancelButton;
- viewModel.isEditModeInPopup = isEditModeInPopup;
- viewModel.isNotModifyMode = isNotModifyMode;
- return viewModel;
- };
|