diff --git a/vendor/built_in_modules/survey/app/assets/javascripts/survey.js b/vendor/built_in_modules/survey/app/assets/javascripts/survey.js index 97f8f7b3b..0479e0a86 100644 --- a/vendor/built_in_modules/survey/app/assets/javascripts/survey.js +++ b/vendor/built_in_modules/survey/app/assets/javascripts/survey.js @@ -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(); }); diff --git a/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_questions.html.erb b/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_questions.html.erb index 151d29467..5bb7daf85 100644 --- a/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_questions.html.erb +++ b/vendor/built_in_modules/survey/app/views/panel/survey/back_end/surveys/_questions.html.erb @@ -1,11 +1,11 @@