Current File : /home/pacjaorg/wpt.pacja.org/km/plugins/djclassifieds/conditionalfields/fields/djcffieldtrigger.php |
<?php
/**
* @package DJ-Classifieds
* @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
* @license http://www.gnu.org/licenses GNU/GPL
* @author url: http://dj-extensions.com
* @author email: contact@dj-extensions.com
*/
defined('_JEXEC') or die('Restricted access');
use Joomla\CMS\Form\FormHelper;
FormHelper::loadFieldClass('list');
class JFormFieldDjcffieldtrigger extends JFormFieldList {
protected $type = 'Djcffieldtrigger';
public function getOptions() {
$app = JFactory::getApplication();
$document = JFactory::getDocument();
$db = JFactory::getDbo();
$field_id = $app->input->get('id', '0');
$query = "SELECT source FROM #__djcf_fields WHERE id=".$field_id;
$db->setQuery($query);
$source = $db->loadResult();
if($source == ''){
return;
}
$query = "SELECT id, name FROM #__djcf_fields WHERE published=1 AND source=".$source." AND id!=".$field_id;
$db->setQuery($query);
$rows = $db->loadObjectList();
$tmp = JHtml::_( 'select.option', '', JText::_('PLG_DJCLASSIFIEDS_CONDITIONALFIELDS_SELECT_CUSTOM_FIELD'), 'value', 'text');
$options[] = $tmp;
foreach ($rows as $option)
{
$tmp = JHtml::_('select.option', (string) $option->id, trim((string) JText::_($option->name)), 'value', 'text');
$options[] = $tmp;
}
$document->addScriptDeclaration("jQuery(function($){
$('#trig_value').replaceWith('<div id=\"trig_value\">".JText::_('PLG_DJCLASSIFIEDS_CONDITIONALFIELDS_FIELD_CONDITIONAL_CHOOSE_FIELD_FIRST')."</div>');
getValues($('[name=\"".$this->name."\"]').val());
$('[name=\"".$this->name."\"]').unbind('change').change(function(){
getValues($(this).val());
})
function getValues(val){
if(val){
$('#trig_value').replaceWith(jQuery('<div id=\"trig_value\"><img src=\"".JURI::root()."administrator/components/com_djclassifieds/images/loading.gif\" /></div>'));
jQuery.ajax({
url: 'index.php',
type: 'post',
data: {
'option': 'com_ajax',
'group': 'djclassifieds',
'plugin': 'getTrigValues',
'format': 'raw',
'trig_field_id': val,
'field_id': ".$field_id."
}
}).done(function(response, textStatus, jqXHR){
if(textStatus == 'success'){
if(response){
$('#trig_value').replaceWith(jQuery('<div id=\"trig_value\">'+response+'</div>'));
// jQuery('#trig_value').find('.field-calendar').each(function(){
// JoomlaCalendar.init(jQuery(this)[0]);
// });
}
}
});
}else{
$('#trig_value').replaceWith('<div id=\"trig_value\">".JText::_('PLG_DJCLASSIFIEDS_CONDITIONALFIELDS_FIELD_CONDITIONAL_CHOOSE_FIELD_FIRST')."</div>');
}
}
})");
return $options;
}
}