function render() { if (!$this->name) { throw new \Exception('must set a name'); } if (!$this->xhr_url) { throw new \Exception('must set xhr url'); } if (!$this->js_format_result || !$this->result_fields) { throw new \Exception('need js code'); } $header = XhtmlHeader::getInstance(); $header->includeCss('core_dev/js/ext/yui/2.9.0/build/fonts/fonts-min.css'); $header->includeCss('core_dev/js/ext/yui/2.9.0/build/autocomplete/assets/skins/sam/autocomplete.css'); $header->includeCss('core_dev/js/ext/yui/2.9.0/build/button/assets/skins/sam/button.css'); $header->includeJs('core_dev/js/ext/yui/2.9.0/build/yahoo-dom-event/yahoo-dom-event.js'); $header->includeJs('core_dev/js/ext/yui/2.9.0/build/get/get-min.js'); $header->includeJs('core_dev/js/ext/yui/2.9.0/build/animation/animation-min.js'); $header->includeJs('core_dev/js/ext/yui/2.9.0/build/datasource/datasource-min.js'); $header->includeJs('core_dev/js/ext/yui/2.9.0/build/autocomplete/autocomplete-min.js'); $header->includeJs('core_dev/js/ext/yui/2.9.0/build/element/element-min.js'); $header->includeJs('core_dev/js/ext/yui/2.9.0/build/button/button-min.js'); $div_holder = 'yui_ac' . mt_rand(); $container_holder = 'ac_contain_' . mt_rand(); $button_id = 'ac_toggle_' . mt_rand(); $input_id = 'ac_input_' . mt_rand(); $header->embedJs('function highlight(s,h)' . '{' . 'var regex = new RegExp("("+h+")","ig");' . 'return s.replace(regex, "<span class=\\"highlighted\\">$1</span>");' . '}'); $header->embedCss('label {' . 'color:#E76300;' . 'font-weight:bold;' . '}' . '#' . $div_holder . ' {' . 'width:20em;' . '}' . '.yui-ac .result {position:relative;height:20px;}' . '.yui-ac .name {position:absolute;bottom:0;}' . '.highlighted {color:#CA485E;font-weight:bold; }' . '.yui-ac .yui-button {vertical-align:middle;}' . '.yui-ac .yui-button button {background: url(http://developer.yahoo.com/yui/examples/autocomplete/assets/img/ac-arrow-rt.png) center center no-repeat}' . '.yui-ac .open .yui-button button {background: url(http://developer.yahoo.com/yui/examples/autocomplete/assets/img/ac-arrow-dn.png) center center no-repeat}' . '.yui-skin-sam .yui-ac-input {position:static; vertical-align:middle;}' . '.yui-skin-sam .yui-ac-content {' . 'max-height:250px;overflow:auto;overflow-x:hidden;' . '}'); $res = 'YAHOO.example.CustomFormatting = (function(){' . 'var oDS = new YAHOO.util.ScriptNodeDataSource("' . $this->xhr_url . '");' . 'oDS.responseSchema = {' . 'resultsList:"records",' . 'fields:' . Json::encode($this->result_fields, false) . '};' . 'var oAC = new YAHOO.widget.AutoComplete("' . $input_id . '","' . $container_holder . '", oDS);' . 'oAC.minQueryLength = 0;' . 'oAC.queryDelay = ' . $this->query_delay . ';' . 'oAC.animSpeed = 0.01;' . 'oAC.maxResultsDisplayed = 100;' . 'oAC.forceSelection = true;' . 'oAC.generateRequest = function(sQuery) {' . 'return sQuery + "&format=json";' . '};' . 'oAC.resultTypeList = false;' . 'oAC.formatResult = function(oResultData, sQuery, sResultMatch) {' . $this->js_format_result . '};' . 'oAC.itemSelectEvent.subscribe(function(sType, aArgs) {' . 'var oData = aArgs[2];' . 'var input = document.createElement("input");' . 'input.setAttribute("type", "hidden");' . 'input.setAttribute("name", "' . $this->name . '");' . 'input.setAttribute("value", oData.id);' . 'document.getElementById("' . $div_holder . '").appendChild(input);' . '});' . 'var validateForm = function() {' . 'return true;' . '};' . 'return {' . 'oDS: oDS,' . 'oAC: oAC,' . 'validateForm: validateForm' . '}' . '})();'; $in = new XhtmlComponentInput(); $in->name = $input_id; $in->width = 200; // XXXX HACK, should not set width at all.. but we do it now so button dont end up on the next line return '<div id="' . $div_holder . '">' . $in->render() . '<div id="' . $container_holder . '"></div>' . '</div>' . js_embed($res); }
public function test1() { $input = new XhtmlComponentInput(); $input->name = "hej"; $input->value = 555; $input->size = 10; $this->assertEquals($input->render(), '<input type="text" name="hej" id="hej" value="555" size="10"/>'); }