From 1e3cffee0a54a29b5a63bf90f5cc6842c11d9946 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Tue, 17 Sep 2013 15:11:59 +0800 Subject: [PATCH] add page completed with attributes and reordering --- .../survey/app/assets/javascripts/survey.js | 16 +++++++++++++--- .../survey/back_end/surveys/_questions.html.erb | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) 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 e6f6f2c8..cce9ad63 100644 --- a/vendor/built_in_modules/survey/app/assets/javascripts/survey.js +++ b/vendor/built_in_modules/survey/app/assets/javascripts/survey.js @@ -8,7 +8,6 @@ function checkQuestionsLength() { }; }; - // Role Attribute Template Data function setData(l, length, optionsI, className) { if(!optionsI) { @@ -104,6 +103,15 @@ $(function() { event.preventDefault(); /* Act on the event */ }); + $(".questions").sortable({ + update : function ( event, ui ){ + $(".questions .attributes").each( function ( i ){ + $( this ).find( "input.sequence" ).val( i ); + $( this ).find( "h4 span:eq(0)" ).text( i + 1 ); + $( this ).attr( "data-index", i ); + }) + } + }); $('.questions').on(clickEvent, '.add-btn a, .remove-input, .delete, .attributes-header h4 i, .btn-group .btn', function(event) { if($(this).hasClass('remove-input')){ @@ -113,7 +121,7 @@ $(function() { $(this).remove(); checkQuestionsLength(); $('.questions > .attributes').each(function(index, el) { - $(this).find('h4').find('span').text(index + 1); + $(this).find('h4').find('span:eq(0)').text(index + 1); }); }); } else if($(this).hasClass('icon-caret-up') || $(this).hasClass('icon-caret-down')) { @@ -129,13 +137,15 @@ $(function() { $tabPane = $(this).closest('.btn-group').siblings('.tab-content'); $questionsTitle.text($tabPane.find('div').not('.active').children('input[type="text"]').val()) } else { - var _i = $('.questions .attributes').length, + var _i = $(this).closest('.control-group').data('index') || 1, _className = $(this).closest('.control-group').attr('class').match(/options|rgl/g)[0], _index = $(this).closest('.attributes').data().index, _length = $(this).closest('.add-btn').siblings('.input-append').length; console.log(_i) $('#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) } 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 b6817a48..1ab01ad4 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 @@ -3,7 +3,7 @@
Delete - +

Q${_length}