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      * 
103      * these should use generally..
104      {
105       xtype: 'Store',
106       xns: Roo.data,
107       reader : Pman.I18n.reader,
108       proxy : {
109          xtype : 'MemoryProxy',
110          xns : Roo.data,
111          data : Pman.I18n.dataToProxy('l'), // eg. language
112          remoteSort : false,
113          sortInfo : { field : 'title' , direction : 'ASC' } 
114       }
115          * 
116          *}
117      * 
118      * 
119      */
120     
121     dataToProxy : function(type)
122     {
123         var lang = Pman.Login.authUser.lang || 'en';
124         return Pman.I18n.Data[lang][type];
125         
126     },
127     
128     
129     // DEPRECIATED...
130     countryStore : function() { return {
131         
132         // load using HTTP
133         xtype: 'Store',
134         proxy: {
135             xtype: 'HttpProxy',
136             url: baseURL + '/I18N/Country.html',
137             method: 'GET'
138         },
139         
140         reader: Pman.I18n.reader,
141         listeners : {
142              
143             loadexception : Pman.loadException
144
145         },
146         remoteSort: false,
147         sortInfo: {
148             field: 'title', direction: 'ASC'
149         }
150               
151     }},
152       // DEPRECIATED...
153     languageStore: function() {return{
154         // load using HTTP
155         xtype: 'Store',
156         proxy: {
157             xtype: 'HttpProxy',
158             url: baseURL + '/I18N/Lang.html',
159             method: 'GET'
160         },
161         
162         reader: Pman.I18n.reader,
163         listeners : {
164              
165             loadexception : Pman.loadException
166     
167         },
168         remoteSort: false,
169         sortInfo: {
170             field: 'title', direction: 'ASC'
171         }
172     }},
173       // DEPRECIATED...
174     currencyStore: function() {return{
175         // load using HTTP
176         xtype: 'Store',
177         proxy: {
178             xtype: 'HttpProxy',
179             url: baseURL + '/I18N/Currency.html',
180             method: 'GET'
181         },
182         
183         reader: Pman.I18n.reader,
184         listeners : {
185              
186             loadexception : Pman.loadException
187     
188         },
189         remoteSort: false,
190         sortInfo: {
191             field: 'title', direction: 'ASC'
192         }
193     }},
194       // DEPRECIATED...
195     country: function(cfg) {
196         var _this = this;
197         cfg = cfg || {};
198         return Roo.apply({
199                 // things that might need chnaging
200                 name : 'country_title',
201                 hiddenName : 'country',
202                 width : 290,
203                 listWidth : 300,
204                 fieldLabel : "Country",
205                 allowBlank : false,
206                 
207                 // less likely
208                 qtip : "Select Country",
209                 
210                 value : '',
211                 // very unlinkly
212                 xtype : 'ComboBox',   
213                 store: this.countryStore(),
214                 displayField:'title',
215                 valueField : 'code',
216                 typeAhead: false,
217                 editable: false,
218                 //mode: 'local',
219                 triggerAction: 'all',
220                 //emptyText:'Select a state...',
221                 selectOnFocus:true 
222                  
223             }, cfg);
224     },
225       // DEPRECIATED...
226     language: function(cfg) {
227                var _this = this;
228         cfg = cfg || {};
229         return Roo.apply({
230                 // things that might need chnaging
231                 
232                 name : 'language_title',
233                 hiddenName : 'language',
234                 width : 290,
235                 listWidth : 300,
236                 fieldLabel : "Language",
237                 allowBlank : false,
238                 
239                 // less likely
240                 qtip : "Select Language",
241                 
242                 value : '',
243                 // very unlinkly
244                 xtype : 'ComboBox',   
245                 store: this.languageStore(),
246                 displayField:'title',
247                 valueField : 'code',
248                 
249                 typeAhead: false,
250                 editable: false,
251                 //mode: 'local',
252                 triggerAction: 'all',
253                 //emptyText:'Select a state...',
254                 selectOnFocus:true 
255                 
256             }, cfg);
257     },
258          // DEPRECIATED...
259     currency: function(cfg) {
260         var _this = this;
261         cfg = cfg || {};
262         return Roo.apply({
263                 // things that might need chnaging
264                 name : 'currency_title',
265                 hiddenName : 'currency',
266                 width : 290,
267                 listWidth : 300,
268                 fieldLabel : "Currency",
269                 allowBlank : false,
270                 
271                 // less likely
272                 qtip : "Select Currency",
273                 
274                 value : '',
275                 // very unlinkly
276                 xtype : 'ComboBox',   
277                 store: this.currencyStore(),
278                 displayField:'code',
279                 valueField : 'code',
280                 typeAhead: false,
281                 editable: false,
282                 //mode: 'local',
283                 triggerAction: 'all',
284                 //emptyText:'Select a state...',
285                 selectOnFocus:true,
286                    tpl: new Ext.Template(
287                     '<div class="x-grid-cell-text x-btn button">',
288                         '{title} ({code})</b>',
289                     '</div>'
290                 ) 
291                  
292             }, cfg);
293     },
294       // DEPRECIATED...
295     languageList : function(cfg) {
296         cfg = cfg || {};
297          
298         return Roo.apply({
299                 
300                 name : 'language',
301                 //hiddenListName
302                 fieldLabel : "Language(s)",
303                 idField : 'code',
304                 nameField: 'title',
305                 renderer : function(d) {
306                     return String.format('{0}',  d.title );
307                 },
308                 
309                 
310                 xtype: 'ComboBoxLister',
311                 displayField:'title',
312                 value : '',
313                
314                 qtip : "Select a language to add.",
315                 selectOnFocus:true,
316                 allowBlank : true,
317                 width: 150,
318                 boxWidth: 300,
319                  
320                 store:  this.languageStore(),
321                
322                 editable: false,
323                 //typeAhead: true,
324                 forceSelection: true,
325                 //mode: 'local',
326                 triggerAction: 'all',
327                 tpl: new Ext.Template(
328                     '<div class="x-grid-cell-text x-btn button">',
329                         '{title}</b>',
330                     '</div>'
331                 ),
332                 queryParam: 'query[name]',
333                 loadingText: "Searching...",
334                 listWidth: 400,
335                
336                 minChars: 2,
337                // pageSize:20,
338                 setList : function(ar) {
339                     var _this = this;
340                     Roo.each(ar, function(a) {
341                         _this.addItem(a);
342                     });
343                 },
344                 toList : function() {
345                     var ret = [];
346                     this.items.each(function(a) {
347                         ret.push(a.data);
348                     });
349                     return ret;
350                 }
351                 
352                  
353             }, cfg);
354     },
355       // DEPRECIATED...
356     countryList : function(cfg) {
357         cfg = cfg || {};
358          
359          
360         return Roo.apply({
361                 
362                 name : 'countries',
363                 fieldLabel : "Country(s)",
364                 idField : 'code',
365                 nameField: 'title',
366                 renderer : function(d) {
367                     return String.format('{0}',  d.title );
368                 },
369                 
370                 
371                 xtype: 'ComboBoxLister',
372                 displayField:'title',
373                 value : '',
374                
375                 qtip : "Select a country to add.",
376                 selectOnFocus:true,
377                 allowBlank : true,
378                 width: 150,
379                 boxWidth: 300,
380                  
381                 store:  this.countryStore(), 
382                
383                 editable: false,
384                 //typeAhead: true,
385                 forceSelection: true,
386                 //mode: 'local',
387                 triggerAction: 'all',
388                 tpl: new Ext.Template(
389                     '<div class="x-grid-cell-text x-btn button">',
390                         '{title}</b>',
391                     '</div>'
392                 ),
393                 queryParam: 'query[name]',
394                 loadingText: "Searching...",
395                 listWidth: 400,
396                
397                 minChars: 2,
398                // pageSize:20,
399                 setList : function(ar) {
400                     var _this = this;
401                     Roo.each(ar, function(a) {
402                         _this.addItem(a);
403                     });
404                 },
405                 toList : function() {
406                     var ret = [];
407                     this.items.each(function(a) {
408                         ret.push(a.data);
409                     });
410                     return ret;
411                 }
412                 
413                  
414             }, cfg);
415     }
416      
417      
418     
419 };
420
421