| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 | 
							- BemsWebApplication.WorkCodeCauseClass = function (params, viewInfo) {
 
-     "use strict";
 
-     var dbModelId = 'FmsWorkCodeCauseClass';
 
-     var initialized = false,
 
-         shouldReload = false,
 
-         dataViewModel = new BemsWebApplication.FmsWorkCodeCauseClassViewModel(),
 
-         isNewInPopup = ko.observable(false),
 
-         isEditModeInPopup = ko.observable(false),
 
-         isViewModeInPopup = ko.observable(true),
 
-         visibleCancelButton = ko.observable(false),
 
-         selectedIds = [{}, {}, {}],
 
-         gridViews = [],
 
-         popupVisible = ko.observable(false),
 
-         popupVisibles = [ko.observable(false), ko.observable(false)],
 
-         buttonEditDisabledFlags = [ko.observable(true), ko.observable(true)],
 
-         dataSources = [];
 
-     var selectedClass = 0;
 
-     var isClass2 = ko.observable(false);
 
-     popupVisible.subscribe(function (visible) {
 
-         if (visible == false) {
 
-             //$.each( selectedIds[selectedClass] , function( name ) {
 
-             //    delete selectedIds[selectedClass][name];
 
-             //});
 
-             $.each(popupVisibles, function (i, item) {
 
-                 item(false);
 
-             });
 
-         }
 
-     });
 
-     popupVisibles[0].subscribe(function (visible) {
 
-         selectedClass = 0;
 
-         isClass2(false);
 
-         if (visible) popupVisible(visible);
 
-     });
 
-     popupVisibles[1].subscribe(function (visible) {
 
-         selectedClass = 1;
 
-         isClass2(true);
 
-         if (visible) popupVisible(visible);
 
-     });
 
-     function handleModification() {
 
-         shouldReload = true;
 
-     }
 
-     function handleSelectionChanged(selectedRowsInfo) {
 
-         var id = $(selectedRowsInfo.element).attr('id');
 
-         console.log(selectedRowsInfo.selectedRowKeys.length);
 
-         switch (id) {
 
-             case 'gridContainer1':
 
-                 {
 
-                     buttonEditDisabledFlags[0](selectedRowsInfo.selectedRowKeys.length == 0);
 
-                     break;
 
-                 }
 
-             case 'gridContainer2':
 
-                 {
 
-                     buttonEditDisabledFlags[1](selectedRowsInfo.selectedRowKeys.length == 0);
 
-                     break;
 
-                 }
 
-         }
 
-         console.log(selectedRowsInfo.selectedRowKeys);
 
-     }
 
-     function handleViewShown() {
 
-         if (shouldReload) {
 
-             shouldReload = false;
 
-             for (var i = 0 ; i < 2 ; i++) {
 
-                 dataSources[i].pageIndex(0);
 
-                 dataSources[i].load();
 
-             }
 
-         }
 
-         if (initialized === false) {
 
-             for (var j = 0 ; j < 2 ; j++) {
 
-                 var options = j == 1 ? {
 
-                     columns: [
 
-                         { dataField: 'Name', caption: $G('className'), width: '70%', alignment: 'center' },
 
-                         utils.datagrid.columnIsUse('30%')
 
-                     ],
 
-                 } : {
 
-                     columns: [
 
-                         { dataField: 'Number', caption: $G('number'), width: '30%', alignment: 'center' },
 
-                         { dataField: 'Name', caption: $G('className'), width: '70%', alignment: 'center' }
 
-                     ],
 
-                     useNumberColumn: true,
 
-                 };
 
-                 options.selectedSourceItem = dataViewModel;
 
-                 options.dbId = dbModelId;
 
-                 options.dxDataSource = dataSources[j];
 
-                 options.selectedId = selectedIds[j];
 
-                 options.datagridId = 'gridContainer' + (j + 1);
 
-                 options.selectionChanged = handleSelectionChanged;
 
-                 options.popupVisible = popupVisibles[j];
 
-                 options.handleDataGridRowClick = handleDataGridRowClick;
 
-                 var id = '#' + options.datagridId;
 
-                 $(id).dxDataGrid(utils.datagrid.defaultOptions(options));
 
-                 gridViews[j] = $(id).dxDataGrid('instance');
 
-             }
 
-             initialized = true;
 
-         }
 
-         $SideMenu.showSideMenuIfWill(params.view);
 
-     }
 
-     function refreshDataSource(dataIndex, parentId) {
 
-         dataSources[dataIndex].filter('ParentId', '=', parentId);
 
-         dataSources[dataIndex].pageIndex(0);
 
-         dataSources[dataIndex].load();
 
-         gridViews[dataIndex].option('dataSource', utils.datagrid.dataSource(dataSources[dataIndex]));
 
-         gridViews[dataIndex].refresh();
 
-     }
 
-     function handleDataGridRowClick(id, dataGrid, clickRow) {
 
-         switch (id) {
 
-             case 'gridContainer1':
 
-                 {
 
-                     refreshDataSource(1, clickRow.data.ClassId());
 
-                     break;
 
-                 }
 
-         }
 
-     }
 
-     function handleViewDisposing() {
 
-         BemsWebApplication.db[dbModelId].modified.remove(handleModification);
 
-     }
 
-     var dataSourceOptions = {
 
-         store: BemsWebApplication.db[dbModelId],
 
-         map: function (item) {
 
-             return new BemsWebApplication.FmsWorkCodeCauseClassViewModel(item);
 
-         }
 
-     };
 
-     for (var k = 0 ; k < 2 ; k++) {
 
-         dataSources[k] = new DevExpress.data.DataSource(dataSourceOptions);
 
-     }
 
-     dataSources[0].filter([
 
-         ['SiteId', '=', BWA.UserInfo.SiteId()],
 
-         'and',
 
-         ['ParentId', '=', 0]
 
-     ]);
 
-     dataSources[1].filter('ParentId', '=', -1);
 
-     function refreshList() {
 
-         for (var i = 0 ; i < 2 ; i++) {
 
-             dataSources[i].pageIndex(0);
 
-             dataSources[i].load();
 
-             gridViews[i].refresh();
 
-         }
 
-     }
 
-     function handlePopupShowing(e) {
 
-         visibleCancelButton(false);
 
-         if (isNewInPopup() == false) {
 
-             activePopupViewMode();
 
-             BemsWebApplication.db[dbModelId].byKey(selectedIds[selectedClass]).done(function (data) {
 
-                 dataViewModel.fromJS(data);
 
-             });
 
-         }
 
-         else {
 
-             //activePopupInsertMode();
 
-             clearDataModelValue(dataViewModel);
 
-         }
 
-     }
 
-     function clearDataModelValue(v) {
 
-         $.each(v, function (name, value) {
 
-             if (name !== 'ParentId') {
 
-                 v[name](null);
 
-             }
 
-         });
 
-         v.SiteId(BWA.UserInfo.SiteId());
 
-         console.log(v.ParentId());
 
-     }
 
-     BemsWebApplication.db[dbModelId].modified.add(handleModification);
 
-     function handleConfirmDelete() {
 
-         BemsWebApplication.db[dbModelId].remove(selectedIds[selectedClass]).done(function () {
 
-             popupVisible(false);
 
-             utils.toast.show('데이터베이스 항목 삭제 작업이 성공하였습니다.');
 
-         });
 
-     }
 
-     function update() {
 
-         //console.log( dataViewModel.BuildingId() );
 
-         BemsWebApplication.db[dbModelId].update(selectedIds[selectedClass], dataViewModel.toJS()).done(function () {
 
-             refreshList();
 
-             utils.toast.show('데이터베이스 항목 수정 작업이 성공하였습니다.');
 
-             //            popupVisible( false );
 
-         });
 
-     }
 
-     function insert() {
 
-         BemsWebApplication.db[dbModelId].insert(dataViewModel.toJS()).done(function (values, newId) {
 
-             refreshList();
 
-             popupVisible(false);
 
-         });
 
-     }
 
-     function activePopupEditMode() {
 
-         isViewModeInPopup(false);
 
-         isEditModeInPopup(true);
 
-     }
 
-     function activePopupViewMode() {
 
-         isViewModeInPopup(true);
 
-         isEditModeInPopup(false);
 
-     }
 
-     function handlePopupButtonEdit() {
 
-         activePopupEditMode();
 
-         visibleCancelButton(true);
 
-     }
 
-     function handlePopupButtonCancel() {
 
-         activePopupViewMode();
 
-         visibleCancelButton(false);
 
-     }
 
-     function popupInsertView() {
 
-         activePopupEditMode();
 
-         popupVisible(true);
 
-     }
 
-     function handlePopupButtonSave() {
 
-         if (isNewInPopup())
 
-             insert();
 
-         else
 
-             update();
 
-     }
 
-     function handlePopupButtonDelete() {
 
-         DevExpress.ui.dialog.confirm($G('deleteConfirmMsg'), "삭제").then(function (result) {
 
-             if (result) {
 
-                 handleConfirmDelete();
 
-                 refreshList();
 
-             }
 
-             else {
 
-                 // toast
 
-             }
 
-         });
 
-     }
 
-     function handlePopupButtonClose() {
 
-         popupVisible(false);
 
-     }
 
-     var toolbarItems = [
 
-         { location: 'before', text: $G('detailInfo') },
 
-         { location: 'after', widget: 'button', options: { text: $G('edit'), icon: 'edit', visible: isViewModeInPopup, clickAction: handlePopupButtonEdit } },
 
-         { location: 'after', widget: 'button', options: { text: $G('delete'), type: 'danger', icon: 'remove', visible: isViewModeInPopup, clickAction: handlePopupButtonDelete } },
 
-         { location: 'after', widget: 'button', options: { text: $G('save'), icon: 'save', visible: isEditModeInPopup, clickAction: handlePopupButtonSave } },
 
-         { location: 'after', widget: 'button', options: { text: $G('cancel'), icon: 'arrowleft', visible: visibleCancelButton, clickAction: handlePopupButtonCancel } },
 
-         { location: 'after', widget: 'button', options: { text: $G('close'), icon: 'close', clickAction: handlePopupButtonClose } }
 
-         //{ location: 'right', widget: 'button', options: { text: '@edit', click: handleEdit } },
 
-         //{ location: 'after', widget: 'button', options: { icon: 'find' } },
 
-         //{ location: 'menu', text: 'Add' },
 
-         //{ location: 'center', text: 'Products' }
 
-     ];
 
-     var popupOptions = {
 
-         width: '480px',
 
-         height: 'auto',
 
-         visible: popupVisible,
 
-         closeOnOutsideClick: true,
 
-         showingAction: handlePopupShowing,
 
-         animation: {
 
-             show: { type: "pop", duration: 200, from: { opacity: 1, scale: 0.4 }, to: { scale: 1 } },
 
-             hide: { type: "fade", duration: 200, from: 1, to: 0 }
 
-         }
 
-     };
 
-     function setInsertPopupInfo(index, classId) {
 
-         isNewInPopup(true);
 
-         activePopupEditMode();
 
-         dataViewModel.ParentId(classId);
 
-         popupVisibles[index](true);
 
-     }
 
-     return {
 
-         dataModel: dataViewModel,
 
-         refreshList: refreshList,
 
-         buttonEditDisabledFlags: buttonEditDisabledFlags,
 
-         //viewShowing: handleViewShowing ,
 
-         viewShown: handleViewShown,
 
-         viewDisposing: handleViewDisposing,
 
-         popupInsertView: popupInsertView,
 
-         isViewModeInPopup: isViewModeInPopup,
 
-         isEditModeInPopup: isEditModeInPopup,
 
-         isNewInPopup: isNewInPopup,
 
-         popupOptions: popupOptions,
 
-         toolbarItems: toolbarItems,
 
-         isClass2: isClass2,
 
-         buttonInsertClass1: function () {
 
-             setInsertPopupInfo(0, 0);
 
-         },
 
-         buttonInsertClass2: function () {
 
-             setInsertPopupInfo(1, selectedIds[0].ClassId);
 
-         },
 
-         buttonEditClass1: function () {
 
-             isNewInPopup(false);
 
-             popupVisibles[0](true);
 
-         },
 
-         buttonEditClass2: function () {
 
-             isNewInPopup(false);
 
-             popupVisibles[1](true);
 
-         },
 
-     };
 
- };
 
 
  |