Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 170 Rev 171
Línea 74... Línea 74...
74
        this.sections = [],
74
        this.sections = [],
75
        this.clear = function() {
75
        this.clear = function() {
76
            this.sections = [];
76
            this.sections = [];
77
            this.render();
77
            this.render();
78
        },
78
        },
79
        this.renderSection = function(section_slug) {
79
        this.renderSection = function(slug_section) {
80
            var s = '';
80
            var s = '';
81
            for (i = 0; i < this.sections.length; i++) {
81
            for (i = 0; i < this.sections.length; i++) {
82
                if (section_slug != this.sections[i].slug_section) {
82
                if (slug_section != this.sections[i].slug_section) {
83
                    continue;
83
                    continue;
84
                }
84
                }
85
                for (j = 0; j < this.sections[i].questions.length; j++) {
85
                for (j = 0; j < this.sections[i].questions.length; j++) {
86
                    this.sections[i].questions[j].position = j;
86
                    this.sections[i].questions[j].position = j;
87
                    if (this.sections[i].questions[j].type == 'simple' || this.sections[i].questions[j].type == 'multiple' || this.sections[i].questions[j].type == 'rating-open') {
87
                    if (this.sections[i].questions[j].type == 'simple' || this.sections[i].questions[j].type == 'multiple' || this.sections[i].questions[j].type == 'rating-open') {
Línea 190... Línea 190...
190
            }
190
            }
191
            if (renderTable) {
191
            if (renderTable) {
192
                $('#panel' + slug).remove();
192
                $('#panel' + slug).remove();
193
            }
193
            }
194
        },
194
        },
195
        this.addQuestion = function(section_slug, text, value, type, maxlength, multiline, range) {
195
        this.addQuestion = function(slug_section, text, value, type, maxlength, multiline, range) {
196
            var d = new Date();
196
            var d = new Date();
197
            var slug_question = 'question' + d.getTime();
197
            var slug_question = 'question' + d.getTime();
198
            var position = 0;
198
            var position = 0;
199
            var renderTable = false;
199
            var renderTable = false;
200
            for (i = 0; i < this.sections.length; i++) {
200
            for (i = 0; i < this.sections.length; i++) {
201
                if (section_slug == this.sections[i].slug_section) {
201
                if (slug_section == this.sections[i].slug_section) {
202
                    $.each(this.sections[i].questions, function(index, question) {
202
                    $.each(this.sections[i].questions, function(index, question) {
203
                        if (position < question.position) {
203
                        if (position < question.position) {
204
                            position = question.position;
204
                            position = question.position;
205
                        }
205
                        }
206
                    });
206
                    });
207
                    position++;
207
                    position++;
208
                    var question = {
208
                    var question = {
209
                        'section_slug': section_slug,
209
                        'slug_section': slug_section,
210
                        'slug_question': slug_question,
210
                        'slug_question': slug_question,
211
                        'text': text,
211
                        'text': text,
212
                        'value': value,
212
                        'value': value,
213
                        'type': type,
213
                        'type': type,
214
                        'position': position,
214
                        'position': position,
Línea 221... Línea 221...
221
                    renderTable = true;
221
                    renderTable = true;
222
                    break;
222
                    break;
223
                }
223
                }
224
            }
224
            }
225
            if (renderTable) {
225
            if (renderTable) {
226
                this.renderSection(section_slug);
226
                this.renderSection(slug_section);
227
            }
227
            }
228
        },
228
        },
229
        this.editQuestion = function(section_slug, question_slug, text, value, type, maxlength, multiline, range) {
229
        this.editQuestion = function(slug_section, question_slug, 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 (section_slug == 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 (question_slug == 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;
Línea 256... Línea 256...
256
                if (renderTable) {
256
                if (renderTable) {
257
                    break;
257
                    break;
258
                }
258
                }
259
            }
259
            }
260
            if (renderTable) {
260
            if (renderTable) {
261
                this.renderSection(section_slug);
261
                this.renderSection(slug_section);
262
            }
262
            }
263
        },
263
        },
264
        this.deleteQuestion = function(section_slug, question_slug) {
264
        this.deleteQuestion = function(slug_section, question_slug) {
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 (section_slug == 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 (question_slug == 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;
Línea 276... Línea 276...
276
                if (renderTable) {
276
                if (renderTable) {
277
                    break;
277
                    break;
278
                }
278
                }
279
            }
279
            }
280
            if (renderTable) {
280
            if (renderTable) {
281
                this.renderSection(section_slug);
281
                this.renderSection(slug_section);
282
            }
282
            }
283
        },
283
        },
284
        this.addOption = function(section_slug, question_slug, text, correct, value) {
284
        this.addOption = function(slug_section, question_slug, 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 (section_slug == 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 (question_slug == 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;
Línea 313... Línea 313...
313
                        }
313
                        }
314
                    }
314
                    }
315
                }
315
                }
316
            }
316
            }
317
            if (renderTable) {
317
            if (renderTable) {
318
                this.renderSection(section_slug);
318
                this.renderSection(slug_section);
319
            }
319
            }
320
        },
320
        },
321
        this.editOption = function(section_slug, question_slug, option_slug, text, correct, value) {
321
        this.editOption = function(slug_section, question_slug, 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 (section_slug == 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 (question_slug == 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;
Línea 342... Línea 342...
342
                if (renderTable) {
342
                if (renderTable) {
343
                    break;
343
                    break;
344
                }
344
                }
345
            }
345
            }
346
            if (renderTable) {
346
            if (renderTable) {
347
                this.renderSection(section_slug);
347
                this.renderSection(slug_section);
348
            }
348
            }
349
        },
349
        },
350
        this.deleteOption = function(section_slug, question_slug, option_slug) {
350
        this.deleteOption = function(slug_section, question_slug, 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 (section_slug == 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 (question_slug == 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);
Línea 369... Línea 369...
369
                if (renderTable) {
369
                if (renderTable) {
370
                    break;
370
                    break;
371
                }
371
                }
372
            }
372
            }
373
            if (renderTable) {
373
            if (renderTable) {
374
                this.renderSection(section_slug);
374
                this.renderSection(slug_section);
375
            }
375
            }
376
        }
376
        }
377
}
377
}
Línea 378... Línea 378...
378
 
378
 
Línea 1104... Línea 1104...
1104
    });
1104
    });
1105
    $('body').on('click', 'button.btn-edit-section', function(e) {
1105
    $('body').on('click', 'button.btn-edit-section', function(e) {
1106
        e.preventDefault();
1106
        e.preventDefault();
1107
        var slug = $(this).data('section');
1107
        var slug = $(this).data('section');
1108
        var section;
1108
        var section;
-
 
1109
        console.log(slug);
1109
        var showForm = false;
1110
        var showForm = false;
1110
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1111
        for (i = 0; i < objFormGenerator.sections.length; i++) {
1111
            section = objFormGenerator.sections[i];
1112
            section = objFormGenerator.sections[i];
1112
            if (slug == section.section_slug) {
1113
            if (slug == section.slug_section) {
1113
                validatorFormSection.resetForm();
1114
                validatorFormSection.resetForm();
1114
                $('#form-section #section-slug').val(section.section_slug);
1115
                $('#form-section #section-slug').val(section.slug_section);
1115
                $('#form-section #section-name').val(section.name);
1116
                $('#form-section #section-name').val(section.name);
1116
                instanceName = 'section-text';
1117
                instanceName = 'section-text';
1117
                let editor = CKEDITOR.instances[instanceName];
1118
                let editor = CKEDITOR.instances[instanceName];
1118
                editor.setData(section.text, function() {
1119
                editor.setData(section.text, function() {
1119
                    editor.focus();
1120
                    editor.focus();
Línea 1287... Línea 1288...
1287
        }
1288
        }
1288
    });
1289
    });
1289
    /**
1290
    /**
1290
     * Render Sections data
1291
     * Render Sections data
1291
     */
1292
     */
1292
    const renderData = (data) => $("#rows").html($("#sectionTemplate").render(data));
1293
    const renderData = (data) =>{
1293
    //const renderData = (data) => console.log(data);
1294
        console.log(data);
-
 
1295
return $("#rows").html($("#sectionTemplate").render(data));
-
 
1296
    } 
-
 
1297
 
-
 
1298
 
1294
    $('body').on('click', 'button.btn-edit-option', function(e) {
1299
    $('body').on('click', 'button.btn-edit-option', function(e) {
1295
        e.preventDefault();
1300
        e.preventDefault();
1296
        var slug_section = $(this).data('section');
1301
        var slug_section = $(this).data('section');
1297
        var slug_question = $(this).data('question');
1302
        var slug_question = $(this).data('question');
1298
        var slug = $(this).data('slug');
1303
        var slug = $(this).data('slug');