Index: lams_central/web/includes/javascript/rating.js =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/includes/javascript/rating.js,v diff -u -r1.1.2.2 -r1.1.2.3 --- lams_central/web/includes/javascript/rating.js 15 Jun 2015 22:42:48 -0000 1.1.2.2 +++ lams_central/web/includes/javascript/rating.js 14 Sep 2015 10:19:50 -0000 1.1.2.3 @@ -1,41 +1,46 @@ -//Please, set up LAMS_URL, COUNT_RATED_ITEMS, COMMENTS_MIN_WORDS_LIMIT, MAX_RATES and MIN_RATES, +//Please, set up LAMS_URL, COUNT_RATED_ITEMS, COMMENTS_MIN_WORDS_LIMIT, MAX_RATES and MIN_RATES, MAX_RATINGS_FOR_ITEM, //COMMENT_TEXTAREA_TIP_LABEL, WARN_COMMENTS_IS_BLANK_LABEL, WARN_MIN_NUMBER_WORDS_LABEL constants in parent document //constant indicating there is rting limits set up var HAS_RATING_LIMITS; $(document).ready(function(){ HAS_RATING_LIMITS = MAX_RATES!=0 || MIN_RATES!=0; - + initializeJRating(); //check minimum rates limit initially if (MIN_RATES != 0) { checkMinimumRatesLimit(COUNT_RATED_ITEMS); } + }); -//initialize jRating and post comment button +//initialize jRating and post comment button. Note: we need the quotes around undefined for the typeof ! function initializeJRating() { + + var maxRatingsForItem; + if ( typeof MAX_RATINGS_FOR_ITEM === "undefined" || MAX_RATINGS_FOR_ITEM === undefined ) + maxRatingsForItem = ""; + else + maxRatingsForItem = MAX_RATINGS_FOR_ITEM; $(".rating-stars-new").filter($(".rating-stars")).jRating({ - phpPath : LAMS_URL + "servlet/rateItem?hasRatingLimits=" + HAS_RATING_LIMITS, + phpPath : LAMS_URL + "servlet/rateItem?hasRatingLimits=" + HAS_RATING_LIMITS+"&maxRatingsForItem="+maxRatingsForItem, rateMax : 5, decimalLength : 1, onSuccess : function(data, itemId){ - $("#user-rating-" + itemId).html(data.userRating); $("#average-rating-" + itemId).html(data.averageRating); $("#number-of-votes-" + itemId).html(data.numberOfVotes); $("#rating-stars-caption-" + itemId).css("visibility", "visible"); //handle rating limits if available handleRatingLimits(data.countRatedItems); - }, onError : function(){ - jError('Error. Please, retry'); + handleError(); } }); @@ -82,25 +87,31 @@ data: { idBox: commentsCriteriaId + '-' + itemId, comment: comment, - hasRatingLimits: HAS_RATING_LIMITS + hasRatingLimits: HAS_RATING_LIMITS, + maxRatingsForItem: MAX_RATINGS_FOR_ITEM }, success: function(data, textStatus) { - - //add comment to HTML - jQuery('
', { - 'class': "rating-comment", - html: data.comment - }).appendTo('#comments-area-' + itemId); - - //hide comments textarea and button - $("#add-comment-area-" + itemId).hide(); - - //handle rating limits if available - if (HAS_RATING_LIMITS) { - handleRatingLimits(data.countRatedItems); - } - - } + if ( data.error ) { + handleError(); + } else { + //add comment to HTML + jQuery('', { + 'class': "rating-comment", + html: data.comment + }).appendTo('#comments-area-' + itemId); + + //hide comments textarea and button + $("#add-comment-area-" + itemId).hide(); + + //handle rating limits if available + if (HAS_RATING_LIMITS) { + handleRatingLimits(data.countRatedItems); + } + } + }, + onError : function(){ + handleError(); + } }); //apply only once }).removeClass("add-comment-new"); @@ -139,4 +150,13 @@ function checkMinimumRatesLimit(countRatedItems) { $( "#learner-submit" ).toggle( countRatedItems >= MIN_RATES ); -} \ No newline at end of file +} + +function handleError() { + //callback function + if (typeof onRatingErrorCallback === "function") { + onRatingErrorCallback(); + } else { + alert("Error saving rating. Please retry."); + } +}