Skip to content

Commit

Permalink
Dev: #11918: Removing jquery-ui ranking : fix for relevance
Browse files Browse the repository at this point in the history
  • Loading branch information
Shnoulle committed Nov 24, 2016
1 parent e8060d3 commit 36f3878
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 31 deletions.
2 changes: 1 addition & 1 deletion application/config/third_party.php
Expand Up @@ -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'])){
Expand Down
53 changes: 28 additions & 25 deletions application/core/packages/questions/ranking/ranking.js
Expand Up @@ -41,31 +41,33 @@ 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();

// 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);
});
}
Expand All @@ -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');
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
});
}
Expand Up @@ -24,7 +24,7 @@

<!-- answer -->
<div class="<?php echo $coreClass; ?>">
<ul class="list-unstyled test-ls-js-hidden-sr answers-list select-list form-horizontal" role="group" aria-labelledby="ls-question-text-<?php echo $basename; ?>">
<ul class="list-unstyled ls-js-hidden-sr answers-list select-list form-horizontal" role="group" aria-labelledby="ls-question-text-<?php echo $basename; ?>">
<?php
// rows/answer_row.php
echo $sSelects;
Expand Down
8 changes: 4 additions & 4 deletions third_party/rubaxa-sortable/jquery.fn.sortable.js
Expand Up @@ -450,11 +450,11 @@
}

try {
if (document.selection) {
// Timeout neccessary for IE9
if (document.selection) {
// Timeout neccessary for IE9
setTimeout(function () {
document.selection.empty();
});
});
} else {
window.getSelection().removeAllRanges();
}
Expand Down Expand Up @@ -1365,7 +1365,7 @@
};



This comment has been minimized.

Copy link
@Shnoulle

Shnoulle Nov 24, 2016

Author Collaborator

Don't open and save a third_party, even with "undo" you leave trace ;)



/**
Expand Down

0 comments on commit 36f3878

Please sign in to comment.