/** * Method to get the field options. * * @return array The field option objects. * * @since 11.1 */ protected function getInput() { $html = array(); $document = JFactory::getDocument(); // Get the Units field options. $unitsoptions = SibdietHelper::getUnitsOptions(); $unitsfield = JHtml::_('select.genericlist', $unitsoptions, 'jform[' . $this->fieldname . '][#index#][unit]', 'class="input-medium input-unit required"', 'value', 'text', '', $this->id . 'unit#index#'); $unitsfield = preg_replace("/\\s+/", " ", $unitsfield); $inputhtml = '<div id="' . $this->id . 'div#index#" class="input-prepend input-append row-fluid"><span class="add-on"><label for="' . $this->id . '#index#" title="#name#">#name#</label></span><input type="text" class="validate-numeric input-mini required" value="" required="required" name="jform[' . $this->fieldname . '][#index#][amount]" id="' . $this->id . '#index#">' . $unitsfield . '<input type="text" class="input-mini required" required="required" value="" name="jform[' . $this->fieldname . '][#index#][uamount]" id="' . $this->id . 'uamount#index#"><span class="btn add-on"><i class="icon-delete" onclick="removeComposition(#index#)"></i></span></div>'; $script = "\nfunction removeComposition(cid)\n{\n\tvar compo = '#{$this->id}'+'div'+cid;\n\tjQuery(compo).remove();\n\n\tvar compoopt = '#{$this->id} option[value=\"'+cid+'\"]';\n\tjQuery(compoopt).removeAttr('disabled');\n\tjQuery('#{$this->id}').trigger('liszt:updated');\n}\n\nfunction newComposition()\n{\n\tvar seletedoption = jQuery('#{$this->id}').find(\":selected\");\n\tvar selectedvalue = jQuery(seletedoption).val();\n\tif(selectedvalue){\n\t\tvar selectedtext = jQuery(seletedoption).text();\n\t\tvar inputtext = '{$inputhtml}';\n\t\tinputtext = inputtext.replace(/#index#/g, selectedvalue);\n\t\tinputtext = inputtext.replace(/#name#/g, selectedtext);\n\t\tjQuery('#subcompositions').append(inputtext);\n\t\tjQuery(seletedoption).attr('disabled','disabled');\n\t\tjQuery('#{$this->id} option:first').attr('selected','selected');\n\t\tvar unitsinputid = '#jform_compositionsunit' + selectedvalue;\n\t}\n\tjQuery('#{$this->id}').trigger('liszt:updated');\n}"; $document->addScriptDeclaration($script); $this->onchange = 'newComposition()'; $html[] = parent::getInput(); $html[] = '<br /><br /><div id="subcompositions"><span></span>'; $db = JFactory::getDbo(); foreach ($this->value as $key => $value) { $query = $db->getQuery(true)->select("title, print_title")->from('#__sibdiet_compositions AS a')->where("a.id = " . $key); $db->setQuery($query); $result = $db->loadObject(); if ($result) { $lang_tag = JFactory::getLanguage()->get('tag'); // Convert the print_title field to an array. $registry = new JRegistry(); $registry->loadString($result->print_title); $print_title = $registry->toArray(); $name = array_key_exists($lang_tag, $print_title) ? $result->title . ' { ' . $print_title[$lang_tag] . ' }' : $result->title; $opthtml = str_replace('#index#', $key, $inputhtml); $count = 1; $opthtml = preg_replace('/value=""/', 'value="' . $value['amount'] . '"', $opthtml, 1); $opthtml = str_replace('value=""', 'value="' . $value['uamount'] . '"', $opthtml); $opthtml = str_replace('#name#', $name, $opthtml); $opthtml = str_replace('value="' . $value['unit'] . '"', 'value="' . $value['unit'] . '" selected="selected"', $opthtml); $html[] = $opthtml; } } $html[] = '</div>'; return implode($html); }
<?php /** * @package Sibdiet.Administrator * @subpackage com_sibdiet * @checked 2020/01/01 * @copyright Copyright (C) 2012 - 2015 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; $published = $this->state->get('filter.state'); $compositionsOptionsHtml = JHtml::_('select.options', SibdietHelper::getCompositionsOptions(), 'value', 'text'); $unitsOptionsHtml = JHtml::_('select.options', SibdietHelper::getUnitsOptions(), 'value', 'text'); ?> <div class="modal hide fade" id="editCompositionsCollapseModal"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h3><?php echo JText::_('COM_SIBDIET_EDIT_SELECTED_FOODS_COMPOSITIONS'); ?> </h3> </div> <div class="modal-body modal-batch"> <p><?php echo JText::_('COM_SIBDIET_FOOD_BATCH_EDIT_TIP'); ?> </p> <?php for ($i = 1; $i <= 10; $i++) { ?>