1: <?php
2:
3: class DbEdit extends \Sphp\tools\Control{
4: private $type = "text";
5: private $options = "";
6: private $ctag = 0;
7:
8: public function oncreate($param) {
9: $this->setHTMLID("");
10: $this->setHTMLName("");
11:
12: }
13: public function setOptions($param) {
14: $this->type = "select";
15: $this->options = "";
16: if(is_string($param)){
17: $p2 = explode(",",$param);
18: foreach($p2 as $index=>$val){
19: $this->options .= '<option value="'. $val .'">'. $val .'</option>';
20: }
21: }else{
22: foreach($param as $index=>$val){
23: $this->options .= '<option value="'. $index .'">'. $val .'</option>';
24: }
25: }
26: //$this->setPreTag('<select id="slt'. $this->name .'" style="display:none; position: absolute;">'. $this->options .'</select>');
27: addHeaderJSCode('slt2','$("body").append(\'<select id="slt'. $this->name .'" data-recid="" style="display:none; position: absolute;">'. $this->options .'</select>\');');
28: }
29:
30: public function onrender() {
31: if($this->type == "text"){
32: $this->contenteditable = "true";
33: $this->setAttribute("class", "dbedit");
34: $this->setAttribute("oninput","fundbedit(this)");
35: addHeaderJSCode('dbedit', ' function fundbedit(obj1){
36: clearTimeout(this.tmr1);
37: $(obj1).css("background-color","#FF0000");
38: this.tmr1 = setTimeout(function(){
39: let data = {};
40: data["flid"] = $(obj1).data("recid");
41: data["flidv"] = $(obj1).data("recidv");
42: data["fld"] = $(obj1).data("field");
43: data["fltbl"] = $(obj1).data("table");
44: data["flval"] = $(obj1).text();
45: getAJAX($(obj1).data("suburl"),data,false,function(ret){
46: $(obj1).css("background-color","");
47: });
48: },1000);
49: }');
50: }else if($this->type == "select"){
51: if($this->ctag < 2){
52: $this->ctag += 1;
53: }else{
54: $this->setPreTag('');
55: }
56: //$this->tagName = "select";
57: $this->setAttribute("class", $this->name);
58: $this->setAttribute("onmouseup","fundbedit2(this)");
59: //$this->setInnerHTML($this->options);
60: addHeaderJSCode($this->name , '
61: function fundbedit2(obj1){
62: //console.log(event);
63: //let obj1 = event.target;
64: var offs = $(obj1).offset();
65: $("#slt'. $this->name . '").css("left",offs.left + 10);
66: $("#slt'. $this->name . '").css("top",offs.top + 10);
67: $("#slt'. $this->name . '").css("display","block");
68: $("#slt'. $this->name . '").data("recid",$(obj1).data("recid"));
69: $("#slt'. $this->name . '").data("recidv",$(obj1).data("recidv"));
70: $("#slt'. $this->name . '").data("field",$(obj1).data("field"));
71: $("#slt'. $this->name . '").data("table",$(obj1).data("table"));
72: $("#slt'. $this->name . '").data("suburl",$(obj1).data("suburl"));
73: let slt1 = $(obj1).data("recidv") + "d";
74: selectByValue($("#slt'. $this->name . '"),$("#" + slt1).data("mval"));
75: }
76: $("#slt'. $this->name .'").on("change",function(event){
77: let obj1 = event.target;
78: if($(obj1).data("recid") !== ""){
79: $(obj1).css("background-color","#FF0000");
80: let data = {};
81: data["flid"] = $(obj1).data("recid");
82: data["flidv"] = $(obj1).data("recidv");
83: data["fld"] = $(obj1).data("field");
84: data["fltbl"] = $(obj1).data("table");
85: data["flval"] = getValue(obj1);
86: let slt1 = $(obj1).data("recidv") + "d";
87: $("#" + slt1).html(obj1.options[obj1.selectedIndex].text);
88: $("#" + slt1).data("mval",obj1.options[obj1.selectedIndex].value);
89: getAJAX($(obj1).data("suburl"),data,false,function(ret){
90: $(obj1).css("background-color","");
91: $(obj1).css("display","none");
92: });
93: }
94: });');
95:
96: }
97: }
98:
99:
100: }
101: