Hi all,
I really need your help on a piece of DOM code.
Basically, what I need to do is create a piece of code that will grab an existing link, verify it's value into database and if it changes, to update the data into the existing table cell.
The process is similar to the vBulletin IP resolve code.
Let me show you what I did so far. The HTML code looks like that:
Code:
<table id="weekdays_{$month}" cellpadding="$stylevar[cellpadding]" cellspacing="0" border="0" width="100%">
<tr>
<td id="actual_{$eventid}" class="$bgclass espace" id="refresh_$eventid" style="text-align: right;" nowrap="nowrap">
<if condition="$show['pendingevent']">
<a id="actual_{$eventid}" href="calendar.php?do=refreshdata&e={$eventid}&actual=pending">
<img alt="$vbphrase[product_refresh]" border="0" class="inlineimg" src="$stylevar[imgdir_misc]/calendar_tool_refresh.gif" width="16" height="16" />
</a>
<else />
<span class="$event[actualkey]" style="float: right;">$event[actual]</span>
</if>
</td>
</tr>
</table>
<script type="text/javascript" src="clientscript/vbulletin_ajax_refreshdata.js?v=$vboptions[simpleversion]"></script>
<script type="text/javascript">
<!--
vB_AJAX_RefreshData_Init('weekdays_{$month}');
//-->
</script>
If we find the value 'pending', the vBulletin template will display an image, else, we display the actual value found, ie. 'extra-light'.
See $show[pendingevent] conditional.
Now, the PHP code that triggers all this is:
Code:
if ($_REQUEST['do'] == 'refreshdata')
{
// init the XML code
require_once(DIR . '/includes/class_xml.php');
$xml = new vB_AJAX_XML_Builder($vbulletin, 'text/xml');
// if we have a valid ID
if ($vbulletin->GPC['eventid'])
{
// define the database field
$event['fields'] = unserialize($eventinfo['customfields']);
// this could be 'pending' or 'new-value'
$event['actual'] = vbstrtolower($event['fields'][25]);
// this is the 'pending' word
$event['actualphrase'] = vbstrtolower($vbphrase['product_pending']);
// if we deal with ajax
if ($vbulletin->GPC['ajax'])
{
// if the database value is not 'pending'
if ($event['actual'] != $event['actualphrase'])
{
// we need to fire the AJAX code here
// first help needed here
}
}
}
else
{
// bad ID
$xml->add_tag('error', 'invalidid');
}
// end XML code
$xml->print_xml();
}
And now, the AJAX .js file:
Code:
function vB_AJAX_RefreshData_Init(tableid)
{
if (AJAX_Compatible && (typeof vb_disable_ajax == 'undefined' || vb_disable_ajax < 2))
{
var link_list = fetch_tags(fetch_object(tableid), 'a');
for (var i = 0; i < link_list.length; i++)
{
if (link_list[i].id && link_list[i].id.substr(0, 7) == 'actual_')
{
link_list[i].onclick = refresh_data;
}
}
}
}
function vB_AJAX_RefreshData(actual, objid)
{
this.actual = actual;
this.objid = objid;
this.xml_sender = null;
var me = this;
this.resolve = function()
{
this.xml_sender = new vB_AJAX_Handler(true);
this.xml_sender.onreadystatechange(this.onreadystatechange);
this.xml_sender.send('calendar.php?do=refreshdata&actual=' + PHP.urlencode(this.actual), 'do=refreshdata&ajax=1&actual=' + PHP.urlencode(this.actual));
}
this.onreadystatechange = function()
{
// need help here
}
}
function refresh_data(e)
{
var refresher = new vB_AJAX_RefreshData(this.innerHTML, this.id);
refresher.resolve();
return false;
}
I apreciate the time you take to help me with this matter.
Thanks.
EDIT: I included a .txt file with all the code, you you can follow better everything.