Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 163 Rev 164
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);
78
			}
218
			},
-
 
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
 
79
			this.addSection = function (name, text, value)
343
			this.addSection = function (name, text, value)
80
			{
344
			{
81
				var d = new Date();
345
				var d = new Date();
82
					var slug = 'section' + d.getTime();
346
					var slug = 'section' + d.getTime();
Línea 95... Línea 359...
95
					'text' 		: text,
359
					'text' 		: text,
96
					'value' 	: value,
360
					'value' 	: value,
97
					'position' 	: position,
361
					'position' 	: position,
98
					'questions' : [],
362
					'questions' : [],
99
				}
363
				}
-
 
364
 
100
				this.sections.push(section);
365
				this.sections.push(section);
-
 
366
				this.drawSection(slug, name, text);
101
			},
367
			},
102
			this.editSection = function (slug, name, text, value)
368
			this.editSection = function (slug, name, text, value)
103
			{
369
			{
104
				var renderTable = false;
370
				var renderTable = false;
105
				for(i = 0; i < this.sections.length; i++) 
371
				for(i = 0; i < this.sections.length; i++) 
Línea 111... Línea 377...
111
							renderTable = true;
377
							renderTable = true;
Línea 112... Línea 378...
112
							
378
							
113
							break;
379
							break;
114
						}
380
						}
-
 
381
				}
-
 
382
				if(renderTable) {
-
 
383
					this.renderSection(slug);
Línea 115... Línea 384...
115
				}
384
				}
116
 
385
 
117
				
386
				
Línea 167... Línea 436...
167
						renderTable = true;
436
						renderTable = true;
168
						break;
437
						break;
169
					}
438
					}
170
				}
439
				}
Línea -... Línea 440...
-
 
440
					
-
 
441
				if(renderTable) {
-
 
442
					this.renderSection(section_slug);
171
					
443
				}
172
			},
444
			},
173
			this.editQuestion = function(section_slug, question_slug, text, value, type, maxlength, multiline, range) 
445
			this.editQuestion = function(section_slug, question_slug, text, value, type, maxlength, multiline, range) 
174
			{
446
			{
175
				var renderTable = false;
447
				var renderTable = false;
Línea 203... Línea 475...
203
					}
475
					}
204
					if(renderTable) {
476
					if(renderTable) {
205
						break;
477
						break;
206
					}
478
					}
207
				}
479
				}
-
 
480
				if(renderTable) {
-
 
481
					this.renderSection(section_slug);
-
 
482
				}
208
			},
483
			},
209
			this.deleteQuestion = function(section_slug, question_slug)
484
			this.deleteQuestion = function(section_slug, question_slug)
210
			{
485
			{
211
				var renderTable = false;
486
				var renderTable = false;
212
				for(i = 0; i < this.sections.length; i++) 
487
				for(i = 0; i < this.sections.length; i++) 
Línea 223... Línea 498...
223
						
498
						
224
					if(renderTable) {
499
					if(renderTable) {
225
						break;
500
						break;
226
					}
501
					}
-
 
502
				}
-
 
503
				if(renderTable) {
-
 
504
					this.renderSection(section_slug);
227
				}
505
				}
228
			},
506
			},
229
			this.addOption = function (section_slug, question_slug, text, correct, value) 
507
			this.addOption = function (section_slug, question_slug, text, correct, value) 
230
			{
508
			{
231
				var d = new Date();
509
				var d = new Date();
Línea 263... Línea 541...
263
								break;
541
								break;
264
							}
542
							}
265
						}
543
						}
266
					}
544
					}
267
				}
545
				}
-
 
546
				if(renderTable) {
-
 
547
					this.renderSection(section_slug);
-
 
548
				}
268
			},
549
			},
269
			this.editOption = function(section_slug, question_slug, option_slug, text, correct, value) 
550
			this.editOption = function(section_slug, question_slug, option_slug, text, correct, value) 
270
			{
551
			{
271
				var renderTable = false;
552
				var renderTable = false;
272
				for(i = 0; i < this.sections.length; i++)
553
				for(i = 0; i < this.sections.length; i++)
Línea 291... Línea 572...
291
					}
572
					}
292
						if(renderTable) {
573
						if(renderTable) {
293
							break;
574
							break;
294
						}
575
						}
295
				}
576
				}
296
				
577
					
-
 
578
				if(renderTable) {
-
 
579
					this.renderSection(section_slug);
-
 
580
				}
297
			},
581
			},
298
			this.deleteOption = function(section_slug, question_slug, option_slug)
582
			this.deleteOption = function(section_slug, question_slug, option_slug)
299
			{
583
			{
300
				var renderTable = false;
584
				var renderTable = false;
301
				for(i = 0; i < this.sections.length; i++) 
585
				for(i = 0; i < this.sections.length; i++) 
Línea 319... Línea 603...
319
						
603
						
320
					if(renderTable) {
604
					if(renderTable) {
321
						break;
605
						break;
322
					}
606
					}
-
 
607
				}
-
 
608
				if(renderTable) {
-
 
609
					this.renderSection(section_slug);
323
				}
610
				}
324
			}
611
			}
Línea 325... Línea 612...
325
		}
612
		}
326
 
613