'use strict';
/**
* controller for User Profile Example
*/
app.controller('priorityCtrl', ["$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= "
";
$scope.gridOptions.rowIdentity = function(row) {
return row.id;
};
$scope.gridOptions.getRowIdentity = function(row) {
return row.id;
};
$scope.gridOptions.columnDefs = [{
name: 'item',
displayName: '序号',
width: 50,
enableFiltering: false
},
{ name: 'name', displayName: '优先级', width: '15%', enableFiltering: false },
{ name: 'description', displayName: '优先级描述', width: '55%', enableFiltering: false },
{
name: '编辑',
cellTemplate: '',
enableFiltering: false
},
];
$scope.saveData = function(selectdata) {
var modalInstance = $modal.open({
templateUrl: 'assets/views/system/tpl/systempriority.html',
controller: function($scope, scope, $modalInstance, api_bpm_data) {
$scope.prioritydata = {};
$scope.prioritydata = selectdata;
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
$scope.savercode = function(prioritydata) {
if (prioritydata.name && prioritydata.name != "") {
var fildata = { "priority": { "id": prioritydata.id, "level": prioritydata.level, "name": prioritydata.name, "description": prioritydata.description } }
api_bpm_data.updData('priority', fildata).then(function(response) {
if (response) {
if (response.status == 200) {
SweetAlert.swal({
title: "修改成功!",
type: "success"
}, function() {
})
} else {
scope.refreshData('expand-right', defaultFilterData);
SweetAlert.swal({
title: "修改失败!",
type: "error"
})
}
}
})
$modalInstance.close();
} else {
scope.refreshData('expand-right', defaultFilterData);
SweetAlert.swal({
title: "修改失败!",
text: "优先级未填",
type: "error"
})
}
}
},
resolve: {
scope: function() {
return $scope;
}
}
});
}
$scope.addData = function() {
var modalInstance = $modal.open({
templateUrl: 'assets/views/system/tpl/systempriority.html',
controller: function($scope, $modalInstance, api_bpm_data) {
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
$scope.savercode = function(prioritydata) {
if (prioritydata.name && prioritydata.name != "") {
$modalInstance.close(prioritydata);
} else {
SweetAlert.swal({
title: "新增失败!",
text: "优先级未填",
type: "error"
})
}
};
}
});
modalInstance.result.then(function(selectedItem) {
// console.log('selectedItem='+JSON.stringify(selectedItem));
if (selectedItem) {
var fildata = { "priority": { "level": selectedItem.level, "name": selectedItem.name, "description": selectedItem.description } }
api_bpm_data.addData('priority', 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.title = '优先级删除';
$scope.connect = '确定要删除此优先级?';
$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('priority', 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.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;
defaultFilterData = filtersData;
$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": 10
}
$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('priority', filterData).then(function(data) {
var myData = Restangular.stripRestangular(data);
$scope.gridOptions.totalItems = myData.totalNum;
$scope.myData = myData.list;
for (var i = 0; i < $scope.myData.length; i++) {
$scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
}
$scope.ldloading[style.replace('-', '_')] = false;
}, function() {
$scope.ldloading[style.replace('-', '_')] = false;
});
};
$scope.refreshData('expand-right', defaultFilterData);
}]);