-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdiligence.js
383 lines (350 loc) · 12.7 KB
/
diligence.js
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
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
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
//URL global para salvar a diligencia
const urlSaveDiligence = MapasCulturais.createUrl('diligence', 'save');
//Objeto com item primário para salvar a diligência
let objSendDiligence = {
registration: MapasCulturais.entity.id,
openAgent: MapasCulturais.userProfile.id,
agent: MapasCulturais.entity.ownerId,
createTimestamp: moment().format("YYYY-MM-DD")
}
$(document).ready(function () {
$("#paragraph_value_project").hide();
hideBtnActionsDiligence();
//Iniciando o accordion Jquery
EntityDiligence.showAccordion('#accordion');
//id da diligencia
let idDiligence = 0;
$("#id-input-diligence").val(idDiligence);
//Buscado diligencia se houver
//Retornar valor se foi autorizado
let authorized = EntityDiligence.returnGetAuthorized();
authorized.then((res) => {
//Alterando a opção do select
$("#select-value-project-diligence").val(res.optionAuthorized).change();
if (res.valueAuthorized !== null) {
//Alterando o valor do projeto
$("#input-value-project-diligence").val(res.valueAuthorized);
}
}).catch(() => {
MapasCulturais.Messages.error('Ocorreu um erro na autorização do projeto');
})
// Ocultando itens em comum do parecerista e do proponente
EntityDiligence.hideCommon();
//Formatando o layout
EntityDiligence.showContentDiligence()
.then((res) => {
let actions = true;
if (res.message === 'sem_diligencia') {
$("#paragraph_loading_content").hide();
$("#paragraph_info_status_diligence").html('A sua diligência ainda não foi enviada');
$("#subject_info_status_diligence").hide();//Oculta o assunto da diligencia
if (res.data && res.data[0]?.status == 0) EntityDiligence.hideBtnOpenDiligence();
}
if (res.message === 'diligencia_aberta') {
EntityDiligence.hideBtnOpenDiligence();
res.data.forEach((element, index) => {
if (element?.status == 0) {
$("#descriptionDiligence").hide();
$("#paragraph_loading_content").hide();
}
});
$("#subject_info_status_diligence").hide();
}
if (res.message !== 'sem_diligencia') {
EntityDiligence.hideBtnOpenDiligence();
res.data.forEach((element, index) => {
if (element == null) {
actions = false;
}
});
if (actions && MapasCulturais.entity.object.opportunity.use_multiple_diligence === 'Sim') {
showBtnActionsDiligence();
}
}
$("#paragraph_loading_content").hide();
})
.catch(() => {
MapasCulturais.Messages.error('Ocorreu um erro ao carregar um conteúdo');
});
$("#select-value-project-diligence").on("change", function (e) {
e.preventDefault();
saveAuthorizedProject('option_authorized', e.target.value)
if (e.target.value === 'Sim') {
$("#paragraph_value_project").show();
} else {
$("#paragraph_value_project").hide();
}
});
$("#input-value-project-diligence").on("blur", function (e) {
saveAuthorizedProject('value_project_diligence', e.target.value)
});
});
//Clico do botão de abrir a diligência
function openDiligence(status) {
objSendDiligence['description'] = '';
objSendDiligence['status'] = status;
//Load
diligenceMessage.loadSimple();
//Mostra opção do assunto
$("#subject_info_status_diligence").show();
setTimeout(() => {
Swal.close();
}, 1000);
$("#descriptionDiligence").show();
showBtnActionsDiligence();
EntityDiligence.hideBtnOpenDiligence();
EntityDiligence.hideRegistration();
}
//Editando a descrição do rascunho.
function editDescription(description, id) {
EntityDiligence.editDescription(description, id);
showBtnActionsDiligence();
//Mostrando itens de assunto
$("#subject_info_status_diligence").show();
}
//Mostrar os botões de ação da diligência
function showBtnActionsDiligence() {
$('#btn-actions-diligence').removeClass('d-none');
$("#btn-save-diligence").show();
$("#btn-send-diligence").show();
}
//Salvando a autorização e o valor do projeto
function saveAuthorizedProject(keyAuth, valueAuth) {
const dataAuthorized = {
entity: MapasCulturais.entity.id
};
dataAuthorized[keyAuth] = valueAuth;
$.ajax({
type: "POST",
url: MapasCulturais.createUrl('diligence', 'valueProject'),
data: dataAuthorized,
dataType: "json",
success: function (res) {
if (res.status == 200) {
MapasCulturais.Messages.success('Valor destinado registrado');
}
},
error: function (err) {
MapasCulturais.Messages.error(err.responseJSON.data);
}
});
}
//Sempre implementar esses métodos
function hideRegistration() {
EntityDiligence.hideRegistration();
}
function showRegistration() {
EntityDiligence.showRegistration();
}
//Enviando diligência
function showSaveContent(status) {
$("#label-save-content-diligence").show();
setTimeout(() => {
$("#label-save-content-diligence").hide()
}, 2000);
if (status == 3) {
Swal.fire({
title: "<strong>Sucesso!</strong>",
html: `
A sua diligência foi enviada!
`,
focusConfirm: false,
timer: 10000,
timerProgressBar: true,
didOpen: () => {
const timer = Swal.getPopup().querySelector("b");
timerInterval = setInterval(() => {
}, 100);
},
willClose: () => {
clearInterval(timerInterval);
},
confirmButtonAriaLabel: "Thumbs up, great!",
allowOutsideClick: false,
showCancelButton: true,
reverseButtons: true,
cancelButtonText: 'Desfazer envio',
confirmButtonText: "OK",
}).then((result) => {
if (result.isConfirmed) {
sendNotification();
hideAfterSend();
showBtnSubmitEvaluation();
EntityDiligence.hideBtnOpenDiligence();
location.reload();
}
if (result.isDismissed && result.dismiss === 'cancel') {
cancelSend();
}
if (
result.dismiss === Swal.DismissReason.timer
) {
sendNotification();
hideAfterSend();
showBtnSubmitEvaluation();
EntityDiligence.hideBtnOpenDiligence();
location.reload();
}
});
}
}
//Enviando notificação
function sendNotification() {
$.ajax({
type: "POST",
url: MapasCulturais.createUrl('diligence', 'sendNotification'),
data: {
registration: MapasCulturais.entity.id,
openAgent: MapasCulturais.userProfile.id,
agent: MapasCulturais.entity.ownerId,
},
dataType: "json",
success: function (res) {
MapasCulturais.Messages.success('Notificação enviada');
if (res.status == 200) {
window.location.href = MapasCulturais.createUrl('inscricao', MapasCulturais.entity.id)
}
}
});
}
function cancelSend() {
const urlSend = MapasCulturais.createUrl('diligence', 'cancelsend');
$.ajax({
type: "PUT",
url: urlSend,
data: { registration: MapasCulturais.entity.id },
dataType: "json",
success: function (res) {
if (res.status == 400) {
Swal.fire("Ops! Ocorreu um erro.");
}
}
});
}
function saveDiligence(status, st, idDiligence) {
if ($("#descriptionDiligence").val() === '') {
diligenceMessage.messageSimple("Ops!", "A descrição precisa ser preenchida", 2000);
return false;
}
if (status == 3) {
//Mensagem de confirmação
Swal.fire({
title: "Confirmar o envio da diligência?",
text: "Você pode desfazer o envio em até 10 segundos. Revise sua diligência com cuidado.",
showConfirmButton: true,
showCloseButton: false,
showCancelButton: true,
reverseButtons: true,
cancelButtonText: `Não, enviar depois`,
confirmButtonText: "Enviar agora",
customClass: {
confirmButton: "btn-success-rec",
cancelButton: "btn-warning-rec"
},
})
.then((result) => {
if (result.isConfirmed) {
sendAjaxDiligence(status, idDiligence);
}
})
} else {
sendAjaxDiligence(status, idDiligence);
}
}
function sendAjaxDiligence(status, idDiligence) {
//Enviando o assunto com formato de array
objSendDiligence['subject'] = verifySubject("subject_exec_physical", "subject_report_finance");
objSendDiligence['description'] = $("#descriptionDiligence").val();
objSendDiligence['status'] = status;
objSendDiligence['idDiligence'] = idDiligence;
$.ajax({
type: "POST",
url: urlSaveDiligence,
data: objSendDiligence,
dataType: "json",
success: function (res) {
if (res.status == 200) {
showSaveContent(status)
$("#id-input-diligence").val(res.entityId);
}
if (res.status == 403) {
diligenceMessage.messageError('Ops! Um erro.', res.message, 3500);
}
},
error: function () {
MapasCulturais.Messages.error('Ocorreu um erro ao enviar a diligência');
}
});
}
/**
* Método que verifica se o assunto está confirmado
* @param subject_exec_physical string
* @param subject_report_finance string
* @returns {array}
*/
function verifySubject(subject_exec_physical, subject_report_finance)
{
objSendDiligence['subject'] = [];
const physicalChecked = $(`#${subject_exec_physical}:checked`).val();
const financialReportChecked = $(`#${subject_report_finance}:checked`).val();
//se a escolha for execução do objeto
if (physicalChecked === 'on') {
objSendDiligence['subject'].push('subject_exec_physical');
}
//se a escolha for relatório financeiro
if (financialReportChecked === 'on') {
objSendDiligence['subject'].push('subject_report_finance');
}
//Na situação de diligência única
if (
MapasCulturais.entity.object.opportunity.use_multiple_diligence === 'Sim'
&& physicalChecked === undefined
&& financialReportChecked === undefined
) {
diligenceMessage.messageSimple("Ops!", "Você precisa escolher um assunto ou mais assuntos", 2000);
return false;
} else if(MapasCulturais.entity.object.opportunity.use_multiple_diligence !== 'Sim'){
objSendDiligence['subject'].push('single_diligence');
}
return objSendDiligence['subject'];
}
//Oculta o botão de Finalizar avaliação
function showBtnSubmitEvaluation() {
$("#btn-submit-evaluation").removeAttr('disabled');
$("#btn-submit-evaluation").removeClass('btn-diligence-open-desactive');
}
//Mostra o botão de avaliação
function hideBtnSubmitEvaluation() {
$("#btn-submit-evaluation").attr('disabled', true);
$("#btn-submit-evaluation").addClass('btn-diligence-open-desactive');
}
//Oculta os botões de ação da diligência
function hideBtnActionsDiligence() {
$("#btn-save-diligence").hide();
$("#btn-send-diligence").hide();
}
//Após o envio da diligência
function hideAfterSend() {
$("#paragraph_content_send_diligence").html($("#descriptionDiligence").val());
$("#div-content-all-diligence-send").show();
$("#div-diligence").hide();
$("#btn-actions-diligence").hide();
$("#descriptionDiligence").hide();
}
function trashDraftDiligence(idDiligence, titleQuestion,textTrash, titleCancel, titleConfirm, classBtnConfirm, classBtnCancel) {
const trashDraft = diligenceMessage.messageConfirm(
titleQuestion, textTrash, titleCancel, titleConfirm, classBtnCancel ,classBtnConfirm
);
trashDraft.then(() => {
$.ajax({
type: "POST",
url: MapasCulturais.createUrl('diligence', 'trashDraftDiligence'),
data: {id : idDiligence},
dataType: 'json',
success: function (response) {
diligenceMessage.messageSimple('Excluído','Rascunho excluído com sucesso', 1500);
window.location.reload();
}
});
})
}