1. why i choose acepolls?
- in joomla 1.5 was standart poll component/module but in j1.7 it dissapears.
I'm writing portal for 3d models, programs and sometimes i need to make different polls on such topics.
So simple poll module is needed with options and ajax support (cause i don't want to make new whole request for single vote/poll). There's also niceajaxpoll module, but it's more complex and bugable (i suppose).
2. When u turn on acepolls ajax support javascript code sends and waits request from server.
Here was a bug (Code shows a div with loading icon - and waits for no reply...)
here's original code
/* id."').addEvent('submit', function(e) {
// Prevent the submit event
new Event(e).stop();
var options = $('poll_vote_".$poll->id."').getElements('input[name=voteid]');
var nothing_selected = 1;
options.each(function(item, index){
if(item.checked==1) {nothing_selected = 0;}
});
if (nothing_selected) {
alert('".JText::_('Please select an option')."');
return false;
} else {
$('submit_vote_".$poll->id."').disabled = 1;
$('poll_loading_".$poll->id."').setStyle('display','');
// Update the page
this.send({
onComplete: function(response, responseXML)
{
// get the XML nodes
var root = responseXML.documentElement;
var options = root.getElementsByTagName('option');
var text = root.getElementsByTagName('text');
//var percentages = root.getElementsByTagName('percentages');
var voters = root.getElementsByTagName('voters');
// prepare the XHTML
var updateValue = '".$updateValue."';
// update the page element 'update'
//$('polldiv_".$poll->id."').removeClass('ajax-loading');
$('polldiv_".$poll->id."').empty().setHTML(updateValue);
var pollSlide = new Fx.Slide('poll_comp_form');
pollSlide.slideOut();
}});
}
});
});/* ]]> */";
code stops on the line
this.send({
onComplete: function(response, responseXML)
Ajax model on the poll waits for request in XML format.
This code was workable with mootools 1.1. In J1.7 mootools 1.2 is ised (maybe higher).
So u need to transform this line with
this.set('send', {
onComplete: function(response, responseXML).send()
Now - enters into this function. (You can see it throw debugging console)
But there's no request from server side.
I only got something like this
23:35:25.879] POST gid360.ru/%5Bobject%20Object%5D [HTTP/1.1
404 Not Found 2мс]
So go to server-side and try to understand why there's no answer.
Go to com_acepolls/views/poll/view.raw.php
function display($tpl = null) {
// Get data from the model
require_once(JPATH_COMPONENT.DS.'models'.DS.'ajaxvote.php');
$model = new AcepollsModelAjaxvote();
$vote = $model->getVoted();
$data = $model->getData();
$total = $model->getTotal();
//print_r($data); exit;
$poll_id = JRequest::getVar('id', 0, 'POST', 'int');
// create root node
$xml = new JSimpleXMLElement('poll', array('id' => $poll_id));
//get total votes
$sum = 0;
foreach ($data as $row) {
$sum += $row->votes;
}
$number_voters = 0;
$options =& $xml->addChild('options');
for ($i=0; $iaddChild('option', array('id'=>$data[$i]->id, 'percentage' => self::_toPercent($data[$i]->votes, $sum), 'votes'=>$data[$i]->votes, 'color'=>$data[$i]->color));
$text =& $option->addChild('text');
$text->setData($data[$i]->text);
$number_voters += $data[$i]->votes;
}
$voters =& $xml->addChild('voters');
$voters->setData($number_voters);
$this->assign('xml', $xml->toString());
$this->setLayout('raw');
parent::display($tpl);
}
In this line
$xml = new JSimpleXMLElement
code execution stops.
Through debugging I got something like this
class not found
.
The reason is
officially commited the change a few minutes ago and marked the
classes JSimpleXML and JSimpleXMLElement as deprecated
I changed JSimpleXMLElement to JXMLElement and few line in xlm creation code
function display($tpl = null) {
// Get data from the model
require_once(JPATH_COMPONENT.DS.'models'.DS.'ajaxvote.php');
$model = new AcepollsModelAjaxvote();
$vote = $model->getVoted();
$data = $model->getData();
$total = $model->getTotal();
//print_r($data); exit;
$poll_id = JRequest::getVar('id', 0, 'POST', 'int');
// create root node
$xml = new JXMLElement('');
$xml->addAttribute('id', $poll_id);
//get total votes
$sum = 0;
foreach ($data as $row)
{
$sum += $row->votes;
}
$number_voters = 0;
$options =& $xml->addChild('options');
for ($i=0; $iaddChild('option');
$option->addAttribute('id', $data[$i]->id);
$option->addAttribute('percentage', self::_toPercent($data[$i]->votes, $sum));
$option->addAttribute('color', $data[$i]->color);
$option->addChild('text', $data[$i]->text);
$number_voters += $data[$i]->votes;
}
$xml->addChild('voters', $number_voters);
$this->assign('xml', $xml->asFormattedXML());
$this->setLayout('raw');
parent::display($tpl);
}
Now all sides working. AJAX sends and gets responses, server echos answer.
In attachment there are 2 modified files (com_acepolls/views/poll/view.raw.php and mod_acepolls/tmpl/default.php)
p.s. a little bit more
1. I don't need to show pollbars in the voting result, so a added var $show_bars = 0. If u want to use bars just comment line with $show_bars or set $show_bars=1 (file - mod_acepolls/mod_acepolls.php)
2. You can change Fx.slide effect in javascript. I set horizontal (default was vertical). To set vertical just change
var sl = new Fx.Slide('polldiv_1', {mode: 'horizontal'}).hide();
to
new Fx.Slide('polldiv_1')
(polldiv_1 - div with poll form)
If there's no need in slider - remove lines with slider.
This attachment is hidden for guests. Please log in or register to see it.