(function (window, document, $) {
window.RatingDialog = function (page) {
var self = this;
self.show = function (options) {
options = options || {};
options.header = options.header || "Rate and Review";
var html = '
';
$(page).append(html);
var popup = $('#popupRatingDialog').popup().trigger('create').on("popupafteropen", function() {
$('#txtRatingDialogTitle', this).focus();
}).popup("open").on("popupafterclose", function() {
$('form', this).off("submit");
$(this).off("popupafterclose").remove();
});
$('form', popup).on('submit', function () {
if (options.callback) {
var review = {
id: options.id,
rating: $('#txtRatingDialogRating', this).val(),
title: $('#txtRatingDialogTitle', this).val(),
recommend: $('#txtRatingDialogRecommend', this).checked(),
review: $('#txtRatingDialogReview', this).val(),
};
if (review.rating < 3) {
if (!review.title) {
$('#errorMsg', this).html("Please give reason for low rating").show();
$('#txtRatingDialogTitle', this).focus();
return false;
}
}
if (!review.recommend) {
if (!review.title) {
$('#errorMsg', this).html("Please give reason for not recommending").show();
$('#txtRatingDialogTitle', this).focus();
return false;
}
}
options.callback(review);
} else console.log("No callback function provided");
return false;
});
};
self.close = function () {
$('#popupRatingDialog', page).popup("close");
};
};
})(window, document, jQuery);