Advertisement
Guest User

Untitled

a guest
Aug 14th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. var app = angular.module('myApp.addFaktura', ['ngRoute'])
  4.  
  5.   .config(['$routeProvider', function($routeProvider) {
  6.     $routeProvider.when('/addFaktura', {
  7.       templateUrl: 'addFaktura/addFaktura.html',
  8.       controller: 'addFakturaCntrl'
  9.     });
  10.   }])
  11.  
  12. app.controller('addFakturaCntrl', function($scope, $http, Data, $rootScope, FileData, $window, $mdDialog, $location, $route) {
  13.  
  14.   log('addFakturaCntrl');
  15.  
  16.   $scope.uploadFile = function(data) {
  17.     var form_data = new FormData();
  18.     log($scope.file_name);
  19.     angular.forEach($scope.files, function(file) {
  20.       form_data.append('file', file);
  21.     });
  22.  
  23.     FileData.post(form_data).then(function(response) {
  24.       log(response);
  25.       // if localeCompare= 0 => strings are equal
  26.       if (response.data == 1) {
  27.         log("file uploaded");
  28.         Data.post('saveFakt', {
  29.             data: data
  30.           })
  31.           .then(function(results) {
  32.             $location.path("/faktury");
  33.             Data.toast(results);
  34.             log(results);
  35.             $window.scrollTo(0, 0);
  36.           });
  37.       } else {
  38.         log("error");
  39.       }
  40.     });
  41.   }
  42.  
  43.   $scope.selectFile = function(id){
  44.     FileData.get(id)
  45.       .then(function(res) {
  46.         $scope.images = res;
  47.         log(res);
  48.       });
  49.   }
  50.  
  51. });
  52.  
  53. app.directive("fileInput", function($parse) {
  54.   return {
  55.     link: function($scope, element, attrs) {
  56.       element.on("change", function(event) {
  57.         var files = event.target.files;
  58.         log(files[0].name);
  59.         $scope.file_name = files[0].name.substr(0, files[0].name.lastIndexOf("."));
  60.         $parse(attrs.fileInput).assign($scope, element[0].files);
  61.         $scope.data= {fak_upload_name: $scope.file_name + ".jpg", fak_name:$scope.file_name} ;
  62.         $scope.$apply();
  63.       })
  64.     }
  65.   }
  66. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement