Hallo zusammen,
ich habe für mein Modul einen Featured und einen Published Button. Beide sollen bei Klick per Ajax den entsprechenden Datensatz bearbeiten und das Icon ändern.
Meines Erachtens sind beide Buttons identisch aufgebaut, dennoch löst der Published Button ein Reload aus, der Featured Button nicht.
Mein Ziel ist es natürlich, dass auch der Published Button keinen Seiten Reload verursacht. Hat jemand Ideen woran es liegen könnte oder habe ich einen Denkfehler?
viele Grüße
Xava
Operations
Funktionen zu Featured ButtonPHP-Code:'operations' =>
[
'featured' =>
[
'label' => &$GLOBALS['TL_LANG']['tl_ps_units']['featured'],
'icon' => 'featured.gif',
'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleFeatured(this,%s)"',
'button_callback' => ['tl_ps_units', 'generateFeaturedButton']
],
'published' =>
[
'label' => &$GLOBALS['TL_LANG']['tl_ps_units']['published'],
'icon' => 'visible.gif',
'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.togglePublished(this,%s)"',
'button_callback' => ['tl_ps_units', 'generatePublishedButton']
],
]
PHP-Code:# Featured Icon and Functionality
public function generateFeaturedButton($row, $href, $label, $title, $icon, $attributes)
{
if (strlen($this->Input->get('fid')))
{
$this->toggleFeatured($this->Input->get('fid'), ($this->Input->get('state') == 0));
$this->redirect($this->getReferer());
}
$href .= '&id='.$this->Input->get('id').'&fid='.$row['id'].'&state='.$row['featured'];
if (!$row['featured'])
{
$icon = 'featured_.gif';
}
return '<a href="'.$this->addToUrl($href).'" title="'.specialchars($title).'"'.$attributes.'>'.$this->generateImage($icon, $label).'</a> ';
}
Funktionen zu Published ButtonPHP-Code:public function toggleFeatured($intId, $blnFeatured)
{
if (is_array($GLOBALS['TL_DCA']['tl_ps_units']['fields']['featured']['save_callback']))
{
foreach ($GLOBALS['TL_DCA']['tl_ps_units']['fields']['featured']['save_callback'] as $callback)
{
$this->import($callback[0]);
$blnFeatured = $this->$callback[0]->$callback[1]($blnFeatured, $this);
}
}
// Update the database
$this->Database->prepare("UPDATE tl_ps_units SET tstamp=". time() .", featured='" . ($blnFeatured ? 1 : '') . "' WHERE id=?")
->execute($intId);
$this->createNewVersion('tl_ps_units', $intId);
}
PHP-Code:public function generatePublishedButton($row, $href, $label, $title, $icon, $attributes)
{
if (strlen($this->Input->get('tid')))
{
$this->togglePublished($this->Input->get('tid'), ($this->Input->get('state') == 0));
$this->redirect($this->getReferer());
}
$href .= '&id='.$this->Input->get('id').'&tid='.$row['id'].'&state='.$row['published'];
if (!$row['published'])
{
$icon = 'invisible.gif';
}
return '<a href="'.$this->addToUrl($href).'" title="'.specialchars($title).'"'.$attributes.'>'.$this->generateImage($icon, $label).'</a> ';
}
PHP-Code:public function togglePublished($intId, $blnPublished)
{
if (is_array($GLOBALS['TL_DCA']['tl_ps_units']['fields']['published']['save_callback']))
{
foreach ($GLOBALS['TL_DCA']['tl_ps_units']['fields']['published']['save_callback'] as $callback)
{
$this->import($callback[0]);
$blnPublished = $this->$callback[0]->$callback[1]($blnPublished, $this);
}
}
// Update the database
$this->Database->prepare("UPDATE tl_ps_units SET tstamp=". time() .", published='" . ($blnPublished ? 1 : '') . "' WHERE id=?")
->execute($intId);
$this->createNewVersion('tl_ps_units', $intId);
}

Zitieren
