Example #1
0
	function toHtml() {
		if(count($this->_cd)>1) {
			load_js('modules/Utils/CommonData/qf.js');
			$id=$this->getAttribute('id');
			if(!isset($id)) {
				$id = $this->getName();
				$this->updateAttributes(array('id'=>$id));
			}
			$val = $this->getValue();
			$val = $val[0];
			if($this->_flagFrozen) {
				eval_js('new Utils_CommonData_freeze(\''.Epesi::escapeJS($id,false).'\', \''.Epesi::escapeJS(json_encode($this->_cd),false).'\')');
				$html = '<span id="'.$id.'_label">&nbsp;</span>';
				$name = $this->getPrivateName();
				// Only use id attribute if doing single hidden input
				$html .= '<input' . $this->_getAttrString(array(
					     'type'  => 'hidden',
					     'name'  => $name,
					     'value' => $val,
					     'id'    => $id
					 )) . ' />';
				return $html;
			}
			eval_js('new Utils_CommonData(\''.Epesi::escapeJS($id,false).'\', \''.Epesi::escapeJS($val,false).'\', \''.Epesi::escapeJS(json_encode($this->_cd),false).'\', '.($this->_add_empty_fields?1:0).')');
		}
	        return parent::toHtml();
	}
Example #2
0
 function toHtml()
 {
     if ($this->_hiddenLabel) {
         $this->_generateId();
         return '<label class="accesshide" for="' . $this->getAttribute('id') . '" >' . $this->getLabel() . '</label>' . parent::toHtml();
     } else {
         return parent::toHtml();
     }
 }
Example #3
0
 /**
  * Returns HTML for select form element.
  *
  * @return string
  */
 function toHtml(){
     $html = '';
     if ($this->getMultiple()) {
         // Adding an hidden field forces the browser to send an empty data even though the user did not
         // select any element. This value will be cleaned up in self::exportValue() as it will not be part
         // of the select options.
         $html .= '<input type="hidden" name="'.$this->getName().'" value="_qf__force_multiselect_submission">';
     }
     if ($this->_hiddenLabel){
         $this->_generateId();
         $html .= '<label class="accesshide" for="'.$this->getAttribute('id').'" >'.$this->getLabel().'</label>';
     }
     $html .= parent::toHtml();
     return $html;
 }
Example #4
0
 function toHtml()
 {
     $retval = '';
     if ($this->_hiddenLabel) {
         $this->_generateId();
         $retval = '<label class="accesshide" for="' . $this->getAttribute('id') . '" >' . $this->getLabel() . '</label>' . parent::toHtml();
     } else {
         $retval = parent::toHtml();
     }
     if (!empty($this->_link)) {
         if (!empty($this->_linkreturn) && is_array($this->_linkreturn)) {
             $appendchar = '?';
             if (strstr($this->_link, '?')) {
                 $appendchar = '&amp;';
             }
             foreach ($this->_linkreturn as $key => $val) {
                 $this->_link .= $appendchar . "{$key}={$val}";
                 $appendchar = '&amp;';
             }
         }
         $retval .= '<a style="margin-left: 5px" href="' . $this->_link . '">' . $this->_linklabel . '</a>';
     }
     return $retval;
 }
 function toHtml()
 {
     if ($this->_flagFrozen) {
         return $this->getFrozenHtml();
     }
     //		$commUtil = new Common_Util();
     $lastPicker = $_REQUEST[$this->_multiname . "PICKER"];
     //$commUtil->request($this->_multiname."PICKER");
     //		$out .= "<script src='/Html/JS/multichooser.js' language='Javascript' type='text/Javascript'></script>\n";
     $out .= "<table>";
     if ($this->_usePicker) {
         //$pickerVals = array("0"=>"Please Select...");
         $pickerVals = array();
         $optionArray = array();
         foreach ($this->_pickerOptions as $label => $options) {
             $pickerVals[] = $label;
             $optionArray[] = $options;
         }
         $elementName = $this->_multiname;
         $out .= "<tr><td colspan='4'><Br><Br>\n";
         $out .= "<script type='text/javascript'>";
         $out .= "var PickerData{$elementName} = [[]";
         foreach ($this->_pickerOptions as $labelSet => $optionSet) {
             $lableArr = explode(',', $labelSet);
             $lableKey = $lableArr[1];
             $out .= ",";
             //'".$lableKey."'
             $first = 1;
             if (sizeof($optionSet)) {
                 foreach ($optionSet as $value => $label) {
                     if ($first == 1) {
                         $first = 0;
                     } else {
                         $out .= ",";
                     }
                     $label = preg_replace("/\\'/", "\\'", $label);
                     $out .= "['{$lableKey}', '{$value}','{$label}']";
                 }
             } else {
                 $out .= "[]";
             }
             $out .= "\n";
         }
         $out .= "];\n";
         $out .= "</script>";
         $out .= "<b>" . $this->_pickerLabel . "</b>&nbsp;";
         $pickerValsArr = array();
         for ($index = 0; $index < sizeof($pickerVals); $index++) {
             $array_element = explode(',', $pickerVals[$index]);
             $key = $array_element[1];
             $value = $array_element[0];
             $pickerValsArr[$key] = $value;
         }
         $picker = new HTML_QuickForm_select($elementName . "PICKER", "", $pickerValsArr, $attributes . " id='{$elementName}PICKER' onchange=\"multichooserPick('{$elementName}')\"");
         $picker->setSize(1);
         $picker->setSelected($lastPicker);
         $out .= $picker->toHtml();
         $out .= "</td></tr>\n";
     }
     $out .= "<tr><td>";
     if ($this->_autoComplete) {
         $out .= $this->txt->toHtml() . "<br>";
     }
     $out .= "<b>" . $this->_fromLabel . "</b><br>";
     $out .= $this->_fromBox->toHtml();
     $out .= "</td><td>";
     $out .= $this->_addButton->toHtml();
     $out .= "<br>";
     $out .= $this->_remButton->toHtml();
     $out .= "</td><td>";
     $out .= "<b>" . $this->_toLabel . "</b><br>";
     $out .= $this->_inBox->toHtml();
     $out .= "</td></tr></table>\n";
     $out .= $this->_hidden->toHtml();
     $out .= "<script type='text/javascript'>document.getElementById('" . $this->_multiname . "').value = '" . $this->_hidden->getValue() . "';</script>";
     return $out;
 }
Example #6
0
    /**
     * The ajax call must contain an array of id and text
     * @return string
     */
    public function toHtml()
    {
        $formatResult = $this->getAttribute('formatResult');
        $formatCondition = null;
        if (!empty($formatResult)) {
            $formatCondition = ',
                templateResult : ' . $formatResult . ',
                templateSelection : ' . $formatResult;
        }
        $width = 'element';
        $givenWidth = '100%';
        if (!empty($givenWidth)) {
            $width = $givenWidth;
        }
        //Get the minimumInputLength for select2
        $minimumInputLength = $this->getAttribute('minimumInputLength') > 3 ? $this->getAttribute('minimumInputLength') : 3;
        $plHolder = $this->getAttribute('placeholder');
        if (empty($plHolder)) {
            $plHolder = get_lang('SelectAnOption');
        }
        $id = $this->getAttribute('id');
        if (empty($id)) {
            $id = $this->getAttribute('name');
            $this->setAttribute('id', $id);
        }
        //$iso = Container
        $url = $this->getAttribute('url');
        $iso = api_get_language_isocode();
        $languageCondition = "language: '{$iso}',";
        if (!$url) {
            $url = $this->getAttribute('url_function');
        } else {
            $url = "'{$url}'";
        }
        $html = <<<JS
            <script>
                \$(function(){
                    \$('#{$this->getAttribute('id')}').select2({
                        {$languageCondition}
                        placeholder: '{$plHolder}',
                        allowClear: true,
                        width: '{$width}',
                        minimumInputLength: '{$minimumInputLength}',
                        ajax: {
                            url: {$url},
                            dataType: 'json',
                            data: function(params) {
                                return {
                                    q: params.term, // search term
                                    page_limit: 10,
                                };
                            },
                            processResults: function (data, page) {
                                //parse the results into the format expected by Select2
                                return {
                                    results: data.items
                                };
                            }
                            {$formatCondition}
                        }
                    });
                });
            </script>
JS;
        $this->removeAttribute('formatResult');
        $this->removeAttribute('minimumInputLength');
        $this->removeAttribute('placeholder');
        $this->removeAttribute('class');
        $this->removeAttribute('url');
        $this->removeAttribute('url_function');
        $this->setAttribute('style', 'width: 100%;');
        return parent::toHtml() . $html;
    }
Example #7
0
    /**
     * The ajax call must contain an array of id and text
     * @return string
     */
    function toHtml()
    {
        $html = api_get_asset('select2/dist/js/select2.min.js');
        $iso = api_get_language_isocode(api_get_interface_language());
        $languageCondition = '';
        if (file_exists(api_get_path(SYS_PATH) . "web/assets/select2/dist/js/i18n/{$iso}.js")) {
            $html .= api_get_asset("select2/dist/js/i18n/{$iso}.js");
            $languageCondition = "language: '{$iso}',";
        }
        $html .= api_get_css(api_get_path(WEB_PATH) . 'web/assets/select2/dist/css/select2.min.css');
        $formatResult = $this->getAttribute('formatResult');
        $formatCondition = null;
        if (!empty($formatResult)) {
            $formatCondition = ',
                templateResult : ' . $formatResult . ',
                templateSelection : ' . $formatResult;
        }
        $width = 'element';
        $givenWidth = '100%';
        if (!empty($givenWidth)) {
            $width = $givenWidth;
        }
        //Get the minimumInputLength for select2
        $minimumInputLength = $this->getAttribute('minimumInputLength') > 3 ? $this->getAttribute('minimumInputLength') : 3;
        $plHolder = $this->getAttribute('placeholder');
        if (empty($plHolder)) {
            $plHolder = get_lang('SelectAnOption');
        }
        $id = $this->getAttribute('id');
        if (empty($id)) {
            $id = $this->getAttribute('name');
            $this->setAttribute('id', $id);
        }
        $html .= <<<JS
            <script>
                \$(function(){
                    \$('#{$this->getAttribute('id')}').select2({
                        {$languageCondition}
                        placeholder: '{$plHolder}',
                        allowClear: true,
                        width: '{$width}',
                        minimumInputLength: '{$minimumInputLength}',
                        ajax: {
                            url: '{$this->getAttribute('url')}',
                            dataType: 'json',
                            data: function(params) {
                                return {
                                    q: params.term, // search term
                                    page_limit: 10,
                                };
                            },
                            processResults: function (data, page) {
                                //parse the results into the format expected by Select2
                                return {
                                    results: data.items
                                };
                            }
                            {$formatCondition}
                        }
                    });
                });
            </script>
JS;
        $this->removeAttribute('formatResult');
        $this->removeAttribute('minimumInputLength');
        $this->removeAttribute('placeholder');
        $this->removeAttribute('class');
        $this->removeAttribute('url');
        $this->setAttribute('style', 'width: 100%;');
        return parent::toHtml() . $html;
    }