jellyfin-web/dashboard-ui/scripts/ratingdialog.js

132 lines
5.3 KiB
JavaScript
Raw Normal View History

2013-11-07 10:27:05 -07:00
(function (window, document, $) {
window.RatingDialog = function (page) {
var self = this;
self.show = function (options) {
options = options || {};
2014-09-23 18:44:05 -07:00
options.header = options.header || Globalize.translate('HeaderRateAndReview');
2014-07-16 20:17:14 -07:00
2013-12-24 11:37:29 -07:00
var html = '<div data-role="popup" id="popupRatingDialog" class="popup" style="min-width:400px;">';
2013-11-07 10:27:05 -07:00
2013-12-24 11:37:29 -07:00
html += '<div class="ui-bar-a" style="text-align: center; padding: 0 20px;">';
2013-11-07 10:27:05 -07:00
html += '<h3>' + options.header + '</h3>';
html += '</div>';
2013-12-24 11:37:29 -07:00
html += '<div style="padding: 1em;">';
2013-11-07 10:27:05 -07:00
html += '<form>';
html += '<div style="margin:0;">';
2014-09-23 18:44:05 -07:00
html += '<label for="txtRatingDialogRating" >' + Globalize.translate('LabelYourRating') + '</label>';
2013-11-07 10:27:05 -07:00
html += '<input id="txtRatingDialogRating" name="rating" type="number" required="required" min=0 max=5 step=1 value=' + options.rating + ' />';
2014-09-23 18:44:05 -07:00
html += '<label for="txtRatingDialogTitle" >' + Globalize.translate('LabelShortRatingDescription') + '</label>';
2013-11-07 10:27:05 -07:00
html += '<input id="txtRatingDialogTitle" name="title" type="text" maxlength=160 />';
2014-09-23 18:44:05 -07:00
html += '<label for="txtRatingDialogRecommend" >' + Globalize.translate('OptionIRecommendThisItem') + '</label>';
2013-11-07 10:27:05 -07:00
html += '<input id="txtRatingDialogRecommend" name="recommend" type="checkbox" checked />';
2014-09-23 18:44:05 -07:00
html += '<label for="txtRatingDialogReview" >' + Globalize.translate('LabelFullReview') + '</label>';
2013-11-07 10:27:05 -07:00
html += '<textarea id="txtRatingDialogReview" name="review" rows=8 style="height:inherit" ></textarea>';
html += '</div>';
html += '<p>';
2014-09-23 18:44:05 -07:00
html += '<button type="submit" data-theme="b" data-icon="check">' + Globalize.translate('ButtonOk') + '</button>';
html += '<button type="button" data-icon="delete" onclick="$(this).parents(\'.popup\').popup(\'close\');">' + Globalize.translate('ButtonCancel') + '</button>';
2013-11-07 10:27:05 -07:00
html += '</p>';
html += '<p id="errorMsg" style="display:none; color:red; font-weight:bold">';
html += '</p>';
html += '</form>';
html += '</div>';
html += '</div>';
$(page).append(html);
2014-07-16 20:17:14 -07:00
var popup = $('#popupRatingDialog').popup().trigger('create').on("popupafteropen", function () {
2013-11-07 10:27:05 -07:00
$('#txtRatingDialogTitle', this).focus();
2014-07-16 20:17:14 -07:00
}).popup("open").on("popupafterclose", function () {
2013-11-07 10:27:05 -07:00
$('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(),
};
options.callback(review);
} else console.log("No callback function provided");
return false;
});
};
self.close = function () {
$('#popupRatingDialog', page).popup("close");
};
};
2014-07-16 20:17:14 -07:00
window.RatingHelpers = {
ratePackage: function (link) {
var id = link.getAttribute('data-id');
var rating = link.getAttribute('data-rating');
var dialog = new RatingDialog($.mobile.activePage);
dialog.show({
2014-09-23 18:44:05 -07:00
header: Globalize.translate('HeaderRateAndReview'),
2014-07-16 20:17:14 -07:00
id: id,
rating: rating,
callback: function (review) {
console.log(review);
dialog.close();
ApiClient.createPackageReview(review).done(function () {
Dashboard.alert({
2014-09-23 18:44:05 -07:00
message: Globalize.translate('MessageThankYouForYourReview'),
title: Globalize.translate('HeaderThankYou')
2014-07-16 20:17:14 -07:00
});
});
}
});
},
getStoreRatingHtml: function (rating, id, name, noLinks) {
var html = "<div style='margin-left: 5px; margin-right: 5px; display: inline-block; vertical-align:middle;'>";
if (!rating) rating = 0;
for (var i = 1; i <= 5; i++) {
var title = noLinks ? rating + " stars" : "Rate " + i + (i > 1 ? " stars" : " star");
2015-05-16 12:09:02 -07:00
html += noLinks ? "" : "<a href='#' data-id=" + id + " data-name='" + name + "' data-rating=" + i + " onclick='RatingHelpers.ratePackage(this);return false;' >";
2014-07-16 20:17:14 -07:00
if (rating <= i - 1) {
html += "<div class='storeStarRating emptyStarRating' title='" + title + "'></div>";
} else if (rating < i) {
html += "<div class='storeStarRating halfStarRating' title='" + title + "'></div>";
} else {
html += "<div class='storeStarRating' title='" + title + "'></div>";
}
2015-05-16 12:09:02 -07:00
html += noLinks ? "" : "</a>";
2014-07-16 20:17:14 -07:00
}
html += "</div>";
return html;
}
};
2013-11-07 10:27:05 -07:00
})(window, document, jQuery);