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