Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- var app = angular.module('myApp.addFaktura', ['ngRoute'])
- .config(['$routeProvider', function($routeProvider) {
- $routeProvider.when('/addFaktura', {
- templateUrl: 'addFaktura/addFaktura.html',
- controller: 'addFakturaCntrl'
- });
- }])
- app.controller('addFakturaCntrl', function($scope, $http, Data, $rootScope, FileData, $window, $mdDialog, $location, $route) {
- log('addFakturaCntrl');
- $scope.uploadFile = function(data) {
- var form_data = new FormData();
- log($scope.file_name);
- angular.forEach($scope.files, function(file) {
- form_data.append('file', file);
- });
- FileData.post(form_data).then(function(response) {
- log(response);
- // if localeCompare= 0 => strings are equal
- if (response.data == 1) {
- log("file uploaded");
- Data.post('saveFakt', {
- data: data
- })
- .then(function(results) {
- $location.path("/faktury");
- Data.toast(results);
- log(results);
- $window.scrollTo(0, 0);
- });
- } else {
- log("error");
- }
- });
- }
- $scope.selectFile = function(id){
- FileData.get(id)
- .then(function(res) {
- $scope.images = res;
- log(res);
- });
- }
- });
- app.directive("fileInput", function($parse) {
- return {
- link: function($scope, element, attrs) {
- element.on("change", function(event) {
- var files = event.target.files;
- log(files[0].name);
- $scope.file_name = files[0].name.substr(0, files[0].name.lastIndexOf("."));
- $parse(attrs.fileInput).assign($scope, element[0].files);
- $scope.data= {fak_upload_name: $scope.file_name + ".jpg", fak_name:$scope.file_name} ;
- $scope.$apply();
- })
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement