Newer
Older
function addVisaUser(users) {
if (!users) {
nb_visa = $j(".droptarget").length;
next_visa = nb_visa + 1;
if(nb_visa == 0){
$j("#emptyVisa").hide();
}
$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 title="Personne signataire" class="visaUserSign fa fa-certificate" aria-hidden="true" style="color:#FDD16C;visibility:hidden;"></i>'
+'</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">'
+'<i class="fa fa-exchange fa-2x fa-rotate-90" aria-hidden="true"></i>'
+'</span>'
+'</div>');
//prototype
document.getElementById("visaUserList").selectedIndex = 0;
Event.fire($("visaUserList"), "chosen:updated");
} else {
nb_visa = $j(".droptarget").length;
next_visa = nb_visa + 1;
if(nb_visa == 0){
$j("#emptyVisa").hide();
}
$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 title="Personne signataire" class="visaUserSign fa fa-certificate" aria-hidden="true" style="color:#FDD16C;visibility:hidden;"></i>'
+'</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">'
+'<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();
$j(".visaUserSign").css("visibility","hidden");
i = 1;
this.id = 'visa_' + i;
$j("#" + this.id).find(".visaUserPos").text(i);
i++;
$j("#visa_" + i).find(".visaUserSign").css("visibility","visible");
}
function updateVisaWorkflow(resId) {
var $i = 0;
var userList = [];
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=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');
if(parent.$j('.contentShow iframe').length){
parent.$j('.contentShow iframe')[0].contentWindow.location.reload(true);
}
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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
166
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
} else if (response.status != 1) {
alert(response.error_txt)
}
},
error : function(error){
alert(error);
}
});
}
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;
Event.fire($("modelList"), "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);
}
}