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