Files
Facilitor/APPL/Shared/rater.inc
Peter Feij 0cdd00ab34 FCLT#63749 FA5 fixes
svn path=/Website/trunk/; revision=48952
2020-11-25 17:03:29 +00:00

134 lines
4.2 KiB
C++

<% /*
$Revision$
$Id$
File: rater.inc
Description: generic interface function for rating
documentation: wbotelhos.com/raty
*/ %>
<%
FCLTHeader.Requires({ plugins: ["jQuery"],
js: ["../localscripts/raty/jquery.raty.min.js"],
extrahead: _initRater });
function _initRater()
{
var ratingParams = rating.getRatingParams();
%>
<script>
function getScore(rating)
{
var score = 0;
if (<%=S("fac_like_bad")%> > 0 && rating >= <%=S("fac_like_bad")%>) score++;
if (<%=S("fac_like_poor")%> > 0 && rating >= <%=S("fac_like_poor")%>) score++;
if (<%=S("fac_like_normal")%> > 0 && rating >= <%=S("fac_like_normal")%>) score++;
if (<%=S("fac_like_good")%> > 0 && rating >= <%=S("fac_like_good")%>) score++;
if (<%=S("fac_like_excellent")%> > 0 && rating >= <%=S("fac_like_excellent")%>) score++;
return score;
}
$(function ()
{
$(".rater").raty({score: function() { return getScore((parseInt($(this).attr('data-score')))); },
readOnly: function() { return $(this).attr('readonly'); },
showHalf : true,
half : true,
path: '../localscripts/raty/img/',
width: 120,
number: <%=ratingParams.nrOfSstars%>,
hints: <%=JSON.stringify(ratingParams.hints)%>
});
});
</script>
<%
}
function rater(rating, params)
{
params = params||{};
if (!rating && params.shownone)
return "";
likesymbol = "<span class='rater' data-score='" + rating + "'" + (params.readonly? " readonly='1'" : "") + "></span>";
return likesymbol;
}
var rating = {
// Gives the (1 out of 5) image that belongs to a given rating
// If no rating is given (null), then depening on params.shownone
// either null or the none-picture is given
getRatingParams: function ()
{
var nrOfSstars = 0;
var hints = [];
if (S("fac_like_bad") > 0)
{
nrOfSstars++;
hints.push(L('lcl_faclike_statisf1'));
}
if (S("fac_like_poor") > 0)
{
nrOfSstars++;
hints.push(L('lcl_faclike_statisf2'));
}
if (S("fac_like_normal") > 0)
{
nrOfSstars++;
hints.push(L('lcl_faclike_statisf3'));
}
if (S("fac_like_good") > 0)
{
nrOfSstars++;
hints.push(L('lcl_faclike_statisf4'));
}
if (S("fac_like_excellent") > 0)
{
nrOfSstars++;
hints.push(L('lcl_faclike_statisf5'));
}
return {nrOfSstars: nrOfSstars, hints: hints};
},
stars: function (rating, params)
{
function getStar(starOn)
{
return (starOn ? I("fa-star", {"fastyle": "fas"}) : I("fa-star", {"fastyle": "far"}));
}
var imgstr = "";
params = params||{};
if (!rating && params.shownone)
{
imgstr = I("fa-question-circle rate", {"fastyle": "far"});
}
else
{
if (S("fac_like_bad") > 0)
imgstr += getStar( rating >= S("fac_like_bad"));
if (S("fac_like_poor") > 0)
imgstr += getStar( rating >= S("fac_like_poor"));
if (S("fac_like_normal") > 0)
imgstr += getStar( rating >= S("fac_like_normal"));
if (S("fac_like_good") > 0)
imgstr += getStar( rating >= S("fac_like_good"));
if (S("fac_like_excellent") > 0)
imgstr += getStar( rating >= S("fac_like_excellent"));
}
if (imgstr != "")
var id = (params.rating.id ? " id=\'" + params.rating.id + "\'" + "' name=\'" + params.rating.id + "\'" : "");
var note = (params.rating.note? " title=\'" + safe.htmlattr(params.rating.note) + "\'" : "");
imgstr = "<span class='rating'" + id + note + ">"
+ imgstr
+ "</span>";
return imgstr;
}
};
%>