Index: lams_central/web/includes/javascript/rating.js =================================================================== diff -u -rcd0c6b460931a29fe23e60bca05d343b935defd8 -rad572fe631188a44a1b0976295ee33af9919ed78 --- lams_central/web/includes/javascript/rating.js (.../rating.js) (revision cd0c6b460931a29fe23e60bca05d343b935defd8) +++ lams_central/web/includes/javascript/rating.js (.../rating.js) (revision ad572fe631188a44a1b0976295ee33af9919ed78) @@ -5,6 +5,11 @@ //constant indicating there is rting limits set up var HAS_RATING_LIMITS; +// Which ones are being rated by the current user? Needed to control what is disabled when the max number of ratings is reached +// when there is a "set" of criteria for each user e.g. one or more criteria and/or a comment. +// Only needed when MAX_RATES > 0 +var idsBeingRated = []; + $(document).ready(function(){ HAS_RATING_LIMITS = MAX_RATES!=0 || MIN_RATES!=0; @@ -37,7 +42,7 @@ $("#rating-stars-caption-" + itemId).css("visibility", "visible"); //handle rating limits if available - handleRatingLimits(data.countRatedItems); + handleRatingLimits(data.countRatedItems, itemId); }, onError : function(){ handleError(); @@ -105,7 +110,7 @@ //handle rating limits if available if (HAS_RATING_LIMITS) { - handleRatingLimits(data.countRatedItems); + handleRatingLimits(data.countRatedItems, itemId); } } }, @@ -117,34 +122,57 @@ }).removeClass("add-comment-new"); } -function handleRatingLimits(countRatedItems) { +// If the call is from a rating then it is ratingCriteriaId-itemId format string, otherwise a comment +// only returns itemId as a number. Pull a string version of itemId of this. +function getItemIdFromObjectId(objectId) { + var str = String(objectId); + var i = str.indexOf('-'); + if ( i >= 0 ) + return str.substr(i+1); + else + return str; +} + +function handleRatingLimits(countRatedItems, objectId) { if (HAS_RATING_LIMITS) { //update info box $("#count-rated-items").html(countRatedItems); - + //callback function - if (typeof onRatingSuccessCallback === "function") { + if (typeof onRatingSuccessCallback === "function") { // safe to use the function - onRatingSuccessCallback(countRatedItems); + onRatingSuccessCallback(countRatedItems, objectId); } - //handle max rates limit + //handle max rates limit if (MAX_RATES != 0) { + + // add the latest itemId to idsBeingRated *before* doing the disabling or this one will be disabled + var newItemId = getItemIdFromObjectId(objectId); + if ( idsBeingRated.indexOf(newItemId) == -1 ) + idsBeingRated.push(newItemId) - //disable rating feature in case MAX_RATES limit reached + //disable rating features in case MAX_RATES limit reached *except for the ones user is already rating* if (countRatedItems >= MAX_RATES) { $(".rating-stars").each(function() { - $(this).unbind().css('cursor','default').addClass('jDisabled'); - }); + if ( ! $(this).hasClass('jDisabled') ) { + var itemId = getItemIdFromObjectId($(this).attr('data-id')); + if ( idsBeingRated.indexOf(itemId) == -1 ) { + $(this).unbind().css('cursor','default').addClass('jDisabled'); + $('#add-comment-area-' + itemId).children().remove(); + } + } + }); } } - + //handle min rates limit if (MIN_RATES != 0) { - checkMinimumRatesLimit(countRatedItems) + checkMinimumRatesLimit(countRatedItems); } + } } Index: lams_tool_images/web/WEB-INF/tags/Rating.tag =================================================================== diff -u -r434a2aec5c62876edcb6dc8908896939080f1cf2 -rad572fe631188a44a1b0976295ee33af9919ed78 --- lams_tool_images/web/WEB-INF/tags/Rating.tag (.../Rating.tag) (revision 434a2aec5c62876edcb6dc8908896939080f1cf2) +++ lams_tool_images/web/WEB-INF/tags/Rating.tag (.../Rating.tag) (revision ad572fe631188a44a1b0976295ee33af9919ed78) @@ -52,16 +52,32 @@ + + + + + + + + + <%--Rating stars area---------------------------------------%>
+ + + + + + + - + @@ -133,13 +149,6 @@
- - - - - - - @@ -155,7 +164,7 @@
- +
Index: lams_tool_laqa/web/WEB-INF/tags/Rating.tag =================================================================== diff -u -rf0d95ac841b3ce978e6d7c49ccdc3501c0158e30 -rad572fe631188a44a1b0976295ee33af9919ed78 --- lams_tool_laqa/web/WEB-INF/tags/Rating.tag (.../Rating.tag) (revision f0d95ac841b3ce978e6d7c49ccdc3501c0158e30) +++ lams_tool_laqa/web/WEB-INF/tags/Rating.tag (.../Rating.tag) (revision ad572fe631188a44a1b0976295ee33af9919ed78) @@ -52,16 +52,32 @@ + + + + + + + + + <%--Rating stars area---------------------------------------%>
+ + + + + + + - + @@ -133,13 +149,6 @@
- - - - - - - @@ -155,7 +164,7 @@
- +
Index: lams_tool_laqa/web/learning/LearnerRep.jsp =================================================================== diff -u -r16415cf118042e59444dcdca092c9fa11e1eeed5 -rad572fe631188a44a1b0976295ee33af9919ed78 --- lams_tool_laqa/web/learning/LearnerRep.jsp (.../LearnerRep.jsp) (revision 16415cf118042e59444dcdca092c9fa11e1eeed5) +++ lams_tool_laqa/web/learning/LearnerRep.jsp (.../LearnerRep.jsp) (revision ad572fe631188a44a1b0976295ee33af9919ed78) @@ -112,12 +112,25 @@ rows += ''; + var usesRatings = false; + var hasStartedRating = false; + if (${generalLearnerFlowDTO.allowRateAnswers == 'true'}) { rows += ''; if (userData["visible"] == 'true') { rows += '
'; - + + // if the user has left a comment or done a rating in a batch of ratings, we need to keep all related ratings open. + usesRatings = true; + for (j = 0; !hasStartedRating && j < userData.criteriaDtos.length; j++){ + hasStartedRating = userData.criteriaDtos[j].userRating != ""; + if ( hasStartedRating) { + idsBeingRated.push(itemId); // idsBeingRated defined in rating.js + } + } + hasStartedRating = hasStartedRating || ${isCommentsEnabled} && userData["commentPostedByUser"] != ""; + for (j = 0; j < userData.criteriaDtos.length; j++){ var criteriaDto = userData.criteriaDtos[j]; var objectId = criteriaDto["ratingCriteriaId"] + "-" + itemId; @@ -126,7 +139,7 @@ var userRating = criteriaDto.userRating; var isCriteriaNotRatedByUser = userRating == ""; var averageRatingDisplayed = (isItemAuthoredByUser || !isCriteriaNotRatedByUser) ? averageRating : 0; - var ratingStarsClass = (IS_DISABLED ||isItemAuthoredByUser || (MAX_RATES > 0) && (countRatedItems >= MAX_RATES) || !isCriteriaNotRatedByUser) ? "rating-stars-disabled" : "rating-stars"; + var ratingStarsClass = (IS_DISABLED || isItemAuthoredByUser || (MAX_RATES > 0) && (countRatedItems >= MAX_RATES) && (!hasStartedRating) || !isCriteriaNotRatedByUser) ? "rating-stars-disabled" : "rating-stars"; rows += '

'; rows += criteriaDto.title; @@ -182,7 +195,7 @@ rows += '

'; //show comments textarea and a submit button - } else if (!IS_DISABLED) { + } else if (! (IS_DISABLED || usesRatings && MAX_RATES>0 && countRatedItems >= MAX_RATES && !hasStartedRating)) { rows += '
'; rows += ''; Index: lams_tool_laqa/web/learning/RevisitedLearnerRep.jsp =================================================================== diff -u -r16415cf118042e59444dcdca092c9fa11e1eeed5 -rad572fe631188a44a1b0976295ee33af9919ed78 --- lams_tool_laqa/web/learning/RevisitedLearnerRep.jsp (.../RevisitedLearnerRep.jsp) (revision 16415cf118042e59444dcdca092c9fa11e1eeed5) +++ lams_tool_laqa/web/learning/RevisitedLearnerRep.jsp (.../RevisitedLearnerRep.jsp) (revision ad572fe631188a44a1b0976295ee33af9919ed78) @@ -115,12 +115,26 @@ rows += ''; + var usesRatings = false; + var hasStartedRating = false; + + if (${generalLearnerFlowDTO.allowRateAnswers == 'true'}) { rows += ''; if (userData["visible"] == 'true') { rows += '
'; + // if the user has left a comment or done a rating in a batch of ratings, we need to keep all related ratings open. + usesRatings = true; + for (j = 0; !hasStartedRating && j < userData.criteriaDtos.length; j++){ + hasStartedRating = userData.criteriaDtos[j].userRating != ""; + if ( hasStartedRating) { + idsBeingRated.push(itemId); // idsBeingRated defined in rating.js + } + } + hasStartedRating = hasStartedRating || ${isCommentsEnabled} && userData["commentPostedByUser"] != ""; + for (j = 0; j < userData.criteriaDtos.length; j++){ var criteriaDto = userData.criteriaDtos[j]; var objectId = criteriaDto["ratingCriteriaId"] + "-" + itemId; @@ -129,7 +143,7 @@ var userRating = criteriaDto.userRating; var isCriteriaNotRatedByUser = userRating == ""; var averageRatingDisplayed = (isItemAuthoredByUser || !isCriteriaNotRatedByUser) ? averageRating : 0; - var ratingStarsClass = (IS_DISABLED ||isItemAuthoredByUser || (MAX_RATES > 0) && (countRatedItems >= MAX_RATES) || !isCriteriaNotRatedByUser) ? "rating-stars-disabled" : "rating-stars"; + var ratingStarsClass = (IS_DISABLED ||isItemAuthoredByUser || (MAX_RATES > 0) && (countRatedItems >= MAX_RATES) && ! hasStartedRating || !isCriteriaNotRatedByUser) ? "rating-stars-disabled" : "rating-stars"; rows += '

'; rows += criteriaDto.title; @@ -185,7 +199,7 @@ rows += '

'; //show comments textarea and a submit button - } else if (!IS_DISABLED) { + } else if (! (IS_DISABLED || usesRatings && MAX_RATES>0 && countRatedItems >= MAX_RATES && !hasStartedRating)) { rows += '
'; rows += ''; Index: lams_tool_laqa/web/learning/mobile/LearnerRep.jsp =================================================================== diff -u -r16415cf118042e59444dcdca092c9fa11e1eeed5 -rad572fe631188a44a1b0976295ee33af9919ed78 --- lams_tool_laqa/web/learning/mobile/LearnerRep.jsp (.../LearnerRep.jsp) (revision 16415cf118042e59444dcdca092c9fa11e1eeed5) +++ lams_tool_laqa/web/learning/mobile/LearnerRep.jsp (.../LearnerRep.jsp) (revision ad572fe631188a44a1b0976295ee33af9919ed78) @@ -118,12 +118,26 @@ rows += ''; + var usesRatings = false; + var hasStartedRating = false; + + if (${generalLearnerFlowDTO.allowRateAnswers == 'true'}) { rows += ''; if (userData["visible"] == 'true') { rows += '
'; + // if the user has left a comment or done a rating in a batch of ratings, we need to keep all related ratings open. + usesRatings = true; + for (j = 0; !hasStartedRating && j < userData.criteriaDtos.length; j++){ + hasStartedRating = userData.criteriaDtos[j].userRating != ""; + if ( hasStartedRating) { + idsBeingRated.push(itemId); // idsBeingRated defined in rating.js + } + } + hasStartedRating = hasStartedRating || ${isCommentsEnabled} && userData["commentPostedByUser"] != ""; + for (j = 0; j < userData.criteriaDtos.length; j++){ var criteriaDto = userData.criteriaDtos[j]; var objectId = criteriaDto["ratingCriteriaId"] + "-" + itemId; @@ -132,7 +146,7 @@ var userRating = criteriaDto.userRating; var isCriteriaNotRatedByUser = userRating == ""; var averageRatingDisplayed = (isItemAuthoredByUser || !isCriteriaNotRatedByUser) ? averageRating : 0; - var ratingStarsClass = (IS_DISABLED ||isItemAuthoredByUser || (MAX_RATES > 0) && (countRatedItems >= MAX_RATES) || !isCriteriaNotRatedByUser) ? "rating-stars-disabled" : "rating-stars"; + var ratingStarsClass = (IS_DISABLED ||isItemAuthoredByUser || (MAX_RATES > 0) && (countRatedItems >= MAX_RATES) && ! hasStartedRating || !isCriteriaNotRatedByUser) ? "rating-stars-disabled" : "rating-stars"; rows += '

'; rows += criteriaDto.title; @@ -188,7 +202,7 @@ rows += '

'; //show comments textarea and a submit button - } else if (!IS_DISABLED) { + } else if (! (IS_DISABLED || usesRatings && MAX_RATES>0 && countRatedItems >= MAX_RATES && !hasStartedRating)) { rows += '
'; rows += ''; Index: lams_tool_laqa/web/learning/mobile/RevisitedLearnerRep.jsp =================================================================== diff -u -r16415cf118042e59444dcdca092c9fa11e1eeed5 -rad572fe631188a44a1b0976295ee33af9919ed78 --- lams_tool_laqa/web/learning/mobile/RevisitedLearnerRep.jsp (.../RevisitedLearnerRep.jsp) (revision 16415cf118042e59444dcdca092c9fa11e1eeed5) +++ lams_tool_laqa/web/learning/mobile/RevisitedLearnerRep.jsp (.../RevisitedLearnerRep.jsp) (revision ad572fe631188a44a1b0976295ee33af9919ed78) @@ -118,12 +118,26 @@ rows += ''; + var usesRatings = false; + var hasStartedRating = false; + + if (${generalLearnerFlowDTO.allowRateAnswers == 'true'}) { rows += ''; if (userData["visible"] == 'true') { rows += '
'; + // if the user has left a comment or done a rating in a batch of ratings, we need to keep all related ratings open. + usesRatings = true; + for (j = 0; !hasStartedRating && j < userData.criteriaDtos.length; j++){ + hasStartedRating = userData.criteriaDtos[j].userRating != ""; + if ( hasStartedRating) { + idsBeingRated.push(itemId); // idsBeingRated defined in rating.js + } + } + hasStartedRating = hasStartedRating || ${isCommentsEnabled} && userData["commentPostedByUser"] != ""; + for (j = 0; j < userData.criteriaDtos.length; j++){ var criteriaDto = userData.criteriaDtos[j]; var objectId = criteriaDto["ratingCriteriaId"] + "-" + itemId; @@ -132,7 +146,7 @@ var userRating = criteriaDto.userRating; var isCriteriaNotRatedByUser = userRating == ""; var averageRatingDisplayed = (isItemAuthoredByUser || !isCriteriaNotRatedByUser) ? averageRating : 0; - var ratingStarsClass = (IS_DISABLED ||isItemAuthoredByUser || (MAX_RATES > 0) && (countRatedItems >= MAX_RATES) || !isCriteriaNotRatedByUser) ? "rating-stars-disabled" : "rating-stars"; + var ratingStarsClass = (IS_DISABLED ||isItemAuthoredByUser || (MAX_RATES > 0) && (countRatedItems >= MAX_RATES) && ! hasStartedRating || !isCriteriaNotRatedByUser) ? "rating-stars-disabled" : "rating-stars"; rows += '

'; rows += criteriaDto.title; @@ -188,7 +202,7 @@ rows += '

'; //show comments textarea and a submit button - } else if (!IS_DISABLED) { + } else if (! (IS_DISABLED || usesRatings && MAX_RATES>0 && countRatedItems >= MAX_RATES && !hasStartedRating)) { rows += '
'; rows += '';