/
home
/
assocoweys
/
avexp
/
modules
/
mod_latestnewsenhancedextended
/
fields
/
Upload File
HOME
<?php /** * @copyright Copyright (C) 2011 Simplify Your Web, Inc. All rights reserved. * @license GNU General Public License version 3 or later; see LICENSE.txt */ defined( '_JEXEC' ) or die; use Joomla\CMS\Factory; use Joomla\CMS\Form\FormHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\Plugin\PluginHelper; FormHelper::loadFieldClass('list'); class JFormFieldDatasourceFields extends \JFormFieldList { protected $type = 'DatasourceFields'; protected function getInput() { //$this->value = array(); $str = array(); $str[] = '<div id="' . $this->id . '_container">'; $str[] = '<div id="' . $this->id . '_modal" class="modal hide">'; $str[] = '<div class="modal-header">'; $str[] = '<h3>'.Text::_('MOD_LATESTNEWSENHANCEDEXTENDED_MODALSELECT_TITLE').'</h3>'; // $str[] = '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>'; $str[] = '</div>'; $str[] = '<div class="modal-body" style="width: 98%; padding: 1%; overflow-y: auto">'; $str[] = '<div class="alert alert-warning">'; $str[] = Text::_('MOD_LATESTNEWSENHANCEDEXTENDED_MODALSELECT_WARNING_PLUGINSELECTIONONLY'); $str[] = '</div>'; foreach ($this->fields as $field) { $str[] = $field->renderField(); } $str[] = '</div>'; $str[] = '<div class="modal-footer">'; $str[] = '<button class="btn btn-link" data-dismiss="modal">' . Text::_('JCANCEL') . '</button>'; $str[] = '<button class="btn btn-primary" id="' . $this->id . '_close" data-dismiss="modal">' . Text::_('JAPPLY') . '</button>'; $str[] = '</div>'; $str[] = '</div>'; $str[] = '</div>'; // Button for display the modal window $select = (string) $this->element['select'] ? Text::_((string) $this->element['select']) : Text::_('JLIB_FORM_BUTTON_SELECT'); $icon = $this->element['icon'] ? '<span class="icon-' . $this->element['icon'] . '"></span> ' : ''; $str[] = '<a href="#' . $this->id . '_modal" class="btn" data-toggle="modal">' . $icon . $select . '</a>'; $script = 'jQuery(document).ready(function ($){'; $script .= '$("#' . $this->id . '_close").on("click", function (e) {'; $script .= 'var values = {}; '; $script .= '$("#' . $this->id . '_modal *[name]").each(function() {'; $script .= 'var id = $(this).attr("id").replace("jform_params_", "");'; $script .= 'var type = $(this).attr("type");'; $script .= 'if ($(this).val() !== null && $(this).val() !== undefined) {'; $script .= 'if (type === "radio") {'; $script .= 'if ($(this).prop("checked")) { var len = id.length; values[id.substr(0, len - 1)] = $(this).val(); }'; $script .= '} else {'; $script .= 'values[id] = $(this).val();'; $script .= '}'; $script .= '}'; $script .= '});'; $script .= '$("#' . $this->id . '").val(JSON.stringify(values));'; //$script .= 'console.log( "json " + JSON.stringify(values));'; $script .= '$("#' . $this->id . '_modal").modal("hide");'; $script .= '})'; $script .= '});'; $doc = Factory::getDocument(); $doc->addScriptDeclaration($script); $value = htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8'); $str[] = '<input type="hidden" name="' . $this->name . '" id="' . $this->id . '" value="' . $value . '" />'; return implode("\n", $str); } public function setup(\SimpleXMLElement $element, $value, $group = null) { $return = parent::setup($element, $value, $group); if ($return) { PluginHelper::importPlugin('latestnewsenhanced'); // Get the dispatcher. $dispatcher = \JEventDispatcher::getInstance(); $results = $dispatcher->trigger('onLatestNewsEnhancedPrepareForm', array($this->form)); $this->fields = array(); //Factory::getApplication()->enqueueMessage('value : '.$this->value, 'warning'); $values = json_decode($this->value, true); // "datasourcefields":"{\"rss_title\":null,\"rss_feed\":\"feed\"}" $lang = Factory::getLanguage(); foreach ($results as $result) { $lang->load('plg_latestnewsenhanced_'.$result['type'].'.sys', JPATH_ADMINISTRATOR, $lang->getTag(), true); foreach ($result['form']->getFieldset() as $field) { if (isset($values[(String) $field->element['name']])) { $field->value = $values[(String) $field->element['name']]; //Factory::getApplication()->enqueueMessage('value : '.$field->value, 'warning'); } $this->fields[] = $field; } } } return $return; } // public function save() // { // Factory::getApplication()->enqueueMessage('save ', 'warning'); // } } ?>