Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 351 | Rev 355 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 351 Rev 352
Línea 144... Línea 144...
144
                    }
144
                    }
145
                }
145
                }
146
            }
146
            }
147
            $('[data-toggle="tooltip"]').tooltip();
147
            $('[data-toggle="tooltip"]').tooltip();
148
        };
148
        };
149
         /**
149
    /**
150
         * Add element to question array
150
     * Add element to question array
151
         */
151
     */
152
        this.editQuestion = function(slug_section, slug_question, status) {
152
    this.editQuestion = function(slug_section, slug_question, status) {
153
            var renderTable = false;
153
        var renderTable = false;
154
            for (i = 0; i < this.sections.length; i++) {
154
        for (i = 0; i < this.sections.length; i++) {
155
                if (slug_section == this.sections[i].slug_section) {
155
            if (slug_section == this.sections[i].slug_section) {
156
                    for (j = 0; j < this.sections[i].questions.length; j++) {
156
                for (j = 0; j < this.sections[i].questions.length; j++) {
157
                        if (slug_question == this.sections[i].questions[j].slug_question) {
157
                    if (slug_question == this.sections[i].questions[j].slug_question) {
158
                            
-
 
159
                            this.sections[i].questions[j].status = status;
158
                        this.sections[i].questions[j].status = status;
160
 
-
 
161
console.log(this.sections[i].questions[j]);
159
                        console.log(this.sections[i].questions[j]);
162
                            renderTable = true;
160
                        renderTable = true;
163
                            break;
161
                        break;
164
                        }
-
 
165
                    }
162
                    }
166
                }
163
                }
167
                if (renderTable) {
-
 
168
                    break;
-
 
169
                }
-
 
170
            }
164
            }
171
            if (renderTable) {
165
            if (renderTable) {
172
                this.renderSection(slug_section);
166
                break;
173
            }
167
            }
174
        };
168
        }
-
 
169
        if (renderTable) {
-
 
170
            this.renderSection(slug_section);
-
 
171
        }
-
 
172
    };
175
}
173
}
176
jQuery(document).ready(function($) {
174
jQuery(document).ready(function($) {
177
    var objFormGenerator = new classFormGenerator();
175
    var objFormGenerator = new classFormGenerator();
178
    objFormGenerator.render();
176
    objFormGenerator.render();
179
    var allowEdit = $allowEdit;
177
    var allowEdit = $allowEdit;
Línea 329... Línea 327...
329
            'url': action,
327
            'url': action,
330
        }).done(function(response) {
328
        }).done(function(response) {
331
            if (response['success']) {
329
            if (response['success']) {
332
                $('#form-main').attr('action', action);
330
                $('#form-main').attr('action', action);
333
                $('#form-main #form-id').val(response['data']['id']),
331
                $('#form-main #form-id').val(response['data']['id']),
334
                $('#name').html(response['data']['name']);
332
                    $('#name').html(response['data']['name']);
335
                $('#text').html(response['data']['text']);
333
                $('#text').html(response['data']['text']);
336
                $('#user').html(response['data']['user']);
334
                $('#user').html(response['data']['user']);
337
                /*-------------Render Sections -------*/
335
                /*-------------Render Sections -------*/
338
                objFormGenerator.clear();
336
                objFormGenerator.clear();
339
                objFormGenerator.sections = response['data']['content'] || [];
337
                objFormGenerator.sections = response['data']['content'] || [];
Línea 346... Línea 344...
346
            }
344
            }
347
        }).fail(function(jqXHR, textStatus, errorThrown) {
345
        }).fail(function(jqXHR, textStatus, errorThrown) {
348
            $.fn.showError(textStatus);
346
            $.fn.showError(textStatus);
349
        });
347
        });
350
    });
348
    });
351
    
-
 
352
    $('button.btn-form-save-close').click(function(e) {
349
    $('button.btn-form-save-close').click(function(e) {
353
 
-
 
354
        var formId = parseInt($('#form-main #form-id').val());
350
        var formId = parseInt($('#form-main #form-id').val());
355
                var formContinue = parseInt($('#form-main #form-continue').val());
351
        var formContinue = parseInt($('#form-main #form-continue').val());
356
                var data = {
352
        var data = {
357
                    'id': formId,
353
            'id': formId,
358
                    'status': $('#form-main #form-status').val(),
354
            'status': $('#form-main #form-status').val(),
359
                    'content': JSON.stringify(objFormGenerator.sections)
355
            'content': JSON.stringify(objFormGenerator.sections)
360
                }
356
        }
361
                $.ajax({
357
        $.ajax({
362
                    'dataType': 'json',
358
            'dataType': 'json',
363
                    'method': 'post',
359
            'method': 'post',
364
                    'url': $('#form-main').attr('action'),
360
            'url': $('#form-main').attr('action'),
365
                    'data': data,
361
            'data': data,
366
                }).done(function(response) {
362
        }).done(function(response) {
367
                    if (response['success']) {
363
            if (response['success']) {
368
                        $.fn.showSuccess(response['data']);
364
                $.fn.showSuccess(response['data']);
369
                            $('#row-edit').hide();
365
                $('#row-edit').hide();
370
                            $('#row-forms').show();
366
                $('#row-forms').show();
371
                            /*---------- Reset Form -------- */
367
                /*---------- Reset Form -------- */
372
                            $('#form-main')[0].reset();
368
                $('#form-main')[0].reset();
373
                            /*--------Reset Sections ----------*/
369
                /*--------Reset Sections ----------*/
374
                            clearSectionData();
370
                clearSectionData();
375
                            /* ------- Refresh Table -----------*/
371
                /* ------- Refresh Table -----------*/
376
                        tableForm.fnDraw();
372
                tableForm.fnDraw();
377
                    } else {
373
            } else {
378
                        $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
374
                $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
379
                    }
375
            }
380
                }).fail(function(jqXHR, textStatus, errorThrown) {
376
        }).fail(function(jqXHR, textStatus, errorThrown) {
381
                    $.fn.showError(textStatus);
377
            $.fn.showError(textStatus);
382
                });
378
        });
383
                return false;
379
        return false;
384
    });
380
    });
385
   
-
 
386
    /**
381
    /**
387
     * Clicked cancel new/edit Form
382
     * Clicked cancel new/edit Form
388
     */
383
     */
389
    $('button.btn-edit-cancel').click(function(e) {
384
    $('button.btn-edit-cancel').click(function(e) {
390
        e.preventDefault();
385
        e.preventDefault();
391
        $('#row-edit').hide();
386
        $('#row-edit').hide();
392
        $('#row-forms').show();
387
        $('#row-forms').show();
393
    });
388
    });
394
    
-
 
395
    /**
389
    /**
396
     * Get Answers
390
     * Get Answers
397
     */
391
     */
398
    const getAnswer = (type, options, answer) => {
392
    const getAnswer = (type, options, answer) => {
399
        if (type == 'open' || type == 'rating-range') {
393
        if (type == 'open' || type == 'rating-range') {
400
            return answer;
394
            return answer;
401
        }
395
        }
402
        if (type == 'multiple') {
396
        if (type == 'multiple') {
403
           let opt = '';
397
            let opt = '';
404
            opt += removeTags(options.filter((opt) => answer.includes(opt.slug_option))[0].text) + ' ';
398
            opt += removeTags(options.filter((opt) => answer.includes(opt.slug_option))[0].text) + ' ';
405
            return opt;
399
            return opt;
406
        }
400
        }
407
        return removeTags(options.filter((opt) => opt.slug_option == answer)[0].text);
401
        return removeTags(options.filter((opt) => opt.slug_option == answer)[0].text);
408
    }
402
    }
409
    /**
403
    /**
410
     * Get Status
404
     * Get Status
411
     */
405
     */
412
    const getStatus = (options, answer) => options.filter((opt) => (opt.slug_option == answer || answer.includes(opt.slug_option)) &&
406
    const getStatus = (options, answer) => options.filter((opt) => (opt.slug_option == answer || answer.includes(opt.slug_option)) &&
413
            opt.correct == 1) ? 'LABEL_CORRECT' : 'LABEL_FAIL'
407
        opt.correct == 1) ? 'LABEL_CORRECT' : 'LABEL_FAIL'
414
    /**
408
    /**
415
     * Remove Html Tags
409
     * Remove Html Tags
416
     */
410
     */
417
    const removeTags = (str) => str.toString().replace(/(<([^>]+)>)/ig, '')
411
    const removeTags = (str) => str.toString().replace(/(<([^>]+)>)/ig, '')
418
    
-
 
419
    /**
412
    /**
420
     * Render Sections data
413
     * Render Sections data
421
     */
414
     */
422
    const renderSectionData = (data) => $("#rows").html($("#sectionTemplate").render(data, {
415
    const renderSectionData = (data) => $("#rows").html($("#sectionTemplate").render(data, {
423
        removeTags: removeTags,
416
        removeTags: removeTags,
424
        getAnswer: getAnswer,
417
        getAnswer: getAnswer,
425
        getStatus: getStatus,
418
        getStatus: getStatus,
426
        editQuestion: objFormGenerator.editQuestion
419
        editQuestion: objFormGenerator.editQuestion
427
    }));
420
    }));
428
 
-
 
429
    /**
421
    /**
430
     * Clear Div Section data 
422
     * Clear Div Section data 
431
     */
423
     */
432
    const clearSectionData = () => $("#rows").html('');
424
    const clearSectionData = () => $("#rows").html('');
433
    /**
425
    /**