123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- BemsWebApplication.SetMenu = function (params, viewInfo) {
- "use strict";
- var viewModel, sidemenuHashSet;
- var headerCheckBoxValues = ko.observable(false);
- var saving = ko.observable(false);
- var headerTemplate = function (header, info) {
- var dataGrid = $('#gridContainer').dxDataGrid('instance');
- var checkbox = $('<div>');
- checkbox.appendTo(header);
- checkbox.dxCheckBox({
- value: headerCheckBoxValues(),
- valueChangeAction: function (e) {
- headerCheckBoxValues(e.value);
- }
- });
- $('<div>')
- .css('display', 'inline-block')
- .html(info.column.caption)
- .appendTo(header);
- };
- var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'CmMenu', {
- popupWidth: 480,
- columns: [
- { dataField: 'SiteId', caption: '번호', width: '10%', allowSorting: false },
- { dataField: 'MenuPath', caption: '메뉴 경로', width: '60%', allowSorting: true },
- { dataField: 'Name', caption: '메뉴 이름', width: '20%', allowSorting: false },
- { dataField: 'MenuId', caption: '메뉴 ID', width: '20%', allowSorting: false },
- { dataField: 'Used', caption: '사용', width: '20%', allowSorting: false },
- ],
- "export": {
- enabled: true,
- fileName: '메뉴 목록',
- },
- onExporting: function (e) {
- e.component.columnOption("SiteId", "visible", false);
- },
- onExported: function (e) {
- e.component.columnOption("SiteId", "visible", true);
- },
- paging: {
- pageSize: 18,
- enabled: true
- },
- pager: {
- },
- cellPrepared: function (cellElement, cellInfo) {
- if (cellInfo.columnIndex == 4) {
- (function (element, info) {
- if (info.rowType == 'data') {
- var index = info.columnIndex - 4; //
- var checker = (1 << index);
- var checked = (info.value & checker);
- //console.log(info.columnIndex + ' ' + checked);
- $(cellElement).text('');
- var checkbox = $('<div>');
- checkbox.appendTo(element);
- checkbox.dxCheckBox({
- value: checked > 0 ? true : false,
- valueChangeAction: function (e) {
- var p = info.data.Used
- if (e.value) {
- p(p() | checker);
- }
- else {
- p(p() & ~checker);
- }
- }
- });
- var dataCheckBoxes = info.data.checkboxes = info.data.checkboxes || [];
- dataCheckBoxes[index] = checkbox;
- }
- })(cellElement, cellInfo);
- }
- },
- selection: {
- mode: 'none'
- },
- searchViewItems: [
- { id: 'MenuPath' },
- { id: 'Name' },
- { id: 'MenuId' }//ignoreValue: 0, defaultValue: 0, withCheckId: 'FirstClassId', value: searchFacilityClassValues[1], dataSource: searchFacilityClasses[1], handleChangedValue: handleSecondClassChangedValueInSearchView },
- ],
- handleViewShown: function () {
- sidemenuHashSet = $SideMenu.getSidemenuHashSet();
- _.each(sidemenuHashSet, function (items, id) {
- items['MenuId'] = id;
- items['Used'] = true;
- });
- //$SearchView.visibleObservable(false);
- },
- handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {
- }
- });
- function handleSave() {
- saving(true);
- var rows = utils.datagrid.getItems($('#gridContainer').dxDataGrid('instance'));
- var newmenus = [];
- _.each(rows, function (menu) {
- newmenus.push({
- SiteId: BWA.UserInfo.SiteId(),
- MenuId: menu.MenuId(),
- MenuPath: menu.MenuPath(),
- Used: menu.Used(),
- Name: menu.Name(),
- });
- });
- BWA.api.post('CmMenu/DeleteAll', { SiteId: BWA.UserInfo.SiteId() }).done(function () {
- BWA.api.post('CmMenu/InsertAll', newmenus).done(function () {
- viewModel.refreshList();
- utils.toast.show($G('successDatabaseProcessMsg'));
- saving(false);
- });
- });
- }
- // 메뉴 초기화
- function handleEdit() {
- var newmenus = [];
- _.each(sidemenuHashSet, function (menu) {
- newmenus.push({
- SiteId: BWA.UserInfo.SiteId(),
- MenuId: menu.MenuId,
- MenuPath: menu.MenuPath,
- Name: menu.Name,
- Used: true,
- });
- });
- BWA.api.post('CmMenu/DeleteAll', { SiteId: BWA.UserInfo.SiteId() }).done(function () {
- BWA.api.post('CmMenu/InsertAll', newmenus).done(function () {
- viewModel.refreshList();
- utils.toast.show($G('successDatabaseProcessMsg'));
- });
- });
- }
- function handleHeaderCheckboxValueFunc(index) {
- return function (check) {
- var rows = utils.datagrid.getItems($('#gridContainer').dxDataGrid('instance'));
- _.each(rows, function (data, i) {
- data.checkboxes[index].dxCheckBox({
- value: check
- });
- });
- };
- }
- headerCheckBoxValues.subscribe(handleHeaderCheckboxValueFunc(0))
- viewModel.popupVisible.subscribe(function (visible) {
- });
- viewModel.handleSave = handleSave;
- viewModel.handleEdit = handleEdit;
- viewModel.sidemenuHashSet = sidemenuHashSet;
- viewModel.saving = saving;
- return viewModel;
- };
|