systemConfigurationModule.controller('keyValueConfigController', ['$log', '$scope', '$translate', '$q', 'KeyValueConfigService', '$uibModal', 'SweetAlert', 'enums', function ($log, $scope, $translate, $q, KeyValueConfigService, $uibModal, SweetAlert, enums) { var prefectDisplay = function (text, len) { (text.length > len) ? text.string.substring(0, len) + '...' : text; }; var selectedEditModel; var removeKeyValue = function (key) { KeyValueConfigService.remove(key).then(function (res) { if (res.data === 0) { SweetAlert.warning('', $translate.instant('ActionFail')); //delete fail } else if (res.data === -1) { //has reference SweetAlert.warning('', $translate.instant('IsUsed')); } else { // SweetAlert.warning('', $translate.instant('DeleteSuccess')); var dataGrid = $("#KVgridContainer").dxDataGrid("instance"); dataGrid.refresh(); //return $q.reject($translate.instant("DeleteSuccess")); } }, function (response) { //return $q.reject($translate.instant("ActionFail")); SweetAlert.warning('', $translate.instant('ActionFail')); }); } var deFineKeyValueGrid = function () { var keyValues = new DevExpress.data.CustomStore({ key: 'id', load: function (loadOptions) { return KeyValueConfigService.getAll().then(function (res) { return { data: res.data, totalCount: res.data.length }; }, function (response) { return $q.reject($translate.instant("DataLoadingError")); }); } }); $scope.keyValues = keyValues; $scope.keyValueOptions = { bindingOptions: { dataSource: { deep: false, dataPath: 'keyValues' }, }, selection: { mode: "single" }, //onSelectionChanged: function (selectedItems) { //}, paging: { pageSize: 15 }, filterRow: { visible: true }, allowColumnResizing: true, loadPanel: { enabled: false }, searchPanel: { visible: true, width: 240, placeholder: $translate.instant('SearchHintText') }, //editing: { // mode: "row", // allowDeleting: true, // texts: { // deleteRow: $translate.instant('Delete') // } //}, "export": { enabled: true, fileName: $translate.instant('KeyValueConfiguration'), allowExportSelectedData: false, texts: { exportAll: $translate.instant('ExportAllData'), exportTo: $translate.instant('Export') } }, height: '95%', scrolling: { mode: 'standard' }, onToolbarPreparing: function (e) { var toolbarItems = e.toolbarOptions.items; toolbarItems.unshift({ location: "before", template: "add" }); }, //onSelectionChanged: function (selectedItems) { // selectedEditModel = selectedItems.selectedRowsData[0]; // if (!selectedEditModel) return; // if (selectedEditModel.keyValueType !== 2) { // return; // } // $scope.editingModel = angular.copy(selectedEditModel); // var vals = selectedEditModel.dataSource.split('_'); // if (vals.length === 2) { // $scope.editingModel.dataSourceKey = parseInt(vals[0]); // $scope.editingModel.dataSourceName = vals[1]; // //if ($scope.editingModel.dataSourceKey === enums.formulaDataSourceType.KeyInSource) { // // $scope.editingModel.dataSourceName = vals[1]; // //} // } // $scope.state = 0; // $('#kvc-editing-modal').modal('show'); //}, //onRowClick: function (e) { // //console.log(e); // selectedEditModel = e.data; // if (!selectedEditModel) return; // //if (selectedEditModel.keyValueType !== 2) { // // return; // //} // $scope.editingModel = angular.copy(selectedEditModel); // $scope.state = 0; // $('#kvc-editing-modal').modal('show'); //}, columns: [ { dataField: 'id', visible: false,allowExporting:false }, //{ dataField: 'keyCode', caption: $translate.instant('KeyCode'), fixed: true }, { dataField: 'name', caption: $translate.instant('KeyName'), fixed: true, filterOperations: [], selectedFilterOperation: 'contains', alignment: 'left' }, { dataField: 'formula', caption: $translate.instant('TemplateFormulaDesc'), filterOperations: [], selectedFilterOperation: 'contains' }, { dataField: 'description', caption: $translate.instant('Description'), filterOperations: [], selectedFilterOperation: 'contains' }, { dataField: 'dataSource', caption: $translate.instant('DataSourceName'), filterOperations: [], selectedFilterOperation: 'contains', width: '10%', calculateCellValue: function (rowData) { if (rowData.dataSource) { var s = rowData.dataSource.split('_'); return s.length === 2 ? s[1] : s[0]; } return rowData.dataSource; }, calculateFilterExpression: function (filterValue, selectedFilterOperation) { return [this.calculateCellValue, selectedFilterOperation || 'contains', filterValue]; } }, { width: '10%', caption: $translate.instant('ApplicationScope'), filterOperations: [], selectedFilterOperation: 'contains', calculateCellValue: function (rowData) { if (rowData.scopeSummary) { var arry = rowData.scopeSummary.split(','); var tArry = ''; if (arry.length > 1) { _.each(arry, function (i) { tArry = tArry + ',' + $translate.instant(i); }); tArry = tArry.substring(1, tArry.length); } else { tArry = $translate.instant(arry[0]); } return tArry; } }, calculateFilterExpression: function (filterValue, selectedFilterOperation) { return [this.calculateCellValue, selectedFilterOperation || 'contains', filterValue]; } }, { width: '10%', dataField: 'keyValueType', caption: $translate.instant('KeyValueType'), filterOperations: [], selectedFilterOperation: 'contains', calculateCellValue: function (rowData) { return rowData.keyValueType ? constant.keyValueType[rowData.keyValueType - 1].name : null; }, calculateFilterExpression: function (filterValue, selectedFilterOperation) { return [this.calculateCellValue, selectedFilterOperation || 'contains', filterValue]; } }, { alignment: 'center', allowExporting: false, //caption: $translate.instant('Delete'), width: '8%', cellTemplate: function (container, options) { var data = options.data; //custom key value if ( data.keyValueType === 2 && $scope.actionPermission) { $('<i class="fa fa-edit delete-icon" aria-hidden="true" style="margin-right:8px;"></i>').click(function (event) { event.stopPropagation(); $scope.editingModel = angular.copy(data); if (data&&data.dataSource) { var vals = data.dataSource.split('_'); if (vals.length === 2) { $scope.editingModel.dataSourceKey = parseInt(vals[0]); $scope.editingModel.dataSourceName = vals[1]; } } $scope.state = 0; $('#kvc-editing-modal').modal('show'); }).appendTo(container); $('<i class="fa fa-trash delete-icon" aria-hidden="true"></i>').click(function (event) { event.stopPropagation(); //show message SweetAlert.swal({ title: $translate.instant('ConfirmDelete'), text: '', type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: $translate.instant('Confirm'), cancelButtonText: $translate.instant('Cancel'), closeOnConfirm: true }, function (isConfirm) { if (isConfirm) { removeKeyValue(data.id); } }); }).appendTo(container); } } } ], masterDetail: { enabled: true, template: "detail" } }; }; var deFineDetailTab = function () { $scope.detailPanel = function (key, countDic) { return { height:400, titleTemplate: function (itemData, itemIndex, itemElement) { itemElement.append("<p>" + itemData.title + "</p>"); }, dataSource: [ { title: $translate.instant('ReferenceFinancialReport') + "-" + (countDic["1"] ? countDic["1"] : 0), template: 'financialReportTemplate', FROptions: { noDataText: '', loadPanel: { enabled: false }, paging: { enabled: true, pageSize:50 }, //scrolling:{ // showScrollbar: 'always' //}, height: 300, dataSource: { store: new DevExpress.data.CustomStore({ load: function (loadOptions) { return KeyValueConfigService.getFinacialReference(key); } }) }, columns: [ { caption: $translate.instant('TemplateName'), dataField: 'name' }, { caption: $translate.instant('IndustryID'), dataField: 'industry' }, { caption: $translate.instant('Cell'), width: '6%', calculateCellValue: function (rowData) { return PWC.numToExcelChar(rowData.row, rowData.column); } }, { caption: $translate.instant('RowName'), dataField: 'row', width: '6%' }, { caption: $translate.instant('ColumnName'), dataField: 'column', width: '6%' } ] } }, { title: $translate.instant('ReferenceTaxReport') + "-" + (countDic["2"] ? countDic["2"] : 0), template: 'taxReportTemplate', TROptions: { noDataText: '', loadPanel: { enabled: false }, paging: { enabled: true, pageSize: 50 }, //scrolling: { // showScrollbar: 'always' //}, height:300, dataSource: { store: new DevExpress.data.CustomStore({ load: function (loadOptions) { return KeyValueConfigService.getTaxReference(key); } }) }, columns: [ //{ dataField: "cellTemplateID", visible: false }, //{ dataField: "templateID", visible: false }, //{ dataField: "templateGroupID", visible: false }, { caption: $translate.instant('ReportType'), dataField: 'category' }, { caption: $translate.instant('IndustryID'), dataField: 'industry' }, { dataField: 'payTaxType', caption: $translate.instant('PayTaxType'), calculateCellValue: function (rowData) { return rowData.payTaxType ? constant.payTaxTypeList[rowData.payTaxType - 1].name : null; } }, { caption: $translate.instant('TemplateGroupName'), dataField: 'templateGroupName' }, { dataField: 'name', caption: $translate.instant('TemplateName'), cellTemplate: 'taxLink' }, { caption: $translate.instant('Cell'), width: '6%', calculateCellValue: function (rowData) { return PWC.numToExcelChar(rowData.row, rowData.column); } }, { caption: $translate.instant('RowName'), dataField: 'row', width: '6%' }, { caption: $translate.instant('ColumnName'), dataField: 'column', width: '6%' } ] } }, { // 'title': $translate.instant('AnalyticsModel') + "<span class='count-custom'>" + (countDic["3"] ? countDic["3"] : 0)+"</span>", 'title': $translate.instant('AnalyticsModel') + "-" + (countDic["3"] ? countDic["3"] : 0), 'template': 'modelTemplate', 'MTOptions': { //noDataText: $translate.instant('NoDataAvailable'), noDataText: '', loadPanel: { enabled: false }, paging: { enabled: true, pageSize: 50 }, //scrolling: { // showScrollbar: 'always' //}, height: 300, dataSource: { store: new DevExpress.data.CustomStore({ load: function (loadOptions) { return KeyValueConfigService.getModelReference(key); } }) }, columns: [ //{ dataField: "modelID", visible: false }, { caption: $translate.instant('ModelCode'), dataField: 'code' }, { caption: $translate.instant('ModelName'), dataField: 'name' }, { caption: $translate.instant('ModelType'), dataField: 'type', calculateCellValue: function (rowData) { return $translate.instant(enums.modelType[rowData.type]); } }, { caption: $translate.instant('IndustryID'), dataField: 'industry' }, { dataField: 'entityName', caption: $translate.instant('OrganizationName'), cellTemplate: 'modelLink' } ] } } ] }; }; }; $scope.addNewKvc = function () { $('#kvc-editing-modal').modal('show'); $scope.state = 2; $scope.editingModel = {}; }; $scope.editDone = function (editingModel) { if ($scope.state === 1) { PWC.assignModel(editingModel, selectedEditModel); } }; // 关于日志部分 $scope.showOperateLogPop = function () { $scope.isShowLog = true; }; var checkPermissionList = function () { var list = []; var userManageTemp = constant.adminPermission.systemConfiguration.keyValueConfig; list = _.values(userManageTemp); $scope.viewPermission = false; $scope.actionPermission = false; $scope.$root.checkUserPermissionList(list).success(function (data) { $scope.viewPermission = data[userManageTemp.viewKey]; $scope.actionPermission = data[userManageTemp.keyAction]; }); }; (function initialize() { checkPermissionList(); deFineKeyValueGrid(); deFineDetailTab(); })(); }]);