delete and sequencing fixed for survey questions
This commit is contained in:
parent
dfec6f7642
commit
74ca99a581
|
@ -21,6 +21,7 @@ function setData(l, length, optionsI, className) {
|
|||
radiogroupsName = l+"][survey_question_radiogroups_attributes]["+optionsI+"][name_translations]";
|
||||
data = {
|
||||
_l: l,
|
||||
_ques: "new",
|
||||
_length: length,
|
||||
_className: className,
|
||||
_destroy: [id+l+"_destroy", name+l+"][_destroy]"],
|
||||
|
@ -48,6 +49,7 @@ function setEditData(l, length, d, optionsI, className) {
|
|||
radiogroupsName = l+"][survey_question_radiogroups_attributes]["+optionsI+"][name_translations]";
|
||||
data = {
|
||||
_l: l,
|
||||
_ques: "old",
|
||||
_length: length,
|
||||
_className: className,
|
||||
_destroy: [id+l+"__destroy", name+l+"][_destroy]"],
|
||||
|
@ -75,11 +77,14 @@ function setEditQuestionAttributes(l, length, d, optionsI, className) {
|
|||
radiogroupsID = l+"_survey_question_radiogroups_attributes_"+optionsI+"_name_translations_",
|
||||
radiogroupsName = l+"][survey_question_radiogroups_attributes]["+optionsI+"][name_translations]",
|
||||
option_id = l+"][survey_question_options_attributes]["+optionsI+"][id]",
|
||||
destroy = l+"][survey_question_options_attributes]["+optionsI+"][_destroy]",
|
||||
radiogroups_id = l+"][survey_question_radiogroups_attributes]["+optionsI+"][id]";
|
||||
data = {
|
||||
_l: l,
|
||||
_length: length,
|
||||
_ques: "old",
|
||||
_className: className,
|
||||
_destroy: [name+destroy],
|
||||
_option: [id+optionID, name+optionName, "attributes_"+l+"_options_"+optionsI+"_", d.name_translations],
|
||||
_radiogroups: [id+radiogroupsID, name+radiogroupsName, "attributes_"+l+"_radiogroups_"+optionsI+"_",d.name_translations],
|
||||
_options_id: [name+option_id,d._id],
|
||||
|
@ -93,7 +98,12 @@ function inputAppendLength(element, length) {
|
|||
if(length == 2) {
|
||||
element.closest('.add-target').find('.remove-input').addClass('hide').prev().addClass('last');
|
||||
}
|
||||
element.closest('.input-append').remove();
|
||||
var option = element.closest('.input-append');
|
||||
if( option.data( 'question-option' ) == "old" ){
|
||||
option.hide().removeAttr( 'question-option' ).find( "input.should_destroy_option" ).val("1");
|
||||
} else if( option.data( "question-option" ) == "new"){
|
||||
option.remove();
|
||||
}
|
||||
}
|
||||
|
||||
function editQuestion (dataArray){
|
||||
|
@ -165,7 +175,7 @@ $(function() {
|
|||
};
|
||||
});
|
||||
$('.add-question').on(clickEvent, function(event) {
|
||||
$('#template-survery').tmpl(setData(l, $('.questions > .attributes').length + 1)).appendTo($('.questions'));
|
||||
$('#template-survery').tmpl(setData(l, $('.questions > .attributes[data-question]').length + 1)).appendTo($('.questions'));
|
||||
checkQuestionsLength();
|
||||
textareaResizable(); // from textarea-lang-btn.js
|
||||
l += 1;
|
||||
|
@ -207,14 +217,26 @@ $(function() {
|
|||
inputAppendLength($(this), $(this).closest('.add-target').children('.input-append').length);
|
||||
} else if($(this).hasClass('delete')) {
|
||||
$(this).closest('.attributes').fadeOut(300, function() {
|
||||
$(this).hide();
|
||||
$( this ).find( '.should_destroy' ).val(1);
|
||||
checkQuestionsLength();
|
||||
$('.questions .attributes').each(function(index, el) {
|
||||
$( this ).find( "input.sequence" ).val( index );
|
||||
$( this ).find( "h4 span:eq(0)" ).text( index + 1 );
|
||||
$( this ).attr( "data-index", index );
|
||||
});
|
||||
if( $( this ).data( 'question' ) == "old" ){
|
||||
$(this).hide().removeAttr('data-question');
|
||||
$( this ).find( '.should_destroy' ).val(1);
|
||||
l--;
|
||||
checkQuestionsLength();
|
||||
$('.questions .attributes[data-question]').each(function(index, el) {
|
||||
$( this ).find( "input.sequence" ).val( index );
|
||||
$( this ).find( "h4 span:eq(0)" ).text( index + 1 );
|
||||
$( this ).attr( "data-index", index );
|
||||
});
|
||||
} else if( $( this ).data( 'question' ) == "new" ){
|
||||
$( this ).remove();
|
||||
l--;
|
||||
checkQuestionsLength();
|
||||
$('.questions .attributes[data-question]').each(function(index, el) {
|
||||
$( this ).find( "input.sequence" ).val( index );
|
||||
$( this ).find( "h4 span:eq(0)" ).text( index + 1 );
|
||||
$( this ).attr( "data-index", index );
|
||||
});
|
||||
}
|
||||
});
|
||||
} else if($(this).hasClass('icon-caret-up') || $(this).hasClass('icon-caret-down')) {
|
||||
if($(this).hasClass('icon-caret-up')) {
|
||||
|
@ -236,7 +258,7 @@ $(function() {
|
|||
$('#template-survery-option').tmpl(setData(_index, "", _i, _className)).insertBefore($(this).closest('.add-btn'));
|
||||
$(this).closest('.add-target').find('.input-append').find('.remove-input').removeClass('hide').prev().removeClass('last');
|
||||
_i += 1
|
||||
$(this).closest('.control-group').data('index', _i)
|
||||
$(this).closest('.control-group').data('index', _i);
|
||||
}
|
||||
event.preventDefault();
|
||||
});
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<script id="template-survery" type="text/x-tmpl">
|
||||
<div class="attributes" data-index="${_l}">
|
||||
<div class="attributes" data-index="${_l}" data-question="${_ques}">
|
||||
<div class="attributes-header clearfix">
|
||||
<a class="btn btn-mini pull-right btn-danger delete" href="#"><i class="icon-trash"></i> Delete</a>
|
||||
<input class="should_destroy" id="${_destroy[0]}" name="${_destroy[1]}" type="hidden">
|
||||
<input id="${_sequence[0]}" class="sequence" name="${_sequence[1]}" type="hidden" value="${_sequence[2]}">
|
||||
{{if _id}}
|
||||
<input id="${_id[0]}" class="sequence" name="${_id[1]}" type="hidden" value="${_id[2]}">
|
||||
<input id="${_id[0]}" name="${_id[1]}" type="hidden" value="${_id[2]}">
|
||||
{{/if}}
|
||||
<h4><b></b> Q<span>${_length}</span> <i class="icon-caret-up"></i> <span class="questions-title">${_title_translations[3].en}</span></h4>
|
||||
</div>
|
||||
|
@ -123,9 +123,10 @@
|
|||
|
||||
<script id="template-survery-option" type="text/x-tmpl">
|
||||
{{if _className == 'rgl'}}
|
||||
<div class="input-append">
|
||||
<div class="input-append" data-question-option="${_ques}">
|
||||
{{if _radiogroups_id}}
|
||||
<input type="hidden" value="${_radiogroups_id[1]}" name="${_radiogroups_id[0]}" />
|
||||
<input type="hidden" class="should_destroy_option" name="${_destroy[0]}" />
|
||||
{{/if}}
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane fade active in" id="${_radiogroups[2]+'en'}">
|
||||
|
@ -144,9 +145,10 @@
|
|||
</div>
|
||||
</div>
|
||||
{{else}}
|
||||
<div class="input-append">
|
||||
<div class="input-append" data-question-option="${_ques}">
|
||||
{{if _options_id}}
|
||||
<input type="hidden" value="${_options_id[1]}" name="${_options_id[0]}" />
|
||||
<input type="hidden" class="should_destroy_option" name="${_destroy[0]}" />
|
||||
{{/if}}
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane fade active in" id="${_option[2]+'en'}">
|
||||
|
|
Loading…
Reference in New Issue