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