1: <?php
2: /**
3: * Description of Autocomplete
4: *
5: * @author SARTAJ
6: */
7:
8:
9:
10: class Autocomplete extends Control{
11: private $url = "";
12: private $minlen = "1";
13: private $req = false;
14: private $formName = '';
15: private $msgName = '';
16: private $synccomp = '';
17:
18: public function oncreate($element){
19: $this->setHTMLName("");
20: $this->url = getEventURL($this->name.'_autocomplete');
21: }
22: public function setForm($val) { $this->formName = $val;}
23: public function setMsgName($val) { $this->msgName = $val;}
24: public function setRequired() {
25: if($this->issubmit){
26: if(strlen($this->value) < 1){
27: setErr($this->name,"Can not submit Empty");
28: }
29: }
30: $this->req = true;
31: }
32:
33: public function setURL($val){
34: $this->url = $val;
35: }
36: public function setMinLen($val){
37: $this->minlen = $val;
38: }
39: public function sendData($val){
40:
41: SphpBase::JSServer()->addJSONBlock('js','proces','
42: '. SphpBase::sphp_api()->getJSArray("data",$val) .'
43: var term = "'.$_REQUEST['term'].'" ;
44: '.$this->name.'_cache[term] = data;
45: '.$this->name.'_response(data);
46: ');
47:
48: }
49:
50: public function onjsrender(){
51: global $jquerypath;
52: /*
53: addFileLink($jquerypath.'themes/base/jquery.ui.all.css');
54: addFileLink($jquerypath.'themes/base/jquery.ui.accordion.css');
55: addFileLink($jquerypath.'ui/jquery.ui.core.min.js');
56: addFileLink($jquerypath.'ui/jquery.ui.widget.min.js');
57: addFileLink($jquerypath.'ui/jquery.ui.position.min.js');
58: addFileLink($jquerypath.'ui/jquery.ui.menu.min.js');
59: addFileLink($jquerypath.'ui/jquery.ui.autocomplete.min.js');
60: *
61: */
62: if($this->formName!=''){
63: if($this->req){
64: addFooterJSFunctionCode("{$this->formName}_submit", "{$this->name}req", "
65: ctlReq['$this->name']= Array('$this->msgName','TextField');");
66: }
67: }
68:
69: addHeaderJSFunction($this->name.'_autocomplete', "function ".$this->name.'_autocomplete(request){ ' , "
70: clearTimeout(this.tmr1); this.tmr1 = setTimeout(function(){
71: getURL('$this->url',request);
72: },1000);
73: }");
74:
75: addHeaderJSCode($this->name, ' window["'.$this->name.'_cache"] = {}; window["'.$this->name.'_response"] = null;');
76: addHeaderJSFunctionCode('ready',$this->name,'
77: $("#'.$this->name.'").autocomplete({
78: minLength: '.$this->minlen.',
79: source: function( request, response ) {
80: var term = request.term;
81: if ( term in '.$this->name.'_cache ) {
82: response('.$this->name.'_cache[term]);
83: return;
84: }
85: '.$this->name.'_response = response;
86: '.$this->name.'_autocomplete(request);
87:
88: }
89: });
90: ');
91: }
92:
93:
94:
95: }
96: ?>