attributeCtrl.js
4.02 KB
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
(function(angular) {
function attributeCtrl($scope, attributeService, $resource, DTOptionsBuilder, DTColumnBuilder, $compile,Utils,$uibModal) {
// 加入列头
$scope.dtColumns = [
DTColumnBuilder.newColumn('id').withOption('width',120).withTitle('编号'),
DTColumnBuilder.newColumn('attrName').withOption('width',100).withTitle('属性'),
DTColumnBuilder.newColumn('attrValName').withOption('width',120).withTitle('属性值'),
DTColumnBuilder.newColumn(null).withTitle(function(){
return '操作';
}).withOption('width', 140).withClass('text-center').renderWith(function(data, type, full, oSettings) {
var str = '<div class="form-inline">'
+'<div class="form-group"><a class="btn btn-link" ng-click="cancel('+ data.id +')">删除</a></div>'
str += '</div>';
return str;
})
];
$scope.cancel = function(item) {
swal({
title: "删除",
text: "是否确认删除此属性?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "确定",
cancelButtonText: "取消",
closeOnConfirm: false
}, function (isConfirm) {
isConfirm && cancelAttr(item);
});
}
$scope.addAttribute = function(){
$uibModal.open({
templateUrl : 'biz/electronicDirectory/view/addAttribute.html',
controller : 'addAttributeCtrl',
size : 'md',
scope:$scope,
resolve : {
}
}).result.then(function(){
//关闭弹框后执行方法
});
}
/**
* 删除
*/
function cancelAttr(id) {
swal({ title:'删除中', text: "请稍候...", showConfirmButton: false });
attributeService.cancelAttribute({'attrValId':id}, function (result) {
if (result.returnCode == '0') {
swal({
type: 'success',
title: '',
html: true,
text: '删除成功',
showConfirmButton: false,
timer: 1000
});
$scope.tableSearch();
} else {
swal({
type: 'error',
title: '',
html: true,
text: '删除失败 ' + (result.message || ''),
confirmButtonText: "确定"
});
}
});
};
// 将自定义头部加入
$scope.dtOptions = DTOptionsBuilder.newOptions()
//.withOption('lengthChange', false)
.withOption('lengthMenu', [20,40,60,100])
.withOption('completeCb', function() {
//使table头部自定义内容能够绑定到当前scope
setTimeout(function(){
$compile(angular.element('.dt-head-ctrl').contents())($scope);
},0)
});
// 数据请求
$scope.dtInstance = {
serverData : attributeService.getAttributeList
};
$scope.tableSearch = function(){
var params = getParams();
$scope.dtInstance.query(params);
};
function getParams(){
var obj = {};
if($scope.selectCondition && $scope.conditionText){
if ($scope.selectCondition == 1) {
obj.attrName = $scope.conditionText;
}else if ($scope.selectCondition == 2) {
obj.idStr = $scope.conditionText;
}
}
var param = {
condition:obj
};
return param;
};
}
angular.module('electronicDirectory').controller('attributeCtrl', attributeCtrl)
})(angular);