فهرست منبع

fixed TableAjax label for Filter Ref btns

Piotr Labudda 7 سال پیش
والد
کامیت
939e084a3a
1فایلهای تغییر یافته به همراه23 افزوده شده و 9 حذف شده
  1. 23 9
      SE/se-lib/TableAjax.php.TableAjax.js

+ 23 - 9
SE/se-lib/TableAjax.php.TableAjax.js

@@ -13,6 +13,21 @@ var ReduxThunk = global.p5VendorJs.ReduxThunk;
 var createStoreWithThunkMiddleware = Redux.applyMiddleware(ReduxThunk)(Redux.createStore); // TODO: to vendor.js
 var p5UI__FieldCheckboxSearch = global.p5VendorJs['p5UI__FieldCheckboxSearch'];
 var p5UI__FieldCheckboxLoading = global.p5VendorJs['p5UI__FieldCheckboxLoading'];
+
+if (!String.prototype.startsWith) { // TODO: to global js utils
+	String.prototype.startsWith = function(search, pos) {
+		return this.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;
+	};
+}
+p5WfsRefFilter = (function () { // convert GET param key ogc filter for ref
+	return {
+		parse: function (filterKey) {
+			if (filterKey.startsWith('Ref_From_')) return { type: 'From', idInstance: filterKey.substr('Ref_From_'.length) };
+			if (filterKey.startsWith('Ref_To_')) return { type: 'To', idInstance: filterKey.substr('Ref_To_'.length) };
+			return null;
+		}
+	};
+})();
 var p5WPSUtils__createConvertToWpsDataInputFunction = function (identifier) {
 	return function (value) {
 		if (!value) return null; // WPS function require value, but for eg. featureQuery mey be empty
@@ -667,11 +682,9 @@ global['P5UI__TableAjaxSpecialFilterRelations'] = createReactClass({
 		DBG && console.log('DBG::P5UI__TableAjaxSpecialFilterRelations::getStateFromStore (name:'+this.props.name+')', { store: state, name: this.props.name, selected: state.specialFilter.get(this.props.name) });
 		var selected = []; // Array of { idInstance, primaryKey }
 		state.specialFilter.forEach(function (value, key) {
-			if ('Ref_From_' === key.substr(0, 'Ref_From_'.length)) {
-				selected.push({ type: 'From', idInstance: key.substr('Ref_From_'.length), primaryKey: value, filterKey: key })
-			}
-			if ('Ref_To_' === key.substr(0, 'Ref_To_'.length)) {
-				selected.push({ type: 'To', idInstance: key.substr('Ref_To_'.length), primaryKey: value, filterKey: key })
+			var refInfo = p5WfsRefFilter.parse(key); // null | { type: 'From' | 'To', idInstance: int }
+			if (refInfo) {
+				selected.push(Object.assign(refInfo, { primaryKey: value, filterKey: key }))
 			}
 		})
 		DBG && console.log('TODO: DBG::P5UI__TableAjaxSpecialFilterRelations::getStateFromStore (name:'+this.props.name+')', { store: state, name: this.props.name, selected });
@@ -837,13 +850,13 @@ global['P5UI__TableAjaxSpecialFilterRelations'] = createReactClass({
 			var foundInstanceInfo = this.props.availableBackRefs.filter(function (instanceInfo) {
 				return ( parseInt(idInstance) === parseInt(instanceInfo.id) );
 			});
-			if (foundInstanceInfo.length > 0) label = foundInstanceInfo[0].label + "." + primaryKey;
+			if (foundInstanceInfo.length > 0) label = 'z ' + foundInstanceInfo[0].label + "." + primaryKey;
 			if (foundInstanceInfo.length > 0) namespace = foundInstanceInfo[0].namespace;
 		} else if ('To' === type) {
 			var foundInstanceInfo = this.props.availableChildRefs.filter(function (instanceInfo) {
 				return ( parseInt(idInstance) === parseInt(instanceInfo.id) );
 			});
-			if (foundInstanceInfo.length > 0) label = foundInstanceInfo[0].label + "." + primaryKey;
+			if (foundInstanceInfo.length > 0) label = 'do ' + foundInstanceInfo[0].label + "." + primaryKey;
 			if (foundInstanceInfo.length > 0) namespace = foundInstanceInfo[0].namespace;
 		}
 		return h(P5UI__TableAjaxSpecialFilterRelationFrom, {
@@ -899,10 +912,11 @@ global['P5UI__TableAjaxSpecialFilterRelationFrom'] = createReactClass({
 	},
 
 	render: function () {
-		DBG && console.log('DBG::P5UI__TableAjaxSpecialFilterRelationFrom::render (filterKey:'+this.props.filterKey+')', { state: this.state, props: this.props });
+		DBG1 && console.log('DBG::P5UI__TableAjaxSpecialFilterRelationFrom::render (filterKey:'+this.props.filterKey+')', { state: this.state, props: this.props });
+		var refInfo = p5WfsRefFilter.parse(this.props.filterKey); // null | { type: 'From' | 'To', idInstance: int }
 		return h('button', {
 			className: "btn btn-xs btn-default active",
-			title: "Powiązane z " + this.props.namespace + " " + this.props.primaryKey,
+			title: "Powiązane" + ( 'From' === refInfo.type ? " z " : " do " ) + this.props.namespace + " " + this.props.primaryKey,
 			// onClick: this.handleUpdate, // TODO: paste param
 		}, [
 			this.props.label,