phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
HtmlSearch.php
Go to the documentation of this file.
1<?php
2
4
9
11 private $_elements=array ();
12 private $_searchFields=array ("title" );
13 private $_local=false;
14
15 public function __construct($identifier, $placeholder=NULL, $icon=NULL) {
16 parent::__construct("search-" . $identifier, "div", "ui search", array ());
17 $this->_identifier=$identifier;
18 $this->createField($placeholder, $icon);
19 $this->createResult();
20 $this->_params["type"]="standard";
21 }
22
23 private function createField($placeholder=NULL, $icon=NULL) {
24 $field=new HtmlInput($this->identifier);
25 if (isset($placeholder))
26 $field->setPlaceholder($placeholder);
27 if (isset($icon))
28 $field->addIcon($icon, Direction::RIGHT);
29 $field->getDataField()->setClass("prompt");
30 $this->content["field"]=$field;
31 return $field;
32 }
33
34 private function createResult() {
35 $this->content["result"]=new HtmlSemDoubleElement("results-" . $this->identifier, "div", "results");
36 return $this->content["result"];
37 }
38
39 public function addResult($object) {
40 $this->_local=true;
41 $this->_elements[]=$object;
42 return $this;
43 }
44
45 public function addResults($objects) {
46 $this->_local=true;
47 $this->_elements=\array_merge($this->_elements, $objects);
48 return $this;
49 }
50
51 public function setUrl($url) {
52 $this->_params["apiSettings"]="%{url: %quote%" . $url . "%quote%}%";
53 return $this;
54 }
55
56 public function setType($type) {
57 $this->_params["type"]=$type;
58 return $this;
59 }
60
61 public function getType() {
62 return $this->_params["type"];
63 }
64
65 private function resultsToJson() {
66 $result=\json_encode($this->_elements);
67 return $result;
68 }
69
70 public function setLocal() {
71 $this->_local=true;
72 }
73
74 public function run(JsUtils $js) {
75 $this->_params["onSelect"]='%function(result,response){$(%quote%#' . $this->identifier . '%quote%).trigger(%quote%onSelect%quote%, {%quote%result%quote%: result, %quote%response%quote%:response} );}%';
76 $searchFields=\json_encode($this->_searchFields);
77 $searchFields=str_ireplace("\"", "%quote%", $searchFields);
78 $this->_params["searchFields"]="%" . $searchFields . "%";
79 if ($this->_local === true) {
80 $this->_params["source"]="%content%";
81 $this->addEvent("beforeExecute", "var content=" . $this->resultsToJson() . ";");
82 }
83 if (isset($this->_bsComponent) === false) {
84 $this->_bsComponent=$js->semantic()->search("#" . $this->identifier, $this->_params);
85 }
86 $this->addEventsOnRun($js);
88 }
89
90 public function setFluid() {
91 return $this->addToProperty("class", "fluid");
92 }
93
94 public function onSelect($jsCode) {
95 $this->addEvent("onSelect", $jsCode);
96 }
97
98 private function _opOnSelect($operation, $url, $responseElement="", $parameters=array()) {
99 return $this->_ajaxOn($operation, "onSelect", $url, $responseElement, $parameters);
100 }
101
102 public function getOnSelect($url, $responseElement="", $parameters=array()) {
103 $parameters["params"]="data.result";
104 return $this->_opOnSelect("get", $url, $responseElement, $parameters);
105 }
106
107 public function postOnSelect($url, $responseElement="", $parameters=array()) {
108 $parameters["params"]="data.result";
109 return $this->_opOnSelect("post", $url, $responseElement, $parameters);
110 }
111}
JQuery PHP library.
Definition JsUtils.php:23
semantic(Semantic $semantic=NULL)
getter or setter of the Semantic-UI variable
Definition JsUtils.php:158
addEvent($event, $jsCode, $stopPropagation=false, $preventDefault=false)
_ajaxOn($operation, $event, $url, $responseElement="", $parameters=array())
Base class for Semantic double elements.
addToProperty($name, $value, $separator=" ")
run(JsUtils $js)
{{SimpleExtComponent\Ajax\common\html\BaseHtmlrun()\Ajax\common\html\BaseHtmlrun()}HtmlDoubleElement:...
__construct($identifier, $placeholder=NULL, $icon=NULL)
postOnSelect($url, $responseElement="", $parameters=array())
getOnSelect($url, $responseElement="", $parameters=array())
createField($placeholder=NULL, $icon=NULL)
_opOnSelect($operation, $url, $responseElement="", $parameters=array())