Advertisement
Guest User

storeLocator.upload.controller

a guest
Oct 23rd, 2015
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function(app) {
  2.     var storeLocatorUploadController = function($scope, storeLocatorApiService) {
  3.         $scope.init = function() {
  4.             $scope.setVariables();
  5.         };
  6.  
  7.         $scope.setVariables = function() {
  8.             $scope.file = false;
  9.             $scope.isUploading = false;
  10.         };
  11.  
  12.         $scope.acceptSelectedFile = function(files) {
  13.             if (files.length > 0) {
  14.                 $scope.file = files[0];
  15.             }
  16.         };
  17.  
  18.         $scope.uploadFile = function() {
  19.             if (!$scope.isUploading) {
  20.                 if ($scope.file) {
  21.                     $scope.isUploading = true;
  22.                     var promise = storeLocatorApiService.uploadFile($scope.file);
  23.                     promise.then(function(response) {
  24.                         if (response) {
  25.                             console.info("Saved to server wit the filename " + response);
  26.                         }
  27.  
  28.                         $scope.isUploading = false;
  29.                     }, function(reason) {
  30.                         console.info("File import falied.");
  31.                         console.info(reason.message);
  32.                         $scope.isUploading = false;
  33.                     });
  34.                 } else {
  35.                     console.info("Must select a file to import.");
  36.                     $scope.isUploading = false;
  37.                 }
  38.             }
  39.         };
  40.  
  41.         scope.init();
  42.     };
  43.  
  44.     app.controller("storeLocatorUploadController", ["$scope", "storeLocatorApiService", storeLocatorUploadController]);
  45. }(angular.module(appName)));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement