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                                         xtype: 'Spacer',
283                                         xns: Roo.Toolbar
284                                     }
285                                 ]
286                             },
287                             colModel : [
288                                 {
289                                     xtype: 'ColumnModel',
290                                     xns: Roo.grid,
291                                     header : 'Name',
292                                     width : 150,
293                                     dataIndex : 'colname',
294                                     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>';                                              }
295                                 },
296                                 {
297                                     xtype: 'ColumnModel',
298                                     xns: Roo.grid,
299                                     header : 'Original',
300                                     width : 300,
301                                     dataIndex : 'origtxt',
302                                     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>';                                              }
303                                 },
304                                 {
305                                     xtype: 'ColumnModel',
306                                     xns: Roo.grid,
307                                     dataIndex : 'reset_tx',
308                                     header : 'Reset',
309                                     width : 50,
310                                     renderer : function(v,x,r) {    
311                                         return  '<img src="' + rootURL + '/Pman/templates/images/edit-clear.gif' + '" width="16" height="16">';
312                                     }
313                                 },
314                                 {
315                                     xtype: 'ColumnModel',
316                                     xns: Roo.grid,
317                                     dataIndex : 'txt',
318                                     header : 'Translated (Click to Edit)',
319                                     width : 150,
320                                     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>';                     },
321                                     editor : {
322                                         xtype: 'GridEditor',
323                                         xns: Roo.grid,
324                                         field : {
325                                             xtype: 'TextField',
326                                             xns: Roo.form
327                                         }
328                                     }
329                                 }
330                             ]
331                         }
332                     },
333                     {
334                         xtype: 'GridPanel',
335                         xns: Roo,
336                         listeners : {
337                             activate : function() {
338                                 _this.langpanel = this;
339                                 if (_this.langgrid) {
340                                     _this.langgrid.ds.load({});
341                                 }
342                             }
343                         },
344                         background : true,
345                         fitContainer : true,
346                         fitToframe : true,
347                         region : 'center',
348                         tableName : 'i18n',
349                         title : "Languages and Countries",
350                         grid : {
351                             xtype: 'EditorGrid',
352                             xns: Roo.grid,
353                             listeners : {
354                                 render : function() 
355                                 {
356                                     _this.langgrid = this; 
357                                     //_this.dialog = Pman.Dialog.FILL_IN
358                                     if (_this.langpanel.active) {
359                                        this.ds.load({});
360                                     }
361                                 },
362                                 afteredit : function (e)
363                                 {
364                                     var saveRec  = function(rec)
365                                     {
366                                         var g = _this.grid;
367                                 
368                                         //g.getView().el.mask('Saving');
369                                         Ext.Ajax.request({
370                                             url : baseURL + '/Roo/I18n.php',
371                                             method: 'POST',
372                                             params : {
373                                                 id : rec.get('id'),
374                                                 lval : rec.get('lval')
375                                             },
376                                             success : function()
377                                             {
378                                                 //g.getView().el.unmask();
379                                                 //g.getDataSource().reload();
380                                             },
381                                             failure : function()
382                                             {
383                                                 Ext.Msg.alert("Error", "There was a problem saving the data - try reloading");
384                                                // g.getView().el.unmask();
385                                             }
386                                             
387                                     });
388                                         };
389                                     
390                                     saveRec.defer(1000, _this, [ e.record ]);
391                                 },
392                                 beforeedit : function(e) {
393                                     console.log('beforeedit');
394                                     //if (e.record.get('origtxt').indexOf('<') > -1) {
395                                                        // console.log("HTML EDITOR!!");
396                                              
397                                             //    return false;
398                                             //}
399                                             if (e.record.get('lval').replace(/\s+/, '').length) {
400                                                 return true;
401                                             }
402                                             
403                                             
404                                             var tl = _this.langgridCombo.getValue();
405                                           
406                                             tl = (tl == 'zh_HK') ? 'zh-TW' : tl; 
407                                             tl = tl.replace('_', '-');
408                                             var rec = e.record;
409                                             
410                                             
411                                             
412                                             Pman.gtranslate(e.record.get('lval_en'), 'en', tl, function(result) { 
413                                                 if (typeof(result) == 'object') { //error
414                                                     return; 
415                                                    }
416                                                 
417                                                 if (_this.grid.activeEditor) {
418                                                     _this.grid.activeEditor.setValue(result);
419                                                 } else {
420                                                     rec.set('lval',result);
421                                                     //_this.saveRec(rec);
422                                                 }
423                                 
424                                                 //
425                                                 
426                                                 
427                                                 //console.log(result.translation);
428                                             });
429                                             
430                                            
431                                             
432                                             return true;
433                                         }
434                             },
435                             autoExpandColumn : 'lval',
436                             clicksToEdit : 1,
437                             loadMask : true,
438                             dataSource : {
439                                 xtype: 'Store',
440                                 xns: Roo.data,
441                                 listeners : {
442                                     beforeload : function (_self, options)
443                                     {
444                                        options  =options ||  {};
445                                        options.params =options.params|| {};
446                                        options.params.ltype = _this.langtypeCombo.getValue();
447                                        options.params.inlang = _this.langgridCombo.getValue();
448                                        options.params['query[_with_en]'] = 1;
449                                        if (!options.params.ltype.length || !options.params.inlang.length) {
450                                            return false;
451                                        }
452                                        
453                                        options.params.limit = 9999;
454                                        
455                                     }
456                                 },
457                                 remoteSort : true,
458                                 sortInfo : { field : 'lkey', direction: 'ASC' },
459                                 proxy : {
460                                     xtype: 'HttpProxy',
461                                     xns: Roo.data,
462                                     method : 'GET',
463                                     url : baseURL + '/Roo/i18n.php'
464                                 },
465                                 reader : {
466                                     xtype: 'JsonReader',
467                                     xns: Roo.data,
468                                     totalProperty : 'total',
469                                     root : 'data',
470                                     id : 'id',
471                                     fields : [
472                                         {
473                                             'name': 'id',
474                                             'type': 'int'
475                                         },
476                                         {
477                                             'name': 'ltype',
478                                             'type': 'string'
479                                         },
480                                         {
481                                             'name': 'lkey',
482                                             'type': 'string'
483                                         },
484                                         {
485                                             'name': 'inlang',
486                                             'type': 'string'
487                                         },
488                                         {
489                                             'name': 'lval',
490                                             'type': 'string'
491                                         }
492                                     ]
493                                 }
494                             },
495                             toolbar : {
496                                 xtype: 'Toolbar',
497                                 xns: Roo,
498                                 items : [
499                                     {
500                                         xtype: 'ComboBox',
501                                         xns: Roo.form,
502                                         listeners : {
503                                             render : function (_self)
504                                             {
505                                               _this.langtypeCombo = _self;
506                                             },
507                                             select : function (combo, record, index)
508                                             {
509                                               _this.langgrid.getDataSource().reload(); 
510                                             }
511                                         },
512                                         displayField : 'lval',
513                                         editable : false,
514                                         emptyText : "Select Translation of",
515                                         mode : 'local',
516                                         selectOnFocus : true,
517                                         triggerAction : 'all',
518                                         typeAhead : false,
519                                         valueField : 'lkey',
520                                         width : 200,
521                                         store : {
522                                             xtype: 'SimpleStore',
523                                             xns: Roo.data,
524                                             data : [
525                                                [ 'l', 'Language Names' ],
526                                                [ 'c', 'Country Names' ],
527                                                 [ 'm', 'Currency Names' ]
528                                             ],
529                                             fields : ['lkey','lval']
530                                         }
531                                     },
532                                     {
533                                         xtype: 'ComboBox',
534                                         xns: Roo.form,
535                                         listeners : {
536                                             select : function (combo, record, index)
537                                             {
538                                               _this.langgrid.getDataSource().reload(); 
539                                             },
540                                             render : function (_self)
541                                             {
542                                               _this.langgridCombo=_self;
543                                             }
544                                         },
545                                         displayField : 'ldisp',
546                                         editable : false,
547                                         emptyText : "Select Language",
548                                         mode : 'local',
549                                         selectOnFocus : true,
550                                         triggerAction : 'all',
551                                         typeAhead : false,
552                                         valueField : 'lang',
553                                         width : 200,
554                                         store : {
555                                             xtype: 'SimpleStore',
556                                             xns: Roo.data,
557                                             fields : ['lang', 'ldisp'],
558                                             data : [                                                [ 'zh_HK' , '\u7E41\u4E2D - Trad. Chin. (HK)' ],                         [ 'zh_CN', '\u7C21\u4E2D - Simp. Chin.' ]                     ]
559                                         }
560                                     }
561                                 ]
562                             },
563                             colModel : [
564                                 {
565                                     xtype: 'ColumnModel',
566                                     xns: Roo.grid,
567                                     dataIndex : 'lkey',
568                                     header : 'Code',
569                                     width : 50,
570                                     renderer : function(v) { return String.format('{0}', v); }
571                                 },
572                                 {
573                                     xtype: 'ColumnModel',
574                                     xns: Roo.grid,
575                                     dataIndex : 'lval_en',
576                                     header : 'English',
577                                     width : 150,
578                                     renderer : function(v) { return String.format('{0}', v); }
579                                 },
580                                 {
581                                     xtype: 'ColumnModel',
582                                     xns: Roo.grid,
583                                     dataIndex : 'lval',
584                                     header : 'Translation',
585                                     width : 200,
586                                     renderer : function(v) { return String.format('{0}', v); },
587                                     editor : {
588                                         xtype: 'GridEditor',
589                                         xns: Roo.grid,
590                                         field : {
591                                             xtype: 'TextField',
592                                             xns: Roo.form
593                                         }
594                                     }
595                                 }
596                             ]
597                         }
598                     }
599                 ],
600                 center : {
601                     xtype: 'LayoutRegion',
602                     xns: Roo,
603                     alwaysShowTabs : true,
604                     tabPosition : 'top'
605                 }
606             }
607         };
608     }
609 });