You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
3.1 KiB
71 lines
3.1 KiB
{% if tarea[0].alias=='exercise9a'%}
|
|
function onChange(){
|
|
$('#segmentos').val('{{segmentos|json_encode|raw}}');
|
|
$("select[name^='ex9bpreg200']").each(function(index){
|
|
var segmentos=JSON.parse($('#segmentos').val());
|
|
var remove=$(this).val();
|
|
if(remove!=null){
|
|
segmentos = segmentos.filter(x => !remove.includes(x));
|
|
$('#segmentos').val(JSON.stringify( segmentos ))
|
|
}
|
|
});
|
|
$("select[name^='ex9bpreg200']").each(function(index){
|
|
var this_values = $(this).val();
|
|
var segmentos=JSON.parse($('#segmentos').val());
|
|
var int=0;
|
|
var data="[";
|
|
for(int=0;int<this_values.length;int++){
|
|
data+=`{id:`+int+`, text:"`+ this_values[int]+`"},`;
|
|
}
|
|
for(i=0;i<segmentos.length;i++){
|
|
int=int+i;
|
|
data+=`{id:`+int+`, text:"`+ segmentos[i]+`"},`;
|
|
}
|
|
data=data.slice(0, -1)+"]";
|
|
$(this).select3({
|
|
placeholder: "Select a Customer segment",
|
|
data: function() { return {results: data}; }
|
|
});
|
|
});
|
|
}
|
|
function addRow(table){
|
|
var rowCount = table.find("tbody").find("tr").length;
|
|
console.log(rowCount);
|
|
$('#segmentos').val('{{segmentos|json_encode|raw}}')
|
|
$("select[name^='ex9bpreg200']").each(function(index){
|
|
var segmentos=JSON.parse($('#segmentos').val());
|
|
console.log(segmentos);
|
|
var remove=$(this).val();
|
|
console.log(remove);
|
|
if(remove!=null){
|
|
segmentos = segmentos.filter(x => !remove.includes(x));
|
|
console.log(segmentos);
|
|
$('#segmentos').val(JSON.stringify( segmentos ))
|
|
}
|
|
});
|
|
if($('#segmentos').val()=="[]"){
|
|
Swal.fire("{{'Good job!'|trans({})}}", "{{'You asigned all stakeolders'|trans({})}}", "success");
|
|
|
|
}else{
|
|
var input='<tr>';
|
|
{% for pregunta in tarea[0].PreguntasId %}
|
|
{% if pregunta.alias=='ex9bpreg20' %}
|
|
input+=`<td><textarea class="form-control" id="{{ pregunta.alias }}-`+rowCount+`" name="{{ pregunta.alias }}[]" placeholder="{{ pregunta.placeholder|trans({}) }}" {% if not pregunta.editable and 'caso_estudio' not in app.user.username %} readonly {% endif %} rows="10"></textarea></td>`;
|
|
{% elseif pregunta.alias=='ex9bpreg200' %}
|
|
input+=`<td><select data-sonata-select2="false" class="js-example-basic-multiple" id="{{ pregunta.alias }}-`+rowCount+`" name="{{ pregunta.alias }}[`+rowCount+`][]" {% if not pregunta.editable and 'caso_estudio' not in app.user.username %} readonly {% endif %} multiple=[true] style="width: 80%;">`;
|
|
var segmentos=JSON.parse($('#segmentos').val()); for(i=0;i<segmentos.length;i++){
|
|
input+=`<option value="`+segmentos[i]+`">`+segmentos[i]+`</option>`;
|
|
}
|
|
input+=`</select>
|
|
</td><td><button type="button" class="btn btn-warning delete-row" onclick="$(this).parents('tr').remove();onChange()">Delete Row</button></td>`;
|
|
|
|
{% endif %}
|
|
{% endfor %}
|
|
input+=`</tr>`;
|
|
table.append(input);
|
|
$("#ex9bpreg200-"+rowCount).select3();
|
|
setTimeout(function(){ $("#ex9bpreg200-0").next().next().remove();}, 2000);
|
|
|
|
}
|
|
}
|
|
{% endif %}
|