251 |
geraldo |
1 |
<?php
|
|
|
2 |
$acl = $this->viewModel()->getRoot()->getVariable('acl');
|
|
|
3 |
$currentUser = $this->currentUserHelper();
|
|
|
4 |
|
|
|
5 |
$roleName = $currentUser->getUserTypeId();
|
|
|
6 |
|
261 |
geraldo |
7 |
$routeAdd = $this->url('self-evaluation/forms/add');
|
262 |
geraldo |
8 |
$routeDatatable = $this->url('self-evaluation/reviews');
|
251 |
geraldo |
9 |
$routeDashboard = $this->url('dashboard');
|
|
|
10 |
|
261 |
geraldo |
11 |
$allowEdit = $acl->isAllowed($roleName, 'self-evaluation/forms/edit') ? 1 : 0;
|
251 |
geraldo |
12 |
|
|
|
13 |
|
|
|
14 |
$this->inlineScript()->appendFile($this->basePath('plugins/ckeditor/ckeditor.js'));
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
$this->headLink()->appendStylesheet($this->basePath('plugins/nprogress/nprogress.css'));
|
|
|
18 |
$this->inlineScript()->appendFile($this->basePath('plugins/nprogress/nprogress.js'));
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/jquery.validate.js'));
|
|
|
22 |
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/additional-methods.js'));
|
|
|
23 |
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-validation/localization/messages_es.js'));
|
|
|
24 |
|
|
|
25 |
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css'));
|
|
|
26 |
$this->headLink()->appendStylesheet($this->basePath('plugins/datatables-responsive/css/responsive.bootstrap4.min.css'));
|
|
|
27 |
|
|
|
28 |
$this->inlineScript()->appendFile($this->basePath('plugins/datatables/jquery.dataTables.min.js'));
|
|
|
29 |
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js'));
|
|
|
30 |
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/dataTables.responsive.min.js'));
|
|
|
31 |
$this->inlineScript()->appendFile($this->basePath('plugins/datatables-responsive/js/responsive.bootstrap4.min.js'));
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
$this->headLink()->appendStylesheet($this->basePath('plugins/select2/css/select2.min.css'));
|
|
|
35 |
$this->headLink()->appendStylesheet($this->basePath('plugins/select2-bootstrap4-theme/select2-bootstrap4.min.css'));
|
|
|
36 |
|
|
|
37 |
$this->inlineScript()->appendFile($this->basePath('plugins/select2/js/select2.full.min.js'));
|
|
|
38 |
|
|
|
39 |
$this->inlineScript()->appendFile($this->basePath('plugins/moment/moment-with-locales.min.js'));
|
|
|
40 |
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css'));
|
|
|
41 |
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js'));
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap4-toggle/css/bootstrap4-toggle.min.css'));
|
|
|
45 |
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap4-toggle/js/bootstrap4-toggle.min.js'));
|
|
|
46 |
|
|
|
47 |
$this->inlineScript()->appendFile($this->basePath('plugins/bootstrap-confirmation/dist/bootstrap-confirmation.js'));
|
|
|
48 |
$this->headLink()->appendStylesheet($this->basePath('plugins/bootstrap-checkbox/awesome-bootstrap-checkbox.css'));
|
|
|
49 |
$this->inlineScript()->appendFile($this->basePath('plugins/jquery-input-number/input-number-format.jquery.js'));
|
261 |
geraldo |
50 |
|
251 |
geraldo |
51 |
// bootbox Alert //
|
|
|
52 |
$this->inlineScript()->appendFile($this->basePath('plugins/bootbox/bootbox.min.js'));
|
261 |
geraldo |
53 |
|
251 |
geraldo |
54 |
// JsRender //
|
|
|
55 |
$this->inlineScript()->appendFile($this->basePath('plugins/jsrender/jsrender.min.js'));
|
|
|
56 |
|
261 |
geraldo |
57 |
// Page Styles
|
|
|
58 |
$this->headLink()->appendStylesheet($this->basePath('css/pages/self-evaluation.css'));
|
251 |
geraldo |
59 |
|
306 |
geraldo |
60 |
|
307 |
geraldo |
61 |
$pending = \LeadersLinked\Model\CompanySelfEvaluationTest::STATUS_PENDING;
|
308 |
geraldo |
62 |
$review = \LeadersLinked\Model\CompanySelfEvaluationTest::STATUS_REVIEW;
|
307 |
geraldo |
63 |
$completed = \LeadersLinked\Model\CompanySelfEvaluationTest::STATUS_COMPLETED;
|
306 |
geraldo |
64 |
|
251 |
geraldo |
65 |
$this->inlineScript()->captureStart();
|
|
|
66 |
echo <<<JS
|
339 |
geraldo |
67 |
const classFormGenerator = function() {
|
251 |
geraldo |
68 |
this.id = 0,
|
|
|
69 |
this.table = '',
|
|
|
70 |
this.name = '',
|
|
|
71 |
this.text = '',
|
|
|
72 |
this.status = 'a',
|
|
|
73 |
this.sections = [],
|
|
|
74 |
this.clear = function() {
|
|
|
75 |
this.sections = [];
|
|
|
76 |
this.render();
|
|
|
77 |
},
|
|
|
78 |
/**
|
|
|
79 |
* Render array sections
|
|
|
80 |
*/
|
|
|
81 |
this.renderSection = function(slug_section) {
|
|
|
82 |
var s = '';
|
|
|
83 |
for (i = 0; i < this.sections.length; i++) {
|
|
|
84 |
if (slug_section != this.sections[i].slug_section) {
|
|
|
85 |
continue;
|
|
|
86 |
}
|
|
|
87 |
for (j = 0; j < this.sections[i].questions.length; j++) {
|
|
|
88 |
this.sections[i].questions[j].position = j;
|
|
|
89 |
if (this.sections[i].questions[j].type == 'simple' || this.sections[i].questions[j].type == 'multiple' || this.sections[i].questions[j].type == 'rating-open') {
|
|
|
90 |
this.sections[i].questions[j].options.sort(function(a, b) {
|
|
|
91 |
if (a.position > b.position) {
|
|
|
92 |
return 1;
|
|
|
93 |
}
|
|
|
94 |
if (a.position < b.position) {
|
|
|
95 |
return -1;
|
|
|
96 |
}
|
|
|
97 |
return 0;
|
|
|
98 |
});
|
|
|
99 |
for (k = 0; k < this.sections[i].questions[j].options.length; k++) {
|
|
|
100 |
this.sections[i].questions[j].options[k].position = j;
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
}
|
|
|
105 |
$('[data-toggle="tooltip"]').tooltip();
|
|
|
106 |
},
|
|
|
107 |
this.render = function() {
|
|
|
108 |
this.sections.sort(function(a, b) {
|
|
|
109 |
if (a.position > b.position) {
|
|
|
110 |
return 1;
|
|
|
111 |
}
|
|
|
112 |
if (a.position < b.position) {
|
|
|
113 |
return -1;
|
|
|
114 |
}
|
|
|
115 |
return 0;
|
|
|
116 |
});
|
|
|
117 |
var s = '';
|
|
|
118 |
for (i = 0; i < this.sections.length; i++) {
|
|
|
119 |
this.sections[i].position = i;
|
|
|
120 |
this.sections[i].questions.sort(function(a, b) {
|
|
|
121 |
if (a.position > b.position) {
|
|
|
122 |
return 1;
|
|
|
123 |
}
|
|
|
124 |
if (a.position < b.position) {
|
|
|
125 |
return -1;
|
|
|
126 |
}
|
|
|
127 |
return 0;
|
|
|
128 |
});
|
|
|
129 |
for (j = 0; j < this.sections[i].questions.length; j++) {
|
|
|
130 |
this.sections[i].questions[j].position = j;
|
|
|
131 |
if (this.sections[i].questions[j].type == 'simple' || this.sections[i].questions[j].type == 'multiple' || this.sections[i].questions[j].type == 'rating-open') {
|
|
|
132 |
this.sections[i].questions[j].options.sort(function(a, b) {
|
|
|
133 |
if (a.position > b.position) {
|
|
|
134 |
return 1;
|
|
|
135 |
}
|
|
|
136 |
if (a.position < b.position) {
|
|
|
137 |
return -1;
|
|
|
138 |
}
|
|
|
139 |
return 0;
|
|
|
140 |
});
|
|
|
141 |
for (k = 0; k < this.sections[i].questions[j].options.length; k++) {
|
|
|
142 |
this.sections[i].questions[j].options[k].position = j;
|
|
|
143 |
}
|
|
|
144 |
}
|
|
|
145 |
}
|
|
|
146 |
}
|
|
|
147 |
$('[data-toggle="tooltip"]').tooltip();
|
266 |
geraldo |
148 |
};
|
345 |
geraldo |
149 |
/**
|
|
|
150 |
* Add element to question array
|
|
|
151 |
*/
|
|
|
152 |
this.editQuestion = function(slug_section, slug_question, status) {
|
|
|
153 |
var renderTable = false;
|
|
|
154 |
for (i = 0; i < this.sections.length; i++) {
|
|
|
155 |
if (slug_section == this.sections[i].slug_section) {
|
|
|
156 |
for (j = 0; j < this.sections[i].questions.length; j++) {
|
|
|
157 |
if (slug_question == this.sections[i].questions[j].slug_question) {
|
|
|
158 |
|
|
|
159 |
this.sections[i].questions[j].status = status;
|
|
|
160 |
|
|
|
161 |
|
|
|
162 |
renderTable = true;
|
|
|
163 |
break;
|
|
|
164 |
}
|
|
|
165 |
}
|
|
|
166 |
}
|
|
|
167 |
if (renderTable) {
|
|
|
168 |
break;
|
|
|
169 |
}
|
|
|
170 |
}
|
|
|
171 |
if (renderTable) {
|
|
|
172 |
this.renderSection(slug_section);
|
|
|
173 |
}
|
|
|
174 |
};
|
339 |
geraldo |
175 |
}
|
251 |
geraldo |
176 |
jQuery(document).ready(function($) {
|
|
|
177 |
var objFormGenerator = new classFormGenerator();
|
|
|
178 |
objFormGenerator.render();
|
|
|
179 |
var allowEdit = $allowEdit;
|
|
|
180 |
/**
|
|
|
181 |
* Get rows and set data table
|
|
|
182 |
*/
|
|
|
183 |
var tableForm = $('#gridTable').dataTable({
|
|
|
184 |
'processing': true,
|
|
|
185 |
'serverSide': true,
|
|
|
186 |
'searching': true,
|
|
|
187 |
'order': [
|
|
|
188 |
[0, 'asc']
|
|
|
189 |
],
|
|
|
190 |
'ordering': true,
|
|
|
191 |
'ordenable': true,
|
|
|
192 |
'responsive': true,
|
|
|
193 |
'select': false,
|
|
|
194 |
'paging': true,
|
|
|
195 |
'pagingType': 'simple_numbers',
|
|
|
196 |
'ajax': {
|
|
|
197 |
'url': '$routeDatatable',
|
|
|
198 |
'type': 'get',
|
|
|
199 |
'beforeSend': function(request) {
|
|
|
200 |
NProgress.start();
|
|
|
201 |
},
|
|
|
202 |
'dataFilter': function(response) {
|
|
|
203 |
var response = jQuery.parseJSON(response);
|
|
|
204 |
var json = {};
|
|
|
205 |
json.recordsTotal = 0;
|
|
|
206 |
json.recordsFiltered = 0;
|
|
|
207 |
json.data = [];
|
|
|
208 |
if (response.success) {
|
|
|
209 |
json.recordsTotal = response.data.total;
|
|
|
210 |
json.recordsFiltered = response.data.total;
|
|
|
211 |
json.data = response.data.items;
|
|
|
212 |
} else {
|
|
|
213 |
$.fn.showError(response.data)
|
|
|
214 |
}
|
|
|
215 |
return JSON.stringify(json);
|
|
|
216 |
}
|
|
|
217 |
},
|
|
|
218 |
'language': {
|
|
|
219 |
'sProcessing': 'LABEL_DATATABLE_SPROCESSING',
|
|
|
220 |
'sLengthMenu': 'LABEL_DATATABLE_SLENGTHMENU',
|
|
|
221 |
'sZeroRecords': 'LABEL_DATATABLE_SZERORECORDS',
|
|
|
222 |
'sEmptyTable': 'LABEL_DATATABLE_SEMPTYTABLE',
|
|
|
223 |
'sInfo': 'LABEL_DATATABLE_SINFO',
|
|
|
224 |
'sInfoEmpty': 'LABEL_DATATABLE_SINFOEMPTY',
|
|
|
225 |
'sInfoFiltered': 'LABEL_DATATABLE_SINFOFILTERED',
|
|
|
226 |
'sInfoPostFix': '',
|
|
|
227 |
'sSearch': 'LABEL_DATATABLE_SSEARCH',
|
|
|
228 |
'sUrl': '',
|
|
|
229 |
'sInfoThousands': ',',
|
|
|
230 |
'sLoadingRecords': 'LABEL_DATATABLE_SLOADINGRECORDS',
|
|
|
231 |
'oPaginate': {
|
|
|
232 |
'sFirst': 'LABEL_DATATABLE_SFIRST',
|
|
|
233 |
'sLast': 'LABEL_DATATABLE_SLAST',
|
|
|
234 |
'sNext': 'LABEL_DATATABLE_SNEXT',
|
|
|
235 |
'sPrevious': 'LABEL_DATATABLE_SPREVIOUS'
|
|
|
236 |
},
|
|
|
237 |
'oAria': {
|
|
|
238 |
'sSortAscending': ': LABEL_DATATABLE_SSORTASCENDING',
|
|
|
239 |
'sSortDescending': ':LABEL_DATATABLE_SSORTDESCENDING'
|
|
|
240 |
},
|
|
|
241 |
},
|
|
|
242 |
'drawCallback': function(settings) {
|
|
|
243 |
NProgress.done();
|
|
|
244 |
$('button.btn-delete').confirmation({
|
|
|
245 |
rootSelector: 'button.btn-delete',
|
|
|
246 |
title: 'LABEL_ARE_YOU_SURE',
|
|
|
247 |
singleton: true,
|
|
|
248 |
btnOkLabel: 'LABEL_YES',
|
|
|
249 |
btnCancelLabel: 'LABEL_NO',
|
|
|
250 |
onConfirm: function(value) {
|
|
|
251 |
action = $(this).data('href');
|
|
|
252 |
NProgress.start();
|
|
|
253 |
$.ajax({
|
|
|
254 |
'dataType': 'json',
|
|
|
255 |
'accept': 'application/json',
|
|
|
256 |
'method': 'post',
|
|
|
257 |
'url': action,
|
|
|
258 |
}).done(function(response) {
|
|
|
259 |
if (response['success']) {
|
|
|
260 |
$.fn.showSuccess(response['data']);
|
|
|
261 |
tableForm.fnDraw();
|
|
|
262 |
} else {
|
|
|
263 |
$.fn.showError(response['data']);
|
|
|
264 |
}
|
|
|
265 |
}).fail(function(jqXHR, textStatus, errorThrown) {
|
|
|
266 |
$.fn.showError(textStatus);
|
|
|
267 |
}).always(function() {
|
|
|
268 |
NProgress.done();
|
|
|
269 |
});
|
|
|
270 |
},
|
|
|
271 |
});
|
|
|
272 |
},
|
339 |
geraldo |
273 |
'aoColumns': [{
|
294 |
geraldo |
274 |
'mDataProp': 'user'
|
339 |
geraldo |
275 |
}, {
|
251 |
geraldo |
276 |
'mDataProp': 'name'
|
|
|
277 |
},
|
|
|
278 |
{
|
|
|
279 |
'mDataProp': 'language'
|
|
|
280 |
},
|
|
|
281 |
{
|
|
|
282 |
'mDataProp': 'status'
|
|
|
283 |
},
|
|
|
284 |
{
|
294 |
geraldo |
285 |
'mDataProp': 'link_edit'
|
251 |
geraldo |
286 |
},
|
|
|
287 |
],
|
339 |
geraldo |
288 |
'columnDefs': [{
|
251 |
geraldo |
289 |
'targets': 0,
|
|
|
290 |
'className': 'text-vertical-middle',
|
339 |
geraldo |
291 |
}, {
|
294 |
geraldo |
292 |
'targets': 1,
|
|
|
293 |
'className': 'text-vertical-middle',
|
251 |
geraldo |
294 |
},
|
|
|
295 |
{
|
294 |
geraldo |
296 |
'targets': -1,
|
251 |
geraldo |
297 |
'className': 'text-vertical-middle',
|
|
|
298 |
},
|
|
|
299 |
{
|
292 |
geraldo |
300 |
'targets': -2,
|
|
|
301 |
'orderable': false,
|
|
|
302 |
'className': 'text-center',
|
293 |
geraldo |
303 |
'className': 'text-vertical-middle',
|
251 |
geraldo |
304 |
},
|
|
|
305 |
{
|
|
|
306 |
'targets': -1,
|
|
|
307 |
'orderable': false,
|
|
|
308 |
'render': function(data, type, row) {
|
|
|
309 |
s = '';
|
|
|
310 |
if (allowEdit) {
|
293 |
geraldo |
311 |
s = s + '<button class="btn btn-primary btn-edit-form" data-href="' + data + '" data-toggle="tooltip" title="LABEL_EDIT"><i class="fa fa-pencil"></i> LABEL_EDIT </button> ';
|
251 |
geraldo |
312 |
}
|
|
|
313 |
return s;
|
|
|
314 |
}
|
|
|
315 |
}
|
|
|
316 |
],
|
|
|
317 |
});
|
|
|
318 |
/**
|
|
|
319 |
* Clicked on edit form
|
|
|
320 |
*/
|
|
|
321 |
$('body').on('click', 'button.btn-edit-form', function(e) {
|
|
|
322 |
e.preventDefault();
|
|
|
323 |
form_id = $(this).data('id')
|
|
|
324 |
var action = $(this).data('href');
|
|
|
325 |
$.ajax({
|
|
|
326 |
'dataType': 'json',
|
|
|
327 |
'accept': 'application/json',
|
|
|
328 |
'method': 'get',
|
|
|
329 |
'url': action,
|
|
|
330 |
}).done(function(response) {
|
|
|
331 |
if (response['success']) {
|
|
|
332 |
validatorForm.resetForm();
|
|
|
333 |
$('#form-main').attr('action', action);
|
|
|
334 |
$('#form-main #form-id').val(response['data']['id']),
|
339 |
geraldo |
335 |
$('#name').html(response['data']['name']);
|
316 |
geraldo |
336 |
$('#text').html(response['data']['text']);
|
|
|
337 |
$('#user').html(response['data']['user']);
|
251 |
geraldo |
338 |
/*-------------Render Sections -------*/
|
|
|
339 |
objFormGenerator.clear();
|
|
|
340 |
objFormGenerator.sections = response['data']['content'] || [];
|
|
|
341 |
objFormGenerator.render();
|
|
|
342 |
renderSectionData(objFormGenerator.sections);
|
254 |
geraldo |
343 |
$('#row-forms').hide();
|
251 |
geraldo |
344 |
$('#row-edit').show();
|
|
|
345 |
} else {
|
|
|
346 |
$.fn.showError(response['message'] || 'ERROR_UNKNOWN');
|
|
|
347 |
}
|
|
|
348 |
}).fail(function(jqXHR, textStatus, errorThrown) {
|
|
|
349 |
$.fn.showError(textStatus);
|
|
|
350 |
});
|
|
|
351 |
});
|
|
|
352 |
//IMPORTANT: update CKEDITOR textarea with actual content before submit
|
|
|
353 |
$("#form-main").on('submit', function() {
|
|
|
354 |
for (var instanceName in CKEDITOR.instances) {
|
|
|
355 |
CKEDITOR.instances[instanceName].updateElement();
|
|
|
356 |
}
|
|
|
357 |
})
|
|
|
358 |
/**
|
|
|
359 |
* Validate rules form
|
|
|
360 |
*/
|
|
|
361 |
var validatorForm = $("#form-main").validate({
|
|
|
362 |
ignore: [],
|
|
|
363 |
errorClass: 'help-block',
|
|
|
364 |
errorElement: 'span',
|
|
|
365 |
rules: {
|
|
|
366 |
'form-name': {
|
|
|
367 |
required: true,
|
|
|
368 |
minlength: 2,
|
|
|
369 |
maxlength: 50
|
|
|
370 |
},
|
|
|
371 |
'form-description': {
|
|
|
372 |
required: true,
|
|
|
373 |
},
|
|
|
374 |
'form-text': {
|
|
|
375 |
required: true,
|
|
|
376 |
},
|
|
|
377 |
'form-language': {
|
|
|
378 |
required: true,
|
|
|
379 |
},
|
|
|
380 |
'forrm-status': {
|
|
|
381 |
required: true,
|
|
|
382 |
},
|
|
|
383 |
},
|
|
|
384 |
highlight: function(element) {
|
|
|
385 |
$(element).closest('.form-group').addClass('has-error');
|
|
|
386 |
},
|
|
|
387 |
unhighlight: function(element) {
|
|
|
388 |
$(element).closest('.form-group').removeClass('has-error');
|
|
|
389 |
},
|
|
|
390 |
errorPlacement: function(error, element) {
|
|
|
391 |
if (element.attr("data-error-container")) {
|
|
|
392 |
error.appendTo(element.attr("data-error-container"));
|
|
|
393 |
} else {
|
|
|
394 |
error.insertAfter(element);
|
|
|
395 |
}
|
|
|
396 |
},
|
|
|
397 |
invalidHandler: function(form, validator) {
|
|
|
398 |
if (!validator.numberOfInvalids())
|
|
|
399 |
return;
|
|
|
400 |
$('html, body').animate({
|
|
|
401 |
scrollTop: $(validator.errorList[0].element).offset().top - 100
|
|
|
402 |
}, 1000);
|
|
|
403 |
},
|
|
|
404 |
submitHandler: function(form) {
|
|
|
405 |
var error = false;
|
|
|
406 |
if (objFormGenerator.sections.length == 0) {
|
|
|
407 |
$.fn.showError('ERROR_SECCTIONS');
|
|
|
408 |
return false;
|
|
|
409 |
} else {
|
|
|
410 |
for (i = 0; i < objFormGenerator.sections.length; i++) {
|
|
|
411 |
if (objFormGenerator.sections[i].questions.length == 0) {
|
|
|
412 |
$.fn.showError('ERROR_QUESTIONS'.replace('%s', objFormGenerator.sections[i].name));
|
|
|
413 |
return false;
|
|
|
414 |
}
|
|
|
415 |
var valueSection = parseInt(objFormGenerator.sections[i].value);
|
|
|
416 |
var totalValueQuestion = 0;
|
|
|
417 |
for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
|
|
|
418 |
valueQuestion = parseInt(objFormGenerator.sections[i].questions[j].value);
|
|
|
419 |
totalValueQuestion = totalValueQuestion + valueQuestion;
|
|
|
420 |
if (objFormGenerator.sections[i].questions[j].type == 'simple' ||
|
|
|
421 |
objFormGenerator.sections[i].questions[j].type == 'multiple' ||
|
|
|
422 |
objFormGenerator.sections[i].questions[j].type == 'rating-open') {
|
|
|
423 |
var questionNumber = j + 1;
|
|
|
424 |
var numberCorrect = 0;
|
|
|
425 |
if (objFormGenerator.sections[i].questions[j].options.length == 0) {
|
|
|
426 |
$.fn.showError('ERROR_OPTIONS'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
|
|
|
427 |
return false;
|
|
|
428 |
}
|
|
|
429 |
var totalOption = 0;
|
|
|
430 |
var maxOption = 0;
|
|
|
431 |
for (k = 0; k < objFormGenerator.sections[i].questions[j].options.length; k++) {
|
|
|
432 |
if (objFormGenerator.sections[i].questions[j].type == 'simple' || objFormGenerator.sections[i].questions[j].type == 'multiple') {
|
|
|
433 |
if (objFormGenerator.sections[i].questions[j].options[k].correct == 1) {
|
|
|
434 |
numberCorrect++;
|
|
|
435 |
}
|
|
|
436 |
}
|
|
|
437 |
if (objFormGenerator.sections[i].questions[j].type == 'multiple' && objFormGenerator.sections[i].questions[j].options[k].correct == 1) {
|
|
|
438 |
totalOption = totalOption + parseInt(objFormGenerator.sections[i].questions[j].options[k].value);
|
|
|
439 |
}
|
|
|
440 |
if (objFormGenerator.sections[i].questions[j].type == 'rating-open') {
|
|
|
441 |
if (parseInt(objFormGenerator.sections[i].questions[j].options[k].value) > maxOption) {
|
|
|
442 |
maxOption = parseInt(objFormGenerator.sections[i].questions[j].options[k].value);
|
|
|
443 |
}
|
|
|
444 |
}
|
|
|
445 |
}
|
|
|
446 |
if (objFormGenerator.sections[i].questions[j].type == 'simple' || objFormGenerator.sections[i].questions[j].type == 'multiple') {
|
|
|
447 |
if (numberCorrect == 0) {
|
|
|
448 |
$.fn.showError('ERROR_OPTIONS_CORRECT'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
|
|
|
449 |
return false;
|
|
|
450 |
}
|
|
|
451 |
if (
|
|
|
452 |
objFormGenerator.sections[i].questions[j].type == 'simple' && numberCorrect > 1) {
|
|
|
453 |
$.fn.showError('ERROR_OPTIONS_DUPLICATE_CORRECT'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
|
|
|
454 |
return false;
|
|
|
455 |
}
|
|
|
456 |
if (objFormGenerator.sections[i].questions[j].type == 'multiple' && numberCorrect == 1) {
|
|
|
457 |
$.fn.showError('ERROR_OPTIONS_ONE_CORRECT'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
|
|
|
458 |
return false;
|
|
|
459 |
}
|
|
|
460 |
}
|
|
|
461 |
if (objFormGenerator.sections[i].questions[j].type == 'multiple' && totalOption != valueQuestion) {
|
|
|
462 |
$.fn.showError('ERROR_OPTIONS_SUM_VALUES'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
|
|
|
463 |
return false;
|
|
|
464 |
}
|
|
|
465 |
if (objFormGenerator.sections[i].questions[j].type == 'rating-open' && maxOption > valueQuestion) {
|
|
|
466 |
$.fn.showError('ERROR_OPTIONS_MAX_OPTION'.replace('%s', objFormGenerator.sections[i].name).replace('%n', questionNumber));
|
|
|
467 |
return false;
|
|
|
468 |
}
|
|
|
469 |
}
|
|
|
470 |
}
|
|
|
471 |
if (valueSection != totalValueQuestion) {
|
|
|
472 |
$.fn.showError('ERROR_VALUE_SECTIONS'.replace('%s', objFormGenerator.sections[i].name));
|
|
|
473 |
return false;
|
|
|
474 |
}
|
|
|
475 |
}
|
|
|
476 |
var formId = parseInt($('#form-main #form-id').val());
|
|
|
477 |
var formContinue = parseInt($('#form-main #form-continue').val());
|
|
|
478 |
var data = {
|
|
|
479 |
'id': formId,
|
|
|
480 |
'name': $('#form-main #form-name').val(),
|
|
|
481 |
'description': $('#form-main #form-description').val(),
|
|
|
482 |
'text': $('#form-main #form-text').val(),
|
|
|
483 |
'language': $('#form-main #form-language').val(),
|
|
|
484 |
'status': $('#form-main #form-status').val(),
|
|
|
485 |
'content': JSON.stringify(objFormGenerator.sections)
|
|
|
486 |
}
|
|
|
487 |
$.ajax({
|
|
|
488 |
'dataType': 'json',
|
|
|
489 |
'method': 'post',
|
|
|
490 |
'url': $('#form-main').attr('action'),
|
|
|
491 |
'data': data,
|
|
|
492 |
}).done(function(response) {
|
|
|
493 |
if (response['success']) {
|
|
|
494 |
$.fn.showSuccess(response['data']);
|
|
|
495 |
if (formContinue == 1) {
|
339 |
geraldo |
496 |
$('#form-main').attr('action', response['action_edit']);
|
251 |
geraldo |
497 |
$('#form-main #form-id').val(response['id']);
|
|
|
498 |
$('#form-main #form-continue').val(0);
|
|
|
499 |
} else {
|
|
|
500 |
$('#row-edit').hide();
|
254 |
geraldo |
501 |
$('#row-forms').show();
|
339 |
geraldo |
502 |
/*---------- Reset Form -------- */
|
|
|
503 |
$('#form-main')[0].reset();
|
|
|
504 |
/*--------Reset Sections ----------*/
|
|
|
505 |
clearSectionData();
|
|
|
506 |
/* ------- Refresh Table -----------*/
|
251 |
geraldo |
507 |
}
|
|
|
508 |
tableForm.fnDraw();
|
|
|
509 |
} else {
|
|
|
510 |
$.fn.showError(response['message'] || 'ERROR_UNKNOWN');
|
|
|
511 |
}
|
|
|
512 |
}).fail(function(jqXHR, textStatus, errorThrown) {
|
|
|
513 |
$.fn.showError(textStatus);
|
|
|
514 |
});
|
|
|
515 |
return false;
|
|
|
516 |
}
|
|
|
517 |
}
|
|
|
518 |
});
|
|
|
519 |
/**
|
|
|
520 |
* Clicked cancel new/edit Form
|
|
|
521 |
*/
|
|
|
522 |
$('button.btn-edit-cancel').click(function(e) {
|
|
|
523 |
e.preventDefault();
|
|
|
524 |
$('#row-edit').hide();
|
254 |
geraldo |
525 |
$('#row-forms').show();
|
251 |
geraldo |
526 |
});
|
|
|
527 |
/**
|
|
|
528 |
* Clicked save and continue new Form
|
|
|
529 |
*/
|
|
|
530 |
$('button.btn-form-save-continue').click(function(e) {
|
|
|
531 |
e.preventDefault();
|
|
|
532 |
$('#form-main #form-continue').val('1')
|
|
|
533 |
$('#form-main').submit();
|
|
|
534 |
});
|
|
|
535 |
/**
|
|
|
536 |
* Clicked save and close new/edit Form
|
|
|
537 |
*/
|
|
|
538 |
$('button.btn-form-save-close').click(function(e) {
|
|
|
539 |
e.preventDefault();
|
|
|
540 |
$('#form-main #form-continue').val('0')
|
|
|
541 |
$('#form-main').submit();
|
|
|
542 |
});
|
339 |
geraldo |
543 |
/**
|
|
|
544 |
* Get Answers
|
|
|
545 |
*/
|
|
|
546 |
const getAnswer = (type, options, answer) => {
|
|
|
547 |
if (type == 'open' || type == 'rating-range') {
|
328 |
geraldo |
548 |
return answer;
|
251 |
geraldo |
549 |
}
|
339 |
geraldo |
550 |
if (type == 'multiple') {
|
344 |
geraldo |
551 |
let opt = '';
|
339 |
geraldo |
552 |
opt += removeTags(options.filter((opt) => answer.includes(opt.slug_option))[0].text) + ' ';
|
332 |
geraldo |
553 |
return opt;
|
330 |
geraldo |
554 |
}
|
338 |
geraldo |
555 |
return removeTags(options.filter((opt) => opt.slug_option == answer)[0].text);
|
251 |
geraldo |
556 |
}
|
|
|
557 |
/**
|
341 |
geraldo |
558 |
* Get Status
|
|
|
559 |
*/
|
344 |
geraldo |
560 |
const getStatus = (options, answer) => options.filter((opt) => (opt.slug_option == answer || answer.includes(opt.slug_option)) &&
|
|
|
561 |
opt.correct == 1) ? 'LABEL_CORRECT' : 'LABEL_FAIL'
|
341 |
geraldo |
562 |
/**
|
251 |
geraldo |
563 |
* Remove Html Tags
|
|
|
564 |
*/
|
339 |
geraldo |
565 |
const removeTags = (str) => str.toString().replace(/(<([^>]+)>)/ig, '')
|
345 |
geraldo |
566 |
|
251 |
geraldo |
567 |
/**
|
|
|
568 |
* Render Sections data
|
|
|
569 |
*/
|
|
|
570 |
const renderSectionData = (data) => $("#rows").html($("#sectionTemplate").render(data, {
|
323 |
geraldo |
571 |
removeTags: removeTags,
|
341 |
geraldo |
572 |
getAnswer: getAnswer,
|
345 |
geraldo |
573 |
getStatus: getStatus,
|
|
|
574 |
editQuestion: objFormGenerator.editQuestion
|
251 |
geraldo |
575 |
}));
|
346 |
geraldo |
576 |
|
|
|
577 |
|
|
|
578 |
const editQuestion = () =>{
|
|
|
579 |
console.log(1)
|
|
|
580 |
}
|
251 |
geraldo |
581 |
/**
|
|
|
582 |
* Clear Div Section data
|
|
|
583 |
*/
|
|
|
584 |
const clearSectionData = () => $("#rows").html('');
|
|
|
585 |
/**
|
|
|
586 |
* Clicked refresh button
|
|
|
587 |
*/
|
|
|
588 |
$('button.btn-refresh').click(function(e) {
|
|
|
589 |
tableForm.fnDraw();
|
|
|
590 |
});
|
|
|
591 |
});
|
|
|
592 |
JS;
|
|
|
593 |
$this->inlineScript()->captureEnd();
|
|
|
594 |
?>
|
|
|
595 |
|
|
|
596 |
<!-- Content Header (Page header) -->
|
|
|
597 |
<section class="content-header">
|
|
|
598 |
<div class="container-fluid">
|
|
|
599 |
<div class="row mb-2">
|
|
|
600 |
<div class="col-sm-12">
|
264 |
geraldo |
601 |
<h1>LABEL_REVIEWS</h1>
|
251 |
geraldo |
602 |
</div>
|
|
|
603 |
</div>
|
|
|
604 |
</div>
|
|
|
605 |
<!-- /.container-fluid -->
|
|
|
606 |
</section>
|
314 |
geraldo |
607 |
<section class="content" style="padding: 13px;">
|
254 |
geraldo |
608 |
<div class="container-fluid" id="row-forms">
|
251 |
geraldo |
609 |
<div class="row">
|
|
|
610 |
<div class="col-12">
|
|
|
611 |
<div class="card">
|
|
|
612 |
<div class="card-body">
|
|
|
613 |
<table id="gridTable" class="table table-hover">
|
|
|
614 |
<thead>
|
|
|
615 |
<tr>
|
294 |
geraldo |
616 |
<th>LABEL_USER</th>
|
251 |
geraldo |
617 |
<th>LABEL_NAME</th>
|
|
|
618 |
<th>LABEL_LANGUAGE</th>
|
294 |
geraldo |
619 |
<th>LABEL_STATUS</th>
|
251 |
geraldo |
620 |
<th>LABEL_ACTIONS</th>
|
|
|
621 |
</tr>
|
|
|
622 |
</thead>
|
|
|
623 |
<tbody></tbody>
|
|
|
624 |
</table>
|
|
|
625 |
</div>
|
|
|
626 |
<div class="card-footer clearfix">
|
|
|
627 |
<div style="float:right;">
|
|
|
628 |
<button type="button" class="btn btn-info btn-refresh"><i class="fa fa-refresh"></i> LABEL_REFRESH </button>
|
|
|
629 |
</div>
|
|
|
630 |
</div>
|
|
|
631 |
</div>
|
|
|
632 |
</div>
|
|
|
633 |
</div>
|
|
|
634 |
</div>
|
|
|
635 |
|
|
|
636 |
<!-- Create/Edit Form -->
|
|
|
637 |
|
|
|
638 |
<div class="row" id="row-edit" style="display: none">
|
|
|
639 |
<div class="col-xs-12 col-md-12">
|
|
|
640 |
<form action="#" name="form-main" id="form-main">
|
261 |
geraldo |
641 |
<input type="hidden" name="form-id" id="form-id" value="0" />
|
251 |
geraldo |
642 |
<div class="form-group">
|
318 |
geraldo |
643 |
<label for="form-status">LABEL_USER:</label>
|
317 |
geraldo |
644 |
<div id="user"></div>
|
|
|
645 |
</div>
|
|
|
646 |
<div class="form-group">
|
318 |
geraldo |
647 |
<label for="form-status">LABEL_FORM:</label>
|
317 |
geraldo |
648 |
<div id="name"></div>
|
|
|
649 |
</div>
|
|
|
650 |
<div class="form-group">
|
318 |
geraldo |
651 |
<label for="form-status">LABEL_DESCRIPTION:</label>
|
317 |
geraldo |
652 |
<div id="text"></div>
|
|
|
653 |
</div>
|
|
|
654 |
<div class="form-group">
|
318 |
geraldo |
655 |
<label for="form-status">LABEL_STATUS:</label>
|
261 |
geraldo |
656 |
<select name="form-status" id="form-status" class="form-control">
|
306 |
geraldo |
657 |
<option value="<?php echo $pending; ?>">LABEL_PENDING</option>
|
|
|
658 |
<option value="<?php echo $review; ?>">LABEL_REVIEW</option>
|
|
|
659 |
<option value="<?php echo $completed; ?>">LABEL_COMPLETED</option>
|
261 |
geraldo |
660 |
</select>
|
303 |
geraldo |
661 |
</div>
|
261 |
geraldo |
662 |
<div class="row">
|
|
|
663 |
<div class="col-xs-12 col-md-12">
|
|
|
664 |
<div class="panel-group" id="rows"></div>
|
|
|
665 |
</div>
|
|
|
666 |
</div>
|
|
|
667 |
<div class="form-group">
|
319 |
geraldo |
668 |
<button type="button" class="btn btn-primary btn-form-save-close">LABEL_SAVE</button>
|
251 |
geraldo |
669 |
<button type="button" class="btn btn-secondary btn-edit-cancel">LABEL_CANCEL</button>
|
|
|
670 |
</div>
|
|
|
671 |
</form>
|
|
|
672 |
</div>
|
|
|
673 |
</div>
|
|
|
674 |
|
261 |
geraldo |
675 |
<!-- Create/Edit Form-->
|
251 |
geraldo |
676 |
|
264 |
geraldo |
677 |
|
261 |
geraldo |
678 |
|
251 |
geraldo |
679 |
<!---Template Sections --->
|
|
|
680 |
<script id="sectionTemplate" type="text/x-jsrender">
|
|
|
681 |
<div class="panel panel-default" id="panel-{{:slug_section}}">
|
|
|
682 |
<div class="panel-heading">
|
|
|
683 |
<h4 class="panel-title">
|
|
|
684 |
<a class="accordion-toggle" data-toggle="collapse" aria-expanded="true" data-parent="#panel-{{:slug_section}}" href="#collapse-{{:slug_section}}">
|
|
|
685 |
<span class="section-name{{:slug_section}}">
|
|
|
686 |
{{:name}}
|
|
|
687 |
</span>
|
|
|
688 |
</a>
|
|
|
689 |
</h4>
|
|
|
690 |
</div>
|
|
|
691 |
<div id="collapse-{{:slug_section}}" class="panel-collapse in collapse show">
|
|
|
692 |
<div class="panel-body">
|
|
|
693 |
<div class="table-responsive">
|
310 |
geraldo |
694 |
{{for questions}}
|
251 |
geraldo |
695 |
<table class="table table-bordered">
|
|
|
696 |
<thead>
|
|
|
697 |
<tr>
|
329 |
geraldo |
698 |
<th style="width: 70%;">LABEL_QUESTION</th>
|
|
|
699 |
<th style="width: 30%;">LABEL_STATUS</th>
|
312 |
geraldo |
700 |
|
251 |
geraldo |
701 |
</tr>
|
|
|
702 |
</thead>
|
|
|
703 |
<tbody>
|
|
|
704 |
<tr class="tr-question">
|
303 |
geraldo |
705 |
<td class="text-left">{{:~removeTags(text)}} </td>
|
339 |
geraldo |
706 |
<td>
|
340 |
geraldo |
707 |
|
|
|
708 |
{{if type == 'simple' || type=='multiple' }}
|
341 |
geraldo |
709 |
|
|
|
710 |
{{:~getStatus( options,answer)}}
|
|
|
711 |
|
340 |
geraldo |
712 |
{{/if}}
|
|
|
713 |
|
|
|
714 |
{{if type == 'open' || type == 'rating-open' || type=='rating-range' }}
|
345 |
geraldo |
715 |
<select class="form-control" onchange="editQuestion()">
|
340 |
geraldo |
716 |
<option value="true">LABEL_CORRECT </option>
|
339 |
geraldo |
717 |
<option value="false">LABEL_FAIL</option>
|
|
|
718 |
</select>
|
340 |
geraldo |
719 |
{{/if}}
|
339 |
geraldo |
720 |
|
|
|
721 |
</td>
|
251 |
geraldo |
722 |
</tr>
|
|
|
723 |
</tbody>
|
310 |
geraldo |
724 |
<thead>
|
|
|
725 |
<tr>
|
329 |
geraldo |
726 |
<th colspan="2">LABEL_ANSWER</th>
|
310 |
geraldo |
727 |
</tr>
|
|
|
728 |
</thead>
|
|
|
729 |
<tbody>
|
|
|
730 |
<tr class="tr-question">
|
329 |
geraldo |
731 |
<td colspan="2" class="text-left">{{:~getAnswer(
|
327 |
geraldo |
732 |
type,
|
326 |
geraldo |
733 |
options,
|
|
|
734 |
answer
|
|
|
735 |
)}} </td>
|
310 |
geraldo |
736 |
</tr>
|
|
|
737 |
</tbody>
|
251 |
geraldo |
738 |
</table>
|
310 |
geraldo |
739 |
|
|
|
740 |
{{/for}}
|
251 |
geraldo |
741 |
</div>
|
|
|
742 |
</div>
|
|
|
743 |
</div>
|
|
|
744 |
</div>
|
|
|
745 |
</script>
|
|
|
746 |
|
|
|
747 |
<!-- End Template Sections-->
|
|
|
748 |
|
|
|
749 |
</section>
|