|
|
@@ -24,6 +24,7 @@ class TableAjax extends ViewAjax {
|
|
|
private $_filterInit = null;
|
|
|
private $_forceFilterInit = null;
|
|
|
private $_showProcesInit = true;
|
|
|
+ public $syncUrl = null;
|
|
|
|
|
|
public function __construct($tblAcl) {
|
|
|
$this->_tbl = $tblAcl->getName();
|
|
|
@@ -49,6 +50,10 @@ class TableAjax extends ViewAjax {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public function setSyncUrl($syncUrl) {
|
|
|
+ $this->syncUrl = $syncUrl;
|
|
|
+ }
|
|
|
+
|
|
|
public function showProcesInit($bool = true) {
|
|
|
$this->_showProcesInit = $bool;
|
|
|
}
|
|
|
@@ -990,63 +995,34 @@ var p5UI_TableAjax_generateFunctionNode = function(funObj, rowPK, props) {
|
|
|
if (!recordID) return;
|
|
|
|
|
|
var selectedRecordId = recordID;
|
|
|
- function notifyAjaxCallback(data) {
|
|
|
- var notify = {};
|
|
|
- notify.type = (data && data.type)? data.type : '';
|
|
|
- notify.msg = (data && data.msg)? data.msg : '';
|
|
|
- switch (notify.type) {
|
|
|
- case 'success':
|
|
|
- if (!notify.msg) notify.msg = 'Usunięto obiekt z mapy dla rekordu ' + selectedRecordId;
|
|
|
- break;
|
|
|
- case 'info':
|
|
|
- if (!notify.msg) notify.msg = 'Rekord nie był powiązany z żadnym obiektem na mapie';
|
|
|
- break;
|
|
|
- case 'error':
|
|
|
- if (!notify.msg) notify.msg = 'Wystąpiły błędy';
|
|
|
- break;
|
|
|
- case 'warning':
|
|
|
- notify.type = 'warn';
|
|
|
- if (!notify.msg) notify.msg = 'Wystąpiły błędy';
|
|
|
- break;
|
|
|
- default:
|
|
|
- notify.msg = 'Nieznany błąd';
|
|
|
- if (data && data.errorCode) notify.msg += ' ' + data.errorCode;
|
|
|
- notify.type = '';
|
|
|
- }
|
|
|
- jQuery.notify(notify.msg, notify.type);
|
|
|
- }
|
|
|
- $.ajax({
|
|
|
- data: {},
|
|
|
- dataType: 'json',
|
|
|
- type: "POST",
|
|
|
- url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=THE_GEOM_REMOVE&ID=' + recordID
|
|
|
- })
|
|
|
- .done(function(data, textStatus, jqXHR){
|
|
|
- notifyAjaxCallback(data);
|
|
|
- if (priv.options.debug) console.log('data.record.the_geom:', data.record.the_geom);
|
|
|
- if (data && data.record && data.record.the_geom) {
|
|
|
- if (priv.options.debug) console.log('data.record.the_geom:2:', data.record.the_geom);
|
|
|
- geomField.setValue(data.record.the_geom);
|
|
|
- }
|
|
|
- else if (data && data.record) {
|
|
|
- if (priv.options.debug) console.log('data.record.the_geom:2:', data.record.the_geom);
|
|
|
- geomField.setValue(data.record.the_geom);
|
|
|
- }
|
|
|
- _mapEditor.TableAjaxMapRefresh();
|
|
|
- })
|
|
|
- .fail(function(jqXHR){// jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
|
|
|
- if (jqXHR.responseJSON) {
|
|
|
- notifyAjaxCallback(jqXHR.responseJSON);
|
|
|
- }
|
|
|
- else {
|
|
|
- var txt = jqXHR.responseText || 'Wystąpiły błędy';
|
|
|
- if (jqXHR.status == 404) {
|
|
|
- jQuery.notify(jqXHR.responseText, 'error');
|
|
|
+ superagent
|
|
|
+ .post('<?= $this->syncUrl; ?>&_hash=<?= $this->_htmlID; ?>&_task=removeTheGeomAjax')
|
|
|
+ .type('json') // header ĺapplication/x-www-form-urlencoded' requires type('form');
|
|
|
+ .send({
|
|
|
+ ID: recordID,
|
|
|
+ namespace: '<?= $acl->getNamespace(); ?>'
|
|
|
+ })
|
|
|
+ .set('Accept', 'application/json')
|
|
|
+ .end(function(err, res) {
|
|
|
+ if(priv.options.debug)console.log('DBG: res:', res, 'res.body:', res.body);
|
|
|
+ var payload;
|
|
|
+ if (err || !res.ok || 'application/json' !== res.type) {
|
|
|
+ payload = {type: 'warning', msg: res.body.msg || 'Wystąpiły błędy', body: res.body};
|
|
|
} else {
|
|
|
- jQuery.notify(jqXHR.responseText, 'warn');
|
|
|
+ payload = {type: 'success', msg: res.body.msg || '', body: res.body};
|
|
|
+ }
|
|
|
+ p5UI__notifyAjaxCallback(payload);
|
|
|
+ var data = res.body;
|
|
|
+ if (data && data.record && data.record.the_geom) {
|
|
|
+ if (priv.options.debug) console.log('data.record.the_geom:2:', data.record.the_geom);
|
|
|
+ geomField.setValue(data.record.the_geom);
|
|
|
}
|
|
|
- }
|
|
|
- });
|
|
|
+ else if (data && data.record) {
|
|
|
+ if (priv.options.debug) console.log('data.record.the_geom:2:', data.record.the_geom);
|
|
|
+ geomField.setValue(data.record.the_geom);
|
|
|
+ }
|
|
|
+ _mapEditor.TableAjaxMapRefresh();
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
@@ -4058,10 +4034,6 @@ function <?php echo $jsToogleFiltrProcesuFunctionName; ?>(n) {
|
|
|
$this->sendAjaxResponseJson('ajaxTheGeomSave', $_REQUEST);
|
|
|
break;
|
|
|
}
|
|
|
- case 'THE_GEOM_REMOVE': {
|
|
|
- $this->sendAjaxResponseJson('ajaxTheGeomRemove', $_REQUEST);
|
|
|
- break;
|
|
|
- }
|
|
|
case 'PROCES_INIT_FILTR': {
|
|
|
$this->sendAjaxResponseJson('ajaxProcesInitFiltr', $_REQUEST);
|
|
|
break;
|
|
|
@@ -6194,61 +6166,6 @@ jQuery(document).ready(function(){
|
|
|
exit;
|
|
|
}
|
|
|
|
|
|
- private function ajaxTheGeomRemove($args) {// ajax task 'THE_GEOM_REMOVE'
|
|
|
- $primaryKeyField = $this->_acl->getPrimaryKeyField();
|
|
|
- $primaryKey = V::get($primaryKeyField, 0, $args, 'int');
|
|
|
- $geomFieldName = 'the_geom';
|
|
|
- $response = new stdClass();
|
|
|
-
|
|
|
- if ($primaryKey <= 0) {
|
|
|
- throw new HttpException("Wrong param ID", 404);
|
|
|
- }
|
|
|
-
|
|
|
- $record = $this->_acl->getItem($primaryKey);
|
|
|
- if (!$record) {
|
|
|
- throw new HttpException("Nie odnaleziono rekordu nr {$primaryKey}", 404);
|
|
|
- }
|
|
|
- if (!$this->_acl->canWriteRecord($record) && !$this->_acl->hasPermSuperWrite()) {
|
|
|
- throw new HttpException("Brak dostępu do rekordu nr {$primaryKey}", 403);
|
|
|
- }
|
|
|
-
|
|
|
- $theGeomFieldId = $this->_acl->getFieldIdByName($geomFieldName);
|
|
|
- if (!$this->_acl->isAllowed($theGeomFieldId, 'W', $record)) {
|
|
|
- throw new HttpException("Brak dostępu do zapisu dla pola {$geomFieldName}", 403);
|
|
|
- }
|
|
|
-
|
|
|
- if (empty($record->{$geomFieldName})) {
|
|
|
- $response->type = 'info';
|
|
|
- $response->msg = "Rekord nie jest powiązany z żadnym obiektem na mapie";
|
|
|
- $response->record = $record;
|
|
|
- return $response;
|
|
|
- }
|
|
|
-
|
|
|
- $itemPatch = array();
|
|
|
- $itemPatch[$geomFieldName] = "NULL";
|
|
|
- $itemPatch[$primaryKeyField] = $primaryKey;
|
|
|
-
|
|
|
- $response = new stdClass();
|
|
|
- try {
|
|
|
- $affected = $this->_acl->updateItem($itemPatch);
|
|
|
-
|
|
|
- if ($affected > 0) {
|
|
|
- $response->type = 'success';
|
|
|
- $response->msg = "Rekord zapisany pomyślnie";//"Record saved successfully";
|
|
|
- } else if ($affected == 0) {
|
|
|
- $response->type = 'info';
|
|
|
- $response->msg = "Nie wprowadzono żadnych zmian";
|
|
|
- }
|
|
|
- $response->record = $this->_acl->getItem($primaryKey);
|
|
|
- }
|
|
|
- catch (Exception $e) {
|
|
|
- $response->type = 'error';
|
|
|
- $response->msg = $e->getMessage();
|
|
|
- }
|
|
|
-
|
|
|
- return $response;
|
|
|
- }
|
|
|
-
|
|
|
private function ajaxProcesInitFiltr($args) {// ajax task 'PROCES_INIT_FILTR'
|
|
|
$response = new stdClass();
|
|
|
|