From 36f3878dbd44ba42b55d4d3d8895710ca0909a6d Mon Sep 17 00:00:00 2001 From: Denis Chenu Date: Thu, 24 Nov 2016 15:24:32 +0100 Subject: [PATCH] Dev: #11918: Removing jquery-ui ranking : fix for relevance --- application/config/third_party.php | 2 +- .../packages/questions/ranking/ranking.js | 53 ++++++++++--------- .../questions/answer/ranking/answer.php | 2 +- .../rubaxa-sortable/jquery.fn.sortable.js | 8 +-- 4 files changed, 34 insertions(+), 31 deletions(-) diff --git a/application/config/third_party.php b/application/config/third_party.php index d50b6532839..4703210d775 100755 --- a/application/config/third_party.php +++ b/application/config/third_party.php @@ -8,7 +8,7 @@ /* This allow us to use minified version according to debug */ $debug = isset($userConfig['config']['debug']) ? $userConfig['config']['debug'] : 0; /* To add more easily min version */ -$minVersion = ($debug<=2) ? ".min": ""; +$minVersion = ($debug<2) ? ".min": ""; /* Please : comment the reason, mantis bug link: ajax don't need any package if i don't make error */ /* Ajax must renderPartial (better : always return json) and never render and don't registerScript (IMHO) / Shnoulle on 2016-11-16 */ if(isset($_GET['isAjax'])){ diff --git a/application/core/packages/questions/ranking/ranking.js b/application/core/packages/questions/ranking/ranking.js index 0914da0869d..9afa05448c0 100644 --- a/application/core/packages/questions/ranking/ranking.js +++ b/application/core/packages/questions/ranking/ranking.js @@ -41,7 +41,13 @@ function doDragDropRank(qID, showpopups, samechoiceheight, samelistheight) { group: "sortable-"+qID, ghostClass: "ls-rank-placeholder", onSort: function (evt) { - updateDragDropRank(qID); + if($(evt.item).hasClass("disabled")){ + /* see https://github.com/RubaXa/Sortable/issues/933 */ + $(evt.item).appendTo('#sortable-choice-'+qID); + /* send a console notice 'from is undefined' in jquery.fn.sortable : must fix Sortable before */ + }else{ + updateDragDropRank(qID); + } } }); $('#question'+qID+' .ls-remove').remove(); @@ -49,23 +55,19 @@ function doDragDropRank(qID, showpopups, samechoiceheight, samelistheight) { // Adapt choice and list height fixChoiceListHeight(qID,samechoiceheight,samelistheight); // Allow users to double click to move to selections from list to list - $('#sortable-choice-'+qID).delegate('li','dblclick', function() { + $('#sortable-choice-'+qID).on('dblclick','li:not(.disabled)', function() { maxanswers=parseInt($("#ranking-"+qID+"-maxans").text().trim(),10); if($(maxanswers>0 && '#sortable-rank-'+qID+' li').length >= maxanswers) { sortableAlert (qID,showpopups,maxanswers); - if(showpopups){return false;} + return false; } else { $(this).appendTo('#sortable-rank-'+qID+''); - $('#sortable-choice-'+qID+'').sortable('refresh'); - $('#sortable-rank-'+qID+'').sortable('refresh'); } updateDragDropRank(qID); }); - $('#sortable-rank-'+qID).delegate('li','dblclick', function() { + $('#sortable-rank-'+qID).on('dblclick','li', function() { $(this).appendTo('#sortable-choice-'+qID+''); - $('#sortable-choice-'+qID+'').sortable('refresh'); - $('#sortable-rank-'+qID+'').sortable('refresh'); updateDragDropRank(qID); }); } @@ -76,16 +78,11 @@ function doDragDropRank(qID, showpopups, samechoiceheight, samelistheight) { * @param {number} qId The qid of the question where apply. */ function updateDragDropRank(qID){ - var maxanswers= parseInt($("#ranking-"+qID+"-maxans").text().trim(),10); - var rankingname= "javatbd"+$("#ranking-"+qID+"-name").text().trim(); - var relevancename= "relevance"+$("#ranking-"+qID+"-name").text().trim(); - var rankingnamewidth=rankingname.length; + var maxanswers= parseInt($("#ranking-"+qID+"-maxans").text().trim(),10); + var relevancename= "relevance"+$("#ranking-"+qID+"-name").text().trim(); $('#question'+qID+' .select-item select').val(''); $('#sortable-rank-'+qID+' li').each(function(index) { - // Get value of ranked item - var liID = $(this).attr("id"); - liValue = liID.substr(rankingnamewidth); - $('#question'+qID+' .select-item select').eq(index).val(liValue); + $('#question'+qID+' .select-item select').eq(index).val($(this).data("value")); }); // Update #relevance and lauch checkconditions function $("[id^=" + relevancename + "]").val('0'); @@ -97,9 +94,9 @@ function updateDragDropRank(qID){ } $(this).trigger("change",{ source : 'dragdrop'}); }); - $('#sortable-rank-'+qID+' li').removeClass("text-error"); - $('#sortable-choice-'+qID+' li').removeClass("text-error"); - $('#sortable-rank-'+qID+' li:gt('+(maxanswers*1-1)+')').addClass("text-error"); + $('#sortable-rank-'+qID+' li').removeClass("text-error"); + $('#sortable-choice-'+qID+' li').removeClass("text-error"); + $('#sortable-rank-'+qID+' li:gt('+(maxanswers*1-1)+')').addClass("text-error"); } /** * Show an alert if needed @@ -176,15 +173,21 @@ function fixChoiceListHeight(qID,samechoiceheight,samelistheight){ function triggerEmRelevanceSortable() { $(".sortable-item").on('relevance:on',function(event,data) { - if(event.target != this) return; // not needed now, but after maybe (2016-11-07) - data = $.extend({style:'hidden'}, data); + //~ if(event.target != this) return; // not needed now, but after maybe (2016-11-07) + //~ data = $.extend({style:'hidden'}, data); $(event.target).closest(".ls-answers").find("option[value="+$(event.target).data("value")+"]").prop('disabled',false); - $(event.target).removeClass("disabled").prop('disabled',false); + $(event.target).removeClass("disabled"); }); $(".sortable-item").on('relevance:off',function(event,data) { - if(event.target != this) return; // not needed now, but after maybe (2016-11-07) - data = $.extend({style:'hidden'}, data); + //~ if(event.target != this) return; // not needed now, but after maybe (2016-11-07) + //~ data = $.extend({style:'hidden'}, data); $(event.target).closest(".ls-answers").find("option[value="+$(event.target).data("value")+"]").prop('disabled',true); - $(event.target).addClass("disabled").prop('disabled',true); + $(event.target).addClass("disabled"); + /* reset already ranked item */ + if($(event.target).parent().hasClass("sortable-rank")){ + $(event.target).appendTo($(event.target).closest(".answers-list").find(".sortable-choice")); + var qID=$(event.target).closest("[id^='question']").attr('id').replace("question",""); + updateDragDropRank(qID); + } }); } diff --git a/application/views/survey/questions/answer/ranking/answer.php b/application/views/survey/questions/answer/ranking/answer.php index 23c115b865a..abff875d586 100644 --- a/application/views/survey/questions/answer/ranking/answer.php +++ b/application/views/survey/questions/answer/ranking/answer.php @@ -24,7 +24,7 @@
-