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