Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 171 Rev 172
Línea 224... Línea 224...
224
            }
224
            }
225
            if (renderTable) {
225
            if (renderTable) {
226
                this.renderSection(slug_section);
226
                this.renderSection(slug_section);
227
            }
227
            }
228
        },
228
        },
229
        this.editQuestion = function(slug_section, question_slug, text, value, type, maxlength, multiline, range) {
229
        this.editQuestion = function(slug_section, slug_question, text, value, type, maxlength, multiline, range) {
230
            var renderTable = false;
230
            var renderTable = false;
231
            for (i = 0; i < this.sections.length; i++) {
231
            for (i = 0; i < this.sections.length; i++) {
232
                if (slug_section == this.sections[i].slug_section) {
232
                if (slug_section == this.sections[i].slug_section) {
233
                    for (j = 0; j < this.sections[i].questions.length; j++) {
233
                    for (j = 0; j < this.sections[i].questions.length; j++) {
234
                        if (question_slug == this.sections[i].questions[j].slug_question) {
234
                        if (slug_question == this.sections[i].questions[j].slug_question) {
235
                            this.sections[i].questions[j].text = text,
235
                            this.sections[i].questions[j].text = text,
236
                                this.sections[i].questions[j].value = value,
236
                                this.sections[i].questions[j].value = value,
237
                                this.sections[i].questions[j].type = type;
237
                                this.sections[i].questions[j].type = type;
238
                            if (type == 'open') {
238
                            if (type == 'open') {
239
                                this.sections[i].questions[j].maxlength = maxlength;
239
                                this.sections[i].questions[j].maxlength = maxlength;
Línea 259... Línea 259...
259
            }
259
            }
260
            if (renderTable) {
260
            if (renderTable) {
261
                this.renderSection(slug_section);
261
                this.renderSection(slug_section);
262
            }
262
            }
263
        },
263
        },
264
        this.deleteQuestion = function(slug_section, question_slug) {
264
        this.deleteQuestion = function(slug_section, slug_question) {
265
            var renderTable = false;
265
            var renderTable = false;
266
            for (i = 0; i < this.sections.length; i++) {
266
            for (i = 0; i < this.sections.length; i++) {
267
                if (slug_section == this.sections[i].slug_section) {
267
                if (slug_section == this.sections[i].slug_section) {
268
                    for (j = 0; j < this.sections[i].questions.length; j++) {
268
                    for (j = 0; j < this.sections[i].questions.length; j++) {
269
                        if (question_slug == this.sections[i].questions[j].slug_question) {
269
                        if (slug_question == this.sections[i].questions[j].slug_question) {
270
                            this.sections[i].questions.splice(j, 1);
270
                            this.sections[i].questions.splice(j, 1);
271
                            renderTable = true;
271
                            renderTable = true;
272
                            break;
272
                            break;
273
                        }
273
                        }
274
                    }
274
                    }
Línea 279... Línea 279...
279
            }
279
            }
280
            if (renderTable) {
280
            if (renderTable) {
281
                this.renderSection(slug_section);
281
                this.renderSection(slug_section);
282
            }
282
            }
283
        },
283
        },
284
        this.addOption = function(slug_section, question_slug, text, correct, value) {
284
        this.addOption = function(slug_section, slug_question, text, correct, value) {
285
            var d = new Date();
285
            var d = new Date();
286
            var slug_option = 'option' + d.getTime();
286
            var slug_option = 'option' + d.getTime();
287
            var position = 0;
287
            var position = 0;
288
            var renderTable = false;
288
            var renderTable = false;
289
            for (i = 0; i < this.sections.length; i++) {
289
            for (i = 0; i < this.sections.length; i++) {
290
                if (slug_section == this.sections[i].slug_section) {
290
                if (slug_section == this.sections[i].slug_section) {
291
                    for (j = 0; j < this.sections[i].questions.length; j++) {
291
                    for (j = 0; j < this.sections[i].questions.length; j++) {
292
                        if (question_slug == this.sections[i].questions[j].slug_question) {
292
                        if (slug_question == this.sections[i].questions[j].slug_question) {
293
                            $.each(this.sections[i].questions[j].options, function(index, option) {
293
                            $.each(this.sections[i].questions[j].options, function(index, option) {
294
                                if (position < option.position) {
294
                                if (position < option.position) {
295
                                    position = option.position;
295
                                    position = option.position;
296
                                }
296
                                }
297
                            });
297
                            });
Línea 316... Línea 316...
316
            }
316
            }
317
            if (renderTable) {
317
            if (renderTable) {
318
                this.renderSection(slug_section);
318
                this.renderSection(slug_section);
319
            }
319
            }
320
        },
320
        },
321
        this.editOption = function(slug_section, question_slug, option_slug, text, correct, value) {
321
        this.editOption = function(slug_section, slug_question, option_slug, text, correct, value) {
322
            var renderTable = false;
322
            var renderTable = false;
323
            for (i = 0; i < this.sections.length; i++) {
323
            for (i = 0; i < this.sections.length; i++) {
324
                if (slug_section == this.sections[i].slug_section) {
324
                if (slug_section == this.sections[i].slug_section) {
325
                    for (j = 0; j < this.sections[i].questions.length; j++) {
325
                    for (j = 0; j < this.sections[i].questions.length; j++) {
326
                        if (question_slug == this.sections[i].questions[j].slug_question) {
326
                        if (slug_question == this.sections[i].questions[j].slug_question) {
327
                            for (k = 0; k < this.sections[i].questions[j].options.length; k++) {
327
                            for (k = 0; k < this.sections[i].questions[j].options.length; k++) {
328
                                if (option_slug == this.sections[i].questions[j].options[k].slug_option) {
328
                                if (option_slug == this.sections[i].questions[j].options[k].slug_option) {
329
                                    this.sections[i].questions[j].options[k].text = text;
329
                                    this.sections[i].questions[j].options[k].text = text;
330
                                    this.sections[i].questions[j].options[k].correct = correct;
330
                                    this.sections[i].questions[j].options[k].correct = correct;
331
                                    this.sections[i].questions[j].options[k].value = value;
331
                                    this.sections[i].questions[j].options[k].value = value;
Línea 345... Línea 345...
345
            }
345
            }
346
            if (renderTable) {
346
            if (renderTable) {
347
                this.renderSection(slug_section);
347
                this.renderSection(slug_section);
348
            }
348
            }
349
        },
349
        },
350
        this.deleteOption = function(slug_section, question_slug, option_slug) {
350
        this.deleteOption = function(slug_section, slug_question, option_slug) {
351
            var renderTable = false;
351
            var renderTable = false;
352
            for (i = 0; i < this.sections.length; i++) {
352
            for (i = 0; i < this.sections.length; i++) {
353
                if (slug_section == this.sections[i].slug_section) {
353
                if (slug_section == this.sections[i].slug_section) {
354
                    for (j = 0; j < this.sections[i].questions.length; j++) {
354
                    for (j = 0; j < this.sections[i].questions.length; j++) {
355
                        if (question_slug == this.sections[i].questions[j].slug_question) {
355
                        if (slug_question == this.sections[i].questions[j].slug_question) {
356
                            for (k = 0; k < this.sections[i].questions[j].options.length; k++) {
356
                            for (k = 0; k < this.sections[i].questions[j].options.length; k++) {
357
                                if (option_slug == this.sections[i].questions[j].options[k].slug_option) {
357
                                if (option_slug == this.sections[i].questions[j].options[k].slug_option) {
358
                                    this.sections[i].questions[j].options.splice(k, 1);
358
                                    this.sections[i].questions[j].options.splice(k, 1);
359
                                    renderTable = true;
359
                                    renderTable = true;
360
                                    break;
360
                                    break;
Línea 1243... Línea 1243...
1243
                    renderData(objFormGenerator.sections);
1243
                    renderData(objFormGenerator.sections);
1244
                }
1244
                }
1245
            }
1245
            }
1246
        });
1246
        });
1247
    });
1247
    });
-
 
1248
 
-
 
1249
        /**
-
 
1250
     * Render Sections data
-
 
1251
     */
-
 
1252
    const renderData = (data) =>{
-
 
1253
        console.log(data);
-
 
1254
return $("#rows").html($("#sectionTemplate").render(data));
-
 
1255
    } 
-
 
1256
 
1248
    $('body').on('click', 'button.btn-add-option', function(e) {
1257
    $('body').on('click', 'button.btn-add-option', function(e) {
1249
        e.preventDefault();
1258
        e.preventDefault();
1250
        var slug_section = $(this).data('section');
1259
        var slug_section = $(this).data('section');
1251
        var slug_question = $(this).data('question');
1260
        var slug_question = $(this).data('question');
1252
        var showForm = false;
1261
        var showForm = false;
Línea 1285... Línea 1294...
1285
        if (showForm) {
1294
        if (showForm) {
1286
            $('#modal-option h4[class="modal-title"]').html('LABEL_ADD LABEL_OPTION');
1295
            $('#modal-option h4[class="modal-title"]').html('LABEL_ADD LABEL_OPTION');
1287
            $('#modal-option').modal('show');
1296
            $('#modal-option').modal('show');
1288
        }
1297
        }
1289
    });
1298
    });
1290
    /**
-
 
1291
     * Render Sections data
-
 
1292
     */
-
 
1293
    const renderData = (data) =>{
-
 
1294
        console.log(data);
-
 
1295
return $("#rows").html($("#sectionTemplate").render(data));
-
 
1296
    } 
-
 
Línea 1297... Línea -...
1297
 
-
 
1298
 
1299
 
1299
    $('body').on('click', 'button.btn-edit-option', function(e) {
1300
    $('body').on('click', 'button.btn-edit-option', function(e) {
1300
        e.preventDefault();
1301
        e.preventDefault();
1301
        var slug_section = $(this).data('section');
1302
        var slug_section = $(this).data('section');
1302
        var slug_question = $(this).data('question');
1303
        var slug_question = $(this).data('question');