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