(function(window, angular, undefined) {
'use strict';
angular.module('testApp').controller('listCtrl', listCtrl);
listCtrl.$inject = ['$scope', '$stateParams', '$state', 'growl', 'httpSvc', 'DTOptionsBuilder', 'DTColumnBuilder', '$compile'];
listCtrl($scope, $stateParams, $state, growl, DTOptionsBuilder, DTColumnBuilder, $compile) {
$scope.pc = {};
$scope.pc.dtInstance = {};
$scope.instances = [];
$scope.pc.dtColumns = [
DTColumnBuilder.newColumn("name").withTitle('Name'),
DTColumnBuilder.newColumn("type").withTitle('Type'),
DTColumnBuilder.newColumn("age").withTitle('Age'),
DTColumnBuilder.newColumn("updated_by").withTitle('Updated By'),
DTColumnBuilder.newColumn("status").withTitle('Status').renderWith(statusHtml),
DTColumnBuilder.newColumn(null).withTitle('Actions').notSortable()
.renderWith(actionsHtml)
]
$scope.pc.dtOptions = DTOptionsBuilder.newOptions()
.withOption('ajax', function(data, callback, settings) {
getListing(data).success(function(res) {
callback({
recordsTotal: res.results.recordsTotal,
recordsFiltered: res.results.recordsFiltered,
data: res.results.data
});
});
})
.withDataProp('data')
.withDOM('lBfrtip')
.withOption('processing', false)
.withOption('serverSide', true)
.withPaginationType('full_numbers')
.withDisplayLength(2)
.withOption('lengthMenu', [2, 4, 6, 10])
.withOption('aaSorting', [0, 'asc'])
.withOption('createdRow', function(row) {
$compile(angular.element(row).contents())($scope);
})
.withButtons([{
extend: 'copy',
text: '<i class="fa fa-files-o"></i> Copy',
titleAttr: 'Copy'
},
{
extend: 'print',
text: '<i class="fa fa-print" aria-hidden="true"></i> Print',
titleAttr: 'Print'
},
{
extend: 'excel',
text: '<i class="fa fa-file-text-o"></i> Excel',
titleAttr: 'Excel'
},
{
extend: "csvHtml5"
}
]);
function actionsHtml(data, type, full, meta) {
return '<button class="btn btn-warning" ng-click="editItem(\'' + data.name + '\');">' + '<i class="fa fa-edit"></i>' + '</button> ' + '<button class="btn btn-danger" ng-click="deleteItem();">' + '<i class="fa fa-trash-o"></i>' + '</button>';
}
function statusHtml(data, type, full, meta) {
console.log(full.id);
var activeClass = data == 'running' ? 'badge-warning' : data == 'success' ? 'badge-green' : 'badge-danger';
return '<button class="btn badge ' + activeClass + '" ng-click="getStatusRequest(\'' + full.name + ',' + full.type + ',' + full.status + '\');">' + data + '</button>';
}
$scope.editItem = function(name) {
console.log(name);
}
$scope.deleteItem = function(name) {
console.log(11);
}
fucntion getListing() {
return $http({
method: 'POST',
url: '/listing',
data: ''
})
}
}
})(window, window.angular);