Skip to content

Commit

Permalink
Improed Sencha Architect integreation
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandschuetz committed Oct 10, 2014
1 parent 4a0f023 commit 79268bd
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 70 deletions.
2 changes: 2 additions & 0 deletions Test/JavaScriptUnitTest/SpecRunner.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
<script type="text/javascript" src="../../webroot/js/data/override/NodeInterface.js"></script>
<script type="text/javascript" src="../../webroot/js/data/override/Validations.js"></script>
<script type="text/javascript" src="../../webroot/js/data/validator/File.js"></script>
<script type="text/javascript" src="../../webroot/js/data/validator/override/Bound.js"></script>
<script type="text/javascript" src="../../webroot/js/data/validator/override/Range.js"></script>
<script type="text/javascript" src="../../webroot/js/data/Validators.js"></script>
<script type="text/javascript" src="../../webroot/js/Main.js"></script>
<script type="text/javascript" src="../../webroot/js/data/Model.js"></script>
Expand Down
4 changes: 4 additions & 0 deletions Test/JavaScriptUnitTest/TouchSpecRunner.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<script type="text/javascript" src="../../webroot/js/Remoting.js"></script>
<script type="text/javascript" src="../../webroot/js/data/override/NodeInterface.js"></script>
<script type="text/javascript" src="../../webroot/js/data/override/Validations.js"></script>
<script type="text/javascript" src="../../webroot/js/data/validator/Validator.js"></script> <!-- Fake for Touch -->
<script type="text/javascript" src="../../webroot/js/data/validator/File.js"></script>
<script type="text/javascript" src="../../webroot/js/data/validator/override/Bound.js"></script>
<script type="text/javascript" src="../../webroot/js/data/validator/override/Range.js"></script>
<script type="text/javascript" src="../../webroot/js/data/Validators.js"></script>
<script type="text/javascript" src="../../webroot/js/Main.js"></script>
<script type="text/javascript" src="../../webroot/js/data/Model.js"></script>
Expand Down
56 changes: 49 additions & 7 deletions _sencha/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@
<!-- Bancha Scaffold sould only by included in Ext JS builds -->
<available file="${bancha.folder}/webroot/js/scaffold" type="dir" property="touch.scaffoldnotmoved"/>
<available file="${bancha.folder}/webroot/js/scaffold/builder" type="dir" property="ext.scaffoldnotmoved"/>
<available file="${bancha.folder}/webroot/js/data/validations.js" type="file" property="ext.validationshimforextjs5notmoved"/>
<available file="${bancha.folder}/webroot/js/data/validations.js" type="file" property="ext.extjs5classesnotmoved"/>
<available file="${bancha.folder}/webroot/js/data/validator/Validator.js" type="file" property="ext.extjs4classesnotmoved"/>
<if>
<and>
<equals arg1="${app.framework}" arg2="touch"/>
Expand Down Expand Up @@ -174,8 +175,32 @@
<move
file="${bancha.folder}/webroot/js/scaffold/tests"
todir="${bancha.folder}/webroot/scaffold-tmp"/>
<!-- move duplicate classes -->
<move
file="${bancha.folder}/webroot/js/scaffold/src/data"
todir="${bancha.folder}/webroot/scaffold-tmp"/>
</then>
</if>

<if>
<and>
<not>
<and>
<equals arg1="${app.framework}" arg2="ext"/>
<contains string="${app.framework.version}" substring="4."/>
</and>
</not>
<equals arg1="${ext.extjs4classesnotmoved}" arg2="true"/>
</and>
<then>
<!-- don't include the Ext JS 4 shim in Ext JS 5 and Sencha Touch applications ??????????? WHAT ABOUT SENCHA TOUCH ?????? -->
<mkdir dir="${bancha.folder}/webroot/data-tmp4" />
<move
file="${bancha.folder}/webroot/js/data/validator/Validator.js"
todir="${bancha.folder}/webroot/data-tmp4"/>
</then>
</if>

<if>
<and>
<not>
Expand All @@ -184,14 +209,14 @@
<contains string="${app.framework.version}" substring="5."/>
</and>
</not>
<equals arg1="${ext.validationshimforextjs5notmoved}" arg2="true"/>
<equals arg1="${ext.extjs5classesnotmoved}" arg2="true"/>
</and>
<then>
<!-- don't include the Ext JS 5 shim in Ext JS 4 and Sencha Touch applications -->
<mkdir dir="${bancha.folder}/webroot/data-tmp" />
<mkdir dir="${bancha.folder}/webroot/data-tmp5" />
<move
file="${bancha.folder}/webroot/js/data/validations.js"
todir="${bancha.folder}/webroot/data-tmp"/>
todir="${bancha.folder}/webroot/data-tmp5"/>
</then>
</if>
</target>
Expand All @@ -200,7 +225,8 @@

<available file="${bancha.folder}/webroot/scaffold" type="dir" property="touch.scaffoldmoved"/>
<available file="${bancha.folder}/webroot/scaffold-tmp/builder" type="dir" property="ext.scaffoldmoved"/>
<available file="${bancha.folder}/webroot/data-tmp/validations.js" type="file" property="ext.validationshimforextjs5moved"/>
<available file="${bancha.folder}/webroot/data-tmp4/Validator.js" type="file" property="ext.validationshimforextjs5moved"/>
<available file="${bancha.folder}/webroot/data-tmp5/validations.js" type="file" property="ext.validationshimforextjs5moved"/>

<!-- Move Bancha Scaffold to default folder again -->
<if>
Expand Down Expand Up @@ -228,20 +254,36 @@
<move
file="${bancha.folder}/webroot/scaffold-tmp/tests"
todir="${bancha.folder}/webroot/js/scaffold"/>
<!-- move duplicate classes -->
<move
file="${bancha.folder}/webroot/scaffold-tmp/data"
todir="${bancha.folder}/webroot/js/scaffold/src"/>
<!-- remove tmp folder -->
<delete dir="${bancha.folder}/webroot/scaffold-tmp"/>
</then>
</if>

<!-- Move Ext JS 4 fake class back -->
<if>
<equals arg1="${ext.validationshimforextjs4moved}" arg2="true"/>
<then>
<move
file="${bancha.folder}/webroot/data-tmp4/Validator.js"
todir="${bancha.folder}/webroot/js/data/validator/Validator.js"/>
<!-- remove tmp folder -->
<delete dir="${bancha.folder}/webroot/data-tmp4"/>
</then>
</if>

<!-- Move Ext JS 5 fake class back -->
<if>
<equals arg1="${ext.validationshimforextjs5moved}" arg2="true"/>
<then>
<move
file="${bancha.folder}/webroot/data-tmp/validations.js"
file="${bancha.folder}/webroot/data-tmp5/validations.js"
todir="${bancha.folder}/webroot/js/data"/>
<!-- remove tmp folder -->
<delete dir="${bancha.folder}/webroot/data-tmp"/>
<delete dir="${bancha.folder}/webroot/data-tmp5"/>
</then>
</if>

Expand Down
11 changes: 11 additions & 0 deletions webroot/js/Initializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ if(Ext.Loader) {
// Since CakePHP does not follow symlinks we need to setup a second path for Bancha Scaffold
Ext.Loader.setPath('Bancha.scaffold', Ext.Loader.getPath('Bancha')+'/scaffold/src');
}

// Fix the Ext pathes for make classes, not privided by the framework (depending which classes are shimed)
var paths = Ext.Loader.getConfig('paths');
delete paths['Ext.data.validator'];
if(Ext.versions.extjs.major===5) {
paths['Ext.data.validations'] = Ext.Loader.getPath('Bancha') + '/data/validations.js';
delete paths['Ext.data.validator.Validator'];
} else {
paths['Ext.data.validator.Validator'] = Ext.Loader.getPath('Bancha') + '/data/validator/Validator.js';
delete paths['Ext.data.validations'];
}
}
//</debug>

Expand Down
2 changes: 2 additions & 0 deletions webroot/js/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ if ('function' !== typeof Array.prototype.reduce) {
// but the have different names, so set up aliases
if(Ext.versions.touch) {
Ext.ClassManager.setAlias('Ext.MessageBox', 'Ext.window.MessageBox');
} else if(Ext.ClassManager.setAlias) {
Ext.ClassManager.setAlias('Ext.window.MessageBox', 'Ext.MessageBox');
}
//</debug>

Expand Down
4 changes: 2 additions & 2 deletions webroot/js/data/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ Ext.define('Bancha.data.Model', {
// default case for Ext JS 4 and Sencha Touch
if(typeof modelCls.setFields === 'function') {
modelCls.setFields(config.fields);
} else if(Ext.versions.extjs && Ext.versions.extjs.major === 4) {
}
if(Ext.versions.extjs && Ext.versions.extjs.major === 4) {
// this is used for three cases:
// - Support for Ext JS 4.0.7
// - Ext JS Support for ScriptTagInitializer, where we hook into Ext.data.Model extend
Expand All @@ -213,7 +214,6 @@ Ext.define('Bancha.data.Model', {
modelCls.setValidations(config.validations);
modelCls.setDisplayField(config.displayField);
} else {
extJsOnClassExtendedData.associations = config.associations;
extJsOnClassExtendedData.associations = config.associations;
extJsOnClassExtendedData.idProperty = config.idProperty;
extJsOnClassExtendedData.validations = config.validations;
Expand Down
73 changes: 12 additions & 61 deletions webroot/js/data/Validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,73 +23,24 @@
* for Ext JS 4 and Sencha Touch it adds a range and
* file validation rule to Ext.data.validations.
*
* The only point of this class is that the the require
* is easier to write for scaffold apps then just requiring multiple
* classes.
*
* @author Roland Schuetz <mail@rolandschuetz.at>
* @docauthor Roland Schuetz <mail@rolandschuetz.at>
*/
Ext.define('Bancha.data.Validators', {
alternateClassName: [
'Bancha.scaffold.data.Validators' // Bancha.Scaffold uses the same class
]
}, function() {

//<if ext>
if(Ext.versions.extjs && Ext.versions.extjs.major === 5) {
],
requires: [
// Ext JS 5 doesn't have a validations class anymore,
// so use the range validator and add a file validator
Ext.syncRequire('Bancha.data.validator.File');

/**
* @private
* @class Bancha.data.validator.override.Bound
*
* Fixes issues with the current Range validator
*
* See http://www.sencha.com/forum/showthread.php?288168
*
* @author Roland Schuetz <mail@rolandschuetz.at>
* @docauthor Roland Schuetz <mail@rolandschuetz.at>
*/
Ext.define('Bancha.data.validator.override.Bound', {
override: 'Ext.data.validator.Bound',
/**
* @class Ext.data.validator.Bound
*
* To normalize the CakePHP, Ext JS 4 and Ext JS 5 validation
* handling Bancha adds an additional check to the Ext JS 5
* Bound validation rules.
*
* The effect is that non-numeric values are invalid using
* the Range validation rule. For the error message an
* additional config is introduced.
*/
config: {
/**
* @cfg {String} nanMessage
* The error message to return when the value is not a number.
*/
nanMessage: 'Must be a number'
},
validate: function(value) {
if(isNaN(this.getValue(value))) {
return this._nanMessage;
}
return this.callParent(arguments);
},
getValue: function(value) {
return parseFloat(value);
}
});
Ext.define('Ext.data.validator.override.Range', {
override: 'Ext.data.validator.Range'
}, function() {
// for some reason setting via config doesn't work
this.prototype.setNanMessage('Must be a number');
});

} else {
//</if>
Ext.syncRequire('Bancha.data.override.Validations');
//<if ext>
}
//</if>
'Bancha.data.validator.File',
'Bancha.data.validator.override.Bound',
'Bancha.data.validator.override.Range',
//Ext JS 4
'Bancha.data.override.Validations'
]
});
24 changes: 24 additions & 0 deletions webroot/js/data/validator/Validator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*!
*
* Bancha : Seamlessly integrates CakePHP with Ext JS and Sencha Touch (http://bancha.io)
* Copyright 2011-2014 codeQ e.U.
*
* @package Bancha
* @copyright Copyright 2011-2014 codeQ e.U.
* @link http://bancha.io Bancha
* @since Bancha v 2.4.0
* @author Roland Schuetz <mail@rolandschuetz.at>
* @version Bancha v PRECOMPILER_ADD_RELEASE_VERSION
*
* For more information go to http://bancha.io
*/

/**
* Sencha CMD is looking for a Ext.data.validations class since
* it is required in a a class which Ext JS 5 would actually never
* touch.
*
* To fake this class for Ext JS 5 and make Sencha CMD happy this
* is the useless Ext JS 5 Ext.data.validations class.
*/
Ext.define('Ext.data.validator.Validator', {});
56 changes: 56 additions & 0 deletions webroot/js/data/validator/override/Bound.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*!
*
* Bancha : Seamlessly integrates CakePHP with Ext JS and Sencha Touch (http://bancha.io)
* Copyright 2011-2014 codeQ e.U.
*
* @package Bancha
* @copyright Copyright 2011-2014 codeQ e.U.
* @link http://bancha.io Bancha
* @since Bancha v 2.4.0
* @author Roland Schuetz <mail@rolandschuetz.at>
* @version Bancha v PRECOMPILER_ADD_RELEASE_VERSION
*
* For more information go to http://bancha.io
*/

/**
* @private
* @class Bancha.data.validator.override.Bound
*
* Fixes issues with the current Range validator
*
* See http://www.sencha.com/forum/showthread.php?288168
*
* @author Roland Schuetz <mail@rolandschuetz.at>
* @docauthor Roland Schuetz <mail@rolandschuetz.at>
*/
Ext.define('Bancha.data.validator.override.Bound', {
override: 'Ext.data.validator.Bound',
/**
* @class Ext.data.validator.Bound
*
* To normalize the CakePHP, Ext JS 4 and Ext JS 5 validation
* handling Bancha adds an additional check to the Ext JS 5
* Bound validation rules.
*
* The effect is that non-numeric values are invalid using
* the Range validation rule. For the error message an
* additional config is introduced.
*/
config: {
/**
* @cfg {String} nanMessage
* The error message to return when the value is not a number.
*/
nanMessage: 'Must be a number'
},
validate: function(value) {
if(isNaN(this.getValue(value))) {
return this._nanMessage;
}
return this.callParent(arguments);
},
getValue: function(value) {
return parseFloat(value);
}
});
36 changes: 36 additions & 0 deletions webroot/js/data/validator/override/Range.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*!
*
* Bancha : Seamlessly integrates CakePHP with Ext JS and Sencha Touch (http://bancha.io)
* Copyright 2011-2014 codeQ e.U.
*
* @package Bancha
* @copyright Copyright 2011-2014 codeQ e.U.
* @link http://bancha.io Bancha
* @since Bancha v 2.4.0
* @author Roland Schuetz <mail@rolandschuetz.at>
* @version Bancha v PRECOMPILER_ADD_RELEASE_VERSION
*
* For more information go to http://bancha.io
*/

/**
* @private
* @class Bancha.data.validator.override.Range
*
* Fixes issues with the current Range validator
*
* See http://www.sencha.com/forum/showthread.php?288168
*
* @author Roland Schuetz <mail@rolandschuetz.at>
* @docauthor Roland Schuetz <mail@rolandschuetz.at>
*/
Ext.define('Bancha.data.validator.override.Range', {
override: 'Ext.data.validator.Range',
requires: [
'Bancha.data.validator.override.Bound'
]
// all the logic can be found in Bancha.data.validator.override.Bound
}, function() {
// for some reason setting via config doesn't work
this.prototype.setNanMessage('Must be a number');
});

0 comments on commit 79268bd

Please sign in to comment.