text: (function () {
    'use strict';
  
    angular
      .module('employees')
      .controller('ChangeEmployeePictureController', ChangeEmployeePictureController);
  
    ChangeEmployeePictureController.$inject = ['$scope', '$timeout', '$window', 'FileUploader'];
  
    function ChangeEmployeePictureController($scope, $timeout, $window, FileUploader) {
      var vm = this;
  
      vm.imageURL = vm.employee.employeeImageURL;
      vm.uploadEmployeePicture = uploadEmployeePicture;
  
      vm.cancelUpload = cancelUpload;
      // Create file uploader instance
      vm.uploader = new FileUploader({
        url: 'api/employees/picture',
        alias: 'newEmployeePicture',
        onAfterAddingFile: onAfterAddingFile,
        onSuccessItem: onSuccessItem,
        onErrorItem: onErrorItem
      });
  
      // Set file uploader image filter
      vm.uploader.filters.push({
        name: 'imageFilter',
        fn: function (item, options) {
          var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
          return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
        }
      });
  
      // Called after the user selected a new picture file
      function onAfterAddingFile(fileItem) {
        if ($window.FileReader) {
          var fileReader = new FileReader();
          fileReader.readAsDataURL(fileItem._file);
  
          fileReader.onload = function (fileReaderEvent) {
            $timeout(function () {
              vm.imageURL = fileReaderEvent.target.result;
            }, 0);
          };
        }
      }
  
      // Called after the user has successfully uploaded a new picture
      function onSuccessItem(fileItem, response, status, headers) {
        // Show success message
        vm.success = true;
  
        // Clear upload buttons
        cancelUpload();
      }
  
      // Called after the user has failed to uploaded a new picture
      function onErrorItem(fileItem, response, status, headers) {
        // Clear upload buttons
        cancelUpload();
  
        // Show error message
        vm.error = response.message;
      }
  
      // Change user profile picture
      function uploadEmployeePicture() {
        // Clear messages
        vm.success = vm.error = null;
  
        // Start upload
        vm.uploader.uploadAll();
      }
  
      // Cancel the upload process
      function cancelUpload() {
        vm.uploader.clearQueue();
        vm.imageURL = vm.employee.employeeImageURL;
      }
    }
  }());
  