Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 263 Rev 264
Línea 146... Línea 146...
146
                    }
146
                    }
147
                }
147
                }
148
            }
148
            }
149
            $('[data-toggle="tooltip"]').tooltip();
149
            $('[data-toggle="tooltip"]').tooltip();
150
        },
150
        },
151
        /**
-
 
152
         * Add element to section array 
-
 
153
         */
-
 
154
        this.addSection = function(name, text, value) {
-
 
155
            var d = new Date();
-
 
156
            var slug = 'section' + d.getTime();
-
 
157
            var position = 0;
-
 
158
            $.each(this.sections, function(index, section) {
-
 
159
                if (position < section.position) {
-
 
160
                    position = section.position;
-
 
161
                }
-
 
162
            });
-
 
163
            position++;
-
 
164
            var section = {
-
 
165
                'slug_section': slug,
-
 
166
                'name': name,
-
 
167
                'text': text,
-
 
168
                'value': value,
-
 
169
                'position': position,
-
 
170
                'questions': [],
-
 
171
                'status': 0
-
 
172
            }
-
 
173
            this.sections.push(section);
-
 
174
        },
-
 
175
         /**
-
 
176
         * Edit element to section array 
-
 
177
         */
-
 
178
        this.editSection = function(slug, name, text, value) {
-
 
179
            var renderTable = false;
-
 
180
            for (i = 0; i < this.sections.length; i++) {
-
 
181
                if (slug == this.sections[i].slug_section) {
-
 
182
                    this.sections[i].name = name;
-
 
183
                    this.sections[i].text = text;
-
 
184
                    this.sections[i].value = value;
-
 
185
                    renderTable = true;
-
 
186
                    break;
-
 
187
                }
-
 
188
            }
-
 
189
            if (renderTable) {
-
 
190
                this.renderSection(slug);
-
 
191
            }
-
 
192
        },
-
 
193
         /**
-
 
194
         * Remove element to section array
-
 
195
         */
-
 
196
        this.deleteSection = function(slug) {
-
 
197
            var renderTable = false;
-
 
198
            for (i = 0; i < this.sections.length; i++) {
-
 
199
                if (slug == this.sections[i].slug_section) {
-
 
200
                    this.sections.splice(i, 1);
-
 
201
                    renderTable = true;
-
 
202
                    break;
-
 
203
                }
-
 
204
            }
-
 
205
            if (renderTable) {
-
 
206
                $('#panel' + slug).remove();
-
 
207
            }
-
 
208
        },
-
 
209
         /**
-
 
210
         * Add element to question array
-
 
211
         */
-
 
212
        this.addQuestion = function(slug_section, text, value, type, maxlength, multiline, range) {
-
 
213
            var d = new Date();
-
 
214
            var slug_question = 'question' + d.getTime();
-
 
215
            var position = 0;
-
 
216
            var renderTable = false;
-
 
217
            for (i = 0; i < this.sections.length; i++) {
-
 
218
                if (slug_section == this.sections[i].slug_section) {
-
 
219
                    $.each(this.sections[i].questions, function(index, question) {
-
 
220
                        if (position < question.position) {
-
 
221
                            position = question.position;
-
 
222
                        }
-
 
223
                    });
-
 
224
                    position++;
-
 
225
                    var question = {
-
 
226
                        'slug_section': slug_section,
-
 
227
                        'slug_question': slug_question,
-
 
228
                        'text': text,
-
 
229
                        'value': value,
-
 
230
                        'type': type,
-
 
231
                        'position': position,
-
 
232
                        'maxlength': maxlength,
-
 
233
                        'multiline': multiline,
-
 
234
                        'range': range,
-
 
235
                        'options': [],
-
 
236
                        'answer': type=='multiple' ? [] : ''
-
 
237
                    }
-
 
238
                    this.sections[i].questions.push(question);
-
 
239
                    renderTable = true;
-
 
240
                    break;
-
 
241
                }
-
 
242
            }
-
 
243
            if (renderTable) {
-
 
244
                this.renderSection(slug_section);
-
 
245
            }
-
 
246
        },
151
        
247
         /**
152
         /**
248
         * Add element to question array
153
         * Add element to question array
249
         */
154
         */
250
        this.editQuestion = function(slug_section, slug_question, text, value, type, maxlength, multiline, range) {
155
        this.editQuestion = function(slug_section, slug_question, text, value, type, maxlength, multiline, range) {
251
            var renderTable = false;
156
            var renderTable = false;
Línea 287... Línea 192...
287
            }
192
            }
288
            if (renderTable) {
193
            if (renderTable) {
289
                this.renderSection(slug_section);
194
                this.renderSection(slug_section);
290
            }
195
            }
291
        },
196
        },
292
        /**
-
 
293
         * Remove element to question array
-
 
294
         */
-
 
295
        this.deleteQuestion = function(slug_section, slug_question) {
-
 
296
            var renderTable = false;
-
 
297
            for (i = 0; i < this.sections.length; i++) {
-
 
298
                if (slug_section == this.sections[i].slug_section) {
-
 
299
                    for (j = 0; j < this.sections[i].questions.length; j++) {
-
 
300
                        if (slug_question == this.sections[i].questions[j].slug_question) {
-
 
301
                            this.sections[i].questions.splice(j, 1);
-
 
302
                            renderTable = true;
-
 
303
                            break;
-
 
304
                        }
-
 
305
                    }
-
 
306
                }
-
 
307
                if (renderTable) {
-
 
308
                    break;
-
 
309
                }
-
 
310
            }
-
 
311
            if (renderTable) {
-
 
312
                this.renderSection(slug_section);
-
 
313
            }
-
 
314
        },
-
 
315
        /**
-
 
316
         * Add element to option array
-
 
317
         */
-
 
318
        this.addOption = function(slug_section, slug_question, text, correct, value) {
-
 
319
            var d = new Date();
-
 
320
            var slug_option = 'option' + d.getTime();
-
 
321
            var position = 0;
-
 
322
            var renderTable = false;
-
 
323
            for (i = 0; i < this.sections.length; i++) {
-
 
324
                if (slug_section == this.sections[i].slug_section) {
-
 
325
                    for (j = 0; j < this.sections[i].questions.length; j++) {
-
 
326
                        if (slug_question == this.sections[i].questions[j].slug_question) {
-
 
327
                            $.each(this.sections[i].questions[j].options, function(index, option) {
-
 
328
                                if (position < option.position) {
-
 
329
                                    position = option.position;
-
 
330
                                }
-
 
331
                            });
-
 
332
                            position++;
-
 
333
                            var option = {
-
 
334
                                'slug_section': slug_section,
-
 
335
                                'slug_question': slug_question,
-
 
336
                                'slug_option': slug_option,
-
 
337
                                'text': text,
-
 
338
                                'correct': correct,
-
 
339
                                'value': value,
-
 
340
                                'checked': false
-
 
341
                            }
-
 
342
                            this.sections[i].questions[j].options.push(option);
-
 
343
                            renderTable = true;
-
 
344
                            break;
-
 
345
                        }
-
 
346
                        if (renderTable) {
-
 
347
                            break;
-
 
348
                        }
-
 
349
                    }
-
 
350
                }
-
 
351
            }
-
 
352
            if (renderTable) {
-
 
353
                this.renderSection(slug_section);
-
 
354
            }
-
 
355
        },
-
 
356
        /**
-
 
357
         * Edit element to option array
-
 
358
         */
-
 
359
        this.editOption = function(slug_section, slug_question, option_slug, text, correct, value) {
-
 
360
            var renderTable = false;
-
 
361
            for (i = 0; i < this.sections.length; i++) {
-
 
362
                if (slug_section == this.sections[i].slug_section) {
-
 
363
                    for (j = 0; j < this.sections[i].questions.length; j++) {
-
 
364
                        if (slug_question == this.sections[i].questions[j].slug_question) {
-
 
365
                            for (k = 0; k < this.sections[i].questions[j].options.length; k++) {
-
 
366
                                if (option_slug == this.sections[i].questions[j].options[k].slug_option) {
-
 
367
                                    this.sections[i].questions[j].options[k].text = text;
-
 
368
                                    this.sections[i].questions[j].options[k].correct = correct;
-
 
369
                                    this.sections[i].questions[j].options[k].value = value;
-
 
370
                                    renderTable = true;
-
 
371
                                    break;
-
 
372
                                }
-
 
373
                            }
-
 
374
                        }
-
 
375
                        if (renderTable) {
-
 
376
                            break;
-
 
377
                        }
-
 
378
                    }
-
 
379
                }
-
 
380
                if (renderTable) {
-
 
381
                    break;
-
 
382
                }
-
 
383
            }
-
 
384
            if (renderTable) {
-
 
385
                this.renderSection(slug_section);
-
 
386
            }
-
 
387
        },
-
 
388
        /**
-
 
389
         * Remove element to option array
-
 
390
         */
-
 
391
        this.deleteOption = function(slug_section, slug_question, option_slug) {
-
 
392
            var renderTable = false;
-
 
393
            for (i = 0; i < this.sections.length; i++) {
-
 
394
                if (slug_section == this.sections[i].slug_section) {
-
 
395
                    for (j = 0; j < this.sections[i].questions.length; j++) {
-
 
396
                        if (slug_question == this.sections[i].questions[j].slug_question) {
-
 
397
                            for (k = 0; k < this.sections[i].questions[j].options.length; k++) {
-
 
398
                                if (option_slug == this.sections[i].questions[j].options[k].slug_option) {
-
 
399
                                    this.sections[i].questions[j].options.splice(k, 1);
-
 
400
                                    renderTable = true;
-
 
401
                                    break;
-
 
402
                                }
-
 
403
                            }
-
 
404
                        }
-
 
405
                        if (renderTable) {
-
 
406
                            break;
-
 
407
                        }
-
 
408
                    }
-
 
409
                }
-
 
410
                if (renderTable) {
-
 
411
                    break;
-
 
412
                }
-
 
413
            }
-
 
414
            if (renderTable) {
-
 
415
                this.renderSection(slug_section);
-
 
416
            }
-
 
417
        }
197
        
418
}
198
}
Línea 419... Línea 199...
419
 
199
 
420
function htmlEntities(str) {
200
function htmlEntities(str) {
421
    return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
201
    return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
Línea 615... Línea 395...
615
            $('[data-type="select"]').prop('checked', false);
395
            $('[data-type="select"]').prop('checked', false);
616
            $('[data-action="delete"]').addClass('hide');
396
            $('[data-action="delete"]').addClass('hide');
617
        }
397
        }
618
    });
398
    });
Línea 619... Línea -...
619
 
-
 
620
    function getLength() {
-
 
621
        return $('[data-type="select"]').length;
399
 
Línea 622... Línea 400...
622
    }
400
    
623
 
401
 
624
    function currentSelected() {
402
    function currentSelected() {
625
        var selected = [];
403
        var selected = [];
Línea 821... Línea 599...
821
                });
599
                });
822
                return false;
600
                return false;
823
            }
601
            }
824
        }
602
        }
825
    });
603
    });
826
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
-
 
827
    $("#form-section").on('submit', function() {
-
 
828
        for (var instanceName in CKEDITOR.instances) {
-
 
829
            CKEDITOR.instances[instanceName].updateElement();
-
 
830
        }
-
 
831
    })
-
 
832
    /**
-
 
833
     * Validate rules form section
-
 
834
     */
-
 
835
    var validatorFormSection = $("#form-section").validate({
-
 
836
        ignore: [],
-
 
837
        errorClass: 'help-block',
-
 
838
        errorElement: 'span',
-
 
839
        rules: {
-
 
840
            'section-name': {
-
 
841
                required: true,
-
 
842
                minlength: 2,
-
 
843
                maxlength: 50
-
 
844
            },
-
 
845
            'section-text': {
-
 
846
                required: false,
-
 
847
            },
-
 
848
            'section-value': {
-
 
849
                required: true,
-
 
850
                number: true,
-
 
851
                min: 1
-
 
852
            },
-
 
853
        },
-
 
854
        highlight: function(element) {
-
 
855
            $(element).closest('.form-group').addClass('has-error');
-
 
856
        },
-
 
857
        unhighlight: function(element) {
-
 
858
            $(element).closest('.form-group').removeClass('has-error');
-
 
859
        },
-
 
860
        errorPlacement: function(error, element) {
-
 
861
            if (element.attr("data-error-container")) {
-
 
862
                error.appendTo(element.attr("data-error-container"));
-
 
863
            } else {
-
 
864
                error.insertAfter(element);
-
 
865
            }
-
 
866
        },
-
 
867
        invalidHandler: function(form, validator) {
-
 
868
            if (!validator.numberOfInvalids())
-
 
869
                return;
-
 
870
            $('html, body').animate({
-
 
871
                scrollTop: $(validator.errorList[0].element).offset().top - 100
-
 
872
            }, 1000);
-
 
873
        },
-
 
874
        submitHandler: function(form) {
-
 
875
            // do other things for a valid form
-
 
876
            //form.submit();
-
 
877
            var slug = $('#form-section #section-slug').val();
-
 
878
            if (slug) {
-
 
879
                objFormGenerator.editSection(
-
 
880
                    $('#form-section #section-slug').val(),
-
 
881
                    $('#form-section #section-name').val(),
-
 
882
                    $('#form-section #section-text').val(),
-
 
883
                    $('#form-section #section-value').val()
-
 
884
                );
-
 
885
            } else {
-
 
886
                objFormGenerator.addSection(
-
 
887
                    $('#form-section #section-name').val(),
-
 
888
                    $('#form-section #section-text').val(),
-
 
889
                    $('#form-section #section-value').val()
-
 
890
                );
-
 
891
            }
-
 
892
            renderSectionData(objFormGenerator.sections);
-
 
893
            $('#modal-section').modal('hide');
-
 
894
            return false;
-
 
895
        }
-
 
896
    });
-
 
897
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
-
 
898
    $("#form-question").on('submit', function() {
-
 
899
        for (var instanceName in CKEDITOR.instances) {
-
 
900
            CKEDITOR.instances[instanceName].updateElement();
-
 
901
        }
-
 
902
    })
-
 
903
    /**
-
 
904
     * Validate rules form Questions
-
 
905
     */
-
 
906
    var validatorFormQuestion = $("#form-question").validate({
-
 
907
        ignore: [],
-
 
908
        errorClass: 'help-block',
-
 
909
        errorElement: 'span',
-
 
910
        rules: {
-
 
911
            'question-text': {
-
 
912
                required: true,
-
 
913
            },
-
 
914
            'question-value': {
-
 
915
                required: true,
-
 
916
                number: true,
-
 
917
                min: 1
-
 
918
            },
-
 
919
            'question-type': {
-
 
920
                required: true,
-
 
921
            },
-
 
922
            'question-max-length': {
-
 
923
                required: true,
-
 
924
                digits: true,
-
 
925
                min: 0
-
 
926
            },
-
 
927
            'question-range': {
-
 
928
                required: true,
-
 
929
                number: true,
-
 
930
                min: 1
-
 
931
            },
-
 
932
        },
-
 
933
        highlight: function(element) {
-
 
934
            $(element).closest('.form-group').addClass('has-error');
-
 
935
        },
-
 
936
        unhighlight: function(element) {
-
 
937
            $(element).closest('.form-group').removeClass('has-error');
-
 
938
        },
-
 
939
        errorPlacement: function(error, element) {
-
 
940
            if (element.attr("data-error-container")) {
-
 
941
                error.appendTo(element.attr("data-error-container"));
-
 
942
            } else {
-
 
943
                error.insertAfter(element);
-
 
944
            }
-
 
945
        },
-
 
946
        invalidHandler: function(form, validator) {
-
 
947
            if (!validator.numberOfInvalids())
-
 
948
                return;
-
 
949
            $('html, body').animate({
-
 
950
                scrollTop: $(validator.errorList[0].element).offset().top - 100
-
 
951
            }, 1000);
-
 
952
        },
-
 
953
        submitHandler: function(form) {
-
 
954
            if ($('#form-question #question-slug').val()) {
-
 
955
                objFormGenerator.editQuestion(
-
 
956
                    $('#form-question #question-section').val(),
-
 
957
                    $('#form-question #question-slug').val(),
-
 
958
                    $('#form-question #question-text').val(),
-
 
959
                    $('#form-question #question-value').val(),
-
 
960
                    $('#form-question #question-type').val(),
-
 
961
                    $('#form-question #question-max-length').val(),
-
 
962
                    $('#form-question #question-multiline').val(),
-
 
963
                    $('#form-question #question-range').val()
-
 
964
                );
-
 
965
            } else {
-
 
966
                objFormGenerator.addQuestion(
-
 
967
                    $('#form-question #question-section').val(),
-
 
968
                    $('#form-question #question-text').val(),
-
 
969
                    $('#form-question #question-value').val(),
-
 
970
                    $('#form-question #question-type').val(),
-
 
971
                    $('#form-question #question-max-length').val(),
-
 
972
                    $('#form-question #question-multiline').val(),
-
 
973
                    $('#form-question #question-range').val()
-
 
974
                );
-
 
975
            }
-
 
976
            renderSectionData(objFormGenerator.sections);
-
 
977
            $('#modal-question').modal('hide');
-
 
978
            return false;
-
 
979
        }
-
 
980
    });
-
 
981
    //IMPORTANT: update CKEDITOR textarea with actual content before submit
-
 
982
    $("#form-option").on('submit', function() {
-
 
983
        for (var instanceName in CKEDITOR.instances) {
-
 
984
            CKEDITOR.instances[instanceName].updateElement();
-
 
985
        }
-
 
986
    })
604
 
987
    /**
-
 
988
     * Validate rules form options
-
 
989
     */
-
 
990
    var validatorFormOption = $("#form-option").validate({
-
 
991
        ignore: [],
-
 
992
        errorClass: 'help-block',
-
 
993
        errorElement: 'span',
-
 
994
        rules: {
-
 
995
            'option-text': {
-
 
996
                required: true,
-
 
997
            },
-
 
998
            'option-value': {
-
 
999
                required: true,
-
 
1000
                number: true,
-
 
1001
                min: 1
-
 
1002
            }
-
 
1003
        },
-
 
1004
        highlight: function(element) {
-
 
1005
            $(element).closest('.form-group').addClass('has-error');
-
 
1006
        },
-
 
1007
        unhighlight: function(element) {
-
 
1008
            $(element).closest('.form-group').removeClass('has-error');
-
 
1009
        },
-
 
1010
        errorPlacement: function(error, element) {
-
 
1011
            if (element.attr("data-error-container")) {
-
 
1012
                error.appendTo(element.attr("data-error-container"));
-
 
1013
            } else {
-
 
1014
                error.insertAfter(element);
-
 
1015
            }
-
 
1016
        },
-
 
1017
        invalidHandler: function(form, validator) {
-
 
1018
            if (!validator.numberOfInvalids())
-
 
1019
                return;
-
 
1020
            $('html, body').animate({
-
 
1021
                scrollTop: $(validator.errorList[0].element).offset().top - 100
-
 
1022
            }, 1000);
-
 
1023
        },
-
 
1024
        submitHandler: function(form) {
-
 
1025
            if ($('#form-option #option-slug').val()) {
-
 
1026
                objFormGenerator.editOption(
-
 
1027
                    $('#form-option #option-section').val(),
-
 
1028
                    $('#form-option #option-question').val(),
-
 
1029
                    $('#form-option #option-slug').val(),
-
 
1030
                    $('#form-option #option-text').val(),
-
 
1031
                    $('#form-option #option-correct').val(),
-
 
1032
                    $('#form-option #option-value').val()
-
 
1033
                );
-
 
1034
            } else {
-
 
1035
                objFormGenerator.addOption(
-
 
1036
                    $('#form-option #option-section').val(),
-
 
1037
                    $('#form-option #option-question').val(),
-
 
1038
                    $('#form-option #option-text').val(),
-
 
1039
                    $('#form-option #option-correct').val(),
-
 
1040
                    $('#form-option #option-value').val()
-
 
1041
                );
-
 
1042
            }
-
 
1043
            renderSectionData(objFormGenerator.sections);
-
 
1044
            $('#modal-option').modal('hide');
-
 
1045
            return false;
-
 
1046
        }
-
 
1047
    });
-
 
1048
    /**
-
 
1049
     * Clicked on add new section
-
 
1050
     */
-
 
1051
    $('body').on('click', 'button[id="btn-add-section"]', function(e) {
-
 
1052
        e.preventDefault();
-
 
1053
        validatorFormSection.resetForm();
-
 
1054
        $('#form-section #section-slug').val('');
-
 
1055
        $('#form-section #section-name').val('');
-
 
1056
        CKEDITOR.instances['section-text'].setData('');
-
 
1057
        $('#form-section #section-value').val('0');
-
 
1058
        $('#modal-section h4[class="modal-title"]').html('LABEL_ADD LABEL_SECTION');
-
 
1059
        $('#modal-section').modal('show');
-
 
1060
    });
-
 
1061
    /**
-
 
1062
     * Clicked on edit section
-
 
1063
     */
-
 
1064
    $('body').on('click', 'button.btn-edit-section', function(e) {
-
 
1065
        e.preventDefault();
-
 
1066
        var slug = $(this).data('section');
-
 
1067
        var section;
-
 
1068
        var showForm = false;
-
 
1069
        for (i = 0; i < objFormGenerator.sections.length; i++) {
-
 
1070
            section = objFormGenerator.sections[i];
-
 
1071
            if (slug == section.slug_section) {
-
 
1072
                validatorFormSection.resetForm();
-
 
1073
                $('#form-section #section-slug').val(section.slug_section);
-
 
1074
                $('#form-section #section-name').val(section.name);
-
 
1075
                CKEDITOR.instances['section-text'].setData(section.text);
-
 
1076
                $('#form-section #section-value').val(section.value);
-
 
1077
                showForm = true;
-
 
1078
                break;
-
 
1079
            }
-
 
1080
        }
-
 
1081
        if (showForm) {
-
 
1082
            $('#modal-section h4[class="modal-title"]').html('LABEL_EDIT LABEL_SECTION');
-
 
1083
            $('#modal-section').modal('show');
-
 
1084
        }
-
 
1085
    });
-
 
1086
    /**
-
 
1087
     * Clicked on remove section
-
 
1088
     */
-
 
1089
    $('body').on('click', 'button.btn-delete-section', function(e) {
-
 
1090
        e.preventDefault();
-
 
1091
        var slug = $(this).data('section');
-
 
1092
        bootbox.confirm({
-
 
1093
            title: "LABEL_DELETE LABEL_SECTION",
-
 
1094
            message: "LABEL_QUESTION_DELETE",
-
 
1095
            buttons: {
-
 
1096
                cancel: {
-
 
1097
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
-
 
1098
                },
-
 
1099
                confirm: {
-
 
1100
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
-
 
1101
                }
-
 
1102
            },
-
 
1103
            callback: function(result) {
-
 
1104
                if (result) {
-
 
1105
                    objFormGenerator.deleteSection(slug);
-
 
1106
                    renderSectionData(objFormGenerator.sections);
-
 
1107
                }
-
 
1108
            }
-
 
1109
        });
-
 
1110
    });
-
 
1111
    /**
-
 
1112
     * Clicked add new question
-
 
1113
     */
-
 
1114
    $('body').on('click', 'button.btn-add-question', function(e) {
-
 
1115
        e.preventDefault();
-
 
1116
        validatorFormQuestion.resetForm();
-
 
1117
        var slug = $(this).data('section');
-
 
1118
        $('#form-question #question-section').val(slug);
-
 
1119
        $('#form-question #question-slug').val('');
-
 
1120
        CKEDITOR.instances['question-text'].setData('');
-
 
1121
        $('#form-question #question-value').val('0');
-
 
1122
        $('#form-question #question-type').val($('#form-question #question-type option:first').val());
-
 
1123
        $('#form-question #question-max-length').val('0');
-
 
1124
        $('#form-question #question-max-length').parent().show();
-
 
1125
        $('#form-question #question-multiline').val('0');
-
 
1126
        $('#form-question #question-multiline').parent().show();
-
 
1127
        $('#form-question #question-range').val('10');
-
 
1128
        $('#form-question #question-range').parent().hide();
-
 
1129
        $('#modal-question h4[class="modal-title"]').html('LABEL_ADD LABEL_QUESTION');
-
 
1130
        $('#modal-question').modal('show');
-
 
1131
    });
-
 
1132
    /**
-
 
1133
     * Clicked edit question
-
 
1134
     */
-
 
1135
    $('body').on('click', 'button.btn-edit-question', function(e) {
-
 
1136
        e.preventDefault();
-
 
1137
        var slug_section = $(this).data('section');
-
 
1138
        var slug = $(this).data('question');
-
 
1139
        var showForm = false;
-
 
1140
        for (i = 0; i < objFormGenerator.sections.length; i++) {
-
 
1141
            if (slug_section == objFormGenerator.sections[i].slug_section) {
-
 
1142
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
-
 
1143
                    if (slug == objFormGenerator.sections[i].questions[j].slug_question) {
-
 
1144
                        validatorFormQuestion.resetForm();
-
 
1145
                        $('#form-question #question-section').val(objFormGenerator.sections[i].slug_section);
-
 
1146
                        $('#form-question #question-slug').val(objFormGenerator.sections[i].questions[j].slug_question);
-
 
1147
                        CKEDITOR.instances['question-text'].setData(objFormGenerator.sections[i].questions[j].text);
-
 
1148
                        $('#form-question #question-value').val(objFormGenerator.sections[i].questions[j].value);
-
 
1149
                        $('#form-question #question-type').val(objFormGenerator.sections[i].questions[j].type);
-
 
1150
                        if (objFormGenerator.sections[i].questions[j].type == 'open') {
-
 
1151
                            $('#form-question #question-max-length').val(objFormGenerator.sections[i].questions[j].maxlength);
-
 
1152
                            $('#form-question #question-max-length').parent().show();
-
 
1153
                            $('#form-question #question-multiline').val(objFormGenerator.sections[i].questions[j].multiline);
-
 
1154
                            $('#form-question #question-multiline').parent().show();
-
 
1155
                        } else {
-
 
1156
                            $('#form-question #question-max-length').val('0');
-
 
1157
                            $('#form-question #question-max-length').parent().hide();
-
 
1158
                            $('#form-question #question-multiline').val('0');
-
 
1159
                            $('#form-question #question-multiline').parent().hide();
-
 
1160
                        }
-
 
1161
                        if (objFormGenerator.sections[i].questions[j].type == 'rating-range') {
-
 
1162
                            $('#form-question #question-range').val(objFormGenerator.sections[i].questions[j].range);
-
 
1163
                            $('#form-question #question-range').parent().show();
-
 
1164
                        } else {
-
 
1165
                            $('#form-question #question-range').val('10');
-
 
1166
                            $('#form-question #question-range').parent().hide();
-
 
1167
                        }
-
 
1168
                        showForm = true;
-
 
1169
                        break;
-
 
1170
                    }
-
 
1171
                }
-
 
1172
                break;
-
 
1173
            }
-
 
1174
        }
-
 
1175
        if (showForm) {
-
 
1176
            $('#modal-question h4[class="modal-title"]').html('LABEL_EDIT LABEL_QUESTION');
-
 
1177
            $('#modal-question').modal('show');
-
 
1178
        }
-
 
1179
    });
-
 
1180
    /**
-
 
1181
     * Clicked remove question
-
 
1182
     */
-
 
1183
    $('body').on('click', 'button.btn-delete-question', function(e) {
-
 
1184
        e.preventDefault();
-
 
1185
        var slug_section = $(this).data('section');
-
 
1186
        var slug = $(this).data('question');
-
 
1187
        bootbox.confirm({
-
 
1188
            title: "LABEL_DELETE LABEL_QUESTION",
-
 
1189
            message: "LABEL_QUESTION_DELETE",
-
 
1190
            buttons: {
-
 
1191
                cancel: {
-
 
1192
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
-
 
1193
                },
-
 
1194
                confirm: {
-
 
1195
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
-
 
1196
                }
-
 
1197
            },
-
 
1198
            callback: function(result) {
-
 
1199
                if (result) {
-
 
1200
                    objFormGenerator.deleteQuestion(slug_section, slug);
-
 
1201
                    renderSectionData(objFormGenerator.sections);
-
 
1202
                }
-
 
1203
            }
-
 
1204
        });
-
 
1205
    });
-
 
1206
    /**
-
 
1207
     * Clicked add new Option
-
 
1208
     */
-
 
1209
    $('body').on('click', 'button.btn-add-option', function(e) {
-
 
1210
        e.preventDefault();
-
 
1211
        var slug_section = $(this).data('section');
-
 
1212
        var slug_question = $(this).data('question');
-
 
1213
        var showForm = false;
-
 
1214
        for (i = 0; i < objFormGenerator.sections.length; i++) {
-
 
1215
            if (slug_section == objFormGenerator.sections[i].slug_section) {
-
 
1216
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
-
 
1217
                    if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
-
 
1218
                        validatorFormOption.resetForm();
-
 
1219
                        $('#form-option #option-section').val(slug_section);
-
 
1220
                        $('#form-option #option-question').val(slug_question);
-
 
1221
                        $('#form-option #option-slug').val('');
-
 
1222
                        CKEDITOR.instances['option-text'].setData('', function() {
-
 
1223
                            editor.focus();
-
 
1224
                        });
-
 
1225
                        $('#form-option #option-correct').val('0');
-
 
1226
                        if (objFormGenerator.sections[i].questions[j].type == 'rating-open') {
-
 
1227
                            $('#form-option #option-correct').parent().hide();
-
 
1228
                        } else {
-
 
1229
                            $('#form-option #option-correct').parent().show();
-
 
1230
                        }
-
 
1231
                        if (objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'rating-open') {
-
 
1232
                            $('#form-option #option-value').val('0');
-
 
1233
                            $('#form-option #option-value').parent().show();
-
 
1234
                        } else {
-
 
1235
                            $('#form-option #option-value').val('1');
-
 
1236
                            $('#form-option #option-value').parent().hide();
-
 
1237
                        }
-
 
1238
                        renderSectionData(objFormGenerator.sections);
-
 
1239
                        $('#modal-option h4[class="modal-title"]').html('LABEL_ADD LABEL_OPTION');
-
 
1240
                        $('#modal-option').modal('show');
-
 
1241
                        return true;
-
 
1242
                    }
-
 
1243
                }
-
 
1244
            }
-
 
1245
        }
-
 
1246
    });
-
 
1247
    /**
-
 
1248
     * Clicked edit option
-
 
1249
     */
-
 
1250
    $('body').on('click', 'button.btn-edit-option', function(e) {
-
 
1251
        e.preventDefault();
-
 
1252
        var slug_section = $(this).data('section');
-
 
1253
        var slug_question = $(this).data('question');
-
 
1254
        var slug = $(this).data('slug');
-
 
1255
        var showForm = false;
-
 
1256
        for (i = 0; i < objFormGenerator.sections.length; i++) {
-
 
1257
            if (slug_section == objFormGenerator.sections[i].slug_section) {
-
 
1258
                for (j = 0; j < objFormGenerator.sections[i].questions.length; j++) {
-
 
1259
                    if (slug_question == objFormGenerator.sections[i].questions[j].slug_question) {
-
 
1260
                        for (k = 0; k < objFormGenerator.sections[i].questions[j].options.length; k++) {
-
 
1261
                            if (slug == objFormGenerator.sections[i].questions[j].options[k].slug_option) {
-
 
1262
                                validatorFormOption.resetForm();
-
 
1263
                                $('#form-option #option-section').val(objFormGenerator.sections[i].slug_section);
-
 
1264
                                $('#form-option #option-question').val(objFormGenerator.sections[i].questions[j].slug_question);
-
 
1265
                                $('#form-option #option-slug').val(objFormGenerator.sections[i].questions[j].options[k].slug_option);
-
 
1266
                                CKEDITOR.instances['option-text'].setData(objFormGenerator.sections[i].questions[j].options[k].text,
-
 
1267
                                    function() {
-
 
1268
                                        editor.focus();
-
 
1269
                                    });
-
 
1270
                                $('#form-option #option-correct').val(objFormGenerator.sections[i].questions[j].options[k].correct);
-
 
1271
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'simple') {
-
 
1272
                                    $('#form-option #option-correct').parent().show();
-
 
1273
                                } else {
-
 
1274
                                    $('#form-option #option-correct').parent().hide();
-
 
1275
                                }
-
 
1276
                                $('#form-option #option-value').val(objFormGenerator.sections[i].questions[j].options[k].value);
-
 
1277
                                if (objFormGenerator.sections[i].questions[j].type == 'multiple' || objFormGenerator.sections[i].questions[j].type == 'rating-open') {
-
 
1278
                                    $('#form-option #option-value').parent().show();
-
 
1279
                                } else {
-
 
1280
                                    $('#form-option #option-value').parent().hide();
-
 
1281
                                }
-
 
1282
                                showForm = true;
-
 
1283
                                break;
-
 
1284
                            }
-
 
1285
                        }
-
 
1286
                    }
-
 
1287
                    if (showForm) {
-
 
1288
                        break;
-
 
1289
                    }
-
 
1290
                }
-
 
1291
            }
-
 
1292
            if (showForm) {
-
 
1293
                break;
-
 
1294
            }
-
 
1295
        }
-
 
1296
        if (showForm) {
-
 
1297
            $('#modal-option h4[class="modal-title"]').html('LABEL_EDIT LABEL_OPTION');
-
 
1298
            $('#modal-option').modal('show');
-
 
1299
        }
-
 
1300
    });
-
 
1301
    /**
-
 
1302
     * Clicked remove option
-
 
1303
     */
-
 
1304
    $('body').on('click', 'button.btn-delete-option', function(e) {
-
 
1305
        e.preventDefault();
-
 
1306
        var slug_section = $(this).data('section');
-
 
1307
        var slug_question = $(this).data('question');
-
 
1308
        var slug = $(this).data('slug');
-
 
1309
        bootbox.confirm({
-
 
1310
            title: "LABEL_DELETE LABEL_OPTION",
-
 
1311
            message: "LABEL_QUESTION_DELETE",
-
 
1312
            buttons: {
-
 
1313
                cancel: {
-
 
1314
                    label: '<i class="fa fa-times"></i> LABEL_CANCEL'
-
 
1315
                },
-
 
1316
                confirm: {
-
 
1317
                    label: '<i class="fa fa-check"></i> LABEL_ACCEPT'
-
 
1318
                }
-
 
1319
            },
-
 
1320
            callback: function(result) {
-
 
1321
                if (result) {
-
 
1322
                    objFormGenerator.deleteOption(slug_section, slug_question, slug);
-
 
1323
                    renderSectionData(objFormGenerator.sections);
-
 
1324
                }
-
 
1325
            }
-
 
1326
        });
-
 
1327
    })
-
 
1328
    /**
-
 
1329
     * Format input number (Form Section) 
-
 
1330
     */
-
 
1331
    $('#form-section #section-value').inputNumberFormat({
-
 
1332
        'decimal': 2
-
 
1333
    });
-
 
1334
    /**
-
 
1335
     * Format input number (Form Question) 
-
 
1336
     */
-
 
1337
    $('#form-question #question-value').inputNumberFormat({
-
 
1338
        'decimal': 2
-
 
1339
    });
-
 
1340
    /**
-
 
1341
     * Format input number (Form Question) 
-
 
1342
     */
-
 
1343
    $('#form-question #question-max-length').inputNumberFormat({
-
 
1344
        'decimal': 0
-
 
1345
    });
-
 
1346
    /**
-
 
1347
     * Format input number (Form Option) 
-
 
1348
     */
-
 
1349
    $('#form-option #option-value').inputNumberFormat({
-
 
1350
        'decimal': 2
-
 
1351
    });
-
 
1352
    /**
-
 
1353
     * Detect when updating question status and hide/Show options
-
 
1354
     */
-
 
1355
    $('#form-question #question-type').change(function(e) {
-
 
1356
        e.preventDefault();
-
 
1357
        if ($('#form-question #question-type').val() == 'open') {
-
 
1358
            $('#form-question #question-max-length').parent().show();
-
 
1359
            $('#form-question #question-multiline').parent().show();
-
 
1360
        } else {
-
 
1361
            $('#form-question #question-max-length').val('0');
-
 
1362
            $('#form-question #question-max-length').parent().hide();
-
 
1363
            $('#form-question #question-multiline').val('0');
-
 
1364
            $('#form-question #question-multiline').parent().hide();
-
 
1365
        }
-
 
1366
        $('#form-question #question-range').val('10');
-
 
1367
        if ($('#form-question #question-type').val() == 'rating-range') {
-
 
1368
            $('#form-question #question-range').parent().show();
-
 
1369
        } else {
-
 
1370
            $('#form-question #question-range').parent().hide();
-
 
1371
        }
-
 
1372
    });
-
 
1373
    /**
-
 
1374
     * Clicked new Form
-
 
1375
     */
-
 
1376
    $('button.btn-add-form').click(function(e) {
-
 
1377
        e.preventDefault();
-
 
1378
        objFormGenerator.clear();
-
 
1379
        objFormGenerator.render();
-
 
1380
        validatorForm.resetForm();
-
 
1381
        clearSectionData();
-
 
1382
        $('#form-main').attr('action', '$routeAdd');
-
 
1383
        $('#form-main #form-id').val('0');
-
 
1384
        $('#form-main #form-continue').val('0');
-
 
1385
        $('#form-main #form-name').val('');
-
 
1386
        $('#form-main #form-language').val('$lang_es'),
-
 
1387
        $('#form-main #form-status').val('$status_inactive');
-
 
1388
        CKEDITOR.instances['form-text'].setData('');
-
 
1389
        CKEDITOR.instances['form-description'].setData('');
-
 
1390
        $('#row-forms').hide();
-
 
1391
        $('#row-edit').show();
-
 
1392
        $('#form-main #form-name').focus();
-
 
1393
    });
-
 
1394
    /**
605
    /**
1395
     * Clicked cancel new/edit Form
606
     * Clicked cancel new/edit Form
1396
     */
607
     */
1397
    $('button.btn-edit-cancel').click(function(e) {
608
    $('button.btn-edit-cancel').click(function(e) {
1398
        e.preventDefault();
609
        e.preventDefault();
Línea 1469... Línea 680...
1469
<!-- Content Header (Page header) -->
680
<!-- Content Header (Page header) -->
1470
<section class="content-header">
681
<section class="content-header">
1471
    <div class="container-fluid">
682
    <div class="container-fluid">
1472
        <div class="row mb-2">
683
        <div class="row mb-2">
1473
            <div class="col-sm-12">
684
            <div class="col-sm-12">
1474
                <h1>LABEL_SELF_EVALUATION_FORMS</h1>
685
                <h1>LABEL_REVIEWS</h1>
1475
            </div>
686
            </div>
1476
        </div>
687
        </div>
1477
    </div>
688
    </div>
1478
    <!-- /.container-fluid -->
689
    <!-- /.container-fluid -->
1479
</section>
690
</section>
Línea 1561... Línea 772...
1561
        </div>
772
        </div>
1562
    </div>
773
    </div>
Línea 1563... Línea 774...
1563
 
774
 
Línea 1564... Línea -...
1564
    <!-- Create/Edit Form-->
-
 
1565
 
-
 
1566
    <!-- Section Modal -->
-
 
1567
    <div  id="modal-section" class="modal" tabindex="-1" role="dialog">
-
 
1568
        <div class="modal-dialog modal-lg" role="document">
-
 
1569
            <form action="#" name="form-section" id="form-section">
-
 
1570
                <input type="hidden" name="section-slug" id="section-slug" value="" />
-
 
1571
                <div class="modal-content">
-
 
1572
                    <div class="modal-header">
-
 
1573
                        <h4 class="modal-title">LABEL_ADD LABEL_SECTION</h4>
-
 
1574
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
-
 
1575
                            <span aria-hidden="true">&times;</span>
-
 
1576
                        </button>
-
 
1577
                    </div>
-
 
1578
                    <div class="modal-body">
-
 
1579
                        <div class="form-group">
-
 
1580
                            <label for="section-name">LABEL_FIRST_NAME</label>
-
 
1581
                            <input type="text" name="section-name" id="section-name" class="form-control" maxlength="50" value="" />
-
 
1582
                        </div>
-
 
1583
                        <div class="form-group">
-
 
1584
                            <label for="section-text">LABEL_TEXT</label>
-
 
1585
                            <!--  ckeditor -->
-
 
1586
                            <textarea  name="section-text" id="section-text" rows="5" class="ckeditor form-control"></textarea>
-
 
1587
                        </div>
-
 
1588
                        <div class="form-group">
-
 
1589
                            <label for="section-value">LABEL_VALUE</label>
-
 
1590
                            <input type="text" name="section-value" id="section-value"  class="form-control" value="0" />
-
 
1591
                        </div>
-
 
1592
                    </div>
-
 
1593
                    <div class="modal-footer">
-
 
1594
                        <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
-
 
1595
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
-
 
1596
                    </div>
-
 
1597
                </div>
-
 
1598
            </form>
-
 
1599
        </div>
-
 
1600
    </div>
-
 
1601
    <!-- End Modal Section -->
-
 
1602
 
-
 
1603
    <!-- Question Modal -->
-
 
1604
 
-
 
1605
    <div  id="modal-question" class="modal" tabindex="-1" role="dialog">
-
 
1606
        <div class="modal-dialog modal-lg" role="document">
-
 
1607
            <form action="#" name="form-question" id="form-question">
-
 
1608
                <input type="hidden" name="question-section" id="question-section" />
-
 
1609
                <input type="hidden" name="question-slug" id="question-slug" />
-
 
1610
                <div class="modal-content">
-
 
1611
                    <div class="modal-header">
-
 
1612
                        <h4 class="modal-title">LABEL_ADD LABEL_QUESTION</h4>
-
 
1613
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
-
 
1614
                            <span aria-hidden="true">&times;</span>
-
 
1615
                        </button>
-
 
1616
                    </div>
-
 
1617
                    <div class="modal-body">
-
 
1618
                        <div class="form-group">
-
 
1619
                            <label for="question-text">LABEL_TEXT</label>
-
 
1620
                            <!--  ckeditor -->
-
 
1621
                            <textarea  name="question-text" id="question-text" rows="5" class="ckeditor form-control"></textarea>
-
 
1622
                        </div>
-
 
1623
                        <div class="form-group">
-
 
1624
                            <label for="question-value">LABEL_VALUE</label>
-
 
1625
                            <input type="text" name="question-value" id="question-value"  class="form-control" />
-
 
1626
                        </div>
-
 
1627
                        <div class="form-group">
-
 
1628
                            <label for="question-type">LABEL_TYPE</label>
-
 
1629
                            <select name="question-type" id="question-type" class="form-control">
-
 
1630
                                <option value="open">LABEL_OPEN</option>
-
 
1631
                                <option value="simple">Simple</option>
-
 
1632
                                <option value="multiple">Multiple</option>
-
 
1633
                                <option value="rating-open">LABEL_RATING_OPEN</option>
-
 
1634
                                <option value="rating-range">LABEL_RATING_RANGE</option>
-
 
1635
                            </select>
-
 
1636
                        </div>
-
 
1637
                        <div class="form-group">
-
 
1638
                            <label for="question-max-length">LABEL_MAXLENGTH</label>
-
 
1639
                            <input type="text" name="question-max-length" id="question-max-length"  class="form-control" />
-
 
1640
                        </div>
-
 
1641
                        <div class="form-group">
-
 
1642
                            <label for="question-multiline">LABEL_MULTI_LINE</label>
-
 
1643
                            <select name="question-multiline" id="question-multiline" class="form-control">
-
 
1644
                                <option value="1">LABEL_YES</option>
-
 
1645
                                <option value="0">LABEL_NOT</option>
-
 
1646
                            </select>
-
 
1647
                        </div>
-
 
1648
                        <div class="form-group">
-
 
1649
                            <label for="question-range">LABEL_RANGE</label>
-
 
1650
                            <select name="question-range" id="question-range" class="form-control">
-
 
1651
                                <option value="10">1-10</option>
-
 
1652
                                <option value="6">1-6</option>
-
 
1653
                                <option value="5">1-5</option>
-
 
1654
                            </select>
-
 
1655
                        </div>
-
 
1656
                    </div>
-
 
1657
                    <div class="modal-footer">
-
 
1658
                        <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
-
 
1659
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
-
 
1660
                    </div>
-
 
1661
                </div>
-
 
1662
            </form>
-
 
1663
        </div>
-
 
1664
    </div>
-
 
1665
 
-
 
1666
    <!-- End Modal Question -->
-
 
1667
 
-
 
1668
    <!-- Modal Options -->
-
 
1669
 
-
 
1670
    <div  id="modal-option" class="modal" tabindex="-1" role="dialog">
-
 
1671
        <div class="modal-dialog modal-lg" role="document">
-
 
1672
            <form action="#" name="form-option" id="form-option">
-
 
1673
                <input type="hidden" name="option-section" id="option-section" value="" />
-
 
1674
                <input type="hidden" name="option-question" id="option-question" value="" />
-
 
1675
                <input type="hidden" name="option-slug" id="option-slug" value="" />
-
 
1676
                <div class="modal-content">
-
 
1677
                    <div class="modal-header">
-
 
1678
                        <h4 class="modal-title">LABEL_OPTION</h4>
-
 
1679
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
-
 
1680
                            <span aria-hidden="true">&times;</span>
-
 
1681
                        </button>
-
 
1682
                    </div>
-
 
1683
                    <div class="modal-body">
-
 
1684
                        <div class="form-group">
-
 
1685
                            <label for="option-text">LABEL_TEXT</label>
-
 
1686
                            <!--  ckeditor -->
-
 
1687
                            <textarea  name="option-text" id="option-text" rows="5" class="ckeditor form-control"></textarea>
-
 
1688
                        </div>
-
 
1689
                        <div class="form-group">
-
 
1690
                            <label for="option-correct">LABEL_ANSWER_CORRECT</label>
-
 
1691
                            <select name="option-correct" id="option-correct" class="form-control">
-
 
1692
                                <option value="1">LABEL_YES</option>
-
 
1693
                                <option value="0">LABEL_NOT</option>
-
 
1694
                            </select>
-
 
1695
                        </div>
-
 
1696
                        <div class="form-group">
-
 
1697
                            <label for="option-value">LABEL_VALUE</label>
-
 
1698
                            <input type="text" name="option-value" id="option-value" class="form-control" />
-
 
1699
                        </div>
-
 
1700
                    </div>
-
 
1701
                    <div class="modal-footer">
-
 
1702
                        <button type="submit" class="btn btn-primary">LABEL_SAVE</button>
-
 
1703
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">LABEL_CLOSE</button>
-
 
1704
                    </div>
-
 
1705
                </div>
-
 
1706
            </form>
-
 
1707
        </div>
775
    <!-- Create/Edit Form-->
1708
    </div>
-
 
Línea 1709... Línea 776...
1709
 
776
 
1710
    <!-- End Modal Options -->
777
   
1711
 
778
 
1712
    <!---Template Sections --->
779
    <!---Template Sections --->