UNPKG

zettapi_client

Version:

Client side CRUD operations in angular to use with zettapi_server rest api to get started quickly in any CMS project

42 lines (38 loc) 2.1 kB
app.directive('entityEdit', function(zapiPath) { return { restrict: 'E', scope: true, replace: false, link: function(scope, element, attrs) { var scaffoldUrl = scope.entity.custom ? 'entity/' : (zapiPath + '/entity/'); scope.contentUrl = scaffoldUrl + scope.entityName + '/' + scope.entityName + '.edit.html'; }, template: '<div ng-include="contentUrl"></div>', /*controller: function($scope, $entity, $translate) { $scope.add = function(item, beforeAdd, callback) { $translate(['api.entity.sendData', $scope.entity.title, 'api.entity.newRecordSuccess', 'api.entity.editRecordSuccess']).then(function(text) { blockUI.start(text['api.entity.sendData']); var next = typeof beforeAdd === 'function' ? beforeAdd : skip; next(function(err) { if (err) { blockUI.stop(); return swal("Antes de guardar", err, "info"); } $entity.add($routeParams.entity, item).then(function(response) { if (item._id) swal("Alterado", translations[$scope.entity.title] + translations['api.entity.newRecordSuccess'], "success"); else swal("Criado", translations[$scope.entity.title] + translations['api.entity.editRecordSuccess'], "success"); if (typeof callback === 'function') callback(); }).catch(function(response) { swal("Problema ao Guardar", response.data, "error"); if (typeof callback === 'function') callback(response.data); }).finally(function() { blockUI.stop(); }); }); }, function() { if (typeof callback === 'function') callback("Erro na tradução"); }); }; }*/ }; });