UNPKG

zettapi_client

Version:

Admin panel and client-side CRUD operations in angular to use with zettapi_server rest api to get started quickly in any CMS project.

34 lines (30 loc) 950 B
app.directive('uploadImage', function ($util, $http) { var defaultHeaders = { transformRequest: angular.identity, headers: { 'Content-Type': undefined } }; function upload(key, item, callback) { var fd = new FormData(); $util.setFormFiles(fd, item); fd.append('item', angular.toJson(item)); $http.post('/api/image/upload/' + key, fd, defaultHeaders).then(function (response) { callback(null, response.data); }).catch(function (response) { callback(response.data); }); } return { restrict: 'E', scope: { item: '=', key: '@', isEditable: '=' }, templateUrl: 'directives/document/uploadImage.html', controller: function ($scope) { $scope.upload = function (key, item, callback) { upload(key, item, function (err, url) { if (err) return swal("Envio falhou", err, "warning"); $scope.item[key] = url; }); }; } }; });