| 1: | <?php
|
| 2: | namespace Sphp\Comp\Server{
|
| 3: |
|
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: |
|
| 9: | class Ajaxsenddata extends \Sphp\tools\Component {
|
| 10: |
|
| 11: | private $url = '';
|
| 12: | private $data = '';
|
| 13: | private $dataa = array();
|
| 14: | private $compa = array();
|
| 15: | private $datacomp = '';
|
| 16: | private $outid = '';
|
| 17: | private $method = 'GET';
|
| 18: | private $mime = '';
|
| 19: | private $onrecieve = '';
|
| 20: |
|
| 21: | protected function oncreate($element) {
|
| 22: | $this->setHTMLName("");
|
| 23: | }
|
| 24: |
|
| 25: | public function fu_setURL($val) {
|
| 26: | $this->url = $val;
|
| 27: | }
|
| 28: |
|
| 29: | public function fu_setData($val) {
|
| 30: | $this->data = $val;
|
| 31: | }
|
| 32: |
|
| 33: | public function fu_setDataFromComps($val) {
|
| 34: | $this->compa = explode(',', $val);
|
| 35: | }
|
| 36: |
|
| 37: | public function fu_setOutID($val) {
|
| 38: | $this->outid = $val;
|
| 39: | }
|
| 40: |
|
| 41: | public function fu_setOnReceive($val) {
|
| 42: | $this->onrecieve = $val;
|
| 43: | }
|
| 44: |
|
| 45: | public function fu_setMethodPost() {
|
| 46: | $this->method = 'POST';
|
| 47: | }
|
| 48: |
|
| 49: | public function fu_setMIME($val) {
|
| 50: | $this->mime = $val;
|
| 51: | }
|
| 52: |
|
| 53: | public function call() {
|
| 54: | return "a_$this->name();";
|
| 55: | }
|
| 56: |
|
| 57: | public function postData($url, $data, $cache = 'false', $dataType = 'json') {
|
| 58: | return "aj_$this->name('$url',$data,$cache,'$dataType');";
|
| 59: | }
|
| 60: |
|
| 61: | public function addJSONBlock($sact, $evtp, $dataar) {
|
| 62: | \SphpBase::JSServer()->addJSONBlock($sact, $evtp, $dataar);
|
| 63: | }
|
| 64: |
|
| 65: | public function addJSONJSBlock($jsdata = '') {
|
| 66: | \SphpBase::JSServer()->addJSONJSBlock($jsdata);
|
| 67: | }
|
| 68: |
|
| 69: | public function echoJSON() {
|
| 70: | \SphpBase::JSServer()->echoJSON();
|
| 71: | }
|
| 72: |
|
| 73: | protected function onjsrender() {
|
| 74: | $ajax = new \Sphp\kit\Ajax();
|
| 75: | \SphpBase::JSServer()->getAjax();
|
| 76: | $valobj = null;
|
| 77: | foreach ($this->compa as $key => $val2) {
|
| 78: | $valobj = readGlobal($val2);
|
| 79: | if ($this->method == 'POST') {
|
| 80: | $this->dataa[] = $valobj;
|
| 81: | } else {
|
| 82: | $this->datacomp .= "&" . $valobj->name . "='+ encodeURIComponent(" . $valobj->getJSValue() . ")+'";
|
| 83: | }
|
| 84: | }
|
| 85: |
|
| 86: | $code = "function a_$this->name(){";
|
| 87: | if ($this->url != '') {
|
| 88: | $code .= "document.getElementById('$this->name').style.visibility = 'visible';";
|
| 89: | if (strpos($this->url, '?')) {
|
| 90: | $chr = '&';
|
| 91: | } else {
|
| 92: | $chr = '?';
|
| 93: | }
|
| 94: | if ($this->method == 'POST') {
|
| 95: | $code .= $ajax->postDataAjax($this->url . $chr . $this->name . "=" . $this->data, $this->outid, "a_e" . $this->name, $this->dataa, $this->mime);
|
| 96: | } else {
|
| 97: | $code .= $ajax->getDataAjax($this->url . $chr . $this->name . "=" . $this->data . $this->datacomp, $this->outid, "a_e" . $this->name);
|
| 98: | }
|
| 99: | }
|
| 100: | $code .= "}
|
| 101: | function aj_$this->name(url,data,cache,dataType){
|
| 102: | sartajgt('$this->name',url,data,cache,dataType);
|
| 103: | }
|
| 104: | ";
|
| 105: | $code .= "
|
| 106: | function a_e$this->name(){
|
| 107: | document.getElementById('$this->name').style.visibility = 'hidden';
|
| 108: | $this->onrecieve
|
| 109: | }
|
| 110: | ";
|
| 111: | addFooterJSCode($this->name, $code);
|
| 112: | }
|
| 113: |
|
| 114: | protected function onrender() {
|
| 115: | if ($this->innerHTML == '') {
|
| 116: | $this->innerHTML = '<img src="' . $this->myrespath . '/res/ajax-loader.gif" />';
|
| 117: | }
|
| 118: | $this->setAttribute('style', "visibility:hidden;" . $this->getAttribute('style'));
|
| 119: | $this->tagName = 'div';
|
| 120: | }
|
| 121: |
|
| 122: |
|
| 123: | public function getJSValue() {
|
| 124: | return "document.getElementById('$this->name').value";
|
| 125: | }
|
| 126: |
|
| 127: | public function setJSValue($exp) {
|
| 128: | return "document.getElementById('$this->name').value = $exp;";
|
| 129: | }
|
| 130: |
|
| 131: | }
|
| 132: |
|
| 133: | }
|
| 134: | |