Hi,
I'm a front end developer/designer who has been thrust into the position of some backend developing. I'm in a bit of a time crunch and could use some help/direction/input on some code.
I'm working on a photo contest site and I need the votes for an image to cost a credit. The voting and credits are all set up, I just need the voting to check the database to see if the logged in user has credits to vote, if so, then reduce their credits by 1 and complete the vote.
Here is the voting code:
Code:
window.addEvent('domready', function() {
$$('#jwajaxvote-inline-rating a').each(function(el) {
el.addEvent('click', function(e) {
e = new Event(e).stop();
if (jwallpapers_is_user_voting) {
alert(jwallpapers_userAlreadyVotedMessage);
return;
} else {
jwallpapers_is_user_voting = true;
}
if (jwallpapers_isUserVoteAllowed == false) {
alert(jwallpapers_isUserVoteAllowedMessage);
return false;
}
if (jwallpapers_userAlreadyVoted == true) {
alert(jwallpapers_userAlreadyVotedMessage);
return false;
}
var id = this.getAttribute('id');
var url = eval("jwallpapers_rating_link_" + id);
var div1 = $('rating_stars_update');
var div2 = $('jwajaxvote').empty();
div2.innerHTML = '<img src="' + jwallpapers_joomla_base_url + 'components/' + jwallpapers_option + '/images/ajax_loader/ajax-loader-rating.gif" border="0" align="absmiddle" />';
var div3 = $('rating_verbose_update');
new Ajax(url, {
method : 'get',
onComplete : function(response, responseXML) {
jwallpapers_userAlreadyVoted = true;
var root = responseXML.documentElement;
var rating_stars_update = root.getElementsByTagName('rating_stars_update').item(0);
var rating_count_update = root.getElementsByTagName('rating_count_update').item(0);
var rating_verbose_update = root.getElementsByTagName('rating_verbose_update').item(0);
var updateRating = rating_stars_update.firstChild.nodeValue;
var updateCounter = rating_count_update.firstChild.nodeValue;
var updateVerbose = rating_verbose_update.firstChild.nodeValue;
div1.empty().setHTML(updateRating);
div2.empty().setHTML(updateCounter);
div3.empty().setHTML(updateVerbose);
jwallpapers_is_user_voting = false;
}
}).request();
});
});
});
I should note this is not my code. I've never done any javascript/ajax coding before. My programmer had done this on a previous version of the site, but he quit and then the site went all haywire and I had to reinstall components which erased what he had done.
Thanks.