Pman.Tab.AdminTranslations.bjs
[Pman.Admin] / Pman.Tab.AdminTranslations.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Pman.Tab.AdminTranslations = new Roo.XComponent({
6     part     :  ["Admin","Translations"],
7     order    : '950-Pman.Tab.AdminTranslations',
8     region   : 'center',
9     parent   : 'Pman.Tab.Admin',
10     name     : "Admin - Translations",
11     disabled : false, 
12     permname : 'Admin.Translations', 
13     _tree : function()
14     {
15         var _this = this;
16         var MODULE = this;
17         return {
18             xtype: 'NestedLayoutPanel',
19             xns: Roo,
20             region : 'center',
21             title : "Translate App",
22             layout : {
23                 xtype: 'BorderLayout',
24                 xns: Roo,
25                 items : [
26                     {
27                         xtype: 'GridPanel',
28                         xns: Roo,
29                         listeners : {
30                             activate : function() {
31                                 _this.panel = this;
32                                 if (_this.grid) {
33                                    _this.grid.getDataSource().reload(); 
34                                 }
35                             }
36                         },
37                         background : true,
38                         fitContainer : true,
39                         fitToframe : true,
40                         region : 'center',
41                         title : "Text in interface",
42                         grid : {
43                             xtype: 'EditorGrid',
44                             xns: Roo.grid,
45                             listeners : {
46                                 render : function() { 
47                                     _this.grid = this; 
48                                     //_this.dialog = Pman.Dialog.FILL_IN
49                                     if (_this.panel.active) {
50                                       _this.grid.getDataSource().reload(); 
51                                     }
52                                 },
53                                 beforeedit : function(e) {
54                                     console.log('beforeedit');
55                                     //if (e.record.get('origtxt').indexOf('<') > -1) {
56                                                        // console.log("HTML EDITOR!!");
57                                                      
58                                                     //    return false;
59                                                     //}
60                                                     if (e.record.get('txt').replace(/\s+/, '').length) {
61                                                         return true;
62                                                     }
63                                                     if (e.record.get('suggest').length) {
64                                                         e.record.set('txt', e.record.get('suggest'));
65                                                     //    _this.saveRec(e.record);
66                                                         return;
67                                                     }
68                                                     
69                                                     
70                                                     
71                                                    
72                                                     var tl = e.record.get('id').split('/')[0];
73                                                   
74                                                     tl = (tl == 'zh_HK') ? 'zh-TW' : tl; 
75                                                     tl = tl.replace('_', '-');
76                                                     var rec = e.record;
77                                                     
78                                                     
79                                                     
80                                                     Pman.gtranslate(e.record.get('origtxt'), 'en', tl, function(result) { 
81                                                         if (typeof(result) == 'object') { //error
82                                                             return; 
83                                                            }
84                                                         
85                                                         if (_this.grid.activeEditor) {
86                                                             _this.grid.activeEditor.setValue(result);
87                                                         } else {
88                                                             rec.set('txt',result);
89                                                             //_this.saveRec(rec);
90                                                         }
91                                 
92                                                         //
93                                                         
94                                                         
95                                                         //console.log(result.translation);
96                                                     });
97                                                     
98                                                    
99                                                     
100                                                     return true;
101                                                 },
102                                 afteredit : function (e)
103                                 {
104                                     var saveRec  = function(rec)
105                                     {
106                                         var g = _this.grid;
107                                 
108                                         //g.getView().el.mask('Saving');
109                                         new Roo.Request({
110                                             url : baseURL + '/Admin/Translations.php',
111                                             method: 'POST',
112                                             params : {
113                                                 id : rec.get('id'),
114                                                 txt : rec.get('txt'),
115                                                 lang :  _this.langCombo.getValue(),
116                                                 module :  _this.modCombo.getValue()
117                                             },
118                                             success : function()
119                                             {
120                                                 //g.getView().el.unmask();
121                                                 //g.getDataSource().reload();
122                                             },
123                                             failure : function()
124                                             {
125                                                 Ext.Msg.alert("Error", "There was a problem saving the data - try reloading");
126                                                // g.getView().el.unmask();
127                                             }
128                                             
129                                     });
130                                         };
131                                     
132                                     saveRec.defer(1000, _this, [ e.record ]);
133                                 },
134                                 celldblclick : function (_self, rowIndex, columnIndex, e)
135                                 {
136                                     var di  = this.colModel.config[columnIndex].dataIndex;
137                                     if (di != 'reset_tx') {
138                                         return;
139                                     }
140                                 }
141                             },
142                             autoExpandColumn : 'txt',
143                             clicksToEdit : 1,
144                             loadMask : true,
145                             dataSource : {
146                                 xtype: 'Store',
147                                 xns: Roo.data,
148                                 listeners : {
149                                     beforeload : function (_self, opts)
150                                     {
151                                     
152                                                             if (!_this.langCombo || !_this.langCombo.getValue().length) {
153                                                                 return false;
154                                                             }
155                                                             if (!_this.modCombo || !_this.modCombo.getValue().length) {
156                                                                 return false;
157                                                             }
158                                                             opts.params = {
159                                                                 lang :  _this.langCombo.getValue(),
160                                                                 module :  _this.modCombo.getValue()
161                                                             };
162                                     },
163                                     loadexception : function (self, ret, load, jsonData)
164                                     {
165                                         Roo.MessageBox.alert("Error", jsonData);
166                                     }
167                                 },
168                                 reader : Pman.Readers.Category,
169                                 proxy : {
170                                     xtype: 'HttpProxy',
171                                     xns: Roo.data,
172                                     method : 'GET',
173                                     url : baseURL + '/Admin/Translations.php'
174                                 },
175                                 reader : {
176                                     xtype: 'JsonReader',
177                                     xns: Roo.data,
178                                     root : 'data',
179                                     totalProperty : 'total',
180                                     id : 'id',
181                                     fields : [                    'id',             'tablename',             'tableid',             'colname',             'txt',             'lang',             { name:'updated', type:'date', dateFormat: 'Y-m-d H:i:s' },             { name:'origupdated', type:'date', dateFormat: 'Y-m-d H:i:s' },             'origtxt',             'msum',             'suggest'                  ]
182                                 }
183                             },
184                             toolbar : {
185                                 xtype: 'Toolbar',
186                                 xns: Roo,
187                                 items : [
188                                     {
189                                         xtype: 'ComboBox',
190                                         xns: Roo.form,
191                                         listeners : {
192                                             render : function (_self)
193                                             {
194                                               _this.modCombo = _self;
195                                             },
196                                             select : function (combo, record, index)
197                                             {
198                                               _this.grid.getDataSource().reload(); 
199                                             }
200                                         },
201                                         valueField : 'module',
202                                         displayField : 'module',
203                                         width : 200,
204                                         typeAhead : false,
205                                         editable : false,
206                                         mode : 'local',
207                                         triggerAction : 'all',
208                                         emptyText : "Select Module",
209                                         selectOnFocus : true,
210                                         store : {
211                                             xtype: 'SimpleStore',
212                                             xns: Roo.data,
213                                             data : (function() {             
214                                                     var modlist = [];             
215                                                     AppModules = typeof(AppModules) == 'undefined' ? '' : AppModules;
216                                                     Roo.each( AppModules.split(','), function(mod) {            
217                                                              modlist.push( [ mod ] );            
218                                                   });             
219                                                   return modlist;
220                                                })(),
221                                             fields : ['module']
222                                         }
223                                     },
224                                     {
225                                         xtype: 'ComboBox',
226                                         xns: Roo.form,
227                                         listeners : {
228                                             select : function (combo, record, index)
229                                             {
230                                               _this.grid.getDataSource().reload(); 
231                                             },
232                                             render : function (_self)
233                                             {
234                                               _this.langCombo=_self;
235                                             }
236                                         },
237                                         valueField : 'lang',
238                                         displayField : 'ldisp',
239                                         width : 200,
240                                         typeAhead : false,
241                                         editable : false,
242                                         mode : 'local',
243                                         triggerAction : 'all',
244                                         emptyText : "Select Language",
245                                         selectOnFocus : true,
246                                         store : {
247                                             xtype: 'SimpleStore',
248                                             xns: Roo.data,
249                                             fields : ['lang', 'ldisp'],
250                                             data : [                                                [ 'zh_HK' , '\u7E41\u4E2D - Trad. Chin. (HK)' ],                         [ 'zh_CN', '\u7C21\u4E2D - Simp. Chin.' ]                     ]
251                                         }
252                                     }
253                                 ]
254                             },
255                             colModel : [
256                                 {
257                                     xtype: 'ColumnModel',
258                                     xns: Roo.grid,
259                                     header : 'Name',
260                                     width : 150,
261                                     dataIndex : 'colname',
262                                     renderer : function(v,x,r) {                         var c = '#666';                         if (r.get('updated') < r.get('origupdated')) {                             c = 'red';                         }                                                  return '<div style="color:'+c+'";>' +r.get('tableid')+ ':' + v + '</div>';                                              }
263                                 },
264                                 {
265                                     xtype: 'ColumnModel',
266                                     xns: Roo.grid,
267                                     header : 'Original',
268                                     width : 300,
269                                     dataIndex : 'origtxt',
270                                     renderer : function(v,x,r) {                         var c = '#666';                         if (r.get('updated') < r.get('origupdated')) {                             c = 'red';                         }                         return '<div style="color:' + c+ '">' +                                  Ext.util.Format.htmlEncode(v) + '</div>';                                              }
271                                 },
272                                 {
273                                     xtype: 'ColumnModel',
274                                     xns: Roo.grid,
275                                     dataIndex : 'reset_tx',
276                                     header : 'Reset',
277                                     width : 50,
278                                     renderer : function(v,x,r) {    
279                                         return '[x]';
280                                     }
281                                 },
282                                 {
283                                     xtype: 'ColumnModel',
284                                     xns: Roo.grid,
285                                     dataIndex : 'txt',
286                                     header : 'Translated (Click to Edit)',
287                                     width : 150,
288                                     renderer : function(v,x,r) {                                                   var c = '#666';                         if (r.get('updated') < r.get('origupdated')) {                             c = 'red';                         }                                                  return '<div style="color:' + c+ '">' + Ext.util.Format.htmlEncode(v) + '</div>';                     },
289                                     editor : {
290                                         xtype: 'GridEditor',
291                                         xns: Roo.grid,
292                                         field : {
293                                             xtype: 'TextField',
294                                             xns: Roo.form
295                                         }
296                                     }
297                                 }
298                             ]
299                         }
300                     },
301                     {
302                         xtype: 'GridPanel',
303                         xns: Roo,
304                         listeners : {
305                             activate : function() {
306                                 _this.langpanel = this;
307                                 if (_this.langgrid) {
308                                     _this.langgrid.ds.load({});
309                                 }
310                             }
311                         },
312                         background : true,
313                         fitContainer : true,
314                         fitToframe : true,
315                         region : 'center',
316                         tableName : 'i18n',
317                         title : "Languages and Countries",
318                         grid : {
319                             xtype: 'EditorGrid',
320                             xns: Roo.grid,
321                             listeners : {
322                                 render : function() 
323                                 {
324                                     _this.langgrid = this; 
325                                     //_this.dialog = Pman.Dialog.FILL_IN
326                                     if (_this.langpanel.active) {
327                                        this.ds.load({});
328                                     }
329                                 },
330                                 afteredit : function (e)
331                                 {
332                                     var saveRec  = function(rec)
333                                     {
334                                         var g = _this.grid;
335                                 
336                                         //g.getView().el.mask('Saving');
337                                         Ext.Ajax.request({
338                                             url : baseURL + '/Roo/I18n.php',
339                                             method: 'POST',
340                                             params : {
341                                                 id : rec.get('id'),
342                                                 lval : rec.get('lval')
343                                             },
344                                             success : function()
345                                             {
346                                                 //g.getView().el.unmask();
347                                                 //g.getDataSource().reload();
348                                             },
349                                             failure : function()
350                                             {
351                                                 Ext.Msg.alert("Error", "There was a problem saving the data - try reloading");
352                                                // g.getView().el.unmask();
353                                             }
354                                             
355                                     });
356                                         };
357                                     
358                                     saveRec.defer(1000, _this, [ e.record ]);
359                                 },
360                                 beforeedit : function(e) {
361                                     console.log('beforeedit');
362                                     //if (e.record.get('origtxt').indexOf('<') > -1) {
363                                                        // console.log("HTML EDITOR!!");
364                                              
365                                             //    return false;
366                                             //}
367                                             if (e.record.get('lval').replace(/\s+/, '').length) {
368                                                 return true;
369                                             }
370                                             
371                                             
372                                             var tl = _this.langgridCombo.getValue();
373                                           
374                                             tl = (tl == 'zh_HK') ? 'zh-TW' : tl; 
375                                             tl = tl.replace('_', '-');
376                                             var rec = e.record;
377                                             
378                                             
379                                             
380                                             Pman.gtranslate(e.record.get('lval_en'), 'en', tl, function(result) { 
381                                                 if (typeof(result) == 'object') { //error
382                                                     return; 
383                                                    }
384                                                 
385                                                 if (_this.grid.activeEditor) {
386                                                     _this.grid.activeEditor.setValue(result);
387                                                 } else {
388                                                     rec.set('lval',result);
389                                                     //_this.saveRec(rec);
390                                                 }
391                                 
392                                                 //
393                                                 
394                                                 
395                                                 //console.log(result.translation);
396                                             });
397                                             
398                                            
399                                             
400                                             return true;
401                                         }
402                             },
403                             autoExpandColumn : 'lval',
404                             clicksToEdit : 1,
405                             loadMask : true,
406                             dataSource : {
407                                 xtype: 'Store',
408                                 xns: Roo.data,
409                                 listeners : {
410                                     beforeload : function (_self, options)
411                                     {
412                                        options  =options ||  {};
413                                        options.params =options.params|| {};
414                                        options.params.ltype = _this.langtypeCombo.getValue();
415                                        options.params.inlang = _this.langgridCombo.getValue();
416                                        options.params['query[_with_en]'] = 1;
417                                        if (!options.params.ltype.length || !options.params.inlang.length) {
418                                            return false;
419                                        }
420                                        
421                                        options.params.limit = 9999;
422                                        
423                                     }
424                                 },
425                                 remoteSort : true,
426                                 sortInfo : { field : 'lkey', direction: 'ASC' },
427                                 proxy : {
428                                     xtype: 'HttpProxy',
429                                     xns: Roo.data,
430                                     method : 'GET',
431                                     url : baseURL + '/Roo/i18n.php'
432                                 },
433                                 reader : {
434                                     xtype: 'JsonReader',
435                                     xns: Roo.data,
436                                     totalProperty : 'total',
437                                     root : 'data',
438                                     id : 'id',
439                                     fields : [
440                                         {
441                                             'name': 'id',
442                                             'type': 'int'
443                                         },
444                                         {
445                                             'name': 'ltype',
446                                             'type': 'string'
447                                         },
448                                         {
449                                             'name': 'lkey',
450                                             'type': 'string'
451                                         },
452                                         {
453                                             'name': 'inlang',
454                                             'type': 'string'
455                                         },
456                                         {
457                                             'name': 'lval',
458                                             'type': 'string'
459                                         }
460                                     ]
461                                 }
462                             },
463                             toolbar : {
464                                 xtype: 'Toolbar',
465                                 xns: Roo,
466                                 items : [
467                                     {
468                                         xtype: 'ComboBox',
469                                         xns: Roo.form,
470                                         listeners : {
471                                             render : function (_self)
472                                             {
473                                               _this.langtypeCombo = _self;
474                                             },
475                                             select : function (combo, record, index)
476                                             {
477                                               _this.langgrid.getDataSource().reload(); 
478                                             }
479                                         },
480                                         displayField : 'lval',
481                                         editable : false,
482                                         emptyText : "Select Translation of",
483                                         mode : 'local',
484                                         selectOnFocus : true,
485                                         triggerAction : 'all',
486                                         typeAhead : false,
487                                         valueField : 'lkey',
488                                         width : 200,
489                                         store : {
490                                             xtype: 'SimpleStore',
491                                             xns: Roo.data,
492                                             data : [
493                                                [ 'l', 'Language Names' ],
494                                                [ 'c', 'Country Names' ],
495                                                 [ 'm', 'Currency Names' ]
496                                             ],
497                                             fields : ['lkey','lval']
498                                         }
499                                     },
500                                     {
501                                         xtype: 'ComboBox',
502                                         xns: Roo.form,
503                                         listeners : {
504                                             select : function (combo, record, index)
505                                             {
506                                               _this.langgrid.getDataSource().reload(); 
507                                             },
508                                             render : function (_self)
509                                             {
510                                               _this.langgridCombo=_self;
511                                             }
512                                         },
513                                         displayField : 'ldisp',
514                                         editable : false,
515                                         emptyText : "Select Language",
516                                         mode : 'local',
517                                         selectOnFocus : true,
518                                         triggerAction : 'all',
519                                         typeAhead : false,
520                                         valueField : 'lang',
521                                         width : 200,
522                                         store : {
523                                             xtype: 'SimpleStore',
524                                             xns: Roo.data,
525                                             fields : ['lang', 'ldisp'],
526                                             data : [                                                [ 'zh_HK' , '\u7E41\u4E2D - Trad. Chin. (HK)' ],                         [ 'zh_CN', '\u7C21\u4E2D - Simp. Chin.' ]                     ]
527                                         }
528                                     }
529                                 ]
530                             },
531                             colModel : [
532                                 {
533                                     xtype: 'ColumnModel',
534                                     xns: Roo.grid,
535                                     dataIndex : 'lkey',
536                                     header : 'Code',
537                                     width : 50,
538                                     renderer : function(v) { return String.format('{0}', v); }
539                                 },
540                                 {
541                                     xtype: 'ColumnModel',
542                                     xns: Roo.grid,
543                                     dataIndex : 'lval_en',
544                                     header : 'English',
545                                     width : 150,
546                                     renderer : function(v) { return String.format('{0}', v); }
547                                 },
548                                 {
549                                     xtype: 'ColumnModel',
550                                     xns: Roo.grid,
551                                     dataIndex : 'lval',
552                                     header : 'Translation',
553                                     width : 200,
554                                     renderer : function(v) { return String.format('{0}', v); },
555                                     editor : {
556                                         xtype: 'GridEditor',
557                                         xns: Roo.grid,
558                                         field : {
559                                             xtype: 'TextField',
560                                             xns: Roo.form
561                                         }
562                                     }
563                                 }
564                             ]
565                         }
566                     }
567                 ],
568                 center : {
569                     xtype: 'LayoutRegion',
570                     xns: Roo,
571                     alwaysShowTabs : true,
572                     tabPosition : 'top'
573                 }
574             }
575         };
576     }
577 });