1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| 'use strict';
/**
* @ngdoc function
* @name extranetApp.controller:UserAddCtrl
* @description
* # UserAddCtrl
* Controller of the extranetApp
*/
angular.module('extranetApp')
.controller('AddCtrl', function ($scope, VarService, $translate, $uibModalInstance, type, data, textAngularManager, RPCService, $uibModal) {
var $ctrl = this;
$ctrl.type = type;
$ctrl.data = data;
console.log($scope);
$scope.form = { };
if ($ctrl.type == "incident") {
$scope.header = "OPEN_NEW_INCIDENT";
} else if ($ctrl.type == "foldermsg") {
$scope.header = "CUST_ADD_INFOS";
$scope.disableSubect = true;
$scope.form.subject = `msg: ${$ctrl.data.subject}`;
} else if ($ctrl.type == "usermsg") {
$scope.header = "CUST_ADD_INFOS";
$scope.disableSubect = true;
$scope.form.subject = `msg: ${$ctrl.data.firstname} ${$ctrl.data.lastname}` ;
}
//console.log
$scope.dzOptions = VarService.getDzOptions();
$scope.submitForm = function (form) {
if ($scope.addForm.$valid) {
console.log($scope);
console.log($scope.dzMethods);
var files = $scope.dzMethods.getAllFiles();
if (files) {
form.attachments = [];
angular.forEach(files, function (file) {
if (file.accepted) {
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = function (e) {
//get the base64 url
var base64URL = e.target.result;
var attach = { "name": file.name, "content": base64URL.split(',')[1] };
form.attachments.push(attach);
};
// Read in the image file as a data URL.
reader.readAsDataURL(file);
}
});
}
switch ($ctrl.type) {
case "incident":
console.log(form);
createIncident(form);
break;
case "foldermsg":
form.unid = $ctrl.data.unid;
addFolderMessage(form);
break;
case "usermsg":
form.unid = $ctrl.data.unid;
addUserMessage(form);
break;
}
}
};
function createIncident(incident) {
RPCService.dossier.new(incident).then(function (data) {
$scope.formSend = "INCIDENT.CONFIRM_DECLARATION";
});
}
function addFolderMessage(message) {
RPCService.dossier.message(message.unid, message).then(function (data) {
console.log(message);
$scope.formSend = "INFO_SEND";
});
}
function addUserMessage(message) {
RPCService.user.message(message.unid, message).then(function (data) {
$scope.formSend = "INFO_SEND";
});
}
function openConfirmModal(items) {
$uibModal.open({
animation: true,
ariaLabelledBy: 'modal-title',
ariaDescribedBy: 'modal-body',
templateUrl: 'views/modal/confirm.html',
controller: 'ModalInstanceCtrl',
controllerAs: '$ctrl',
size: 'md',
resolve: {
data: { },
items: function () {
return items;
}
}
});
}
$ctrl.ok = function () {
$uibModalInstance.close($scope.newStatus);
};
$ctrl.cancel = function () {
$uibModalInstance.dismiss('cancel');
};
}); |
Partager