1: <?php
2: /**
3: * DbEdit by Sartaj
4: * <td id="txtedit2" fursetHTMLID="##{ $this->frontobj->showall->getRow('id_c')}#d"
5: * path="libpath/comp/data/DbEdit.php" data-suburl="index-dbedit.html"
6: data-field="shipper_c" data-table="leads_cstm" value="##{ $this->frontobj->showall->getRow('shipper_c') }#"
7: fur_data-recidv="##{ $this->frontobj->showall->getRow('id_c') }#"
8: * fur_data-mval="##{ $this->frontobj->showall->getRow('shipper_c') }#"
9: * data-recid="id_c" runat="server">
10: * ##{ $this->frontobj->parentgate->getShipList2($this->frontobj->showall->getRow('shipper_c')) }#
11: * </td>
12: */
13: class DbEdit extends \Sphp\tools\Component{
14: private $type = "text";
15: private $options = "";
16: private $ctag = 0;
17:
18: protected function oncreate($element) {
19: $this->setHTMLID("");
20: $this->setHTMLName("");
21:
22: }
23: public function fu_setOptions($param) {
24: $this->type = "select";
25: $this->options = "";
26: if(is_string($param)){
27: $p2 = explode(",",$param);
28: foreach($p2 as $index=>$val){
29: $this->options .= '<option value="'. $val .'">'. $val .'</option>';
30: }
31: }else{
32: foreach($param as $index=>$val){
33: $this->options .= '<option value="'. $index .'">'. $val .'</option>';
34: }
35: }
36: //$this->setPreTag('<select id="slt'. $this->name .'" style="display:none; position: absolute;">'. $this->options .'</select>');
37: addHeaderJSCode('slt2','$("body").append(\'<select id="slt'. $this->name .'" data-recid="" style="display:none; position: absolute;">'. $this->options .'</select>\');');
38: }
39: public function fu_setAuth($param) {
40: $blnF = \SphpBase::page()->checkAuth($param);
41: if (!$blnF) {
42: $this->renderTag = false;
43: }
44: }
45:
46: protected function onrender() {
47: if($this->renderTag) $this->renderT1();
48: }
49: private function renderT1() {
50: if($this->type == "text"){
51: $this->contenteditable = "true";
52: $this->setAttribute("class", "dbedit");
53: $this->setAttribute("oninput","fundbedit()");
54: $this->setAttribute("onclick","return(false)");
55: addHeaderJSCode('dbedit', ' window["fundbedit"] = function(){
56: let obj1 = event.target;
57: clearTimeout(obj1.tmr1);
58: $(obj1).css("background-color","#FF0000");
59: obj1.tmr1 = setTimeout(function(){
60: let data = {};
61: data["flid"] = $(obj1).data("recid");
62: data["flidv"] = $(obj1).data("recidv");
63: data["fld"] = $(obj1).data("field");
64: data["fltbl"] = $(obj1).data("table");
65: data["flval"] = $(obj1).text();
66: getAJAX($(obj1).data("suburl"),data,false,function(ret){
67: $(obj1).css("background-color","");
68: });
69: },1000);
70: };');
71: }else if($this->type == "select"){
72: if($this->ctag < 2){
73: $this->ctag += 1;
74: }else{
75: $this->setPreTag('');
76: }
77: //$this->tagName = "select";
78: $this->setAttribute("class", $this->name);
79: $this->setAttribute("onmouseup","fundbedit2()");
80: //$this->setInnerHTML($this->options);
81: addHeaderJSCode($this->name , '
82: window["fundbedit2"] = function(){
83: //console.log(event);
84: let obj1 = event.target;
85: var offs = $(obj1).offset();
86: $("#slt'. $this->name . '").css("left",offs.left + 10);
87: $("#slt'. $this->name . '").css("top",offs.top + 10);
88: $("#slt'. $this->name . '").css("display","block");
89: $("#slt'. $this->name . '").data("recid",$(obj1).data("recid"));
90: $("#slt'. $this->name . '").data("recidv",$(obj1).data("recidv"));
91: $("#slt'. $this->name . '").data("field",$(obj1).data("field"));
92: $("#slt'. $this->name . '").data("table",$(obj1).data("table"));
93: $("#slt'. $this->name . '").data("suburl",$(obj1).data("suburl"));
94: let slt1 = $(obj1).data("recidv") + "d";
95: selectByValue($("#slt'. $this->name . '"),$("#" + slt1).data("mval"));
96: };
97: $("#slt'. $this->name .'").on("change",function(event){
98: let obj1 = event.target;
99: if($(obj1).data("recid") !== ""){
100: $(obj1).css("background-color","#FF0000");
101: let data = {};
102: data["flid"] = $(obj1).data("recid");
103: data["flidv"] = $(obj1).data("recidv");
104: data["fld"] = $(obj1).data("field");
105: data["fltbl"] = $(obj1).data("table");
106: data["flval"] = getValue(obj1);
107: let slt1 = $(obj1).data("recidv") + "d";
108: $("#" + slt1).html(obj1.options[obj1.selectedIndex].text);
109: $("#" + slt1).data("mval",obj1.options[obj1.selectedIndex].value);
110: getAJAX($(obj1).data("suburl"),data,false,function(ret){
111: $(obj1).css("background-color","");
112: $(obj1).css("display","none");
113: });
114: }
115: });');
116:
117: }
118: }
119:
120:
121: }
122: