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                                                 Roo.MessageBox.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                                     rec = this.ds.getAt(rowIndex);
141                                     
142                                       var g = _this.grid;
143                                 
144                                         //g.getView().el.mask('Saving');
145                                         new Roo.Request({
146                                             url : baseURL + '/Admin/Translations.php',
147                                             method: 'POST',
148                                             params : {
149                                                 id : rec.get('id'),
150                                                 txt : '',
151                                                 lang :  _this.langCombo.getValue(),
152                                                 module :  _this.modCombo.getValue()
153                                             },
154                                             success : function()
155                                             {
156                                                 //g.getView().el.unmask();
157                                                 //g.getDataSource().reload();
158                                             },
159                                             failure : function()
160                                             {
161                                                 Roo.MessageBox.alert("Error", "There was a problem saving the data - try reloading");
162                                                // g.getView().el.unmask();
163                                             }
164                                             
165                                     });
166                                        
167                                     
168                                 }
169                             },
170                             autoExpandColumn : 'txt',
171                             clicksToEdit : 1,
172                             loadMask : true,
173                             dataSource : {
174                                 xtype: 'Store',
175                                 xns: Roo.data,
176                                 listeners : {
177                                     beforeload : function (_self, opts)
178                                     {
179                                     
180                                                             if (!_this.langCombo || !_this.langCombo.getValue().length) {
181                                                                 return false;
182                                                             }
183                                                             if (!_this.modCombo || !_this.modCombo.getValue().length) {
184                                                                 return false;
185                                                             }
186                                                             opts.params = {
187                                                                 lang :  _this.langCombo.getValue(),
188                                                                 module :  _this.modCombo.getValue()
189                                                             };
190                                     },
191                                     loadexception : function (self, ret, load, jsonData)
192                                     {
193                                         Roo.MessageBox.alert("Error", jsonData);
194                                     }
195                                 },
196                                 reader : Pman.Readers.Category,
197                                 proxy : {
198                                     xtype: 'HttpProxy',
199                                     xns: Roo.data,
200                                     method : 'GET',
201                                     url : baseURL + '/Admin/Translations.php'
202                                 },
203                                 reader : {
204                                     xtype: 'JsonReader',
205                                     xns: Roo.data,
206                                     root : 'data',
207                                     totalProperty : 'total',
208                                     id : 'id',
209                                     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'                  ]
210                                 }
211                             },
212                             toolbar : {
213                                 xtype: 'Toolbar',
214                                 xns: Roo,
215                                 items : [
216                                     {
217                                         xtype: 'ComboBox',
218                                         xns: Roo.form,
219                                         listeners : {
220                                             render : function (_self)
221                                             {
222                                               _this.modCombo = _self;
223                                             },
224                                             select : function (combo, record, index)
225                                             {
226                                               _this.grid.getDataSource().reload(); 
227                                             }
228                                         },
229                                         valueField : 'module',
230                                         displayField : 'module',
231                                         width : 200,
232                                         typeAhead : false,
233                                         editable : false,
234                                         mode : 'local',
235                                         triggerAction : 'all',
236                                         emptyText : "Select Module",
237                                         selectOnFocus : true,
238                                         store : {
239                                             xtype: 'SimpleStore',
240                                             xns: Roo.data,
241                                             data : (function() {             
242                                                     var modlist = [];             
243                                                     AppModules = typeof(AppModules) == 'undefined' ? '' : AppModules;
244                                                     Roo.each( AppModules.split(','), function(mod) {            
245                                                              modlist.push( [ mod ] );            
246                                                   });             
247                                                   return modlist;
248                                                })(),
249                                             fields : ['module']
250                                         }
251                                     },
252                                     {
253                                         xtype: 'ComboBox',
254                                         xns: Roo.form,
255                                         listeners : {
256                                             select : function (combo, record, index)
257                                             {
258                                               _this.grid.getDataSource().reload(); 
259                                             },
260                                             render : function (_self)
261                                             {
262                                               _this.langCombo=_self;
263                                             }
264                                         },
265                                         valueField : 'lang',
266                                         displayField : 'ldisp',
267                                         width : 200,
268                                         typeAhead : false,
269                                         editable : false,
270                                         mode : 'local',
271                                         triggerAction : 'all',
272                                         emptyText : "Select Language",
273                                         selectOnFocus : true,
274                                         store : {
275                                             xtype: 'SimpleStore',
276                                             xns: Roo.data,
277                                             fields : ['lang', 'ldisp'],
278                                             data : [                                                [ 'zh_HK' , '\u7E41\u4E2D - Trad. Chin. (HK)' ],                         [ 'zh_CN', '\u7C21\u4E2D - Simp. Chin.' ]                     ]
279                                         }
280                                     }
281                                 ]
282                             },
283                             colModel : [
284                                 {
285                                     xtype: 'ColumnModel',
286                                     xns: Roo.grid,
287                                     header : 'Name',
288                                     width : 150,
289                                     dataIndex : 'colname',
290                                     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>';                                              }
291                                 },
292                                 {
293                                     xtype: 'ColumnModel',
294                                     xns: Roo.grid,
295                                     header : 'Original',
296                                     width : 300,
297                                     dataIndex : 'origtxt',
298                                     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>';                                              }
299                                 },
300                                 {
301                                     xtype: 'ColumnModel',
302                                     xns: Roo.grid,
303                                     dataIndex : 'reset_tx',
304                                     header : 'Reset',
305                                     width : 50,
306                                     renderer : function(v,x,r) {    
307                                         return  '<img src="' + rootURL + '/Pman/templates/images/edit-clear.gif' + '" width="16" height="16">';
308                                     }
309                                 },
310                                 {
311                                     xtype: 'ColumnModel',
312                                     xns: Roo.grid,
313                                     dataIndex : 'txt',
314                                     header : 'Translated (Click to Edit)',
315                                     width : 150,
316                                     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>';                     },
317                                     editor : {
318                                         xtype: 'GridEditor',
319                                         xns: Roo.grid,
320                                         field : {
321                                             xtype: 'TextField',
322                                             xns: Roo.form
323                                         }
324                                     }
325                                 }
326                             ]
327                         }
328                     },
329                     {
330                         xtype: 'GridPanel',
331                         xns: Roo,
332                         listeners : {
333                             activate : function() {
334                                 _this.langpanel = this;
335                                 if (_this.langgrid) {
336                                     _this.langgrid.ds.load({});
337                                 }
338                             }
339                         },
340                         background : true,
341                         fitContainer : true,
342                         fitToframe : true,
343                         region : 'center',
344                         tableName : 'i18n',
345                         title : "Languages and Countries",
346                         grid : {
347                             xtype: 'EditorGrid',
348                             xns: Roo.grid,
349                             listeners : {
350                                 render : function() 
351                                 {
352                                     _this.langgrid = this; 
353                                     //_this.dialog = Pman.Dialog.FILL_IN
354                                     if (_this.langpanel.active) {
355                                        this.ds.load({});
356                                     }
357                                 },
358                                 afteredit : function (e)
359                                 {
360                                     var saveRec  = function(rec)
361                                     {
362                                         var g = _this.grid;
363                                 
364                                         //g.getView().el.mask('Saving');
365                                         Ext.Ajax.request({
366                                             url : baseURL + '/Roo/I18n.php',
367                                             method: 'POST',
368                                             params : {
369                                                 id : rec.get('id'),
370                                                 lval : rec.get('lval')
371                                             },
372                                             success : function()
373                                             {
374                                                 //g.getView().el.unmask();
375                                                 //g.getDataSource().reload();
376                                             },
377                                             failure : function()
378                                             {
379                                                 Ext.Msg.alert("Error", "There was a problem saving the data - try reloading");
380                                                // g.getView().el.unmask();
381                                             }
382                                             
383                                     });
384                                         };
385                                     
386                                     saveRec.defer(1000, _this, [ e.record ]);
387                                 },
388                                 beforeedit : function(e) {
389                                     console.log('beforeedit');
390                                     //if (e.record.get('origtxt').indexOf('<') > -1) {
391                                                        // console.log("HTML EDITOR!!");
392                                              
393                                             //    return false;
394                                             //}
395                                             if (e.record.get('lval').replace(/\s+/, '').length) {
396                                                 return true;
397                                             }
398                                             
399                                             
400                                             var tl = _this.langgridCombo.getValue();
401                                           
402                                             tl = (tl == 'zh_HK') ? 'zh-TW' : tl; 
403                                             tl = tl.replace('_', '-');
404                                             var rec = e.record;
405                                             
406                                             
407                                             
408                                             Pman.gtranslate(e.record.get('lval_en'), 'en', tl, function(result) { 
409                                                 if (typeof(result) == 'object') { //error
410                                                     return; 
411                                                    }
412                                                 
413                                                 if (_this.grid.activeEditor) {
414                                                     _this.grid.activeEditor.setValue(result);
415                                                 } else {
416                                                     rec.set('lval',result);
417                                                     //_this.saveRec(rec);
418                                                 }
419                                 
420                                                 //
421                                                 
422                                                 
423                                                 //console.log(result.translation);
424                                             });
425                                             
426                                            
427                                             
428                                             return true;
429                                         }
430                             },
431                             autoExpandColumn : 'lval',
432                             clicksToEdit : 1,
433                             loadMask : true,
434                             dataSource : {
435                                 xtype: 'Store',
436                                 xns: Roo.data,
437                                 listeners : {
438                                     beforeload : function (_self, options)
439                                     {
440                                        options  =options ||  {};
441                                        options.params =options.params|| {};
442                                        options.params.ltype = _this.langtypeCombo.getValue();
443                                        options.params.inlang = _this.langgridCombo.getValue();
444                                        options.params['query[_with_en]'] = 1;
445                                        if (!options.params.ltype.length || !options.params.inlang.length) {
446                                            return false;
447                                        }
448                                        
449                                        options.params.limit = 9999;
450                                        
451                                     }
452                                 },
453                                 remoteSort : true,
454                                 sortInfo : { field : 'lkey', direction: 'ASC' },
455                                 proxy : {
456                                     xtype: 'HttpProxy',
457                                     xns: Roo.data,
458                                     method : 'GET',
459                                     url : baseURL + '/Roo/i18n.php'
460                                 },
461                                 reader : {
462                                     xtype: 'JsonReader',
463                                     xns: Roo.data,
464                                     totalProperty : 'total',
465                                     root : 'data',
466                                     id : 'id',
467                                     fields : [
468                                         {
469                                             'name': 'id',
470                                             'type': 'int'
471                                         },
472                                         {
473                                             'name': 'ltype',
474                                             'type': 'string'
475                                         },
476                                         {
477                                             'name': 'lkey',
478                                             'type': 'string'
479                                         },
480                                         {
481                                             'name': 'inlang',
482                                             'type': 'string'
483                                         },
484                                         {
485                                             'name': 'lval',
486                                             'type': 'string'
487                                         }
488                                     ]
489                                 }
490                             },
491                             toolbar : {
492                                 xtype: 'Toolbar',
493                                 xns: Roo,
494                                 items : [
495                                     {
496                                         xtype: 'ComboBox',
497                                         xns: Roo.form,
498                                         listeners : {
499                                             render : function (_self)
500                                             {
501                                               _this.langtypeCombo = _self;
502                                             },
503                                             select : function (combo, record, index)
504                                             {
505                                               _this.langgrid.getDataSource().reload(); 
506                                             }
507                                         },
508                                         displayField : 'lval',
509                                         editable : false,
510                                         emptyText : "Select Translation of",
511                                         mode : 'local',
512                                         selectOnFocus : true,
513                                         triggerAction : 'all',
514                                         typeAhead : false,
515                                         valueField : 'lkey',
516                                         width : 200,
517                                         store : {
518                                             xtype: 'SimpleStore',
519                                             xns: Roo.data,
520                                             data : [
521                                                [ 'l', 'Language Names' ],
522                                                [ 'c', 'Country Names' ],
523                                                 [ 'm', 'Currency Names' ]
524                                             ],
525                                             fields : ['lkey','lval']
526                                         }
527                                     },
528                                     {
529                                         xtype: 'ComboBox',
530                                         xns: Roo.form,
531                                         listeners : {
532                                             select : function (combo, record, index)
533                                             {
534                                               _this.langgrid.getDataSource().reload(); 
535                                             },
536                                             render : function (_self)
537                                             {
538                                               _this.langgridCombo=_self;
539                                             }
540                                         },
541                                         displayField : 'ldisp',
542                                         editable : false,
543                                         emptyText : "Select Language",
544                                         mode : 'local',
545                                         selectOnFocus : true,
546                                         triggerAction : 'all',
547                                         typeAhead : false,
548                                         valueField : 'lang',
549                                         width : 200,
550                                         store : {
551                                             xtype: 'SimpleStore',
552                                             xns: Roo.data,
553                                             fields : ['lang', 'ldisp'],
554                                             data : [                                                [ 'zh_HK' , '\u7E41\u4E2D - Trad. Chin. (HK)' ],                         [ 'zh_CN', '\u7C21\u4E2D - Simp. Chin.' ]                     ]
555                                         }
556                                     }
557                                 ]
558                             },
559                             colModel : [
560                                 {
561                                     xtype: 'ColumnModel',
562                                     xns: Roo.grid,
563                                     dataIndex : 'lkey',
564                                     header : 'Code',
565                                     width : 50,
566                                     renderer : function(v) { return String.format('{0}', v); }
567                                 },
568                                 {
569                                     xtype: 'ColumnModel',
570                                     xns: Roo.grid,
571                                     dataIndex : 'lval_en',
572                                     header : 'English',
573                                     width : 150,
574                                     renderer : function(v) { return String.format('{0}', v); }
575                                 },
576                                 {
577                                     xtype: 'ColumnModel',
578                                     xns: Roo.grid,
579                                     dataIndex : 'lval',
580                                     header : 'Translation',
581                                     width : 200,
582                                     renderer : function(v) { return String.format('{0}', v); },
583                                     editor : {
584                                         xtype: 'GridEditor',
585                                         xns: Roo.grid,
586                                         field : {
587                                             xtype: 'TextField',
588                                             xns: Roo.form
589                                         }
590                                     }
591                                 }
592                             ]
593                         }
594                     }
595                 ],
596                 center : {
597                     xtype: 'LayoutRegion',
598                     xns: Roo,
599                     alwaysShowTabs : true,
600                     tabPosition : 'top'
601                 }
602             }
603         };
604     }
605 });