Fix #5700 - Order Follow up Table
[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
20
21 Pman.I18n = {
22     
23     
24     
25     /**
26      * turn zh_HK,en  => into Chinese(HK) , English
27      * @arg type type (c = country, l = lang)
28      * @arg codes list of languages
29      */
30     listToNames: function (type, codes)
31     {
32         var ret = [];
33         var _this = this;
34         var cl = codes.split(',');
35         Roo.each(cl , function(c) {
36             ret.push(_this.toName(type, c));
37         });
38         return ret.join(', ');
39     },
40     /**
41      * 
42      * turns zh_HK into a Chinese(HK)
43      * @arg type type (c = country, l = lang)
44      * @arg langcode language code (eg. zh_HK, UK etc.)
45      * 
46      */
47     toName: function(type, code) 
48     {
49         var ret = code;
50         
51         var lang = 'en';
52         
53         if(typeof(Pman.Login) != 'undefined' && typeof(Pman.Login.authUser.lang) == 'undefined'){
54             lang = Pman.Login.authUser.lang;
55         }
56         
57         if (code.indexOf('_') > -1) {
58             var clang = code.split('_').shift();
59             var cc = code.split('_').pop();
60             return this.toName('l', clang.toLowerCase()) + ' (' +  this.toName('c', cc.toUpperCase()) + ')';
61         }
62         
63         
64         Roo.each(Pman.I18n.Data[lang][type], function(d) {
65             if (d.code == code) {
66                 ret = d.title;
67                 return false; // stop!
68             }
69             return true;
70         });
71         return ret;
72         
73     },
74     /**
75      * List to Objects
76      * zh_HK,en to [ { code=zh_HK, title=Chinese }, .... ]
77      * @arg type type (c = country, l = lang)
78      * @arg codes list of languages
79      */
80     listToObjects: function (type, codes)
81     {
82         var ret = [];
83         var _this = this;
84         if (!codes.length) {
85             return ret;
86         };
87         var cl = codes.split(',');
88         Roo.each(cl , function(c) {
89             ret.push({
90                 code : c,
91                 title : _this.toName(type,c)
92             })
93         });
94         return ret;
95     },
96     
97     
98     
99     reader :   { // std. reader for i18n items.
100         root : 'data',
101         totalProperty : 'total',
102         id : 'code',
103         xtype : 'JsonReader',
104         fields : [
105             'code',
106             'title'
107         ]
108         },
109     
110     
111     
112     /**
113      * dataToProxy
114      * return proxy data for a pulldown.
115      * @param {String} type  eg. l,c,m (lang/country/money)
116      *    
117      * usage:
118      {
119       xtype: 'Store',
120       xns: Roo.data,
121       reader : Pman.I18n.reader,
122       proxy : {
123          xtype : 'MemoryProxy',
124          xns : Roo.data,
125          data : Pman.I18n.dataToProxy('l'), // eg. language
126          remoteSort : false,
127          sortInfo : { field : 'title' , direction : 'ASC' } 
128       }
129          * 
130          *}
131      * 
132      * 
133      */
134     
135     dataToProxy : function(type)
136     {
137         var lang = Pman.Login.authUser.lang || 'en';
138         return Pman.I18n.Data[lang][type];
139     },
140     
141     /**
142      * simpleStoreData:
143      * return a simplestore to be used by country/language combos
144      * eg.
145      * store: (function() {
146             return Pman.I18n.simpleStoreData('c');
147         })(),
148      *
149      * @param {Char} type (c,l,m)
150      * @param {function} (optional) filter language list
151      *     called with object { code: xxx , title: xxx }
152      *     if it exists then returning false will hide the entry.
153      */
154     
155     simpleStoreData : function(type, filter)
156     {
157         filter = typeof(filter) == 'undefined' ? false : filter;
158         var lang =  'en';
159         try {
160             lang = Pman.Login.authUser.lang;
161         } catch (E) {};
162         lang = lang || 'en';
163         var ret = [];
164         Roo.each(Pman.I18n.Data[lang][type], function (o) {
165             if (filter !== false && filter(o) === false) {
166                 return;
167             }
168             ret.push([ o.code, o.title ]);
169         });
170         
171          ret = ret.sort(function(a,b) {
172             if (a[0] == '**') { return 1; } // other always at end..
173             if (b[0] == '**') { return -1; } // other always at end..
174             return a[1]  > b[1] ? 1 : -1;
175         });
176         
177         return ret;
178     },
179     // DEPRECIATED... -- see dataToProxy
180     countryStore : function() { return {
181         
182         // load using HTTP
183         xtype: 'Store',
184         proxy: {
185             xtype: 'HttpProxy',
186             url: baseURL + '/Core/I18n/Country.html',
187             method: 'GET'
188         },
189         
190         reader: Pman.I18n.reader,
191         listeners : {
192              
193             loadexception : Pman.loadException
194
195         },
196         remoteSort: false,
197         sortInfo: {
198             field: 'title', direction: 'ASC'
199         }
200               
201     }},
202       // DEPRECIATED...
203     languageStore: function() {return{
204         // load using HTTP
205         xtype: 'Store',
206         proxy: {
207             xtype: 'HttpProxy',
208             url: baseURL + '/Core/I18n/Lang.html',
209             method: 'GET'
210         },
211         
212         reader: Pman.I18n.reader,
213         listeners : {
214              
215             loadexception : Pman.loadException
216     
217         },
218         remoteSort: false,
219         sortInfo: {
220             field: 'title', direction: 'ASC'
221         }
222     }},
223       // DEPRECIATED...
224     currencyStore: function() {return{
225         // load using HTTP
226         xtype: 'Store',
227         proxy: {
228             xtype: 'HttpProxy',
229             url: baseURL + '/Core/I18n/Currency.html',
230             method: 'GET'
231         },
232         
233         reader: Pman.I18n.reader,
234         listeners : {
235              
236             loadexception : Pman.loadException
237     
238         },
239         remoteSort: false,
240         sortInfo: {
241             field: 'title', direction: 'ASC'
242         }
243     }},
244       // DEPRECIATED...
245     country: function(cfg) {
246         var _this = this;
247         cfg = cfg || {};
248         return Roo.apply({
249                 // things that might need chnaging
250                 name : 'country_title',
251                 hiddenName : 'country',
252                 width : 290,
253                 listWidth : 300,
254                 fieldLabel : "Country",
255                 allowBlank : false,
256                 
257                 // less likely
258                 qtip : "Select Country",
259                 
260                 value : '',
261                 // very unlinkly
262                 xtype : 'ComboBox',   
263                 store: this.countryStore(),
264                 displayField:'title',
265                 valueField : 'code',
266                 typeAhead: false,
267                 editable: false,
268                 //mode: 'local',
269                 triggerAction: 'all',
270                 //emptyText:'Select a state...',
271                 selectOnFocus:true 
272                  
273             }, cfg);
274     },
275       // DEPRECIATED...
276     language: function(cfg) {
277                var _this = this;
278         cfg = cfg || {};
279         return Roo.apply({
280                 // things that might need chnaging
281                 
282                 name : 'language_title',
283                 hiddenName : 'language',
284                 width : 290,
285                 listWidth : 300,
286                 fieldLabel : "Language",
287                 allowBlank : false,
288                 
289                 // less likely
290                 qtip : "Select Language",
291                 
292                 value : '',
293                 // very unlinkly
294                 xtype : 'ComboBox',   
295                 store: this.languageStore(),
296                 displayField:'title',
297                 valueField : 'code',
298                 
299                 typeAhead: false,
300                 editable: false,
301                 //mode: 'local',
302                 triggerAction: 'all',
303                 //emptyText:'Select a state...',
304                 selectOnFocus:true 
305                 
306             }, cfg);
307     },
308          // DEPRECIATED...
309     currency: function(cfg) {
310         var _this = this;
311         cfg = cfg || {};
312         return Roo.apply({
313                 // things that might need chnaging
314                 name : 'currency_title',
315                 hiddenName : 'currency',
316                 width : 290,
317                 listWidth : 300,
318                 fieldLabel : "Currency",
319                 allowBlank : false,
320                 
321                 // less likely
322                 qtip : "Select Currency",
323                 
324                 value : '',
325                 // very unlinkly
326                 xtype : 'ComboBox',   
327                 store: this.currencyStore(),
328                 displayField:'code',
329                 valueField : 'code',
330                 typeAhead: false,
331                 editable: false,
332                 //mode: 'local',
333                 triggerAction: 'all',
334                 //emptyText:'Select a state...',
335                 selectOnFocus:true,
336                    tpl: new Ext.Template(
337                     '<div class="x-grid-cell-text x-btn button">',
338                         '{title} ({code})</b>',
339                     '</div>'
340                 ) 
341                  
342             }, cfg);
343     },
344       // DEPRECIATED...
345     languageList : function(cfg) {
346         cfg = cfg || {};
347          
348         return Roo.apply({
349                 
350                 name : 'language',
351                 //hiddenListName
352                 fieldLabel : "Language(s)",
353                 idField : 'code',
354                 nameField: 'title',
355                 renderer : function(d) {
356                     return String.format('{0}',  d.title );
357                 },
358                 
359                 
360                 xtype: 'ComboBoxLister',
361                 displayField:'title',
362                 value : '',
363                
364                 qtip : "Select a language to add.",
365                 selectOnFocus:true,
366                 allowBlank : true,
367                 width: 150,
368                 boxWidth: 300,
369                  
370                 store:  this.languageStore(),
371                
372                 editable: false,
373                 //typeAhead: true,
374                 forceSelection: true,
375                 //mode: 'local',
376                 triggerAction: 'all',
377                 tpl: new Ext.Template(
378                     '<div class="x-grid-cell-text x-btn button">',
379                         '{title}</b>',
380                     '</div>'
381                 ),
382                 queryParam: 'query[name]',
383                 loadingText: "Searching...",
384                 listWidth: 400,
385                
386                 minChars: 2,
387                // pageSize:20,
388                 setList : function(ar) {
389                     var _this = this;
390                     Roo.each(ar, function(a) {
391                         _this.addItem(a);
392                     });
393                 },
394                 toList : function() {
395                     var ret = [];
396                     this.items.each(function(a) {
397                         ret.push(a.data);
398                     });
399                     return ret;
400                 }
401                 
402                  
403             }, cfg);
404     },
405       // DEPRECIATED...
406     countryList : function(cfg) {
407         cfg = cfg || {};
408          
409          
410         return Roo.apply({
411                 
412                 name : 'countries',
413                 fieldLabel : "Country(s)",
414                 idField : 'code',
415                 nameField: 'title',
416                 renderer : function(d) {
417                     return String.format('{0}',  d.title );
418                 },
419                 
420                 
421                 xtype: 'ComboBoxLister',
422                 displayField:'title',
423                 value : '',
424                
425                 qtip : "Select a country to add.",
426                 selectOnFocus:true,
427                 allowBlank : true,
428                 width: 150,
429                 boxWidth: 300,
430                  
431                 store:  this.countryStore(), 
432                
433                 editable: false,
434                 //typeAhead: true,
435                 forceSelection: true,
436                 //mode: 'local',
437                 triggerAction: 'all',
438                 tpl: new Ext.Template(
439                     '<div class="x-grid-cell-text x-btn button">',
440                         '{title}</b>',
441                     '</div>'
442                 ),
443                 queryParam: 'query[name]',
444                 loadingText: "Searching...",
445                 listWidth: 400,
446                
447                 minChars: 2,
448                // pageSize:20,
449                 setList : function(ar) {
450                     var _this = this;
451                     Roo.each(ar, function(a) {
452                         _this.addItem(a);
453                     });
454                 },
455                 toList : function() {
456                     var ret = [];
457                     this.items.each(function(a) {
458                         ret.push(a.data);
459                     });
460                     return ret;
461                 }
462                 
463                  
464             }, cfg);
465     }
466      
467      
468     
469 };
470