Forráskód Böngészése

TableAjaxMap: add save function for the_geom field

Piotr Labudda 11 éve
szülő
commit
f82e144fc5
3 módosított fájl, 113 hozzáadás és 35 törlés
  1. 2 0
      SE/se-lib/Core/Database/Mysql.php
  2. 88 6
      SE/se-lib/TableAjax.php
  3. 23 29
      SE/se-lib/TableAjaxMap.php

+ 2 - 0
SE/se-lib/Core/Database/Mysql.php

@@ -331,6 +331,8 @@ class Core_Database_Mysql extends Core_Database {
 				$v = 'NOW()';
 			} else if (strtoupper($v) == 'NULL') {
 				$v = 'NULL';
+			} else if (substr($v, 0, strlen('GeomFromText')) == 'GeomFromText') {
+				
 			} else {
 				$v = $this->_($v);
 				$v = "'{$v}'";

+ 88 - 6
SE/se-lib/TableAjax.php

@@ -1533,12 +1533,32 @@ class TableAjax extends ViewAjax {
 				wpsUrl: 'http://biuro.biall-net.pl/wps',
 				wfsUrl: 'http://biuro.biall-net.pl/wps',
 				layerName: '<?php echo $this->getLabelHtml(); ?>',
-				onfeatureselect: function() {
-					// this.selectedFeatures
-					console.log('onfeatureselect (',this.selectedFeatures.length,'): ', this);
-				},
-				onfeatureselect: function() {
-					console.log('onfeatureselect (',this.selectedFeatures.length,'): ', this);
+				onSaveFeature: function(selectedRecordId, selectedFeatureExtent) {
+					console.log('onSaveFeature (',selectedRecordId,'/',selectedFeatureExtent,') ', this);
+					if (!selectedRecordId) {
+						alert('Brak zaznaczonego rekordu - wybierz rekord z tabeli');
+						return;
+					}
+
+
+					$.ajax({
+						data: {polygon: selectedFeatureExtent},
+						type: "POST",
+						url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=THE_GEOM_SAVE&ID=' + selectedRecordId
+					})
+					.done(function(data, textStatus, jqXHR){
+						//TODO: update table cell data; that.data("treetable").updateNodeHtmlData(id, jqXHR.responseText);
+						jQuery.notify('Aktualizacja danych dla rekordu ' + selectedRecordId, 'success');
+					})
+					.fail(function(jqXHR){// jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
+						var txt = jqXHR.responseText || 'Error';
+						if (jqXHR.status == 404) {
+							jQuery.notify(jqXHR.responseText, 'error');
+						} else {
+							jQuery.notify(jqXHR.responseText, 'warn');
+						}
+					});
+
 				}
 			});
 
@@ -2521,6 +2541,10 @@ function hidePopover() {
 				$this->sendHiddenColsSave($_REQUEST);
 				break;
 			}
+			case 'THE_GEOM_SAVE': {
+				$this->sendTheGeomSave($_REQUEST);
+				break;
+			}
 			default:
 				$this->sendAjaxData($_REQUEST);
 		}
@@ -4469,4 +4493,62 @@ jQuery(document).ready(function(){
 		UserProfile::save();
 	}
 
+	private function sendTheGeomSave($args) {
+		$id = V::get('ID', 0, $args, 'int');
+		$polygon = V::get('polygon', 0, $args);
+		$geomFieldName = 'the_geom';
+
+		if ($id <= 0) {
+			header('HTTP/1.0 404 Not Found');
+			echo "Wrong param ID";
+			exit;
+		}
+		// TODO: validate polygon - ex.: POLYGON((2072030.2315435 7234115.910678,2072029.4815435 7234093.660678,2072115.2315435 7234091.160678,2072115.4815435 7234113.660678,2072115.2315435 7234113.660678,2072094.2315435 7234113.910678,2072030.2315435 7234115.910678)))
+
+		$tblName = $this->_acl->getName();
+
+		$db = DB::getDB();
+		$record = $db->get_by_id($tblName, $id);
+		if (!$this->_acl->canWriteRecord($record) && !$this->_acl->hasPermSuperWrite()) {
+			header('HTTP/1.0 403.3 - Write access forbidden');
+			echo "Brak dostępu do rekordu";
+			exit;
+		}
+
+		$theGeomFieldId = $this->_acl->getFieldIdByName($geomFieldName);
+		if (!$this->_acl->isAllowed($theGeomFieldId, 'W', $record)) {
+			header('HTTP/1.0 403.3 - Write access forbidden');
+			echo "Brak dostępu do zapisu dla pola {$geomFieldName}";
+			exit;
+		}
+
+		$sqlObj = new stdClass();
+		$sqlObj->{$geomFieldName} = "GeomFromText('{$polygon}')";
+		$sqlObj->ID = $id;
+		if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sqlObj);echo'</pre>';}
+
+		$ret = $db->UPDATE_OBJ($tblName, $sqlObj);
+
+		if ($ret > 0) {
+			echo '<div class="alert alert-success">';
+				echo "Rekord zapisany pomyślnie";//"Record saved successfully";
+			echo '</div>';
+		} else if ($ret == 0) {
+			echo '<div class="alert alert-info">';
+				echo "Nie wprowadzono żadnych zmian";
+			echo '</div>';
+		} else {
+			header('HTTP/1.0 404 Not Found');
+			echo '<div class="alert alert-error">';
+				echo '<h4>' . "Wystąpiły błędy!" . '</h4>';
+				if ($db->has_errors()) {
+					$errors = $db->get_errors();
+					echo implode('<br>', $errors);
+				}
+			echo '</div>';
+		}
+
+		exit;
+	}
+
 }

+ 23 - 29
SE/se-lib/TableAjaxMap.php

@@ -61,8 +61,6 @@ OpenLayers.ProxyHost = "index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_
 			wpsUrl: '',
 			wfsUrl: '',
 			layerName: 'Warstwa rysowania',
-			onfeatureselect: null,
-			onfeatureunselect: null,
 			debug: false
 		};
 
@@ -81,8 +79,6 @@ OpenLayers.ProxyHost = "index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_
 		 initialize the plugin.
 		 */
 		priv.init = function() {
-			console.log('test jQuery plugin init...', priv);
-			// create dom:
 			/*
 				<div id="map" class="TableAjaxMap"></div>
 
@@ -202,25 +198,10 @@ OpenLayers.ProxyHost = "index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_
 				})
 			});
 
-			_layer.events.on({
-				'featureselected': function(feature) {
-					console.log('_layer onfeatureselect (',this.selectedFeatures.length,'): ', this);
-					//document.getElementById('counter').innerHTML = this.selectedFeatures.length;
-					if (typeof priv.options.onfeatureselect == "function") {
-						priv.options.onfeatureselect.apply(this);
-					}
-				},
-				'featureunselected': function(feature) {
-					console.log('_layer onfeatureselect (',this.selectedFeatures.length,'): ', this);
-					if (typeof priv.options.onfeatureunselect == "function") {
-						priv.options.onfeatureunselect.apply(this);
-					}
-				}
-			});
 			_layer.events.on({
 				'beforefeaturemodified': function(e) {
 					console.log('Event: beforefeaturemodified modified(', e.feature.attributes._modified, ')', e.feature.attributes, ' selAttras', (_selectedFeature)? _selectedFeature.attributes : 'null');// TODO: DBG
-					// NOTE: beforefeaturemodified from new node is fired before afterfeaturemodified from old node when click from one shape to enother
+					// NOTE: beforefeaturemodified from new node is fired before afterfeaturemodified from old node when click from one node to enother
 					priv.checkSelectedFeatureModifications('before');
 					priv.setSelectedFeature(e.feature);
 				},
@@ -270,20 +251,20 @@ OpenLayers.ProxyHost = "index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_
 			]);
 			toolbar.addControls([
 				new OpenLayers.Control.Button({
-					title: "Test mark as recordId 999",
+					title: "Zapisz zmiany",
 					displayClass: "olControlSave",
 					trigger: function() {
 						if (_selectedFeature) {
 							if (!_selectedRecordId) {
-								alert('Select Record from table');
+								alert('Wybierz rekord  tabeli');
 							}
 							else {
-								_selectedFeature.attributes['tblId'] = <?php echo $this->_zasobID; ?>;
-								_selectedFeature.attributes['recordId'] = _selectedRecordId;
+								priv.saveSelectedFeature();
+								priv.cancelSelectedFeatureModifications();
 							}
 						}
 						else {
-							alert('Select feature')
+							alert('Wybierz element na mapie');
 						}
 					}
 				})
@@ -360,7 +341,8 @@ OpenLayers.ProxyHost = "index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_
 		};
 
 		priv.isSelectedFeature = function() {
-			return !!_selectedFeature;
+			console.log('_selectedFeature:', _selectedFeature);
+			return (_selectedFeature)? true : false;
 		};
 
 		priv.cancelSelectedFeatureModifications = function() {
@@ -385,14 +367,25 @@ OpenLayers.ProxyHost = "index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_
 			}
 		};
 
+		priv.saveSelectedFeature = function() {
+			if (priv.isSelectedFeatureModified()) {
+				if (typeof priv.options.onSaveFeature == "function") {
+					var selFeatureExtent = new OpenLayers.Format.WKT().write(_selectedFeature);
+					priv.options.onSaveFeature.call(this, _selectedRecordId, selFeatureExtent);
+				}
+			}
+		}
+
 		priv.checkSelectedFeatureModifications = function(when) {
 			if (priv.isSelectedFeatureModified()) {
-				if (confirm('Anulować zmiany wprowadzone dla zaznaczonego elementu?' + when)) {
+				if (confirm('Czy zapisać zmiany wprowadzone dla zaznaczonego elementu?')) {
+					// _layer.refresh();
+					priv.saveSelectedFeature();
 					priv.cancelSelectedFeatureModifications();
-					_layer.refresh({force:true});
 				}
 				else {
-					// _layer.refresh();
+					priv.cancelSelectedFeatureModifications();
+					_layer.refresh({force:true});
 				}
 			}
 		};
@@ -703,6 +696,7 @@ OpenLayers.ProxyHost = "index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_
 		};
 
 		publ.zoomToExtent = function(extent) {
+			if (!extent) return;
 			var extentBounds = OpenLayers.Geometry.fromWKT(extent).getBounds();
 			_map.zoomToExtent(extentBounds);
 		};