Bläddra i källkod

fixed TableAjax variables

Piotr Labudda 8 år sedan
förälder
incheckning
003de364f5
2 ändrade filer med 51 tillägg och 32 borttagningar
  1. 23 7
      SE/se-lib/TableAjax.php
  2. 28 25
      SE/se-lib/TableAjax.php.TableAjax.js

+ 23 - 7
SE/se-lib/TableAjax.php

@@ -517,14 +517,7 @@ class TableAjax extends ViewAjax {
 			]);
 		}
 		UI::inlineJS(__FILE__ . '.TableAjax.js', [
-			'SYNC_URL' => $this->syncUrl,
-			'HTML_ID' => $this->_htmlID,
-			'NAMESPACE' => $acl->getNamespace(),
 			'URI_BASE' => Request::getPathUri(),
-			'ZASOB_ID' => $this->_zasobID,
-			'CLASS_NAME' => __CLASS__,
-			'HAS_ADDITIONAL_LAYERS' => $this->hasAdditionalLayers(),
-			'LABEL_HTML' => $this->getLabelHtml(),
 		]);
 	$filterInit = $this->_filterInit;
 	$forceFilterInit = $this->_forceFilterInit;
@@ -558,6 +551,7 @@ class TableAjax extends ViewAjax {
 
 	$fltrs = (method_exists($acl, 'getSpecialFilters')) ? $acl->getSpecialFilters() : null;
 	$jsonSpecialFilters = (!empty($fltrs)) ? json_encode($fltrs) : 'false';
+	$className = __CLASS__;
 ?>
 		<script>
 var TABLE_AJAX_NODE_ID = '<?= $this->_htmlID; ?>';
@@ -570,11 +564,33 @@ var FILER_INIT = <?= json_encode($filterInit); ?>;
 var FIRCE_FILER_INIT = <?= json_encode($forceFilterInit); ?>;
 var PAGE_SIZE = '<?= $pageSize; ?>';
 var PAGE_SIZES = <?= json_encode($pageSizes); ?>;
+var URL_REMOVE_THE_GEOM_AJAX = '<?= "{$this->syncUrl}&_hash={$this->_htmlID}&_task=removeTheGeomAjax"; ?>';
+var URL_MORE_FUNCTIONS_CELL_AJAX = '<?= "{$this->syncUrl}?_hash={$this->_htmlID}&_task=moreFunctionsCellAjax"; ?>';
+var URL_EDIT_INLINE_SAVE = '<?= "index-ajax.php?_zasobID={$this->_zasobID}&_cls={$className}&_hash={$this->_htmlID}&_task=EDIT_INLINE_SAVE"; ?>';
+var URL_THE_GEOM_SAVE = '<?= "index-ajax.php?_zasobID={$this->_zasobID}&_cls={$className}&_hash={$this->_htmlID}&_task=THE_GEOM_SAVE"; ?>';
+var URL_PAGE_SIZE_SAVE = '<?= "index-ajax.php?_zasobID={$this->_zasobID}&_cls={$className}&_hash={$this->_htmlID}&_task=PAGE_SIZE_SAVE"; ?>';
+var URL_HIDDEN_COLS_SAVE = '<?= "index-ajax.php?_zasobID={$this->_zasobID}&_cls={$className}&_hash={$this->_htmlID}&_task=HIDDEN_COLS_SAVE"; ?>';
+var URL_EDIT_INLINE = '<?= "index-ajax.php?_zasobID={$this->_zasobID}&_cls={$className}&_hash={$this->_htmlID}&_task=EDIT_INLINE"; ?>';
+var HAS_ADDITIONAL_LAYERS = <?= $this->hasAdditionalLayers() ? 1 : 0; ?>;
+var URL_ADD_USER_TABLE_FILTER_AJAX = '<?= Request::getPathUri() . "index.php?_route=ViewTableAjax&_task=addUserTableFilterAjax"; ?>';
+var URL_RM_USER_TABLE_FILTER_AJAX = '<?= Request::getPathUri() . "index.php?_route=ViewTableAjax&_task=rmUserTableFilterAjax"; ?>';
+var LABEL_HTML = '<?= $this->getLabelHtml(); ?>';
 
 jQuery(document).ready(function(){
 	jQuery('#' + TABLE_AJAX_NODE_ID).TableAjax({
 		namespace: NAMESPACE,
 		url: URL_LOAD_AJAX_BASE,
+		removeTheGeomAjaxUrl: URL_REMOVE_THE_GEOM_AJAX,
+		moreFunctionsCellAjaxUrl: URL_MORE_FUNCTIONS_CELL_AJAX,
+		editInlineSaveUrl: URL_EDIT_INLINE_SAVE,
+		theGeomSaveUrl: URL_THE_GEOM_SAVE,
+		pageSizeSave: URL_PAGE_SIZE_SAVE,
+		hiddenColsSaveUrl: URL_HIDDEN_COLS_SAVE,
+		editInlineUrl: URL_EDIT_INLINE,
+		addUserTableFilterAjaxUrl: URL_ADD_USER_TABLE_FILTER_AJAX,
+		rmUserTableFilterAjaxUrl: URL_RM_USER_TABLE_FILTER_AJAX,
+		hasAdditionalLayers: HAS_ADDITIONAL_LAYERS,
+		labelHtml: LABEL_HTML,
 		userTableFilterUrl: URL_USER_TABLE_FILTER,
 		columnPicker: true,
 		filter: true,

+ 28 - 25
SE/se-lib/TableAjax.php.TableAjax.js

@@ -1,11 +1,4 @@
-if (!SYNC_URL) throw "Missing SYNC_URL"; // => $this->syncUrl,
-if (!HTML_ID) throw "Missing HTML_ID"; // => $this->_htmlID,
-if (!NAMESPACE) throw "Missing NAMESPACE"; // => $acl->getNamespace()
 if (!URI_BASE) throw "Missing URI_BASE"; // => Request::getPathUri()
-if (!ZASOB_ID) throw "Missing ZASOB_ID"; // => $this->_zasobID
-if (!CLASS_NAME) throw "Missing CLASS_NAME"; // => __CLASS__
-if ("undefined" === typeof HAS_ADDITIONAL_LAYERS) throw "Missing HAS_ADDITIONAL_LAYERS"; // => $this->hasAdditionalLayers()
-if ("undefined" === typeof LABEL_HTML) throw "Missing LABEL_HTML"; // => $this->getLabelHtml()
 if (!global.jQuery) throw "Missing jQuery"
 var $ = global.jQuery
 
@@ -17,8 +10,18 @@ var TableAjax = function() {
 	var defaults = {
 		namespace: '',
 		url: '', //webservice url
-		urlData: '', //webservice params
 		urlPost: false, //use POST instead of GET
+		removeTheGeomAjaxUrl: '',
+		moreFunctionsCellAjaxUrl: '',
+		editInlineSaveUrl: '',
+		theGeomSaveUrl: '',
+		pageSizeSave: '',
+		hiddenColsSaveUrl: '',
+		editInlineUrl: '',
+		addUserTableFilterAjaxUrl: '',
+		rmUserTableFilterAjaxUrl: '',
+		hasAdditionalLayers: 0,
+		labelHtml: '',
 		debug: false, //prints debug info to console
 		filter: false, //show filter row
 		filterInit: false,// init filters data
@@ -525,11 +528,11 @@ var TableAjax = function() {
 
 									var selectedRecordId = recordID;
 									superagent
-										.post(SYNC_URL + '&_hash=' + HTML_ID + '&_task=removeTheGeomAjax')
+										.post(priv.options.removeTheGeomAjaxUrl)
 										.type('json') // header ĺapplication/x-www-form-urlencoded' requires type('form');
 										.send({
 											ID: recordID,
-											namespace: NAMESPACE
+											namespace: priv.options.namespace
 										})
 										.set('Accept', 'application/json')
 										.end(function(err, res) {
@@ -840,7 +843,7 @@ var TableAjax = function() {
 
 		_popoverCellAjaxXhr = $.ajax({
 			type: 'GET',
-			url: SYNC_URL + '&_hash=' + HTML_ID + '&_task=moreFunctionsCellAjax&ID=' + rowPK,
+			url: priv.options.moreFunctionsCellAjaxUrl + '&ID=' + rowPK,
 			dataType: 'json',
 			contentType: "application/json; charset=utf-8",
 			data: ''
@@ -1489,7 +1492,7 @@ var TableAjax = function() {
 				data: data,
 				dataType: 'json',
 				type: "POST",
-				url: 'index-ajax.php?_zasobID=' + ZASOB_ID + '&_cls=' + CLASS_NAME + '&_hash=' + HTML_ID + '&_task=EDIT_INLINE_SAVE'
+				url: priv.options.editInlineSaveUrl
 			})
 			.done(function(data, textStatus, jqXHR){
 				notifyAjaxCallback(data);
@@ -1562,7 +1565,7 @@ var TableAjax = function() {
 			}
 		}
 
-		var exportUrl = 'index.php?_route=ViewTableAjax&_task=export&namespace=' + NAMESPACE;
+		var exportUrl = 'index.php?_route=ViewTableAjax&_task=export&namespace=' + priv.options.namespace;
 		exportUrl += '&format=' + format;
 		exportUrl += '&flds=' + exportFields.join(',');
 		exportUrl += '&sortCol=' + (_state.filters.currSortCol || '');
@@ -1603,7 +1606,7 @@ var TableAjax = function() {
 			return;
 		}
 
-		if (priv.options.debug) console.log(p5Utils__format('requesting data from url:{0} data:{1}', [priv.options.url, JSON.stringify(priv.options.urlData) || '']));
+		if (priv.options.debug) console.log(p5Utils__format('requesting data from url:{0}', priv.options.url));
 
 		var initUrlAdd = '';
 		var filtersInitSet = false;
@@ -2001,9 +2004,9 @@ var TableAjax = function() {
 			//debug: true,
 			wpsUrl: 'http://biuro.biall-net.pl/wps',
 			wfsUrl: 'http://biuro.biall-net.pl/wps',
-			showAddLayerWidget: (HAS_ADDITIONAL_LAYERS) ? true : false,
+			showAddLayerWidget: (priv.options.hasAdditionalLayers) ? true : false,
 			zoomStrategyActivate: 14,
-			layerName: LABEL_HTML,
+			layerName: priv.options.labelHtml,
 			addBtn: {
 				title: 'Przenieś mapę do okna',
 				displayClass: 'mapEditor-btnBackToWindow',
@@ -2051,7 +2054,7 @@ var TableAjax = function() {
 					data: {polygon: selectedFeatureExtent},
 					dataType: 'json',
 					type: "POST",
-					url: 'index-ajax.php?_zasobID=' + ZASOB_ID + '&_cls=' + CLASS_NAME + '&_hash=' + HTML_ID + '&_task=THE_GEOM_SAVE&ID=' + selectedRecordId
+					url: priv.options.theGeomSaveUrl + '&ID=' + selectedRecordId
 				})
 				.done(function(data, textStatus, jqXHR){
 					notifyAjaxCallback(data);
@@ -2262,7 +2265,7 @@ var TableAjax = function() {
 			type: "POST",
 			dataType: 'json',
 			// async: true,
-			url: 'index-ajax.php?_zasobID=' + ZASOB_ID + '&_cls=' + CLASS_NAME + '&_hash=' + HTML_ID + '&_task=PAGE_SIZE_SAVE'
+			url: priv.options.pageSizeSave
 		})
 		.done(function(data, textStatus, jqXHR){
 			if (data && data.type && data.type == 'info') {
@@ -2290,7 +2293,7 @@ var TableAjax = function() {
 			type: "POST",
 			dataType: 'json',
 			// async: true,
-			url: 'index-ajax.php?_zasobID=' + ZASOB_ID + '&_cls=' + CLASS_NAME + '&_hash=' + HTML_ID + '&_task=HIDDEN_COLS_SAVE'
+			url: priv.options.hiddenColsSaveUrl
 		})
 		.done(function(data, textStatus, jqXHR){
 			if (data && data.type && data.type == 'info') {
@@ -2393,14 +2396,14 @@ var TableAjax = function() {
 		e.stopPropagation()
 		var filtrName = $(this).data('col_filter')
 		if (!filtrName) return
-		window.fetch(URI_BASE + 'index.php?_route=ViewTableAjax&_task=rmUserTableFilterAjax', {
+		window.fetch(priv.options.rmUserTableFilterAjaxUrl, {
 			method: 'POST',
 			headers: {
 				'Content-Type': 'application/json'
 			},
 			credentials: 'same-origin',// add cookies
 			body: JSON.stringify({
-				namespace: NAMESPACE,
+				namespace: priv.options.namespace,
 				filtrName: filtrName,
 			})
 		}).then(function (response) {
@@ -2443,14 +2446,14 @@ var TableAjax = function() {
 				return new Promise(function(resolve, reject) {
 					if (!filtrName) reject('Proszę podać nazwę filtra')
 					if (filtrName.length > 255) reject('Nazwa za długa')
-					window.fetch(URI_BASE + 'index.php?_route=ViewTableAjax&_task=addUserTableFilterAjax', {
+					window.fetch(priv.options.addUserTableFilterAjaxUrl, {
 						method: 'POST',
 						headers: {
 							'Content-Type': 'application/json'
 						},
 						credentials: 'same-origin',// add cookies
 						body: JSON.stringify({
-							namespace: NAMESPACE,
+							namespace: priv.options.namespace,
 							filtrName: filtrName,
 							visibleCols: Object.keys(_data.cols).filter(function(col) {
 								return !_data.cols[col].hidden
@@ -2692,7 +2695,7 @@ var TableAjax = function() {
 			inlineEditBox$Node.find('input[name=col]').val(e.data.col);
 			inlineEditBox$Node.find('.inlineEditBox-cnt').html('<span class="loading-info"> loading ...</span>');
 			$.ajax({
-				url: 'index-ajax.php?_zasobID=' + ZASOB_ID + '&_cls=' + CLASS_NAME + '&_hash=' + HTML_ID + '&_task=EDIT_INLINE&ID=' + e.data.id + '&col=' + e.data.col,
+				url: priv.options.editInlineUrl + '&ID=' + e.data.id + '&col=' + e.data.col,
 				type: 'GET',
 				dataType: 'json',
 				success: function(data) {
@@ -2770,7 +2773,7 @@ var TableAjax = function() {
 
 		_popoverCellAjaxXhr = $.ajax({
 			type: 'GET',
-			url: 'index.php?_route=ViewTableAjax&_task=typeSpecialCell&namespace=' + NAMESPACE + '&ID=' + id + '&col=' + col,
+			url: 'index.php?_route=ViewTableAjax&_task=typeSpecialCell&namespace=' + priv.options.namespace + '&ID=' + id + '&col=' + col,
 			dataType: 'json',
 			contentType: "application/json; charset=utf-8",
 			data: '',