File: D:/HostingSpaces/SBogers10/vebon.komma.pro/wwwroot/build/js/vebon-0052e2b638.js
'use strict';
//inject directives and services.
var app = angular.module('auditApp', ['ngFileUpload', 'ngDialog']);
app.service('DocumentGroups', function () {
return {
validateMemberSubmit: function () {
var faults = {}
//s
//For an member audit to be ready to submit, we are going to check:
//If all the required groups have files
//If there are no rejected files
//If a no required group has correct files or is not applicable
angular.forEach(this.documentGroups, function (documentGroup, id) {
//If there are no files, and there should be
if (documentGroup.files.length == 0 && documentGroup.applicable && documentGroup.required) {
//set no_files error
faults[documentGroup.id] = 'no_files'
//and stop this run
return;
}
if (documentGroup.files.length == 0 && documentGroup.applicable) {
//set no_files error
faults[documentGroup.id] = 'no_files_or_not_applicable'
//and stop this run
return;
}
var fileError = false
angular.forEach(documentGroup.files, function (file, id) {
if (file.status == 1) fileError = true;
})
//If there is one ore more rejected fiels, set these fault
if (fileError) {
faults[documentGroup.id] = 'rejected_files'
}
})
return faults;
},
validateAuditorReject: function () {
var faults = {}
angular.forEach(this.documentGroups, function (documentGroup, id) {
var fileError = false
angular.forEach(documentGroup.files, function (file, id) {
if (file.status == 0 && documentGroup.applicable == true) fileError = true;
})
//If there is one ore more rejected fiels, set these fault
if (fileError) {
faults[documentGroup.id] = 'unchecked_files'
}
})
return faults;
},
validateAuditorSubmit: function () {
var faults = {}
angular.forEach(this.documentGroups, function (documentGroup, id) {
var fileError = false
angular.forEach(documentGroup.files, function (file, id) {
if (file.status != 2 && documentGroup.applicable == true) fileError = true;
})
//If there is one ore more rejected fiels, set these fault
if (fileError) {
faults[documentGroup.id] = 'not_all_files_approved'
}
})
return faults;
},
//unchecked_or_rejected
documentGroups: {}
}
})
app.controller('documentGroupController', ['$scope', 'Upload', '$timeout', '$http', 'ngDialog', 'DocumentGroups', function ($scope, Upload, $timeout, $http, ngDialog, DocumentGroups) {
$scope.files = [];
$scope.errorMsg = {};
$scope.path = '/ajax/documentGroup/{documentGroupId}'
$scope.filePath = '/ajax/documentGroup/{documentGroupId}/files'
/**------------------------------|
| |
| Global functions |
| |
|-------------------------------*/
$scope.initialize = function (documentGroup, files) {
//Set the documentGroupId
$scope.documentGroupId = documentGroup.id;
$scope.documentGroup = documentGroup;
//Set the not_applicable as reverse of applicable
$scope.not_applicable = !documentGroup.applicable
//Add each file to the files array of the current scope
angular.forEach(files, function (file, key) {
$scope.files.push(file);
}
)
//Add the local documentGroup to the global documentGroups
$scope.updateGlobalDocumentGroup(documentGroup, files)
}
$scope.updateGlobalDocumentGroup = function (documentGroup, files, validate) {
documentGroup.files = $scope.files
DocumentGroups.documentGroups[documentGroup.id] = documentGroup;
if (validate == 'member') {
//Validate
var faults = DocumentGroups.validateMemberSubmit()
$scope.faults = faults;
}
}
/**------------------------------|
| |
| Member functions |
| |
|-------------------------------*/
/**
* This function uploads files passed by ngf-select
* @param files
* @param errFiles
* @param maximages
*/
$scope.uploadFiles = function (files, errFiles, maximages) {
//If files doesn exist, create new array
if (typeof $scope.files == 'undefined') $scope.files = []
//Set the errors
$scope.errFiles = errFiles;
//Foreach each file
angular.forEach(files, function (file) {
//check if the file exists in the files list
var existingKey = $scope.getFileKey($scope.files, file);
//If existingKey 0s not null, it is an existing file
if (existingKey !== null) {
//Create new ngDialog instance
var dialog = ngDialog;
//If the status of the existng file is 2 (approved)
if ($scope.files[existingKey].status == 2) {
//Open a dialog to show the file can not be overwritten
dialog.open({
//Get the template
template: '/ajax/template/overWriteBlockedPopup',
data: {file: file},
scope: $scope,
});
//Stop this foreach instance
return;
}
//This is a not approved file
//Open a popup to ask if the file may be overwritten
dialog.open({
//Get the template
template: '/ajax/template/overWritePopup',
data: {
//Set the file
file: file,
//Set the existingKey as the filesKey
filesKey: existingKey
},
scope: $scope,
});
} else {
//This is a new file
//Get the key where the next item will be pushed
var filesKey = $scope.files.length
//New file, so upload this
$scope.uploadFile(file, filesKey);
}
});
}
/**
* This method saves the file to the server
*
* @param file
* @param filesKey
*/
$scope.uploadFile = function (file, filesKey) {
//If it is not an existing file, create a new empty object
if (!$scope.files[filesKey]) $scope.files.push({});
//Set the file_name to the file name of file
$scope.files[filesKey].file_name = file.name
//Set the status to -1 (uploading)
$scope.files[filesKey].status = -1
//Set the documentGroupId to the upload path
var uploadPath = $scope.setDocumentGroup($scope.filePath, $scope.documentGroupId)
//Upload to the server
file.upload = Upload.upload({
url: uploadPath,
data: {
//Sent the data and the options
file: file,
uploadSizes: $scope.uploadSizes,
}
});
//After uploading
file.upload.then(function (response) {
//Success
$timeout(function () {
//Set the response data to documents
var documents = response.data;
//Add the file to the current files
angular.forEach(documents, function (document, key) {
$scope.files[filesKey] = document
})
$scope.updateGlobalDocumentGroup($scope.documentGroup, $scope.files, 'member')
});
}, function (response) {
//Fails
if (response.status > 0)
$scope.errorMsg = response.status + ': ' + response.data;
});
}
/**
* Show an popup to ask if
* a file may be deleted
* @param index
*/
$scope.deleteFilePopup = function (index) {
//Set the currentFileIndex to the scope
$scope.currentIndex = index;
//Open the popup dialog
ngDialog.open({
//Get the template
template: '/ajax/template/deleteFilePopup',
//Set the $scope
scope: $scope
});
}
/**
* This function will delete a file
* from the $scope.files with the index
*
* @param index
*/
$scope.deleteFile = function (index) {
var deletePath = $scope.setDocumentGroup($scope.filePath + '/' + index, $scope.documentGroupId)
$http.delete(deletePath)
.then(
function (response) {
//Success
//The still existing documents will be returned as response.data
var documents = response.data
//Set these documents as $scope.files
$scope.files = documents
$scope.updateGlobalDocumentGroup($scope.documentGroup, documents, 'member')
},
function (response) {
//Fault
//console.log(response.data.message);
}
);
}
/**
* Check if the file can be deleted
*
* @param file
* @returns {boolean}
*/
$scope.canIDelete = function (file) {
//You can not delete when the status is 2 (accepted)
if (file.status == 2) return false;
//You can not delete when the status is -1 (placeholder)
if (file.status == -1) return false;
//Se can delete
return true;
}
/**
* Overwrite {documentGroupId}
* with the $scope.documentGroupId
*
* @param string
* @param documentGroupId
* @returns {*}
*/
$scope.setDocumentGroup = function (string, documentGroupId) {
return string.replace('{documentGroupId}', documentGroupId)
}
/**
* Save the applicable checkbox to the server
* @param not_applicable
*/
$scope.updateApplicable = function (not_applicable) {
$http({
method: 'POST',
url: $scope.setDocumentGroup($scope.path, $scope.documentGroupId),
data: {
'applicable': +!not_applicable
}
}).then(function successCallback(response) {
$scope.documentGroup.applicable = response.data.applicable
$scope.updateGlobalDocumentGroup($scope.documentGroup, $scope.files, 'member')
// this callback will be called asynchronously
// when the response is available
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
}
/**------------------------------|
| |
| Auditor functions |
| |
|-------------------------------*/
/**
* Update a status for one file
*
* @param file
* @param status
*/
$scope.updateStatus = function (file, status) {
//Set the docuemntGroup for the path
var url = $scope.setDocumentGroup($scope.filePath + '/' + file.id, $scope.documentGroupId)
//Create a put request (update)
$http.put(url, {status: status})
.then(
function (response) {
file.status = status
//todo auditor functions
$scope.updateGlobalDocumentGroup($scope.documentGroup, $scope.files, 'reject')
},
function (response) {
// failure callback
}
);
}
/**
* Update all statusses for one documentGroup at once
* @param status
*/
$scope.updateMultipleStatuses = function (status) {
var url = $scope.setDocumentGroup($scope.filePath, $scope.documentGroupId)
//Create a put request (update)
$http.put(url, {status: status})
.then(
function (response) {
//The documents will be returned as response.data
var documents = response.data
//Set these documents as $scope.files
$scope.files = documents
$scope.updateGlobalDocumentGroup($scope.documentGroup, $scope.files, 'reject')
},
function (response) {
// failure callback
}
);
}
/**
*
* @param statusInt
* @returns {string}
*/
$scope.setStatus = function (statusInt) {
var statusString = statusInt + '';
return statusString;
}
/**
*
* @param files
* @param file
* @returns {boolean}
*/
$scope.getFileKey = function (existingFiles, file) {
var newKey = null;
for (var i = 0; i < existingFiles.length; i++) {
if (file.name == existingFiles[i].file_name) {
newKey = i;
break;
}
}
return newKey;
}
$scope.makeDate = function (dateString) {
var date = new Date(dateString)
return date;
}
}])
app.controller('auditTableController', ['$scope', 'ngDialog', function ($scope, ngDialog) {
$scope.hide = false;
$scope.toggleHide = function ($event) {
$scope.hide = !$scope.hide
}
$scope.claimPopup = function ($event) {
$event.preventDefault();
ngDialog.open({
//Get the template
template: '/ajax/template/claimPopup',
data: {event: $event},
//Set the $scope
scope: $scope
});
$scope.clickLink = function (event) {
window.location = event.target.href;
}
}
}])
app.controller('auditController', ['$scope', 'Upload', '$timeout', '$http', 'ngDialog', 'DocumentGroups', function ($scope, Upload, $timeout, $http, ngDialog, DocumentGroups) {
$scope.popup = function ($type, $event) {
//Stop the form from submitting
$event.preventDefault();
if ($type == 'file') {
var faults = DocumentGroups.validateMemberSubmit();
if (!jQuery.isEmptyObject(faults)) {
$type = 'filedError';
$scope.faults = faults;
}
} else if ($type == 'reject') {
var faults = DocumentGroups.validateAuditorReject();
if (!jQuery.isEmptyObject(faults)) {
$type = 'rejectError';
$scope.faults = faults;
}
}
else if ($type == 'approve') {
var faults = DocumentGroups.validateAuditorSubmit();
if (!jQuery.isEmptyObject(faults)) {
$type = 'approveError';
$scope.faults = faults;
}
}
ngDialog.open({
//Get the template
template: '/ajax/template/' + $type + 'Popup',
data: {type: $type},
//Set the $scope
scope: $scope
});
}
/**
* Scroll to the first document-group with an error
*/
$scope.goToFirstError = function () {
//Get the top offset of the first document-group with an error
var offset = $('.document-group.group-error').offset().top
//Get the topBar height
var topBar = $('.topBar').height()
//subract the (topBar height + 30 px for extra margin)
offset -= topBar+30
//Slowly scroll to the correct x value
$('html,body').animate({scrollTop: offset}, "slow");
}
$scope.submitForm = function (id) {
$("#" + id).unbind('click').click(); // the html click submit work now !
}
}])
app.controller('dateController', ['$scope', function ($scope) {
$scope.makeDate = function (dateString) {
var date = new Date(dateString)
return date;
}
}])
app.controller('popupController', ['$scope', 'Upload', '$timeout', '$http', 'ngDialog', 'DocumentGroups', function ($scope, Upload, $timeout, $http, ngDialog, DocumentGroups) {
$scope.closedPopup = function () {
var $type = 'save';
ngDialog.open({
//Get the template
template: '/ajax/template/closedPopup',
//Set the $scope
scope: $scope,
});
};
$scope.rejectedPopup = function () {
var $type = 'save';
ngDialog.open({
//Get the template
template: '/ajax/template/rejectedPopup',
//Set the $scope
scope: $scope,
});
};
$scope.reviewedInPracticePopup = function () {
ngDialog.open({
//Get the template
template: '/ajax/template/reviewedInPracticePopup',
//Set the $scope
scope: $scope,
});
}
}])
app.directive('closeDialog', function (ngDialog, $timeout) {
return {
link: function (scope, element, attrs) {
if (attrs.closeDialog) {
$timeout(function () {
ngDialog.close()
}, attrs.closeDialog * 1000);
}
element.bind('click', function (element) {
ngDialog.close();
})
}
}
});
/**
* Created by driesjanssen on 11/10/16.
*/
$(document).ready(function(){
$('.popup').on('click', function() {
alert('test');
});
});
//# sourceMappingURL=vebon.js.map