Pman.I18n.js
[Pman.Core] / Pman.I18n.js
1 //<script type="text/javascript">
2
3
4 /**
5 * A few usefull tools to convert language info...
6
7 * Our login details contain the available translation data..
8
9
10 * Languages are included in the main application
11 * using <script src="baseURL/Core/I18N/Data.js"></script>
12 * which set's up. Pman.I18n.data 
13
14
15
16 * includes standard pulldowns.
17 */
18
19 Pman.I18n = {
20     
21     /**
22      * turn zh_HK,en  => into Chinese(HK) , English
23      * @arg type type (c = country, l = lang)
24      * @arg codes list of languages
25      */
26     listToNames: function (type, codes)
27     {
28         var ret = [];
29         var _this = this;
30         var cl = codes.split(',');
31         Roo.each(cl , function(c) {
32             ret.push(_this.toName(type, c));
33         });
34         return ret.join(', ');
35     },
36     /**
37      * 
38      * turns zh_HK into a Chinese(HK)
39      * @arg type type (c = country, l = lang)
40      * @arg langcode language code (eg. zh_HK, UK etc.)
41      * 
42      */
43     toName: function(type, code) 
44     {
45         var ret = code;
46         var lang = Pman.Login.authUser.lang || 'en'
47         if (code.indexOf('_') > -1) {
48             var clang = code.split('_').shift();
49             var cc = code.split('_').pop();
50             return this.toName('l', clang) + ' (' +  cc + ')';
51         }
52         
53         
54         Roo.each(Pman.I18n.Data[lang][type], function(d) {
55             if (d.code == code) {
56                 ret = d.title;
57                 return false; // stop!
58             }
59         });
60         return ret;
61         
62     },
63     /**
64      * List to Objects
65      * zh_HK,en to [ { code=zh_HK, title=Chinese }, .... ]
66      * @arg type type (c = country, l = lang)
67      * @arg codes list of languages
68      */
69     listToObjects: function (type, codes)
70     {
71         var ret = [];
72         var _this = this;
73         if (!codes.length) {
74             return ret;
75         };
76         var cl = codes.split(',');
77         Roo.each(cl , function(c) {
78             ret.push({
79                 code : c,
80                 title : _this.toName(type,c)
81             })
82         });
83         return ret;
84     },
85     
86     
87     
88     reader :   { // std. reader for i18n items.
89         root : 'data',
90         totalProperty : 'total',
91         id : 'code',
92         xtype : 'JsonReader',
93         fields : [
94             'code',
95             'title'
96         ]
97         },
98     
99     
100     
101     /**
102      * dataToProxy
103      * return proxy data for a pulldown.
104      * @param {String} type  eg. l,c,m (lang/country/money)
105      *    
106      * usage:
107      {
108       xtype: 'Store',
109       xns: Roo.data,
110       reader : Pman.I18n.reader,
111       proxy : {
112          xtype : 'MemoryProxy',
113          xns : Roo.data,
114          data : Pman.I18n.dataToProxy('l'), // eg. language
115          remoteSort : false,
116          sortInfo : { field : 'title' , direction : 'ASC' } 
117       }
118          * 
119          *}
120      * 
121      * 
122      */
123     
124     dataToProxy : function(type)
125     {
126         var lang = Pman.Login.authUser.lang || 'en';
127         return Pman.I18n.Data[lang][type];
128     },
129     
130     
131     // DEPRECIATED... -- see dataToProxy
132     countryStore : function() { return {
133         
134         // load using HTTP
135         xtype: 'Store',
136         proxy: {
137             xtype: 'HttpProxy',
138             url: baseURL + '/I18N/Country.html',
139             method: 'GET'
140         },
141         
142         reader: Pman.I18n.reader,
143         listeners : {
144              
145             loadexception : Pman.loadException
146
147         },
148         remoteSort: false,
149         sortInfo: {
150             field: 'title', direction: 'ASC'
151         }
152               
153     }},
154       // DEPRECIATED...
155     languageStore: function() {return{
156         // load using HTTP
157         xtype: 'Store',
158         proxy: {
159             xtype: 'HttpProxy',
160             url: baseURL + '/I18N/Lang.html',
161             method: 'GET'
162         },
163         
164         reader: Pman.I18n.reader,
165         listeners : {
166              
167             loadexception : Pman.loadException
168     
169         },
170         remoteSort: false,
171         sortInfo: {
172             field: 'title', direction: 'ASC'
173         }
174     }},
175       // DEPRECIATED...
176     currencyStore: function() {return{
177         // load using HTTP
178         xtype: 'Store',
179         proxy: {
180             xtype: 'HttpProxy',
181             url: baseURL + '/I18N/Currency.html',
182             method: 'GET'
183         },
184         
185         reader: Pman.I18n.reader,
186         listeners : {
187              
188             loadexception : Pman.loadException
189     
190         },
191         remoteSort: false,
192         sortInfo: {
193             field: 'title', direction: 'ASC'
194         }
195     }},
196       // DEPRECIATED...
197     country: function(cfg) {
198         var _this = this;
199         cfg = cfg || {};
200         return Roo.apply({
201                 // things that might need chnaging
202                 name : 'country_title',
203                 hiddenName : 'country',
204                 width : 290,
205                 listWidth : 300,
206                 fieldLabel : "Country",
207                 allowBlank : false,
208                 
209                 // less likely
210                 qtip : "Select Country",
211                 
212                 value : '',
213                 // very unlinkly
214                 xtype : 'ComboBox',   
215                 store: this.countryStore(),
216                 displayField:'title',
217                 valueField : 'code',
218                 typeAhead: false,
219                 editable: false,
220                 //mode: 'local',
221                 triggerAction: 'all',
222                 //emptyText:'Select a state...',
223                 selectOnFocus:true 
224                  
225             }, cfg);
226     },
227       // DEPRECIATED...
228     language: function(cfg) {
229                var _this = this;
230         cfg = cfg || {};
231         return Roo.apply({
232                 // things that might need chnaging
233                 
234                 name : 'language_title',
235                 hiddenName : 'language',
236                 width : 290,
237                 listWidth : 300,
238                 fieldLabel : "Language",
239                 allowBlank : false,
240                 
241                 // less likely
242                 qtip : "Select Language",
243                 
244                 value : '',
245                 // very unlinkly
246                 xtype : 'ComboBox',   
247                 store: this.languageStore(),
248                 displayField:'title',
249                 valueField : 'code',
250                 
251                 typeAhead: false,
252                 editable: false,
253                 //mode: 'local',
254                 triggerAction: 'all',
255                 //emptyText:'Select a state...',
256                 selectOnFocus:true 
257                 
258             }, cfg);
259     },
260          // DEPRECIATED...
261     currency: function(cfg) {
262         var _this = this;
263         cfg = cfg || {};
264         return Roo.apply({
265                 // things that might need chnaging
266                 name : 'currency_title',
267                 hiddenName : 'currency',
268                 width : 290,
269                 listWidth : 300,
270                 fieldLabel : "Currency",
271                 allowBlank : false,
272                 
273                 // less likely
274                 qtip : "Select Currency",
275                 
276                 value : '',
277                 // very unlinkly
278                 xtype : 'ComboBox',   
279                 store: this.currencyStore(),
280                 displayField:'code',
281                 valueField : 'code',
282                 typeAhead: false,
283                 editable: false,
284                 //mode: 'local',
285                 triggerAction: 'all',
286                 //emptyText:'Select a state...',
287                 selectOnFocus:true,
288                    tpl: new Ext.Template(
289                     '<div class="x-grid-cell-text x-btn button">',
290                         '{title} ({code})</b>',
291                     '</div>'
292                 ) 
293                  
294             }, cfg);
295     },
296       // DEPRECIATED...
297     languageList : function(cfg) {
298         cfg = cfg || {};
299          
300         return Roo.apply({
301                 
302                 name : 'language',
303                 //hiddenListName
304                 fieldLabel : "Language(s)",
305                 idField : 'code',
306                 nameField: 'title',
307                 renderer : function(d) {
308                     return String.format('{0}',  d.title );
309                 },
310                 
311                 
312                 xtype: 'ComboBoxLister',
313                 displayField:'title',
314                 value : '',
315                
316                 qtip : "Select a language to add.",
317                 selectOnFocus:true,
318                 allowBlank : true,
319                 width: 150,
320                 boxWidth: 300,
321                  
322                 store:  this.languageStore(),
323                
324                 editable: false,
325                 //typeAhead: true,
326                 forceSelection: true,
327                 //mode: 'local',
328                 triggerAction: 'all',
329                 tpl: new Ext.Template(
330                     '<div class="x-grid-cell-text x-btn button">',
331                         '{title}</b>',
332                     '</div>'
333                 ),
334                 queryParam: 'query[name]',
335                 loadingText: "Searching...",
336                 listWidth: 400,
337                
338                 minChars: 2,
339                // pageSize:20,
340                 setList : function(ar) {
341                     var _this = this;
342                     Roo.each(ar, function(a) {
343                         _this.addItem(a);
344                     });
345                 },
346                 toList : function() {
347                     var ret = [];
348                     this.items.each(function(a) {
349                         ret.push(a.data);
350                     });
351                     return ret;
352                 }
353                 
354                  
355             }, cfg);
356     },
357       // DEPRECIATED...
358     countryList : function(cfg) {
359         cfg = cfg || {};
360          
361          
362         return Roo.apply({
363                 
364                 name : 'countries',
365                 fieldLabel : "Country(s)",
366                 idField : 'code',
367                 nameField: 'title',
368                 renderer : function(d) {
369                     return String.format('{0}',  d.title );
370                 },
371                 
372                 
373                 xtype: 'ComboBoxLister',
374                 displayField:'title',
375                 value : '',
376                
377                 qtip : "Select a country to add.",
378                 selectOnFocus:true,
379                 allowBlank : true,
380                 width: 150,
381                 boxWidth: 300,
382                  
383                 store:  this.countryStore(), 
384                
385                 editable: false,
386                 //typeAhead: true,
387                 forceSelection: true,
388                 //mode: 'local',
389                 triggerAction: 'all',
390                 tpl: new Ext.Template(
391                     '<div class="x-grid-cell-text x-btn button">',
392                         '{title}</b>',
393                     '</div>'
394                 ),
395                 queryParam: 'query[name]',
396                 loadingText: "Searching...",
397                 listWidth: 400,
398                
399                 minChars: 2,
400                // pageSize:20,
401                 setList : function(ar) {
402                     var _this = this;
403                     Roo.each(ar, function(a) {
404                         _this.addItem(a);
405                     });
406                 },
407                 toList : function() {
408                     var ret = [];
409                     this.items.each(function(a) {
410                         ret.push(a.data);
411                     });
412                     return ret;
413                 }
414                 
415                  
416             }, cfg);
417     }
418      
419      
420     
421 };
422
423