Permalink
Browse files

Sencha Touch PR4 update

  • Loading branch information...
1 parent 8073b67 commit 679429689e769e2aaaae6f46c9d3eab8420bf276 @elmasse committed Jan 26, 2012
Showing with 86 additions and 93 deletions.
  1. +5 −3 README.md
  2. +12 −10 demo/demo.js
  3. +2 −2 i18n/Bundle.js
  4. +5 −3 i18n/model/Property.js
  5. +30 −23 i18n/reader/Property.js
  6. +10 −3 index.html
  7. +0 −49 js/AjaxLocalProxy.js
  8. +22 −0 patch/AjaxProxy.js
View
8 README.md
@@ -1,6 +1,6 @@
# Ext.i18n.Bundle
-##v0.3
+##v0.3.1
Ext.i18n.Bundle allows to use properties files (or bundle files) from Java to use them as i18n resources with Sencha Touch.
@@ -40,11 +40,13 @@ You need to call your code once your bundle file is loaded, so you need to place
##Release Notes
+###v0.3.1
+* Sencha Touch 2 PR4 compatible code.
+* Patch for PhoneGap. PhoneGap is using XHR thru file:// protocol then AjaxProxy doesn't retrieve data.
+
###v0.3
* Sencha Touch 2 PR3 comaptible code.
* Removed config method. All the requests are made using GET method.
* Solved issue with extra arguments passed to URL. Now you have no limits, start nor group extra parameters in URL.
-###Known issues
-* PhoneGap is using XHR thru file:// protocol then AjaxProxy doesn't retrieve data. Note: This was solved in previous version for Sencha Touch 1 overriding AjaxProxy createRequestCallback method (v0.2.2) see js/AjaxLocalProxy.js
View
22 demo/demo.js
@@ -1,18 +1,20 @@
+Ext.require('Ext.i18n.Bundle', function(){
+ //create global bundle in here
+ Ext.i18n.appBundle = Ext.create('Ext.i18n.Bundle',{
+ bundle: 'Application',
+ lang: 'es-ES',
+ path: 'resources',
+ noCache: true
+ });
+});
+
Ext.application({
name: 'AppTest',
launch: function(){
-
- bundle = Ext.create('Ext.i18n.Bundle',{
- bundle: 'Application',
- lang: 'es-ES',
- path: 'resources',
- noCache: true
- });
-
- bundle.onReady(function(){
+ Ext.i18n.appBundle.onReady(function(){
Ext.create('Ext.Panel',{
fullscreen: true,
- html: bundle.getMsg('panel.html')
+ html: Ext.i18n.appBundle.getMsg('panel.html')
});
});
}
View
4 i18n/Bundle.js
@@ -101,7 +101,7 @@ Ext.define('Ext.i18n.Bundle', {
});
me.callParent([config]);
- me.proxy.on('exception', this.loadParent, this, {single: true});
+ me.getProxy().on('exception', this.loadParent, this, {single: true});
},
/**
@@ -166,7 +166,7 @@ Ext.define('Ext.i18n.Bundle', {
* @private
*/
loadParent: function(){
- this.proxy.url = this.buildURL();
+ this.getProxy().setUrl(this.buildURL());
this.load();
},
View
8 i18n/model/Property.js
@@ -1,7 +1,9 @@
Ext.define('Ext.i18n.model.Property', {
extend: 'Ext.data.Model',
-
- idProperty: 'key',
- fields: ['key', 'value']
+
+ config: {
+ idProperty: 'key',
+ fields: ['key', 'value']
+ }
});
View
53 i18n/reader/Property.js
@@ -6,48 +6,55 @@ Ext.define('Ext.i18n.reader.Property', {
config = config || {};
Ext.applyIf(config, {
- idProperty: 'id',
+ idProperty: 'key',
successProperty: 'success',
totalProperty: 'total'
});
this.callParent([config]);
},
- read: function(response){
- var propertyFile = response.responseText;
- if(!propertyFile)
- throw {message: "PropertyReader.read: File not found"};
-
- return this.readRecords(propertyFile);
+ getResponseData: function(response){
+ return response;
},
- readRecords: function(propertyFile){
- var Record = this.recordType,
- Model = this.model,
- records = [], record, kv,
- f = this.readLines(propertyFile),
+ getData: function(data){
+ var records = [], record, kv,
+ f = this.readLines(data),
l = f.length;
for(var i = 0; i < l; i++){
var kl = f[i].search(/[\s:=]/);
- record = new Model({
+ record = {
value : this.clearValueExtraChars(f[i].substring(kl+1)),
key : this.clearKeyExtraChars(f[i].substring(0, kl))
- });
-
+ };
records[i] = record;
}
-
- return Ext.create('Ext.data.ResultSet', {
- total : records.length,
- count : records.length,
- records: records,
- success: true
- });
+ return records;
},
- createAccessor: function(){},
+ createAccessor: function() {
+ var re = /[\[\.]/;
+
+ return function(expr) {
+ if (Ext.isEmpty(expr)) {
+ return Ext.emptyFn;
+ }
+ if (Ext.isFunction(expr)) {
+ return expr;
+ }
+ if (this._useSimpleAccessors !== true) {
+ var i = String(expr).search(re);
+ if (i >= 0) {
+ return Ext.functionFactory('obj', 'return obj' + (i > 0 ? '.' : '') + expr);
+ }
+ }
+ return function(obj) {
+ return obj[expr];
+ };
+ };
+ }(),
clearKeyExtraChars: function(s){
return (s ? s.replace(/[:=]/gi, "") : "");
View
13 index.html
@@ -4,18 +4,25 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Ext.i18n.Bundle for Sencha Touch</title>
<meta name="author" content="Maximiliano Fierro">
- <link rel="stylesheet" href="../common-libs/sencha-touch-2-pr3/resources/css/sencha-touch.css">
- <script src="../common-libs/sencha-touch-2-pr3/sencha-touch-all-debug.js"></script>
+ <link rel="stylesheet" href="http://dev.sencha.com/deploy/sencha-touch-2-pr4/resources/css/sencha-touch.css" type="text/css">
+ <script type="text/javascript" src="http://dev.sencha.com/deploy/sencha-touch-2-pr4/sencha-touch-all-debug.js"></script>
<script>
Ext.Loader.setConfig({
enabled: true,
paths: {
- 'Ext.i18n': 'i18n'
+ 'Ext.i18n': 'i18n',
+ 'patch': 'patch'
}
});
</script>
+ <!-- Uncomment the following script to load an override for AjaxProxy if you plan to use Bundle with PhoneGap -->
+ <!--
+ <script>
+ Ext.require('patch.AjaxProxy');
+ </script>
+ -->
<script type="text/javascript" src="demo/demo.js"></script>
</head>
<body>
View
49 js/AjaxLocalProxy.js
@@ -1,49 +0,0 @@
-Ext.data.AjaxProxy.override({
-
- createRequestCallback: function(request, operation, callback, scope) {
- var me = this;
-
- return function(options, success, response) {
-
- if (success === true || (response.status === 0 && response.responseText !== "" )) { //fixing xhr to local files
- var reader = me.getReader(),
- result = reader.read(response),
- records = result.records,
- length = records.length,
- mc = new Ext.util.MixedCollection(true, function(r) {return r.getId();}),
- record, i;
- mc.addAll(operation.records);
-
- for (i = 0; i < length; i++) {
- record = mc.get(records[i].getId());
-
- if (record) {
- record.set(record.data);
- }
- }
-
- //see comment in buildRequest for why we include the response object here
- Ext.apply(operation, {
- response : response,
- resultSet: result
- });
-
- operation.setCompleted();
- operation.setSuccessful();
- } else {
- me.fireEvent('exception', this, response, operation);
-
- //TODO: extract error message from reader
- operation.setException();
- }
-
- //this callback is the one that was passed to the 'read' or 'write' function above
- if (typeof callback == 'function') {
- callback.call(scope || me, operation);
- }
-
- me.afterRequest(request, true);
- };
- }
-
-});
View
22 patch/AjaxProxy.js
@@ -0,0 +1,22 @@
+/**
+ *
+
+ */
+Ext.define('patch.AjaxProxy', {
+ override: 'Ext.data.proxy.Ajax',
+
+ /**
+ * @override
+ */
+ createRequestCallback: function(request, operation, callback, scope) {
+ var me = this;
+
+ return function(options, success, response) {
+ // Fix for PhoneGap: XHR to local files are made thru file:// protocol this means that
+ // status code will be 0 indicating a success xhr request, if so we will check that responseText
+ // is not empty to assume request is successful.
+ success = success || (response.status === 0 && response.responseText !== "" );
+ me.processResponse(success, operation, request, response, callback, scope);
+ };
+ }
+});

0 comments on commit 6794296

Please sign in to comment.