123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- 'use strict';
- /**
- * controller for User Profile Example
- */
- app.controller('incidentsourceCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm_data", function($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm_data) {
- $scope.langs = i18nService.getAllLangs();
- $scope.lang = 'zh-cn';
- i18nService.setCurrentLang($scope.lang);
- var loginUser = $rootScope.user;
- $scope.gridOptions = {};
- $scope.gridOptions.data = 'myData';
- $scope.gridOptions.enableColumnResizing = true;
- $scope.gridOptions.enableFiltering = true;
- $scope.gridOptions.enableGridMenu = false;
- $scope.gridOptions.enableRowSelection = true;
- $scope.gridOptions.showGridFooter = true;
- $scope.gridOptions.showColumnFooter = false;
- $scope.gridOptions.fastWatch = true;
- $scope.gridOptions.useExternalFiltering = true;
- $scope.gridOptions.useExternalPagination = true;
- $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
- $scope.gridOptions.paginationPageSize = 10;
- $scope.gridOptions.multiSelect = false;
- //$scope.gridOptions.rowTemplate= "<div ng-dblclick=\"grid.appScope.onDblClick(row)\" ng-repeat=\"(colRenderIndex, col) in colContainer.renderedColumns track by col.uid\" ui-grid-one-bind-id-grid=\"rowRenderIndex + '-' + col.uid + '-cell'\" class=\"ui-grid-cell\" ng-class=\"{ 'ui-grid-row-header-cell': col.isRowHeader }\" role=\"{{col.isRowHeader ? 'rowheader' : 'gridcell'}}\" ui-grid-cell></div>";
- $scope.gridOptions.rowIdentity = function(row) {
- return row.id;
- };
- $scope.gridOptions.getRowIdentity = function(row) {
- return row.id;
- };
- $scope.gridOptions.columnDefs = [{
- name: '编辑',
- cellTemplate: '<div><div class="links cl-effect-1 ui-grid-cell-contents" ><a ng-click="grid.appScope.saveData(row.entity)" tooltip="编辑" tooltip-placement="right">' +
- '<i class="fa fa-pencil-square-o"></i></a></div></div>',
- width: 60,
- enableFiltering: false
- },
- { name: 'source', displayName: '事件来源', width: 100, enableFiltering: false },
- { name: 'code', displayName: '来源关联', width: 300, enableFiltering: false }
- // {
- // name: '修改',
- // cellTemplate: '<a class="btn btn-sm btn-info" ng-click="grid.appScope.saveData(row.entity)" tooltip="编辑">' +
- // '<i class="fa fa-pencil-square-o"/></a>',
- // width: 100,
- // enableFiltering: false
- // }
- ];
- $scope.saveData = function(selectdata) {
- var modalInstance = $modal.open({
- templateUrl: 'assets/views/system/tpl/systemsource.html',
- controller: function($scope, $modalInstance, api_bpm_data) {
- $scope.sourcedata = {};
- $scope.sourcedata = selectdata;
- $scope.options = {
- language: 'zh-cn',
- allowedContent: true,
- entities: false
- };
- $scope.cancel = function() {
- $modalInstance.dismiss('cancel');
- };
- $scope.savercode = function(sourcedata) {
- var fildata = { "incidentsource": { "id": sourcedata.id, "source": sourcedata.source, "code": sourcedata.code } }
- api_bpm_data.updData('incidentsource', fildata).then(function(response) {
- if (response) {
- if (response.status == 200) {
- SweetAlert.swal({
- title: "修改成功!",
- type: "success"
- }, function() {
- // $scope.refreshData('expand-right', defaultFilterData);
- })
- } else {
- SweetAlert.swal({
- title: "修改失败!",
- type: "error"
- })
- }
- }
- })
- $modalInstance.close();
- }
- }
- });
- }
- $scope.addData = function() {
- console.log($scope.selected)
- var modalInstance = $modal.open({
- templateUrl: 'assets/views/system/tpl/systemsource.html',
- controller: function($scope, $modalInstance, api_bpm_data) {
- $scope.options = {
- language: 'zh-cn',
- allowedContent: true,
- entities: false
- };
- $scope.cancel = function() {
- $modalInstance.dismiss('cancel');
- };
- $scope.savercode = function(sourcedata) {
- $modalInstance.close(sourcedata);
- };
- }
- });
- modalInstance.result.then(function(selectedItem) {
- console.log('selectedItem=' + JSON.stringify(selectedItem));
- if (selectedItem) {
- var fildata = { "incidentsource": { "source": selectedItem.source, "code": selectedItem.code } }
- api_bpm_data.addData('incidentsource', fildata).then(function(response) {
- if (response) {
- if (response.status == 200) {
- SweetAlert.swal({
- title: "新增成功!",
- type: "success"
- }, function() {
- $scope.refreshData('expand-right', defaultFilterData);
- })
- } else {
- SweetAlert.swal({
- title: "新增失败!",
- type: "error"
- })
- }
- }
- })
- }
- });
- }
- $scope.removeData = function() {
- var modalInstance = $modal.open({
- templateUrl: 'assets/views/delete.html',
- controller: function($scope, scope, $modalInstance, api_bpm_data) {
- var rmvList = [scope.selected.items.id]
- $scope.ok = function() {
- $modalInstance.close(rmvList);
- // }
- };
- $scope.cancel = function() {
- $modalInstance.dismiss('cancel');
- };
- },
- size: 'sm',
- resolve: {
- scope: function() {
- return $scope;
- }
- }
- });
- modalInstance.result.then(function(selectedItem) {
- if (selectedItem) {
- if (selectedItem.length > 0) {
- api_bpm_data.rmvData('incidentsource', selectedItem).then(function(response) {
- if (response.status == 200) {
- SweetAlert.swal({
- title: "删除成功!",
- type: "success",
- confirmButtonColor: "#007AFF"
- }, function() {
- $scope.myData = _.reject($scope.myData, function(o) { return _.includes(selectedItem, o.id); });
- $scope.selected = {
- items: []
- };
- $scope.gridOptions.totalItems = $scope.gridOptions.totalItems - selectedItem.length
- $scope.gridApi.grid.selection.selectedCount = 0;
- });
- } else {
- SweetAlert.swal({
- title: "操作异常!",
- text: "系统异常,请稍后重试,或者联系管理员!",
- type: "error"
- });
- }
- })
- }
- }
- })
- }
- // $scope.removeData = function(){
- // var rmvList = [$scope.selected.items.id]
- // if(rmvList.length>0){
- // api_bpm_data.rmvData('incidentsource',rmvList).then(function(response){
- // if(response.status==200){
- // SweetAlert.swal({
- // title: "删除成功!",
- // type: "success",
- // confirmButtonColor: "#007AFF"
- // },function(){
- // $scope.myData = _.reject($scope.myData, function(o) { return _.includes(rmvList,o.id); });
- // $scope.selected = {
- // items:[]
- // };
- // });
- // }else{
- // SweetAlert.swal({
- // title: "操作异常!",
- // text: "系统异常,请稍后重试,或者联系管理员!",
- // type: "error"
- // });
- // }
- // })
- // }
- // }
- $scope.selected = {
- items: []
- }
- $scope.editted = {
- items: []
- }
- $scope.gridOptions.onRegisterApi = function(gridApi) {
- $scope.gridApi = gridApi;
- // gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
- // console.log(rowEntity);
- // });
- gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) {
- var filtersData = $scope.memoryfilterData;
- filtersData.idx = newPage - 1;
- filtersData.sum = pageSize;
- $scope.refreshData('expand-right', filtersData);
- });
- gridApi.selection.on.rowSelectionChanged($scope, function(scope) {
- scope.grid.appScope.selected.items = scope.entity
- });
- };
- var defaultFilterData = {
- "idx": 0,
- "sum": 10
- };
- $scope.memoryfilterData = {
- "idx": 0,
- "sum": 1000
- }
- $scope.ldloading = {};
- $scope.refreshData = function(style, filterData) {
- $scope.ldloading[style.replace('-', '_')] = true;
- if (angular.isUndefined(filterData)) {
- filterData = defaultFilterData;
- }
- $scope.myData = [];
- $scope.selected = { items: [] };
- if ($scope.gridApi) {
- $scope.gridApi.grid.selection.selectedCount = 0;
- }
- api_bpm_data.fetchDataList('incidentsource', filterData).then(function(data) {
- var myData = Restangular.stripRestangular(data);
- $scope.gridOptions.totalItems = myData.totalNum;
- $scope.myData = myData.list;
- $scope.ldloading[style.replace('-', '_')] = false;
- }, function() {
- $scope.ldloading[style.replace('-', '_')] = false;
- });
- };
- $scope.refreshData('expand-right', defaultFilterData);
- }]);
|