123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654 |
- (function () {
- 'use strict';
- BWA.View = BWA.View || {};
- BWA.View.Facility = BWA.View.Facility || {};
- BWA.View.Facility.createCodeClassView = function (params, viewInfo, options) {
- var dbModelId = options.dbModelId,
- selectedClassNameTitle = options.selectedClassNameTitle,
- classIdFieldName = [options.classId, 'ClassId'].join(''),
- parentClassIdFieldName = ['Parent', options.classId, 'ClassId'].join(''),
- viewModelName = ['Fms', options.classId, 'CodeClassViewModel'].join('');
- var initialized = false,
- shouldReload = false,
- dataViewModel = new BemsWebApplication[viewModelName](),
- isNewInPopup = ko.observable(false),
- isEditModeInPopup = ko.observable(false),
- viewModeInPopup = ko.observable(true),
- selectedClassName = ko.observable(selectedClassNameTitle),
- visibleCancelButton = ko.observable(false),
- selectedIds = [{}, {}, {}],
- selectedId = null,
- viewModel,
- hasnotModificationPermission,
- gridViews = [],
- popupVisible = ko.observable(false),
- disabledUpdateButton = ko.observable(true),
- disabledInsertButtons = [ko.observable(false), ko.observable(true), ko.observable(true)],
- dataSources = [];
- var selectedClassDepth = 0,
- backupSelectedClassDepth = 0;
- var isClass3 = ko.observable(false);
- var commandInsertButtonOptions = [{
- id: 'create1',
- title: '대분류 등록',
- disabled: disabledInsertButtons[0],
- action: function () {
- setInsertPopupInfo(0, null);
- }
- }, {
- id: 'create2',
- title: '중분류 등록',
- disabled: disabledInsertButtons[1],
- action: function () {
- setInsertPopupInfo(1, selectedIds[0][classIdFieldName]);
- }
- }, {
- id: 'create3',
- title: '소분류 등록',
- disabled: disabledInsertButtons[2],
- action: function () {
- setInsertPopupInfo(2, selectedIds[1][classIdFieldName]);
- }
- }];
- var commandUpdateButtonOption = {
- id: 'edit',
- title: '수정',
- disabled: disabledUpdateButton,
- action: function () {
- isNewInPopup(false);
- isClass3(selectedClassDepth === 2);
- popupVisible(true);
- }
- };
- var FmsFacilityCodeClassDataSource = BemsWebApplication.db.createDataSource('FmsFacilityCodeClass');
- var FmsMaterialCodeClassDataSource = BemsWebApplication.db.createDataSource('FmsMaterialCodeClass');
- var FmsFacilityCodeClassInfo = ko.observableArray();
- var FmsMaterialCodeClassInfo = ko.observableArray();
- var RowName;
- function handleModification() {
- shouldReload = true;
- }
- function handleSelectionChanged(selectedRowsInfo) {
- //var id = $(selectedRowsInfo.element).attr('id');
- //console.log(selectedRowsInfo.selectedRowKeys.length);
- //var isNotExistSelectedRow = (selectedRowsInfo.selectedRowKeys.length === 0);
- //var classDepth = Number(id.replace('gridContainer', '')) - 1;
- //if (classDepth < 2) {
- // disabledInsertButtons[classDepth + 1](isNotExistSelectedRow);
- //}
- refreshAllStatus();
- }
- function refreshAllStatus() {
- var isSelected = false;
- var names = [];
- selectedClassDepth = 0;
- for (var i = 0 ; i < gridViews.length ; i++) {
- var rows = gridViews[i].getSelectedRowsData();
- if (_.isEmpty(rows) === false) {
- var row = rows[0];
- selectedClassDepth = i;
- isSelected = true;
- selectedIds[i].SiteId = row.SiteId();
- selectedIds[i][classIdFieldName] = row[classIdFieldName]();
- if (i < 2) {
- disabledInsertButtons[i + 1](false);
- }
- names.push(row.Name());
- }
- else {
- delete selectedIds[i].SiteId;
- delete selectedIds[i][classIdFieldName];
- if (i < 2) {
- disabledInsertButtons[i + 1](true);
- }
- }
- }
- if (hasnotModificationPermission()) {
- for (var i = 0 ; i < 3 ; i++) {
- disabledInsertButtons[i](true);
- }
- disabledUpdateButton(true);
- }
- else {
- disabledUpdateButton(isSelected === false);
- }
- selectedClassName([selectedClassNameTitle, names.join(' /')].join(' '));
- }
- function handleViewShown() {
- if (hasnotModificationPermission()) {
- for (var i = 0 ; i < 3 ; i++) {
- disabledInsertButtons[i](true);
- }
- disabledUpdateButton(true);
- }
- if (shouldReload) {
- shouldReload = false;
- refreshList();
- //for (var i = 0 ; i < 3 ; i++) {
- // dataSources[i].pageIndex(0);
- // dataSources[i].load();
- //}
- }
- if (initialized === false) {
- for (var j = 0 ; j < 3 ; j++) {
- var dataGridOptions = j == 2 ? {
- columns: [
- { dataField: 'Abbreviation', caption: $G('abbreviation'), width: '20%', alignment: 'center' },
- { dataField: 'Name', caption: $G('className'), width: '50%', alignment: 'center' },
- utils.datagrid.columnIsUse('30%')
- ]
- } : {
- columns: [
- { dataField: 'Abbreviation', caption: $G('abbreviation'), width: '30%', alignment: 'center' },
- { dataField: 'Name', caption: $G('className'), width: '70%', alignment: 'center' }
- ]
- };
- dataGridOptions.selectedSourceItem = dataViewModel;
- dataGridOptions.dbId = dbModelId;
- dataGridOptions.selectedId = selectedIds[j];
- dataGridOptions.datagridId = 'gridContainer' + (j + 1);
- dataGridOptions.selectionChanged = handleSelectionChanged;
- dataGridOptions.handleDataGridRowClick = handleDataGridRowClick;
- var id = ['#', 'gridContainer', (j + 1)].join('');
- dataGridOptions = utils.datagrid.defaultOptions(dataGridOptions);
- $(id).dxDataGrid(dataGridOptions);
- gridViews[j] = $(id).dxDataGrid('instance');
- }
- $("#gridContainer1").dxDataGrid({
- paging: {
- pageSize: 19
- }
- });
- $("#gridContainer2").dxDataGrid({
- paging: {
- pageSize: 19
- }
- });
- $("#gridContainer3").dxDataGrid({
- paging: {
- pageSize: 19
- }
- });
- refreshDataSource(0, null);
- initialized = true;
- }
- }
- function refreshDataSource(depth, parentId) {
- dataSources[depth].filter([parentClassIdFieldName, '=', parentId], 'and', ['SiteId', '=', BWA.UserInfo.SiteId()]); //**kgpark
- dataSources[depth].load().done(function (array) {
- gridViews[depth].option('dataSource', array);
- gridViews[depth].refresh();
- });
- }
- function handleDataGridRowClick(id, dataGrid, clickRow) {
- switch (id) {
- case 'gridContainer1':
- refreshDataSource(1, clickRow.data[classIdFieldName]());
- refreshDataSource(2, -1);
- break;
- case 'gridContainer2':
- refreshDataSource(2, clickRow.data[classIdFieldName]());
- break;
- case 'gridContainer3':
- break;
- }
- if (dbModelId == 'FmsFacilityCodeClass') {
- FmsFacilityCodeClassDataSource.filter([
- ["SiteId", "=", BWA.UserInfo.SiteId()],
- "and",
- ["Depth", "=", clickRow.data.Depth()],
- "and",
- ["ParentFacilityClassId", "=", clickRow.data.ParentFacilityClassId()]
- ]);
- FmsFacilityCodeClassDataSource.load().done(function (result) {
- FmsFacilityCodeClassInfo(result);
- });
- }
- else if (dbModelId == 'FmsMaterialCodeClass') {
- FmsMaterialCodeClassDataSource.filter([
- ["SiteId", "=", BWA.UserInfo.SiteId()],
- "and",
- ["Depth", "=", clickRow.data.Depth()],
- "and",
- ["ParentMaterialClassId", "=", clickRow.data.ParentFacilityClassId()]
- ]);
- FmsMaterialCodeClassDataSource.load().done(function (result) {
- FmsMaterialCodeClassInfo(result);
- });
- }
- RowName = clickRow.data.Name;
- }
- function handleViewDisposing() {
- BemsWebApplication.db[dbModelId].modified.remove(handleModification);
- }
- viewModel = BWA.CommonView.create(params, viewInfo, null, null, handleViewShown);
- hasnotModificationPermission = viewModel.hasnotModificationPermission;
- var dataSourceOptions = {
- store: BemsWebApplication.db[dbModelId],
- map: function (item) {
- return new BemsWebApplication[viewModelName](item);
- }
- };
- for (var k = 0 ; k < 3 ; k++) {
- dataSources[k] = new DevExpress.data.DataSource(dataSourceOptions);
- dataSources[k].pageSize(30);
- }
- dataSources[0].filter([
- ['SiteId', '=', BWA.UserInfo.SiteId()],
- 'and',
- [parentClassIdFieldName, '=', null]
- ]);
- dataSources[1].filter(parentClassIdFieldName, '=', -1);
- dataSources[2].filter(parentClassIdFieldName, '=', -1);
- function refreshList() {
- if (selectedClassDepth === 0) {
- refreshDataSource(0, null);
- }
- for (var i = Math.max(1, selectedClassDepth) ; i < 3 ; i++) {
- var classId = selectedIds[i - 1][classIdFieldName];
- if (_.isUndefined(classId)) continue;
- refreshDataSource(i, selectedIds[i - 1][classIdFieldName]);
- }
- }
- function handlePopupShowing(e) {
- if (isNewInPopup() == false) {
- activePopupViewMode();
- BemsWebApplication.db[dbModelId].byKey(selectedIds[selectedClassDepth]).done(function (data) {
- dataViewModel.fromJS(data);
- });
- }
- else {
- //activePopupInsertMode();
- clearDataModelValue(dataViewModel);
- }
- visibleCancelButton(false);
- }
- function clearDataModelValue(v) {
- $.each(v, function (name, value) {
- if (name !== parentClassIdFieldName && name !== 'Depth') {
- v[name](null);
- }
- });
- v.SiteId(BWA.UserInfo.SiteId());
- v.IsUse(true); // hcLee 2016 03 10
- }
- BemsWebApplication.db[dbModelId].modified.add(handleModification);
- // TODO: 아래 breakpoint 에 대해 FmsBudgetCodeClass 의 분기가 필요 함
- function handleConfirmDelete() {
- //alert(classIdFieldName);
- //alert(classIdFieldName.FacilityClassId);
- if (dbModelId == 'FmsBudgetCodeClass') {
- BWA.api.post('FmsBudgetCodeClass2/Delete', dataViewModel.toJS()).done(function () {
- refreshList();
- utils.toast.show($G('successDatabaseDeleteMsg'));
- popupVisible(false);
- });
- }
- else {
- var parameters = {
- SiteId: dataViewModel.SiteId(),
- Depth: dataViewModel.Depth()
- };
- parameters[classIdFieldName] = dataViewModel[classIdFieldName]();
- // alert(classIdFieldName + parameters[classIdFieldName]);
- BemsWebApplication.api.delete(dbModelId, parameters).done(function () {
- refreshList();
- utils.toast.show($G('successDatabaseDeleteMsg'));
- popupVisible(false);
- });
- }
- }
- function update() {
- if (dbModelId == 'FmsBudgetCodeClass') {
- BWA.api.post('FmsBudgetCodeClass2/Update', dataViewModel.toJS()).done(function () {
- refreshList();
- utils.toast.show($G('successDatabaseUpdateMsg'));
- popupVisible(false);
- });
- }
- else
- if (dbModelId == 'FmsFacilityCodeClass') {
- BWA.api.post('FmsFacilityCodeClass/Update', dataViewModel.toJS()).done(function () {
- refreshList();
- utils.toast.show($G('successDatabaseUpdateMsg'));
- popupVisible(false);
- });
- }
- else {
- BemsWebApplication.db[dbModelId].update(selectedIds[selectedClassDepth], dataViewModel.toJS()).done(function () {
- refreshList();
- utils.toast.show($G('successDatabaseUpdateMsg'));
- popupVisible(false);
- });
- }
- }
- function insert() {
- if (dbModelId == 'FmsBudgetCodeClass') {
- BWA.api.post('FmsBudgetCodeClass2/Insert', dataViewModel.toJS()).done(function () {
- refreshList();
- refreshAllStatus();
- utils.toast.show($G('successDatabaseInsertionMsg'));
- popupVisible(false);
- });
- }
- else {
- //if (dbModelId == 'FmsFacilityCodeClass') {
- // BWA.api.post('FmsFacilityCodeClass/Insert', dataViewModel.toJS()).done(function () {
- // refreshList();
- // refreshAllStatus();
- // utils.toast.show($G('successDatabaseInsertionMsg'));
- // popupVisible(false);
- // });
- //}
- //else {
- BemsWebApplication.db[dbModelId].insert(dataViewModel.toJS()).done(function (values, newId) {
- refreshList();
- refreshAllStatus();
- utils.toast.show($G('successDatabaseInsertionMsg'));
- popupVisible(false);
- });
- //}
- }
- }
- function activePopupEditMode() {
- viewModeInPopup(false);
- isEditModeInPopup(true);
- }
- function activePopupViewMode() {
- viewModeInPopup(true);
- isEditModeInPopup(false);
- }
- var tmpName, tmpAbbreviation;
- function handlePopupButtonEdit() {
- tmpName = dataViewModel.Name();
- tmpAbbreviation = dataViewModel.Abbreviation();
- activePopupEditMode();
- visibleCancelButton(true);
- }
- function handlePopupButtonCancel() {
- dataViewModel.Name(tmpName);
- dataViewModel.Abbreviation(tmpAbbreviation);
- activePopupViewMode();
- visibleCancelButton(false);
- }
- function popupInsertView() {
- activePopupEditMode();
- popupVisible(true);
- }
- function handlePopupButtonSave() {
- // 필수 입력 조건 체크
- // cyim 2015.12.28 : 설정-시설관리-시설등록-시설분류목록에 추가되는 항목에 입력 조건 추가 (약어,분류 명칭)
- //if (dbModelId == 'FmsFacilityCodeClass') {
- // if (BWA.DataUtil.isValidInputValue(dataViewModel.Abbreviation()) == false || BWA.DataUtil.isValidInputValue(dataViewModel.Name()) == false) {
- // utils.toast.show($G('Error_FmsFacilityCodeClass_NotInputData'), 'error');
- // return;
- // }
- // // hcLee 2016 01 15
- // // cyim 2015.12.30 : 설정-시설관리-시설등록-시설분류목록에 중복 입력 체크
- // BWA.api.post('FmsFacilityCodeClass/Check', dataViewModel.toJS()).done(function (result) {
- // if (result == false) {
- // utils.toast.show($G('Error_SameInputData'), 'error');
- // return;
- // }
- // if (isNewInPopup())
- // insert();
- // else
- // update();
- // });
- //}
- var isDuplicated = false;
-
- if (dbModelId == 'FmsFacilityCodeClass') {
-
- if (isNewInPopup()) {
- for (var i = 0; i < FmsFacilityCodeClassInfo().length; i++) {
- if (dataViewModel.Name() == FmsFacilityCodeClassInfo()[i].Name() || dataViewModel.Abbreviation() == FmsFacilityCodeClassInfo()[i].Abbreviation()) {
- isDuplicated = true;
- break;
- }
- }
- }
- else {
- for (var i = 0; i < FmsFacilityCodeClassInfo().length; i++) {
- if (RowName() != FmsFacilityCodeClassInfo()[i].Name() && (dataViewModel.Name() == FmsFacilityCodeClassInfo()[i].Name() || dataViewModel.Abbreviation() == FmsFacilityCodeClassInfo()[i].Abbreviation())) {
- isDuplicated = true;
- break;
- }
- }
- }
- if (!BWA.DataUtil.isValidInputValue(dataViewModel.Name()) || !BWA.DataUtil.isValidInputValue(dataViewModel.Abbreviation())) {
- utils.toast.show('저장 혹은 수정 반드시 필수 입력 정보를 모두 입력하셔야 합니다 (앞뒤공백 허용안함)', 'error');
- }
- else {
- if (isDuplicated) {
- utils.toast.show('이미 동일 정보가 존재합니다.', 'error');
- }
- else {
- if (isNewInPopup())
- insert();
- else
- update();
- }
- }
- }
- else if (dbModelId == 'FmsMaterialCodeClass') {
- if (isNewInPopup()) {
- for (var i = 0; i < FmsMaterialCodeClassInfo().length; i++) {
- if (dataViewModel.Name() == FmsMaterialCodeClassInfo()[i].Name() || dataViewModel.Abbreviation() == FmsMaterialCodeClassInfo()[i].Abbreviation()) {
- isDuplicated = true;
- break;
- }
- }
- }
- else {
- for (var i = 0; i < FmsMaterialCodeClassInfo().length; i++) {
- if (RowName() != FmsMaterialCodeClassInfo()[i].Name() && (dataViewModel.Name() == FmsMaterialCodeClassInfo()[i].Name() || dataViewModel.Abbreviation() == FmsMaterialCodeClassInfo()[i].Abbreviation())) {
- isDuplicated = true;
- break;
- }
- }
- }
- if (!BWA.DataUtil.isValidInputValue(dataViewModel.Name()) || !BWA.DataUtil.isValidInputValue(dataViewModel.Abbreviation())) {
- utils.toast.show('저장 혹은 수정 반드시 필수 입력 정보를 모두 입력하셔야 합니다 (앞뒤공백 허용안함)', 'error');
- }
- else {
- if (isDuplicated) {
- utils.toast.show('이미 동일 정보가 존재합니다.', 'error');
- }
- else {
- if (isNewInPopup())
- insert();
- else
- update();
- }
- }
- }
- else {
- // hcLee 2016 01 15
- if (isNewInPopup())
- insert();
- else
- update();
- }
- }
- function handlePopupButtonDelete() {
- DevExpress.ui.dialog.confirm($G('deleteConfirmMsg'), "삭제").then(function (result) {
- if (result) {
- handleConfirmDelete();
- }
- else {
- // toast
- }
- });
- }
- function handlePopupButtonClose() {
- popupVisible(false);
- }
- function setInsertPopupInfo(depth, parentClassId) {
-
- if (dbModelId == 'FmsFacilityCodeClass') {
- FmsFacilityCodeClassDataSource.filter([
- ["SiteId", "=", BWA.UserInfo.SiteId()],
- "and",
- ["Depth", "=", depth],
- "and",
- ["ParentFacilityClassId", "=", parentClassId]
- ]);
- FmsFacilityCodeClassDataSource.load().done(function (result) {
- FmsFacilityCodeClassInfo(result);
- });
- }
- else if (dbModelId == 'FmsMaterialCodeClass') {
- FmsMaterialCodeClassDataSource.filter([
- ["SiteId", "=", BWA.UserInfo.SiteId()],
- "and",
- ["Depth", "=", depth],
- "and",
- ["ParentMaterialClassId", "=", parentClassId]
- ]);
- FmsMaterialCodeClassDataSource.load().done(function (result) {
- FmsMaterialCodeClassInfo(result);
- });
- }
- isNewInPopup(true);
- activePopupEditMode();
- dataViewModel[parentClassIdFieldName](parentClassId);
- dataViewModel.Depth(depth);
- selectedClassDepth = depth;
- isClass3(depth === 2);
- popupVisible(true);
- }
- var toolbarItems = [
- { location: 'before', text: $G('detailInfo') },
- { location: 'after', widget: 'button', options: { text: $G('edit'), icon: 'edit', visible: viewModeInPopup, clickAction: handlePopupButtonEdit } },
- { location: 'after', widget: 'button', options: { text: $G('delete'), type: 'danger', icon: 'remove', visible: viewModeInPopup, clickAction: handlePopupButtonDelete } },
- { location: 'after', widget: 'button', options: { text: $G('cancel'), icon: 'arrowleft', type: 'default', visible: visibleCancelButton, clickAction: handlePopupButtonCancel } },
- { location: 'after', widget: 'button', options: { text: $G('save'), icon: 'save', visible: isEditModeInPopup, clickAction: handlePopupButtonSave } },
- { location: 'after', widget: 'button', options: { text: $G('close'), icon: 'close', clickAction: handlePopupButtonClose } }
- ];
- 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 }
- }
- };
- return $.extend(viewModel, {
- dataModel: dataViewModel,
- refreshList: refreshList,
- //viewShowing: handleViewShowing ,
- //viewShown: handleViewShown,
- viewDisposing: handleViewDisposing,
- popupInsertView: popupInsertView,
- viewModeInPopup: viewModeInPopup,
- isEditModeInPopup: isEditModeInPopup,
- isNewInPopup: isNewInPopup,
- popupOptions: popupOptions,
- commandInsertButtonOptions: commandInsertButtonOptions,
- commandUpdateButtonOption: commandUpdateButtonOption,
- selectedClassName: selectedClassName,
- toolbarItems: toolbarItems,
- isClass3: isClass3,
- });
- };
- })();
|