/// /// var ItemRating = (function () { function ItemRating(controllerBaseURL, itemTypeID, itemID, userID, $ratingControlDiv) { /// Constructor for the ItemRating javascript object. /// The type of item the rating control is used for. /// The ID of the item the rating control is for. /// The ID of the user viewing the rating control /// A jQuery container for the rating control div. 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; })();