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