zettapi_client
Version:
Client side CRUD operations in angular to use with zettapi_server rest api to get started quickly in any CMS project
56 lines (47 loc) • 1.9 kB
JavaScript
app.directive('zlList', function (zapiPath) {
return {
restrict: 'E',
scope: {
dbs: '=',
channel: '@'
},
replace: false,
templateUrl: zapiPath + '/directives/list/list.html',
controller: function ($scope, $list, NgTableParams, $httpParamSerializer) {
$scope.items = [];
$scope.tableParams = null;
$scope.list = { name: "", parameters: [], values: {} };
$scope.selectedDbs = [];
$list.getMetadata(function (lists) {
$scope.lists = lists;
});
$scope.reset = function () {
$scope.items = [];
$scope.tableParams = null;
};
$scope.get = function (list) {
$list.get(list, $scope.selectedDbs, $scope.channel, function (items) {
var initialParams = {}, params = { dataset: items };
if (list.group) {
initialParams.group = list.group;
}
if (typeof list.groupOptions !== 'undefined') {
params.groupOptions = list.groupOptions;
}
$scope.items = items;
$scope.tableParams = new NgTableParams(initialParams, params);
});
};
$scope.getExcelUrl = function (list) {
return '/api/list/values/' + list.name + '?xls=1&' + $httpParamSerializer({ query: list.values, dbs: $scope.selectedDbs });
};
$scope.applySearch = function (search) {
var criteria = angular.copy(search.text);
if (search.inverted) {
criteria = "!" + criteria;
}
$scope.tableParams.filter({ $: criteria });
};
}
};
});