瀏覽代碼

+ support for xsdType p5:link

Umowy aktywacja link
Piotr Labudda 6 年之前
父節點
當前提交
fa7d1118af

+ 7 - 0
SE/schema/ant-object/default_db.DEALS_TABLE/DEALS_TABLE/DEALS_TABLE.xsd

@@ -234,6 +234,13 @@
                <xs:documentation>Jedna usluga moze miec max jedna umowe raczej. Ta relacja jest potrzebna do raportu sprzedazy. Uwaga podwojne dojscie przez ID_PROJECT jest rowniez! Do tuningu</xs:documentation>
             </xs:annotation>
          </xs:element>
+         <xs:element name="AKTYWACJA_link" type="p5:link">
+            <xs:annotation>
+               <xs:appinfo>
+                  <p5Type:simpleLink href="index.php?MENU_INIT=POKAZ_OFERTY_AKTUALNE_FUNC&amp;task=activate_deal&amp;id_deal={ID}" target="_blank" label="Aktywuj umowę {ID}"/>
+               </xs:appinfo>
+            </xs:annotation>
+         </xs:element>
       </xs:sequence>
    </xs:complexType>
    <xs:element name="DEALS_TABLE" type="default_db__x3A__DEALS_TABLE:DEALS_TABLE"

+ 22 - 0
SE/se-lib/AntAclBase.php

@@ -21,6 +21,7 @@ class AntAclBase extends Core_AclBase {
 		$this->_hasReadGroupField = false; // TODO: from cache
 		$this->_hasOwnerField = false; // TODO: from cache
 		$this->_xsdRestrictions = [];
+		$this->_xsdAppInfo = [];
 		$this->_zasobyInfoFetched = false;
 	}
 	public function getDB() { return $this->_db; }
@@ -235,6 +236,17 @@ class AntAclBase extends Core_AclBase {
 		$defaultValue = null;
 		if ('enumeration' === $paramKey && 'p5:enum' === $xsdType) $defaultValue = [];
 		if ('maxLength' === $paramKey && 'xsd:string' === $xsdType) $defaultValue = 255;
+
+		// if ('appInfo:' === substr($paramKey, 0, strlen('appInfo:'))) {
+		// 	$appInfo = $this->getXsdAppInfo($fieldName);
+		// }
+		if ('appInfo' === $paramKey && 'p5:link' == $xsdType) {
+			// appInfo: {"simpleLink":{"@href":"index.php?MENU_INIT=POKAZ_OFERTY_AKTUALNE_FUNC&task=activate_deal&id_deal={ID}","@target":"_blank","@label":"Aktywuj umow\u0119 {ID}"}}
+			$appInfo = $this->getXsdAppInfo($fieldName);
+			// DBG::log($appInfo, 'array', "TODO:appInfo({$fieldName})...");
+			return $appInfo;
+		}
+
 		return V::get($paramKey, $defaultValue, $this->getXsdRestrictions($fieldName));
 	}
 	public function getEnumerations($fieldName) {
@@ -251,6 +263,16 @@ class AntAclBase extends Core_AclBase {
 		}
 		return $this->_xsdRestrictions[$fieldName];
 	}
+	public function getXsdAppInfo($fieldName) {
+		if (array_key_exists($fieldName, $this->_xsdAppInfo)) return $this->_xsdAppInfo[$fieldName];
+		$this->_xsdAppInfo[$fieldName] = [];
+		$field = $this->_getField($fieldName);
+		if (!$field['appInfo']) return [];
+		if (is_string($field['appInfo']) && '{' === substr($field['appInfo'], 0, 1)) {
+			$this->_xsdAppInfo[$fieldName] = @json_decode($field['appInfo'], $assoc = true);
+		}
+		return $this->_xsdAppInfo[$fieldName];
+	}
 	// public function getXsdFieldParam($fieldName, $paramKey) { // TableAcl
 	// 	return ($this->_schemaClass)
 	// 		? $this->_schemaClass->getFieldParam($fieldName, $paramKey)

+ 5 - 0
SE/se-lib/TableAjax.php

@@ -2232,6 +2232,11 @@ jQuery(document).ready(function(){
 						$columnConfig->_tsSimpleLink->format = $acl->getXsdFieldParam($col, 'format');
 						$columnConfig->_tsSimpleLink->aliasMap = $acl->getXsdFieldParam($col, 'aliasMap');
 					} break;
+					case 'p5:link': { // more general then typeSpecialSimpleLink
+						// appInfo: {"simpleLink":{"@href":"index.php?MENU_INIT=POKAZ_OFERTY_AKTUALNE_FUNC&task=activate_deal&id_deal={ID}","@target":"_blank","@label":"Aktywuj umow\u0119 {ID}"}}
+						$columnConfig->type = 'p5:link';
+						$columnConfig->_appInfo = $acl->getXsdFieldParam($col, 'appInfo');
+					} break;
 				}
 			}
 

+ 48 - 3
SE/se-lib/TableAjax.php.TableAjax.js

@@ -66,6 +66,12 @@ function p5Utils__objectToQueryWithKeyPrefix(obj, prefix, callback) {
 		.join('&')
 }
 
+function p5Utils__multiReplaceValues(input, row) {
+	return Object.keys(row).reduce(function (ret, fieldName) {
+		return ret.replace(new RegExp('\{' + fieldName + '\}', 'g'), row[fieldName])
+	}, input)
+}
+
 
 global['P5UI__TableAjaxSpecialFilter'] = createReactClass({
 	// props.store: Redux store with state: { isLoading bool, selected array of strings }
@@ -1326,8 +1332,8 @@ var TableAjax = function() {
 				break;
 			case "p5:www_link":// @return Element
 				fieldWidget = (function(fldName, fieldProps) {
-					var _fieldName = fldName,
-							_fieldProps = fieldProps;
+					var _fieldName = fldName;
+					var _fieldProps = fieldProps;
 					//  console.log('FieldWidget: generate function to render field('+_fieldName+') ', fieldProps);
 					return function(val, fieldPK, row) {
 						//  console.log('FieldWidget: pk('+fieldPK+') run function to render field('+_fieldName+') with value('+val+') ', fieldProps);
@@ -1358,6 +1364,45 @@ var TableAjax = function() {
 					}
 				}(fldName, fieldProps));
 				break;
+			case "p5:link":// @return Element
+				fieldWidget = (function(fldName, fieldProps) {
+					var _fieldName = fldName;
+					var _fieldProps = fieldProps;
+					DBG && console.log('FieldWidget: generate function to render field('+_fieldName+') ', fieldProps);
+					return function(val, fieldPK, row) {
+						DBG && console.log('FieldWidget: pk('+fieldPK+') run function to render field('+_fieldName+') with value('+val+') ', fieldProps);
+						// fieldProps._appInfo.simpleLink: {
+						// 		@href: "index.php?MENU_INIT=POKAZ_OFERTY_AKTUALNE_FUNC&task=activate_deal&id_deal={ID}"
+						// 		@label: "Aktywuj umowę {ID}"
+						// 		@target: "_blank"
+						if (!_fieldProps._appInfo.simpleLink) return 'BUG: missing _appInfo.simpleLink!';
+						if (!_fieldProps._appInfo.simpleLink['@label']) return 'BUG: missing _appInfo.simpleLink[@label]!';
+						var label = p5Utils__multiReplaceValues(_fieldProps._appInfo.simpleLink['@label'], row);
+						var relativeLink = p5Utils__multiReplaceValues(_fieldProps._appInfo.simpleLink['@href'], row);
+						if ('index.php' == relativeLink.substr(0, 9) || 'procesy5.php' == relativeLink.substr(0, 12)) {
+							link = window.location.protocol + '//' + window.location.hostname
+							link += window.location.pathname.split('/').slice(0, -1).join('/')
+							link += '/' + relativeLink
+						} else if ('http' == relativeLink.substr(0, 4)) {
+							link = relativeLink
+						// else if ('ftp' == val.substr(0, 3))
+						} else {
+							link = 'http://' + relativeLink
+						}
+
+						var linkErrors = validate({www_link: link}, {www_link: {url: true}});
+						if (linkErrors) {
+							DBG && console.log('DBG:linkErrors (' + _fieldName + ': ' + link + ')', linkErrors);
+							return label;
+						}
+						fldNode = document.createElement('a');
+						fldNode.setAttribute('href', link);
+						if (_fieldProps._appInfo.simpleLink['@target']) fldNode.setAttribute('target', _fieldProps._appInfo.simpleLink['@target']);
+						fldNode.appendChild(document.createTextNode(label));
+						return fldNode;
+					}
+				}(fldName, fieldProps));
+				break;
 			case "special":
 				fieldWidget = (function(fldName, fieldProps) {
 					var _fieldName = fldName;
@@ -1651,7 +1696,7 @@ var TableAjax = function() {
 			// TODO: support for ui-function in rowFunctions
 			// var funObj = rowFunctions[key];
 			// var funcNode = p5UI_TableAjax_generateFunctionNode(funObj, rowPK, {ico: true, label: false});
-			// DBG1 && console.log('TableAjax::renderCellRowFunctions: rowFunction[' + key + ']', { funObj: funObj, uiFunc: funObj['ui-function'], uiFuncExists: global[funObj['ui-function']] });
+			// DBG && console.log('TableAjax::renderCellRowFunctions: rowFunction[' + key + ']', { funObj: funObj, uiFunc: funObj['ui-function'], uiFuncExists: global[funObj['ui-function']] });
 			// if (funObj['ui-function'] && global[funObj['ui-function']]) {
 			// 	funcNode.on('click', function (event) { event.preventDefault(); global[funObj['ui-function']](rowPK); });
 			// }