-
-
Save patrickatwsrn/205dafb8989293acf09faba33f9327ad to your computer and use it in GitHub Desktop.
XPDO to simple ExtJS 3 Stores
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var SimplxStudio = {}; | |
SimplxStudio.modx = {}; | |
/* Creating JSON representation for modAccess */ | |
SimplxStudio.modx.modAccess={ | |
"class": "modAccess", | |
"extends":"xPDOSimpleObject", | |
"fields": [ | |
"id","alias","target","principal_class","principal","authority","policy" | |
], | |
"associations": [ | |
{ | |
"type": "belongsTo", | |
"model": "modAccessPolicy", | |
"primaryKey": "policy", | |
"foreignKey": "id", | |
"associationKey": "policy" | |
}, | |
{ | |
"type": "belongsTo", | |
"model": "modPrincipal", | |
"primaryKey": "principal", | |
"foreignKey": "id", | |
"associationKey": "principal" | |
}, | |
] | |
}; | |
/* Creating ExtJS 3.* Store for modAccess */ | |
SimplxStudio.modx.modAccess.extStore = new Ext.data.JsonStore({ | |
root:"result", | |
fields: SimplxStudio.modx.modAccess["fields"] | |
}); | |
/* Creating JSON representation for modAccessPolicy */ | |
SimplxStudio.modx.modAccessPolicy={ | |
"class": "modAccessPolicy", | |
"extends":"", | |
"fields": [ | |
"id","alias","name","description","parent","template","class","data","lexicon" | |
], | |
"associations": [] | |
}; | |
/* Creating ExtJS 3.* Store for modAccessPolicy */ | |
SimplxStudio.modx.modAccessPolicy.extStore = new Ext.data.JsonStore({ | |
root:"result", | |
fields: SimplxStudio.modx.modAccessPolicy["fields"] | |
}); | |
/* Creating JSON representation for modPrincipal */ | |
SimplxStudio.modx.modPrincipal={ | |
"class": "modPrincipal", | |
"extends":"", | |
"fields": [ | |
"id","alias" | |
], | |
"associations": [] | |
}; | |
/* Creating ExtJS 3.* Store for modPrincipal */ | |
SimplxStudio.modx.modPrincipal.extStore = new Ext.data.JsonStore({ | |
root:"result", | |
fields: SimplxStudio.modx.modPrincipal["fields"] | |
}); | |
/* Creating JSON representation for modSnippet */ | |
SimplxStudio.modx.modSnippet={ | |
"class": "modSnippet", | |
"extends":"modScript", | |
"fields": [ | |
"id","alias","cache_type","snippet","locked","properties","moduleguid" | |
], | |
"associations": [] | |
}; | |
/* Creating ExtJS 3.* Store for modSnippet */ | |
SimplxStudio.modx.modSnippet.extStore = new Ext.data.JsonStore({ | |
root:"result", | |
fields: SimplxStudio.modx.modSnippet["fields"] | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> | |
<xsl:output omit-xml-declaration="yes" /> | |
<xsl:output method="text" /> | |
<xsl:output indent="yes" /> | |
<xsl:output media-type="text/plain" /> | |
<xsl:param name="directory"/> | |
<xsl:param name="label-composite">Composites</xsl:param> | |
<xsl:param name="label-aggregate">Aggregates</xsl:param> | |
<xsl:param name="xpdo-model">modx</xsl:param> | |
<xsl:param name="include-objects">modAccess modSnippet</xsl:param> | |
<xsl:param name="include-dependencies">1</xsl:param> | |
<xsl:param name="include-local-only">0</xsl:param> | |
<xsl:param name="include-var-declaration">1</xsl:param> | |
<xsl:param name="include-extjs-stores">1</xsl:param> | |
<xsl:param name="global-namespace">SimplxStudio</xsl:param> | |
<xsl:param name="extjs-store-namespace">modx</xsl:param> | |
<xsl:param name="ident"> | |
<xsl:text> </xsl:text> | |
</xsl:param> | |
<xsl:template match="/"> | |
<xsl:apply-templates /> | |
</xsl:template> | |
<xsl:template match="model"> | |
<xsl:if test="$include-var-declaration=1"> | |
var <xsl:value-of select="$global-namespace" /> = {}; | |
<xsl:value-of select="$global-namespace" />.<xsl:value-of select="$xpdo-model" /> = {}; | |
</xsl:if> | |
<xsl:for-each select="./object"> | |
<xsl:if test="contains($include-objects,@class) or $include-objects='*'"> | |
<xsl:call-template name="xpdo-object" > | |
<xsl:with-param name="skip-delimiter">0</xsl:with-param> | |
</xsl:call-template> | |
<!-- Get all associated Classes --> | |
<xsl:for-each select="./aggregate"> | |
<xsl:call-template name="xpdo-object" > | |
<xsl:with-param name="object" select="@class"></xsl:with-param> | |
<xsl:with-param name="include-dependencies" select="1"></xsl:with-param> | |
<xsl:with-param name="skip-delimiter">0</xsl:with-param> | |
</xsl:call-template> | |
</xsl:for-each> | |
<xsl:for-each select="./composite"> | |
<xsl:call-template name="xpdo-object" > | |
<xsl:with-param name="object" select="@class"></xsl:with-param> | |
<xsl:with-param name="include-dependencies" select="1"></xsl:with-param> | |
<xsl:with-param name="skip-delimiter">0</xsl:with-param> | |
</xsl:call-template> | |
</xsl:for-each> | |
<!-- /Get all associated Classes --> | |
</xsl:if> | |
</xsl:for-each> | |
</xsl:template> | |
<xsl:template name="xpdo-object" match="object"> | |
<xsl:param name="object" /> | |
<xsl:param name="skip-delimiter" /> | |
<xsl:for-each select="."> | |
/* Creating JSON representation for <xsl:value-of select="@class" /> */ | |
<xsl:value-of select="$global-namespace" />.<xsl:value-of select="$xpdo-model" />.<xsl:value-of select="@class" /><xsl:text>=</xsl:text>{ | |
"class": "<xsl:value-of select="@class" />", | |
"extends":"<xsl:value-of select="@extends" />", | |
"fields": [ | |
<xsl:text>"id",</xsl:text> | |
<xsl:text>"alias"</xsl:text> | |
<xsl:for-each select="//object[@class=current()/@class]/field"> | |
<xsl:apply-templates select="current()" /> | |
</xsl:for-each> | |
], | |
"associations": [<xsl:choose> | |
<xsl:when test="$include-dependencies=1"> | |
<xsl:choose> | |
<xsl:when test="$include-local-only=1"> | |
<xsl:apply-templates select="./aggregate[@owner!='foreign']" /> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:apply-templates select="./aggregate" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
<xsl:apply-templates select="./composite" /> | |
</xsl:when> | |
<xsl:otherwise> | |
</xsl:otherwise> | |
</xsl:choose>] | |
}; | |
<xsl:if test="$include-extjs-stores=1"> | |
/* Creating ExtJS 3.* Store for <xsl:value-of select="@class" /> */ | |
<xsl:value-of select="$global-namespace" />.<xsl:value-of select="$xpdo-model" />.<xsl:value-of select="@class" />.extStore <xsl:text>=</xsl:text> new Ext.data.JsonStore({ | |
root:"result", | |
fields: <xsl:value-of select="$global-namespace" />.<xsl:value-of select="$xpdo-model" />.<xsl:value-of select="@class" />["fields"] | |
}); | |
</xsl:if> | |
</xsl:for-each> | |
</xsl:template> | |
<xsl:template match="field"> | |
<xsl:text>,"</xsl:text> | |
<xsl:value-of select="@key" /> | |
<xsl:text>"</xsl:text> | |
</xsl:template> | |
<xsl:template match="aggregate"> | |
{ | |
<xsl:choose> | |
<xsl:when test="@owner='local'"> "type": "hasMany",</xsl:when> | |
<xsl:otherwise> "type": "belongsTo",</xsl:otherwise> | |
</xsl:choose> | |
"model": "<xsl:value-of select="./@class" />", | |
"primaryKey": "<xsl:value-of select="@local" />", | |
"foreignKey": "<xsl:value-of select="@foreign" />", | |
"associationKey": "<xsl:value-of select="@local" />" | |
}, | |
</xsl:template> | |
<xsl:template match="composite"> | |
{ | |
<xsl:choose> | |
<xsl:when test="@owner='local'"> "type": "hasMany",</xsl:when> | |
<xsl:otherwise> "type": "belongsTo",</xsl:otherwise> | |
</xsl:choose> | |
"model": "<xsl:value-of select="./@class" />", | |
"primaryKey": "<xsl:value-of select="@local" />", | |
"foreignKey": "<xsl:value-of select="@foreign" />", | |
"associationKey": "<xsl:value-of select="@local" />" | |
}, | |
</xsl:template> | |
</xsl:stylesheet> | |
<!-- | |
<validation> | |
<rule field="category" name="preventBlank" type="xPDOValidationRule" rule="xPDOMinLengthValidationRule" value="1" message="category_err_ns_name" /> | |
</validation> | |
<validation> | |
<rule field="name" name="invalid" type="preg_match" rule="/^(?!\s)[a-zA-Z0-9\x2d-\x2f\x7f-\xff_-\s]+(?!\s)$/" message="tv_err_invalid_name" /> | |
<rule field="name" name="reserved" type="preg_match" rule="/(?!^(id|type|contentType|pagetitle|longtitle|description|alias|link_attributes|published|pub_date|unpub_date|parent|isfolder|introtext|content|richtext|template|menuindex|searchable|cacheable|createdby|createdon|editedby|editedon|deleted|deletedby|deletedon|publishedon|publishedby|menutitle|donthit|haskeywords|hasmetatags|privateweb|privatemgr|content_dispo|hidemenu|class_key|context_key|content_type)$)/" message="tv_err_reserved_name" /> | |
</validation> | |
<validation> | |
<rule field="name" name="name" type="xPDOValidationRule" rule="xPDOMinLengthValidationRule" value="1" message="content_type_err_ns_name" /> | |
</validation> | |
<validation> | |
<rule field="name" name="invalid" type="preg_match" rule="/^(?!\s)[a-zA-Z0-9\x2d-\x2f\x7f-\xff_-\s]+(?!\s)$/" message="chunk_err_invalid_name" /> | |
</validation | |
<validation> | |
<rule field="category" name="preventBlank" type="xPDOValidationRule" rule="xPDOMinLengthValidationRule" value="1" message="category_err_ns_name" /> | |
</validation> | |
--> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment