Newer
Older
function addVisaUser(users) {
if (!users) {
nb_visa = $j(".droptarget").length;
next_visa = nb_visa + 1;
if(nb_visa == 0){
$j("#emptyVisa").hide();
}

Alex ORLUC
committed
selected = ' selected="selected" ';
if($j("#isAllAttachementSigned").val() == 'allsigned' || $j("#isAllAttachementSigned").val() == 'false'){
signRequest = '<br/><sub><select id="signRequest_'+next_visa+'"><option value="false" '+selected+'>VISEUR</option><option value="true">SIGNATAIRE</option></select></sub>';
signRequest = '<br/><sub><select id="signRequest_'+next_visa+'" disabled="disabled"><option value="false" '+selected+'>VISEUR</option><option value="true">SIGNATAIRE</option></select></sub>';
$j("#visa_content").append('<div class="droptarget" id="visa_' + next_visa + '" draggable="true">'
+'<span class="visaUserStatus">'
+'<i class="fa fa-hourglass-half" aria-hidden="true"></i>'
+'</span>'
+'<span class="visaUserInfo">'
+'<sup class="visaUserPos nbResZero">'+next_visa+'</sup> '
+'<i class="fa fa-user fa-2x" aria-hidden="true"></i> '+ $j("select#visaUserList option:selected").text() +' <sup class="nbRes">'+$j("select#visaUserList option:selected").parent().get( 0 ).label+'</sup>'
+'<input class="userId" type="hidden" value="' + $j("select#visaUserList option:selected").val() + '"/><input class="visaDate" type="hidden" value=""/>'
+' <i id="signedUser_'+next_visa+'" title="Personne signataire" class="visaUserSign fa fa-certificate" aria-hidden="true" style="color:#FDD16C;visibility:hidden;"></i>'
+ signRequest
+'</span>'
+'<span class="visaUserAction">'
+'<i class="fa fa-trash" aria-hidden="true" onclick="delVisaUser(this.parentElement.parentElement);"></i>'
+'</span>'
+'<span class="visaUserConsigne">'
+'<input type="text" class="consigne" value=""/>'
+'</span>'
+'<span id="dropZone" title="Glisser/déposer pour modifier l\'ordre du circuit" style="cursor: pointer">'
+'<i class="fa fa-exchange fa-2x fa-rotate-90" aria-hidden="true"></i>'
+'</span>'
+'</div>');
//prototype
document.getElementById("visaUserList").selectedIndex = 0;
$j('#visaUserList').trigger("chosen:updated");
} else {
nb_visa = $j(".droptarget").length;
next_visa = nb_visa + 1;
if(nb_visa == 0){
$j("#emptyVisa").hide();
}

Alex ORLUC
committed
selected = ' selected="selected" ';
if($j("#isAllAttachementSigned").val() == 'allsigned' || $j("#isAllAttachementSigned").val() == 'false'){
signRequest = '<br/><sub><select id="signRequest_'+next_visa+'"><option value="false" '+selected+'>VISEUR</option><option value="true">SIGNATAIRE</option></select></sub>';
signRequest = '<br/><sub><select id="signRequest_'+next_visa+'" disabled="disabled"><option value="false" '+selected+'>VISEUR</option><option value="true">SIGNATAIRE</option></select></sub>';
$j("#visa_content").append('<div class="droptarget" id="visa_' + next_visa + '" draggable="true">'
+'<span class="visaUserStatus">'
+'<i class="fa fa-hourglass-half" aria-hidden="true"></i>'
+'</span>'
+'<span class="visaUserInfo">'
+'<sup class="visaUserPos nbResZero">'+next_visa+'</sup> '
+'<i class="fa fa-user fa-2x" aria-hidden="true"></i> ' + users.lastname + ' ' + users.firstname + ' <sup class="nbRes">'+users.entity_id+'</sup>'
+'<input class="userId" type="hidden" value="' + users.user_id + '"/><input class="visaDate" type="hidden" value=""/>'
+' <i id="signedUser_'+next_visa+'" title="Personne signataire" class="visaUserSign fa fa-certificate" aria-hidden="true" style="color:#FDD16C;visibility:hidden;"></i>'
+ signRequest
+'</span>'
+'<span class="visaUserAction">'
+'<i class="fa fa-trash" aria-hidden="true" onclick="delVisaUser(this.parentElement.parentElement);"></i>'
+'</span>'
+'<span class="visaUserConsigne">'
+'<input type="text" class="consigne" value="' + users.process_comment + '"/>'
+'</span>'
+'<span id="dropZone" title="Glisser/déposer pour modifier l\'ordre du circuit" style="cursor: pointer">'
+'<i class="fa fa-exchange fa-2x fa-rotate-90" aria-hidden="true"></i>'
+'</span>'
+'</div>');
resetPosVisa();
function delVisaUser(target) {
var id = '#' + target.id;
if ($j(".droptarget").length == 1) {
$j("#emptyVisa").show();
}
$j(id).remove();
resetPosVisa();
this.id = 'visa_' + i;
$j("#" + this.id).find("select[id^=signRequest_]")[0].id='signRequest_'+i;
$j("#" + this.id).find("[id^=signedUser_]")[0].id='signedUser_'+i;
$j("#" + this.id).find(".visaUserPos").text(i);
i++;
i--;
}
function updateVisaWorkflow(resId) {

Alex ORLUC
committed
var i = 0;
var hasSignatory = false;

Alex ORLUC
committed
if (($j("select[id^=signRequest_] option:selected[value=true]").length == 0) && $j(".droptarget").length != 0) {
$j('#signRequest_'+i).val("true");
}
if ($j(".droptarget").length) {
$j(".droptarget").each(function () {
if ($j("#signRequest_"+(i+1)+" option:selected[value=true]").length) {
userRequestSign=true;
} else {
userRequestSign=false;
}
if ($j("#signedUser_"+(i+1)).css('visibility') == 'visible') {
userSignatory=true;
} else {
userSignatory=false;
}

Alex ORLUC
committed
userId = $j("#" + this.id).find(".userId").val();
userConsigne = $j("#" + this.id).find(".consigne").val();
userVisaDate = $j("#" + this.id).find(".visaDate").val();
userPos = i;
// last one is signatory if no one selected
if(userRequestSign || userSignatory){
hasSignatory = true;
}
if ($j("#signRequest_"+(i+2)).length == 0 && !hasSignatory) {
userRequestSign=true;
$j('#signRequest_'+(i+1)).val("true");
}

Alex ORLUC
committed
userList.push({userId: userId, userPos: userPos, userConsigne: userConsigne, userVisaDate: userVisaDate, userRequestSign: userRequestSign, userSignatory: userSignatory});
i++;

Alex ORLUC
committed
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
$j.ajax({
url : 'index.php?display=true&module=visa&page=updateVisaWF',
type : 'POST',
dataType : 'JSON',
data: {
resId: resId,
userList: JSON.stringify(userList)
},
success : function(response){
if (response.status == 0) {
parent.$('main_info').innerHTML = 'Mise à jour du circuit effectuée';
parent.$('main_info').style.display = 'table-cell';
parent.Element.hide.delay(5, 'main_info');
eval(response.exec_js);
if(parent.$j('.contentShow iframe').length){
parent.$j('.contentShow iframe')[0].contentWindow.location.reload(true);
}
} else if (response.status != 1) {
alert(response.error_txt)
}
},
error : function(error){
alert(error);
}
});
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
}
function saveVisaWorkflowAsModel () {
var $i = 0;
var userList = [];
var title = $j("#titleModel").val();
if($j(".droptarget").length){
$j(".droptarget").each(function() {
//console.log('viseur : '+$j("#"+this.id+" .userdId").val());
userId = $j("#"+this.id).find(".userId").val();
userConsigne = $j("#"+this.id).find(".consigne").val();
userVisaDate = $j("#"+this.id).find(".visaDate").val();
userPos = $i;
userList.push({userId:userId, userPos:userPos, userConsigne:userConsigne, userVisaDate:userVisaDate});
$i++;
});
$j.ajax({
url : 'index.php?display=true&module=visa&page=saveVisaModel',
type : 'POST',
dataType : 'JSON',
data: {
title: title,
userList: JSON.stringify(userList)
},
success : function(response){
if (response.status == 0) {
$('divInfoVisa').innerHTML = 'Modèle enregistré';
$('divInfoVisa').style.display = 'table-cell';
Element.hide.delay(5, 'divInfoVisa');
$j('#modalSaveVisaModel').hide();
eval(response.exec_js);
} else {
alert(response.error_txt)
}
},
error : function(error){
alert(error);
}
});
}else{
alert('Aucun utilisateur dans le circuit !');
}
}
function loadVisaModelUsers() {
var objectId = $j("select#modelList option:selected").val();
var objectType = 'VISA_CIRCUIT';
$j.ajax({
url : 'index.php?display=true&module=visa&page=load_listmodel_visa_users',
type : 'POST',
dataType : 'JSON',
data: {
objectType: objectType,
objectId: objectId
},
success : function(response){
if (response.status == 0) {
var userList = response.result;
if(userList){
userList.each(function(user, key) {
addVisaUser(user);
});
}
} else {
alert(response.error_txt);
}
},
error : function(error){
alert(error);
}
});
//prototype
document.getElementById("modelList").selectedIndex = 0;
$j('#modelList').trigger("chosen:updated");
}
function initDragNDropVisa() {
document.getElementById("visa_content").addEventListener("dragstart", function(event) {
$j(".droptarget").not(".vised,.currentVis").css("border","dashed 2px #93D1E4");
// The dataTransfer.setData() method sets the data type and the value of the dragged data
event.dataTransfer.setData("Text", event.target.id);
// Output some text when starting to drag the p element
//document.getElementById("demo").innerHTML = "Started to drag the p element.";
// Change the opacity of the draggable element
event.target.style.opacity = "0.4";
});
// While dragging the p element, change the color of the output text
document.getElementById("visa_content").addEventListener("drag", function(event) {
//document.getElementById("demo").style.color = "red";
});
// Output some text when finished dragging the p element and reset the opacity
document.getElementById("visa_content").addEventListener("dragend", function(event) {
//document.getElementById("demo").innerHTML = "Finished dragging the p element.";
$j(".droptarget").not(".vised,.currentVis").css("border","dashed 2px #93D1E4");
event.target.style.opacity = "1";
});
/* Events fired on the drop target */
// When the draggable p element enters the droptarget, change the DIVS's border style
document.getElementById("visa_content").addEventListener("dragenter", function(event) {
if ( event.target.className == "droptarget") {
event.target.style.border = "dashed 2px green";
}
});
// By default, data/elements cannot be dropped in other elements. To allow a drop, we must prevent the default handling of the element
document.getElementById("visa_content").addEventListener("dragover", function(event) {
event.preventDefault();
});
// When the draggable p element leaves the droptarget, reset the DIVS's border style
document.getElementById("visa_content").addEventListener("dragleave", function(event) {
if ( event.target.className == "droptarget" ) {
event.target.style.border = "dashed 2px #ccc";
}
});
/* On drop - Prevent the browser default handling of the data (default is open as link on drop)
Reset the color of the output text and DIV's border color
Get the dragged data with the dataTransfer.getData() method
The dragged data is the id of the dragged element ("drag1")
Append the dragged element into the drop element
*/
document.getElementById("visa_content").addEventListener("drop", function(event) {
event.preventDefault();
if ( event.target.className == "droptarget" ) {
var data = event.dataTransfer.getData("Text");
var oldContent = event.target.innerHTML;
var draggedConsigne = $j('#'+data+' .consigne').val();
var replaceConsigne = $j('#'+event.target.id+' .consigne').val();
event.target.innerHTML = document.getElementById(data).innerHTML;
$j('#'+event.target.id+' .consigne').val(draggedConsigne);
document.getElementById(data).innerHTML = oldContent;
$j('#'+data+' .consigne').val(replaceConsigne);*/
var data = event.dataTransfer.getData("Text");
var target =event.target.id;
posData = data.split("_");
posTarget = target.split("_");
if(posData[1] > posTarget[1]){
$j('#'+target).before($j('#'+data));
}else{
$j('#'+target).after($j('#'+data));
}
resetPosVisa();
$j('#visa_content')
.on('focus', '.consigne', function(e) {
$j(this).closest('.droptarget').attr("draggable", false);
console.log($j(this).closest('.droptarget'));
})
.on('blur', '.consigne', function(e) {
$j(this).closest('.droptarget').attr("draggable", true);
});
function setTitle(input) {
input.title = input.value;
}
//load applet in a modal
function loadAppletSign(url){
displayModal(url, 'VisaApplet', 300, 300);
}
function printFolder(res_id, coll_id, form_id, path) {
//console.log("printFolder");
new Ajax.Request(path,
{
asynchronous: false,
method: 'post',
parameters: Form.serialize(form_id),
encoding: 'UTF-8',
onSuccess: function (answer) {
eval("response = " + answer.responseText);
if (response.status == 0) {
var id_folder = response.id_folder;
var winPrint = window.open('index.php?display=true&module=attachments&page=view_attachment&res_id_master=' + res_id + '&id=' + id_folder, '', 'height=800, width=700,scrollbars=yes,resizable=yes');
/*winPrint.focus();
winPrint.print();*/
}
else if (response.status == 1 || response.status == -1) {
$('divErrorPrint').innerHTML = response.error_txt;
$('divErrorPrint').style.display = 'table-cell';
Element.hide.delay(5, 'divErrorPrint');
}
}
});
function selectAllPrintFolder() {
console.log($j('#allPrintFolder')[0].checked);
if($j('#allPrintFolder')[0].checked == true){
$j('.checkPrintFolder').prop('checked', true);
}else{
$j('.checkPrintFolder').prop('checked', false);
}
}