HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/debierbaron.komma.pro/workbench/komma/kms/public/js/fileupload.ng.js
'use strict';
//inject directives and services.
var app = angular.module('fileUpload', ['ngFileUpload']);


app.controller('fileUploadController', ['$scope', 'Upload', '$timeout', function ($scope, Upload, $timeout) {

    //The files list
    //Todo, extend with the files form the database
    $scope.files = [];
    //These are the fileIds, used for saving
    $scope.fileIds = [];

    /**
     * This function uploads the new files
     * @param files
     * @param errFiles
     */
    $scope.uploadFiles = function (files, errFiles, maximages) {

        if ($scope.files.length >= maximages) return false;
        //Set the files
        $scope.errFiles = errFiles;
        //Foreach each file
        angular.forEach(files, function (file) {
            if ($scope.files.length >= maximages) return false;

            //Upload to the server
            file.upload = Upload.upload({
                url: '/kms/upload',
                data: {file: file}
            });
            //After uploading
            file.upload.then(function (response) {
                $timeout(function () {
                    //Set the respons data
                    file.result = response.data;
                    //Add the file to the current files
                    $scope.files.push(file.result);
                    //Add the id
                    $scope.fileIds.push(file.result.id);

                    //Reverse push
                    //Add the file to the current files
                    //$scope.files.unshift(file.result);
                    //Add the id
                    //$scope.fileIds.unshift(file.result.id);

                });
            }, function (response) {
                if (response.status > 0)
                    $scope.errorMsg = response.status + ': ' + response.data;
            }, function (evt) {
                file.progress = Math.min(100, parseInt(100.0 *
                    evt.loaded / evt.total));
            });
        });
    }

    $scope.deleteImage = function (index) {
        //Delete the image
        $scope.files.splice(index, 1)
        //Delete the image id
        $scope.fileIds.splice(index, 1)
    }

    $scope.moveImage = function (index, direction) {
        var currentFile = $scope.files[index]
        var currentFileId = $scope.fileIds[index]

        if (direction == 'left') {
            $scope.files[index] = $scope.files[index - 1];
            $scope.fileIds[index] = $scope.fileIds[index - 1];
            $scope.files[index - 1] = currentFile;
            $scope.fileIds[index - 1] = currentFileId;
        } else {
            $scope.files[index] = $scope.files[index + 1];
            $scope.fileIds[index] = $scope.fileIds[index + 1];
            $scope.files[index + 1] = currentFile;
            $scope.fileIds[index + 1] = currentFileId;
        }
    }

    $scope.initFiles = function (files) {
        $scope.files = files
        angular.forEach(files, function (file) {
            $scope.fileIds.push(file.id);
        });

    }

}]);