123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- $(function () {
- "use strict";
- var TEXTAREA_HEIGHT_MAX = 420,
- TEXTAREA_HEIGHT_MIN = 240;
- BWA.Popup = BWA.Popup || {};
- BWA.Popup.UserLicense = {
- create: function (viewModel, params) {
- // 다운로드 기능은 다른 창으로 url를 열면 될 듯하다.
- var userDataModel = viewModel.dataModel,
- popupVisible = ko.observable(false),
- position = ko.observable(),
- isNewData = ko.observable(false),
- isVisibleDeleteButton = ko.observable(true),
- isVisibleSaveButton = ko.observable(false),
- timerObj = { timer: null },
- mainPopupElement = params.mainPopupElement
- ;
- BWA.db.FmsDrawingHistory.modified.add(function () {
- reloadDrawingHistory(drawingId());
- historyGridView.refresh();
- });
- function handleButtonSave() {
- historyViewModel.SiteId(BWA.UserInfo.SiteId());
- historyViewModel.DrawingId(drawingId());
- if (isNewData()) {
- if (_.isUndefined(historyViewModel.FileId())) {
- utils.toast.show('도면 파일을 업로드하여 주십시오.', 'error');
- return;
- }
- historyViewModel.UpdatedDate(new Date());
- historyViewModel.UpdatedUserId(BWA.UserInfo.UserId());
- BWA.db.FmsDrawingHistory.insert(historyViewModel.toJS()).done(function (res) {
- utils.toast.show('도면 이력 항목이 성공적으로 저장되었습니다.');
- dropZone.resetUploadedFileInfo();
- popupVisible(false);
- });
- }
- else {
- historyViewModel.RevisionNo(undefined);
- historyViewModel.FileId(undefined);
- historyViewModel.UpdatedDate(undefined);
- historyViewModel.UpdatedUserId(undefined);
- var keys = BWA.db.extractKeysObject('FmsDrawingHistory', historyViewModel);
- BWA.db.FmsDrawingHistory.update(keys, historyViewModel.toJS()).done(function (res) {
- utils.toast.show('도면 이력 항목이 성공적으로 저장되었습니다.');
- popupVisible(false);
- });
- }
- }
- function handleButtonDelete() {
- var keys = BWA.db.extractKeysObject('FmsDrawingHistory', historyViewModel);
- BWA.db.FmsDrawingHistory.remove(keys).done(function () {
- BWA.db.CmFile.remove({
- SiteId: historyViewModel.SiteId(),
- FileId: historyViewModel.FileId()
- }).done(function () {
- utils.toast.show('도면 이력 항목 삭제 처리가 성공하였습니다.');
- popupVisible(false);
- });
- });
- }
- function setupDropzone() {
- if (_.isNull(dropZone)) {
- dropZone = BWA.DropZone.create({
- id: '#drawingHistoryFileUpload',
- categoryId: $Code.FileCategory.DRAWING,
- uploadedFileInfo: uploadedFileInfo,
- handleSuccess: function (fileInfo) {
- historyViewModel.FileId(fileInfo.FileId);
- },
- handleRemovedFile: function () {
- historyViewModel.FileId(null);
- },
- });
- }
- }
- popupVisible.subscribe(utils.popup.getAttachFunc('#popupDetail', timerObj, position));
- position.subscribe(function (value) {
- console.log(value);
- });
- isNewData.subscribe(function (isNew) {
- // isVisibleDeleteButton(isNew === false);
- textAreaHistoryNoteHeight(isNew ? TEXTAREA_HEIGHT_MIN : TEXTAREA_HEIGHT_MAX);
- if (isNew && popupVisible()) {
- isVisibleDropZone('visible');
- }
- else {
- isVisibleDropZone('hidden');
- }
- });
- viewModel.popupVisible.subscribe(function (value) {
- if (value === false) {
- popupVisible(false);
- }
- });
- viewModel.isEditModeInPopup.subscribe(function (value) {
- if (value === false && isNewData()) {
- popupVisible(false);
- }
- isVisibleSaveButton(value);
- isVisibleDeleteButton(!value);
- });
- return {
- visible: popupVisible,
- isNewData: isNewData,
- show: function () {
- popupVisible(true);
- },
- hide: function () {
- popupVisible(false);
- },
- popupOptions: {
- width: '480px',
- height: '616px',
- dragEnabled: false,
- position: position,
- visible: popupVisible,
- showingAction: function () { },
- closeOnOutsideClick: false,
- shading: false,
- animation: {
- show: { type: "slide", duration: 150, from: { left: '-=10', opacity: 0 }, to: { opacity: 1 } },
- hide: { type: "slide", duration: 150, from: { left: '-=10', opacity: 1 }, to: { opacity: 0 } }
- },
- shownAction: function () {
- if (isNewData()) {
- isVisibleDropZone('visible');
- }
- else {
- isVisibleDropZone('hidden');
- }
- setupDropzone();
- },
- hidingAction: function () {
- dropZone.dispose(uploadedFileInfo);
- }
- },
- toolbarItems: [
- { location: 'before', text: $G('drawingHistoryDetailInfo') },
- {
- location: 'after', widget: 'button', options: {
- text: $G('save'),
- icon: 'save',
- visible: isVisibleSaveButton,
- disabled: viewModel.hasnotModificationPermission,
- clickAction: handleButtonSave
- }
- },
- {
- location: 'after', widget: 'button', options: {
- text: $G('delete'),
- icon: 'remove',
- type: 'danger',
- visible: isVisibleDeleteButton,
- disabled: viewModel.hasnotModificationPermission,
- clickAction: handleButtonDelete
- }
- },
- {
- location: 'after', widget: 'button', options: {
- text: $G('close'),
- icon: 'close',
- clickAction: function () { popupVisible(false); }
- }
- }
- ],
- setDrawingHistoryGridViewInstance: function (instance) {
- historyGridView = instance;
- },
- setSelectedDrawingHistory: function (history) {
- isNewData(false);
- BWA.DataUtil.copyViewModel(history, historyViewModel);
- historyViewModel.FileName(history['CmFile/Name']());
- historyViewModel.UpdatedUserName(history['CmUser/Name']());
- console.log(historyViewModel.toJS());
- },
- handleInsertDrawingHistory: function () {
- isNewData(true);
- BWA.DataUtil.resetDataModel(_.omit(historyViewModel, 'DrawingId'));
- var maxHistory = _.max(drawingHistories(), function (x) {
- return x.RevisionNo();
- });
- historyViewModel.RevisionNo(maxHistory.RevisionNo() + 1);
- historyViewModel.UpdatedUserName(BWA.UserInfo.Name());
- popupVisible(true);
- }
- };
- }
- }
- });
|