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