Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 160 Rev 163
Línea 73... Línea 73...
73
			this.status				= 'a',
73
			this.status				= 'a',
74
			this.sections 			= [],
74
			this.sections 			= [],
75
			this.clear = function() 
75
			this.clear = function() 
76
			{
76
			{
77
				this.sections = [];
77
				this.sections = [];
78
				this.render();
-
 
79
			},
-
 
80
			this.renderSection = function(section_slug)
-
 
81
			{
-
 
82
			
-
 
83
				var s = '';
-
 
84
				for(i = 0; i < this.sections.length; i++)
-
 
85
				{
-
 
86
					if(section_slug !=  this.sections[i].slug_section) {
-
 
87
						continue;
-
 
88
					}
-
 
89
 
-
 
90
					$('span.section-name' + section_slug).html(this.sections[i].name);
-
 
91
 
-
 
92
					let table = 'table-section-question-option' + this.sections[i].slug_section; 
-
 
93
					$('#' + table  + ' tbody').empty();
-
 
94
					
-
 
95
					s = '<tr class="tr-section" data-slug="' + this.sections[i].slug_section + '">';
-
 
96
					s = s  + '<td class="text-left">LABEL_SECTION</td>';
-
 
97
					s = s  + '<td class="text-left">' + this.sections[i].name +  '</td>';
-
 
98
					s = s  + '<td class="text-right">' + this.sections[i].value + '</td>';
-
 
99
					s = s  + '<td>&nbsp</td>';
-
 
100
					s = s  + '<td>';
-
 
101
					s = s  + '<button class="btn btn-default btn-edit-section" data-slug="' + this.sections[i].slug_section + '" data-toggle="tooltip" title="LABEL_EDIT LABEL_SECTION"><i class="fa fa-edit" aria-hidden="true"></i> LABEL_EDIT LABEL_SECTION </button>&nbsp';
-
 
102
					s = s  + '<button class="btn btn-default btn-delete-section" data-slug="' + this.sections[i].slug_section + '" data-toggle="tooltip" title="LABEL_DELETE LABEL_SECTION"><i class="fa fa-ban" aria-hidden="true"></i> LABEL_DELETE LABEL_SECTION </button>&nbsp';
-
 
103
					s = s  + '<button class="btn btn-default btn-add-question" data-slug="' + this.sections[i].slug_section + '" data-toggle="tooltip" title="LABEL_ADD LABEL_QUESTION"><i class="fa fa-plus" aria-hidden="true"></i> LABEL_ADD LABEL_QUESTION </button>&nbsp';
-
 
104
					s = s  + '</td>';
-
 
105
					s = s  + '</tr>';
-
 
106
					$('#' + table + ' tbody').append(s);
-
 
107
					
-
 
108
					
-
 
109
 
-
 
110
					for(j = 0; j < this.sections[i].questions.length; j++)
-
 
111
					{
-
 
112
						this.sections[i].questions[j].position = j;
-
 
113
 
-
 
114
						this.drawQuestion( this.sections[i].slug_section, this.sections[i].questions[j].slug_question, this.sections[i].questions[j].text, this.sections[i].questions[j].value , this.sections[i].questions[j].type);
-
 
115
						if(this.sections[i].questions[j].type == 'simple' || this.sections[i].questions[j].type == 'multiple'|| this.sections[i].questions[j].type == 'rating-open') {
-
 
116
							
-
 
117
								
-
 
118
							this.sections[i].questions[j].options.sort(function(a, b) {
-
 
119
										if (a.position > b.position) {
-
 
120
												return 1;
-
 
121
										}
-
 
122
										if (a.position < b.position) {
-
 
123
											return -1;
-
 
124
										}
-
 
125
										return 0;
-
 
126
									});
-
 
127
								
-
 
128
							
-
 
129
							for(k = 0; k < this.sections[i].questions[j].options.length; k++)
-
 
130
							{
-
 
131
								this.sections[i].questions[j].options[k].position = j;
-
 
132
								this.drawOption(
-
 
133
									this.sections[i].slug_section, 
-
 
134
									this.sections[i].questions[j].slug_question,  
-
 
135
									this.sections[i].questions[j].type, 
-
 
136
									this.sections[i].questions[j].options[k].slug_option, 
-
 
137
									this.sections[i].questions[j].options[k].text, 
-
 
138
									this.sections[i].questions[j].options[k].type, 
-
 
139
									this.sections[i].questions[j].options[k].correct, 
-
 
140
									this.sections[i].questions[j].options[k].value
-
 
141
								);
-
 
142
							}
-
 
143
						}
-
 
144
					}
-
 
145
				}
-
 
146
				
-
 
147
				$('[data-toggle="tooltip"]').tooltip();
-
 
148
			},
-
 
149
			this.drawSection = function(section_slug, section_name, section_value)
-
 
150
			{
-
 
151
				let table = 'table-section-question-option' + section_slug; 
-
 
152
				let collapse = 'collapse-' + section_slug;
-
 
153
 
-
 
154
				s = '<div class="panel panel-default" id="panel' + section_slug + '">';
-
 
155
				s = s + '	<div class="panel-heading">';
-
 
156
				s = s + '		<h4 class="panel-title">';
-
 
157
				s = s + '			<a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion" href="#' + collapse + '"><span class="section-name' + section_slug + '">' + section_name + '</span></a>';
-
 
158
				s = s + '		</h4>';
-
 
159
				s = s + '	</div>';
-
 
160
				s = s + '	<div id="' + collapse + '" class="panel-collapse collapse">';
-
 
161
				s = s + '		<div class="panel-body">';
-
 
162
				s = s + '			<div class="table-responsive">';
-
 
163
				s = s + '				<table class="table table-bordered" id="' + table + '">';
-
 
164
				s = s + '					<thead>';
-
 
165
				s = s + '						<tr>';
-
 
166
				s = s + '							<th>LABEL_ELEMENT</th>';
-
 
167
				s = s + '							<th>LABEL_TEXT</th>';
-
 
168
				s = s + '							<th>LABEL_VALUE</th>';
-
 
169
				s = s + '							<th>LABEL_TYPE</th>';
-
 
170
				s = s + '							<th>LABEL_ACTIONS</th>';
-
 
171
				s = s + '						</tr>';
-
 
172
				s = s + '					</thead>';
-
 
173
				s = s + '					<tbody>';
-
 
174
				s = s + '					</tbody>';					
-
 
175
				s = s + '				</table>';
-
 
176
				s = s + '			</div>';
-
 
177
				s = s + '		</div>';
-
 
178
				s = s + '	</div>';
-
 
179
				s = s + '</div>';
-
 
180
 
-
 
181
				$('#accordion').append(s);
-
 
182
 
-
 
183
 
-
 
184
				s = '<tr class="tr-section" data-slug="' + section_slug + '">';
-
 
185
				s = s  + '<td class="text-left">LABEL_SECTION</td>';
-
 
186
				s = s  + '<td class="text-left">' + section_name +  '</td>';
-
 
187
				s = s  + '<td class="text-right">' + section_value + '</td>';
-
 
188
				s = s  + '<td>&nbsp</td>';
-
 
189
				s = s  + '<td>';
-
 
190
				s = s  + '<button class="btn btn-default btn-edit-section" data-slug="' + section_slug + '" data-toggle="tooltip" title="LABEL_EDIT LABEL_SECTION"><i class="fa fa-edit" aria-hidden="true"></i> LABEL_EDIT LABEL_SECTION </button>&nbsp';
-
 
191
				s = s  + '<button class="btn btn-default btn-delete-section" data-slug="' + section_slug + '" data-toggle="tooltip" title="LABEL_DELETE LABEL_SECTION"><i class="fa fa-ban" aria-hidden="true"></i> LABEL_DELETE LABEL_SECTION </button>&nbsp';
-
 
192
				s = s  + '<button class="btn btn-default btn-add-question" data-slug="' + section_slug + '" data-toggle="tooltip" title="LABEL_ADD LABEL_QUESTION"><i class="fa fa-plus" aria-hidden="true"></i> LABEL_ADD LABEL_QUESTION </button>&nbsp';
-
 
193
				s = s  + '</td>';
-
 
194
				s = s  + '</tr>';
-
 
195
				$('#' + table + ' tbody').append(s);
-
 
196
			},
-
 
197
 
-
 
198
			this.drawQuestion = function(section_slug, question_slug, question_text, question_value, question_type)
-
 
199
			{
-
 
200
				
-
 
201
				
-
 
202
				s = '<tr class="tr-question" data-slug="' + question_slug + '">';
-
 
203
				s = s  + '<td class="text-left">--LABEL_QUESTION</td>';
-
 
204
				s = s  + '<td class="text-left">' + question_text +  '</td>';
-
 
205
				s = s  + '<td class="text-right"><font color="red">' + question_value + '</font></td>';
-
 
206
				s = s  + '<td>' + question_type.substr(0,1).toUpperCase() + question_type.substr(1) +  '</td>';
-
 
207
				s = s  + '<td>';
-
 
208
				s = s  + '<button class="btn btn-default btn-edit-question" data-section="' + section_slug + '" data-slug="' + question_slug + '" data-toggle="tooltip" title="LABEL_EDIT LABEL_QUESTION"><i class="fa fa-edit" aria-hidden="true"></i> LABEL_EDIT LABEL_QUESTION</button>&nbsp';
-
 
209
				s = s  + '<button class="btn btn-default btn-delete-question" data-section="' + section_slug + '" data-slug="' + question_slug + '" data-toggle="tooltip" title="LABEL_DELETE LABEL_QUESTION"><i class="fa fa-ban" aria-hidden="true"></i> LABEL_DELETE LABEL_QUESTION</button>&nbsp';
-
 
210
				if(question_type == 'simple' || question_type == 'multiple' || question_type == 'rating-open') {
-
 
211
					s = s  + '<button class="btn btn-default btn-add-option" data-section="' + section_slug + '" data-slug="' + question_slug + '" data-toggle="tooltip" title="LABEL_ADD LABEL_OPTION"><i class="fa fa-plus" aria-hidden="true"></i> LABEL_ADD LABEL_OPTION</button>&nbsp';
-
 
212
				}
-
 
213
				
-
 
214
				s = s  + '</td>';
-
 
215
 
-
 
216
				let table = 'table-section-question-option' + section_slug; 
-
 
217
				$('#' + table + ' tbody').append(s);
-
 
218
			},
78
			}
219
 
-
 
220
			this.drawOption = function(section_slug, question_slug,  question_type, option_slug, option_text, option_type, option_correct, option_value)
-
 
221
			{
-
 
222
				
-
 
223
				
-
 
224
				s = '<tr class="tr-option" data-slug="' + option_slug + '">';
-
 
225
				s = s  + '<td class="text-left">---LABEL_OPTION</td>';
-
 
226
				s = s  + '<td class="text-left">' + option_text +  '</td>';
-
 
227
				if(question_type == 'multiple' || question_type == 'rating-open') {
-
 
228
 
-
 
229
					if(question_type == 'multiple') {
-
 
230
						if(option_correct == 1) {
-
 
231
							s = s  + '<td class="text-right">' + option_value + '</td>';
-
 
232
						} else {
-
 
233
							s = s  + '<td>&nbsp</td>';
-
 
234
						}
-
 
235
					} else {
-
 
236
						s = s  + '<td class="text-right">' + option_value + '</td>';
-
 
237
					}	
-
 
238
				} else {
-
 
239
					s = s  + '<td>&nbsp</td>';
-
 
240
				}
-
 
241
 
-
 
242
				if(question_type == 'simple' || question_type == 'multiple') {
-
 
243
					if(option_correct == 1) {
-
 
244
						s = s  + '<td class="text-left"><font color="green">LABEL_CORRECT</font></td>';
-
 
245
					} else {
-
 
246
						s = s  + '<td class="text-left"><font color="red">LABEL_FAIL</font></td>';
-
 
247
						
-
 
248
					}
-
 
249
				} else {
-
 
250
					s = s  + '<td>&nbsp</td>';
-
 
251
				}
-
 
252
				
-
 
253
				
-
 
254
				s = s  + '<td>';
-
 
255
				s = s  + '<button class="btn btn-default btn-edit-option" data-section="' + section_slug + '" data-question="' + question_slug + '" data-slug="' + option_slug + '" data-toggle="tooltip" title="LABEL_EDIT LABEL_OPTION"><i class="fa fa-edit" aria-hidden="true"></i></button>&nbsp';
-
 
256
				s = s  + '<button class="btn btn-default btn-delete-option" data-section="' + section_slug + '" data-question="' + question_slug + '" data-slug="' + option_slug + '" data-toggle="tooltip" title="LABEL_DELETE LABEL_OPTION"><i class="fa fa-ban" aria-hidden="true"></i></button>&nbsp';
-
 
257
				s = s  + '</td>';
-
 
258
 
-
 
259
				let table = 'table-section-question-option' + section_slug; 
-
 
260
				$('#' + table + ' tbody').append(s);
-
 
261
 
-
 
262
			},
-
 
263
			
-
 
264
			this.render = function() 
-
 
265
			{
-
 
266
				$('#accordion').empty();
-
 
267
 
-
 
268
				this.sections.sort(function(a, b) {
-
 
269
					if (a.position > b.position) {
-
 
270
							return 1;
-
 
271
					}
-
 
272
					if (a.position < b.position) {
-
 
273
						return -1;
-
 
274
					}
-
 
275
					return 0;
-
 
276
				});
-
 
277
				
-
 
278
				var s = '';
-
 
279
				for(i = 0; i < this.sections.length; i++)
-
 
280
				{
-
 
281
					this.sections[i].position = i;
-
 
282
 
-
 
283
 
-
 
284
					this.drawSection(this.sections[i].slug_section, this.sections[i].name, this.sections[i].value);
-
 
285
					
-
 
286
					
-
 
287
					this.sections[i].questions.sort(function(a, b) {
-
 
288
						if (a.position > b.position) {
-
 
289
								return 1;
-
 
290
						}
-
 
291
						if (a.position < b.position) {
-
 
292
							return -1;
-
 
293
						}
-
 
294
						return 0;
-
 
295
					});
-
 
296
					
-
 
297
					
-
 
298
					for(j = 0; j < this.sections[i].questions.length; j++)
-
 
299
					{
-
 
300
						this.sections[i].questions[j].position = j;
-
 
301
 
-
 
302
						this.drawQuestion( this.sections[i].slug_section, this.sections[i].questions[j].slug_question, this.sections[i].questions[j].text, this.sections[i].questions[j].value , this.sections[i].questions[j].type);
-
 
303
						if(this.sections[i].questions[j].type == 'simple' || this.sections[i].questions[j].type == 'multiple'|| this.sections[i].questions[j].type == 'rating-open') {
-
 
304
							
-
 
305
								
-
 
306
							this.sections[i].questions[j].options.sort(function(a, b) {
-
 
307
										if (a.position > b.position) {
-
 
308
												return 1;
-
 
309
										}
-
 
310
										if (a.position < b.position) {
-
 
311
											return -1;
-
 
312
										}
-
 
313
										return 0;
-
 
314
									});
-
 
315
								
-
 
316
							
-
 
317
							for(k = 0; k < this.sections[i].questions[j].options.length; k++)
-
 
318
							{
-
 
319
								this.sections[i].questions[j].options[k].position = j;
-
 
320
								this.drawOption(
-
 
321
									this.sections[i].slug_section, 
-
 
322
									this.sections[i].questions[j].slug_question,  
-
 
323
									this.sections[i].questions[j].type, 
-
 
324
									this.sections[i].questions[j].options[k].slug_option, 
-
 
325
									this.sections[i].questions[j].options[k].text, 
-
 
326
									this.sections[i].questions[j].options[k].type, 
-
 
327
									this.sections[i].questions[j].options[k].correct, 
-
 
328
									this.sections[i].questions[j].options[k].value
-
 
329
								);
-
 
330
							}
-
 
331
						}
-
 
332
 
-
 
333
					}
-
 
334
					
-
 
335
					
-
 
336
				}
-
 
337
 
-
 
338
				
-
 
339
				$('[data-toggle="tooltip"]').tooltip();
-
 
340
 
-
 
341
			},
-
 
342
 
-
 
343
			this.addSection = function (name, text, value)
79
			this.addSection = function (name, text, value)
344
			{
80
			{
345
				var d = new Date();
81
				var d = new Date();
346
					var slug = 'section' + d.getTime();
82
					var slug = 'section' + d.getTime();
Línea 359... Línea 95...
359
					'text' 		: text,
95
					'text' 		: text,
360
					'value' 	: value,
96
					'value' 	: value,
361
					'position' 	: position,
97
					'position' 	: position,
362
					'questions' : [],
98
					'questions' : [],
363
				}
99
				}
364
 
-
 
365
				this.sections.push(section);
100
				this.sections.push(section);
366
				this.drawSection(slug, name, text);
-
 
367
			},
101
			},
368
			this.editSection = function (slug, name, text, value)
102
			this.editSection = function (slug, name, text, value)
369
			{
103
			{
370
				var renderTable = false;
104
				var renderTable = false;
371
				for(i = 0; i < this.sections.length; i++) 
105
				for(i = 0; i < this.sections.length; i++) 
Línea 377... Línea 111...
377
							renderTable = true;
111
							renderTable = true;
Línea 378... Línea 112...
378
							
112
							
379
							break;
113
							break;
380
						}
114
						}
381
				}
-
 
382
				if(renderTable) {
-
 
383
					this.renderSection(slug);
-
 
Línea 384... Línea 115...
384
				}
115
				}
385
 
116
 
386
				
117
				
Línea 404... Línea 135...
404
				}
135
				}
405
			},
136
			},
406
			this.addQuestion = function (section_slug, text, value, type, maxlength, multiline, range) 
137
			this.addQuestion = function (section_slug, text, value, type, maxlength, multiline, range) 
407
			{
138
			{
408
				var d = new Date();
139
				var d = new Date();
409
				var slug = 'question' + d.getTime();
140
				var slug_question = 'question' + d.getTime();
Línea 410... Línea 141...
410
					
141
					
411
				var position = 0;
142
				var position = 0;
412
				var renderTable = false;
143
				var renderTable = false;
413
				for(i = 0; i < this.sections.length; i++)
144
				for(i = 0; i < this.sections.length; i++)
Línea 419... Línea 150...
419
							}
150
							}
420
						});
151
						});
421
						position++;
152
						position++;
Línea 422... Línea 153...
422
							
153
							
-
 
154
						var question = {
423
						var question = {
155
							'section_slug': section_slug,
424
							'slug_question' : slug,
156
							'slug_question' : slug_question,
425
								'text' : text,
157
								'text' : text,
426
								'value' : value,
158
								'value' : value,
427
								'type' : type,
159
								'type' : type,
428
								'position' : position,
160
								'position' : position,
Línea 435... Línea 167...
435
						renderTable = true;
167
						renderTable = true;
436
						break;
168
						break;
437
					}
169
					}
438
				}
170
				}
Línea 439... Línea -...
439
					
-
 
440
				if(renderTable) {
-
 
441
					this.renderSection(section_slug);
-
 
442
				}
171
					
443
			},
172
			},
444
			this.editQuestion = function(section_slug, question_slug, text, value, type, maxlength, multiline, range) 
173
			this.editQuestion = function(section_slug, question_slug, text, value, type, maxlength, multiline, range) 
445
			{
174
			{
446
				var renderTable = false;
175
				var renderTable = false;
Línea 474... Línea 203...
474
					}
203
					}
475
					if(renderTable) {
204
					if(renderTable) {
476
						break;
205
						break;
477
					}
206
					}
478
				}
207
				}
479
				if(renderTable) {
-
 
480
					this.renderSection(section_slug);
-
 
481
				}
-
 
482
			},
208
			},
483
			this.deleteQuestion = function(section_slug, question_slug)
209
			this.deleteQuestion = function(section_slug, question_slug)
484
			{
210
			{
485
				var renderTable = false;
211
				var renderTable = false;
486
				for(i = 0; i < this.sections.length; i++) 
212
				for(i = 0; i < this.sections.length; i++) 
Línea 497... Línea 223...
497
						
223
						
498
					if(renderTable) {
224
					if(renderTable) {
499
						break;
225
						break;
500
					}
226
					}
501
				}
-
 
502
				if(renderTable) {
-
 
503
					this.renderSection(section_slug);
-
 
504
				}
227
				}
505
			},
228
			},
506
			this.addOption = function (section_slug, question_slug, text, correct, value) 
229
			this.addOption = function (section_slug, question_slug, text, correct, value) 
507
			{
230
			{
508
				var d = new Date();
231
				var d = new Date();
Línea 509... Línea 232...
509
				var slug = 'option' + d.getTime();
232
				var slug_option = 'option' + d.getTime();
510
				
233
				
511
				var position = 0;
234
				var position = 0;
512
				var renderTable = false;
235
				var renderTable = false;
Línea 521... Línea 244...
521
										}
244
										}
522
									});
245
									});
523
									position++;
246
									position++;
Línea 524... Línea 247...
524
										
247
										
-
 
248
									var option = {
-
 
249
										'slug_section' : slug_section,
525
									var option = {
250
										'slug_question' : slug_question,
526
										'slug_option' : slug,
251
										'slug_option' : slug_option,
527
											'text' : text,
252
											'text' : text,
528
											'correct' : correct,
253
											'correct' : correct,
529
											'value' : value
254
											'value' : value
Línea 538... Línea 263...
538
								break;
263
								break;
539
							}
264
							}
540
						}
265
						}
541
					}
266
					}
542
				}
267
				}
543
				if(renderTable) {
-
 
544
					this.renderSection(section_slug);
-
 
545
				}
-
 
546
			},
268
			},
547
			this.editOption = function(section_slug, question_slug, option_slug, text, correct, value) 
269
			this.editOption = function(section_slug, question_slug, option_slug, text, correct, value) 
548
			{
270
			{
549
				var renderTable = false;
271
				var renderTable = false;
550
				for(i = 0; i < this.sections.length; i++)
272
				for(i = 0; i < this.sections.length; i++)
Línea 569... Línea 291...
569
					}
291
					}
570
						if(renderTable) {
292
						if(renderTable) {
571
							break;
293
							break;
572
						}
294
						}
573
				}
295
				}
574
					
296
				
575
				if(renderTable) {
-
 
576
					this.renderSection(section_slug);
-
 
577
				}
-
 
578
			},
297
			},
579
			this.deleteOption = function(section_slug, question_slug, option_slug)
298
			this.deleteOption = function(section_slug, question_slug, option_slug)
580
			{
299
			{
581
				var renderTable = false;
300
				var renderTable = false;
582
				for(i = 0; i < this.sections.length; i++) 
301
				for(i = 0; i < this.sections.length; i++) 
Línea 600... Línea 319...
600
						
319
						
601
					if(renderTable) {
320
					if(renderTable) {
602
						break;
321
						break;
603
					}
322
					}
604
				}
-
 
605
				if(renderTable) {
-
 
606
					this.renderSection(section_slug);
-
 
607
				}
323
				}
608
			}
324
			}
Línea 609... Línea 325...
609
		}
325
		}
610
 
326