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