key-value-configuration.ctrl.js 19.8 KB
Newer Older
eddie.woo's avatar
eddie.woo committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
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();
    })();
}]);