nm3clol-archived-russellcou.../mirror/www.russellcountyva.us/Assets/Scripts/ItemRating/ItemRating.js

59 lines
1.8 KiB
JavaScript

/// <reference path="../Shared.js" />
/// <reference path="../jquery-1.7.2.min.js" />
var ItemRating = (function () {
function ItemRating(controllerBaseURL, itemTypeID, itemID, userID, $ratingControlDiv) {
/// <summary>Constructor for the ItemRating javascript object.</summary>
/// <param name="itemTypeID">The type of item the rating control is used for.</param>
/// <param name="itemID">The ID of the item the rating control is for.</param>
/// <param name="userID">The ID of the user viewing the rating control</param>
/// <param name="$ratingControlDiv">A jQuery container for the rating control div.</param>
this.itemTypeID = itemTypeID;
this.itemID = itemID;
this.userID = userID;
this.$ratingControlDiv = $ratingControlDiv;
this.controllerBaseURL = controllerBaseURL;
this.initEventHandlers();
}
ItemRating.prototype.getNumericRating = function (clickTarget) {
var numericRating = 0;
var $target = $(clickTarget);
numericRating = $target.attr('data-rating-value');
return numericRating;
};
ItemRating.prototype.initEventHandlers = function () {
var self = this;
this.$ratingControlDiv.delegate('a.myRating', 'click', function (e) {
e.preventDefault();
var numericRating = self.getNumericRating(e.target);
self.rateItem(numericRating);
});
};
ItemRating.prototype.rateItem = function (rating) {
var self = this;
if (this.userID <= 0) {
var currentLocation = window.location.pathname;
popupSignIn(currentLocation, '');
return;
}
var url = self.controllerBaseURL + '/RateItem/' + this.itemID;
var data = {
rating: rating
};
var success = function (response) {
self.$ratingControlDiv.replaceWith(response);
};
AJAX(url, 'POST', data, success, false);
};
return ItemRating;
})();