Skip to content

Commit

Permalink
Dev: Fixed issue : 5 point radio have value 6 for no-answer ...
Browse files Browse the repository at this point in the history
  • Loading branch information
Shnoulle committed Oct 31, 2016
1 parent 0bfb1c6 commit 454fda7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 34 deletions.
2 changes: 1 addition & 1 deletion application/helpers/qanda_helper.php
Expand Up @@ -887,7 +887,7 @@ function do_5pointchoice($ia)
}
$aData = array(
'name' => $ia[1],
'value' => $fp,
'value' => "",
'id' => $ia[1],
'labelText' => gT('No answer'),
'itemExtraClass' => 'noanswer-item',
Expand Down
16 changes: 10 additions & 6 deletions scripts/slider-rating.js
Expand Up @@ -52,10 +52,11 @@ function getRatingSlider(qID){
},
//Method setting the value on the EM-calculateable part
setValueAndColorize = function(index){
answersList.find('input[type=radio][value='+index+']').prop('checked',true).trigger('click');
answersList.find('input[type=radio][value='+index+']').trigger('click');
$("#emoji_slider_container_"+qID).find(".slider-label").find('i').removeClass('emoji-color'); //remove all other color-classes
if(index==6){ //if it is the "no Answer" set, add text-danger instead of emoji-color
$("#emoji_slider_container_"+qID).find(".slider-label-"+index).find('i').addClass('text-danger');
$("#emoji_slider_container_"+qID).find(".slider-label-6").find('i').addClass('text-danger');
answersList.find('input[type=radio][value=""]').trigger('click');
} else {
$("#emoji_slider_container_"+qID).find(".slider-label-6").find('i').removeClass('text-danger');
$("#emoji_slider_container_"+qID).find(".slider-label-"+index).find('i').addClass('emoji-color');
Expand All @@ -81,7 +82,7 @@ function getRatingSlider(qID){
return (answersList.find('.noanswer-item').length > 0);
},
checkOpenValue = function(){
var openValue = answersList.find("input:radio:checked").val() || (checkHasNoAnswerOption() ? 6 : 1); //Select either noAnswer, or the preselected
var openValue = (answersList.find("input:radio:checked").val() || 0)*1; //Select either noAnswer, or the preselected
return openValue || false;
},
relativeOffset = function(rawOffset){
Expand Down Expand Up @@ -117,7 +118,7 @@ function getRatingSlider(qID){
//Register the events
bindEventsToContainer = function(){
//Register the click event on the slider container
//this event will trigger when the slider area is clicked,
//this event will trigger when the slider area is clicked,
//to move the slider to where the click was generated
$("#emoji_slider_grab_container_"+qID).on('click', onSetHandlePosition );
//Registers to the event, when the handle is dragged.
Expand Down Expand Up @@ -145,7 +146,7 @@ function getRatingSlider(qID){
}
//append the colored line on the bottom
package.sliderGrabContainer.append(package.sliderLine);
//append the handle
//append the handle
package.sliderGrabContainer.append(package.sliderHandle);

//Append things to the main elemen
Expand All @@ -168,7 +169,10 @@ function getRatingSlider(qID){
if(openValue){
setValueAndColorize(openValue);
setSliderPosition(getSliderPositionFromIndex(openValue), package.sliderGrabContainer);
}
}else if(checkHasNoAnswerOption()){
setValueAndColorize(6);
setSliderPosition(getSliderPositionFromIndex(6), package.sliderGrabContainer);
}
}

return doRatingSlider;
Expand Down
24 changes: 9 additions & 15 deletions scripts/star-rating.js
Expand Up @@ -9,7 +9,7 @@
*
* @author Denis Chenu (Shnoulle)
* @author Markus Fluer (lacrioque)
*
*
* @param {number} qId The qid of the question where apply.
*/
function doRatingStar(qID) {
Expand All @@ -33,26 +33,20 @@ function doRatingStar(qID) {
//Define stars-element container
var starsHtmlElement=$("<div class='stars-list answers-list noread' ></div>");

//Check if there is a given answer
var openValue=answersList.find("input:radio:checked").val();

//Reset openValue to null, when no Answer is chosen
if(openValue == numberOfPossibleAnswers){
openValue = null;
}

//Check if there is a given answer : set itto 0 if '' or null
var openValue=(answersList.find("input:radio:checked").val() || 0)*1;
//Add no-answer-option to stars List
if(itemNoAnswer){
if(itemNoAnswer){
starsHtmlElement
.append("<div class='star-rating star-cancel' data-star='"+(numberOfPossibleAnswers)+"' title='"+$('#question'+qID+' .noanswer-item label').html()+"'><i class='fa fa-ban'></i></div>");
.append("<div class='star-rating star-cancel' data-star='' title='"+$('#question'+qID+' .noanswer-item label').html()+"'><i class='fa fa-ban'></i></div>");
} else {
numberOfPossibleAnswers++;
}

//Add stars to the container
for (i=1; i<numberOfPossibleAnswers; i++) {
//if there is a selected answer, add the fitting classes
var classes = openValue!=null ? "star-rated-on star-rating star " : "star-rating star ";
var classes = openValue!="" ? "star-rated-on star-rating star " : "star-rating star ";
//light all stars lower thgan the selected
if(i<=openValue){
classes+=" star-rated";
Expand All @@ -76,7 +70,7 @@ function doRatingStar(qID) {
//add/remove classes from sibling-elements
$(this).siblings('.star-rating').each(function(){
//smaller than the chosen and not "no answer" => add class to emphasize them
if($(this).data('star') < thisnum && thisnum != numberOfPossibleAnswers){
if($(this).data('star') < thisnum && thisnum != numberOfPossibleAnswers){
$(this).addClass("star-drained");
} else {
$(this).addClass("star-stub");
Expand Down Expand Up @@ -106,11 +100,11 @@ function doRatingStar(qID) {
$(this).addClass("star-rated").addClass("star-thisrated").addClass("star-rated-on");
//iterate through the siblings to mark the stars lower than the current
$(this).siblings('.star-rating').each(function(){
if($(this).data("star") < thischoice){
if($(this).data("star") < thischoice){
$(this).addClass("star-rated").addClass("star-rated-on");
}
});
// if cancel, remove all classes
// if cancel, remove all classes
if($(this).hasClass('star-cancel')){
$(this).siblings('.star-rating').removeClass("star-rated-on").removeClass("star-rated");
}
Expand Down
12 changes: 0 additions & 12 deletions tmp/assets/index.html

This file was deleted.

0 comments on commit 454fda7

Please sign in to comment.