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                                             
368                                             
369                                             Pman.gtranslate(e.record.get('lval_en'), 'en', tl, function(result) { 
370                                                 if (typeof(result) == 'object') { //error
371                                                     return; 
372                                                    }
373                                                 
374                                                 if (_this.grid.activeEditor) {
375                                                     _this.grid.activeEditor.setValue(result);
376                                                 } else {
377                                                     rec.set('lval',result);
378                                                     //_this.saveRec(rec);
379                                                 }
380                                 
381                                                 //
382                                                 
383                                                 
384                                                 //console.log(result.translation);
385                                             });
386                                             
387                                            
388                                             
389                                             return true;
390                                         }
391                             },
392                             autoExpandColumn : 'lval',
393                             clicksToEdit : 1,
394                             loadMask : true,
395                             dataSource : {
396                                 xtype: 'Store',
397                                 xns: Roo.data,
398                                 listeners : {
399                                     beforeload : function (_self, options)
400                                     {
401                                        options  =options ||  {};
402                                        options.params =options.params|| {};
403                                        options.params.ltype = _this.langtypeCombo.getValue();
404                                        options.params.inlang = _this.langgridCombo.getValue();
405                                        options.params['query[_with_en]'] = 1;
406                                        if (!options.params.ltype.length || !options.params.inlang.length) {
407                                            return false;
408                                        }
409                                        
410                                        options.params.limit = 9999;
411                                        
412                                     }
413                                 },
414                                 remoteSort : true,
415                                 sortInfo : { field : 'lkey', direction: 'ASC' },
416                                 proxy : {
417                                     xtype: 'HttpProxy',
418                                     xns: Roo.data,
419                                     method : 'GET',
420                                     url : baseURL + '/Roo/i18n.php'
421                                 },
422                                 reader : {
423                                     xtype: 'JsonReader',
424                                     xns: Roo.data,
425                                     totalProperty : 'total',
426                                     root : 'data',
427                                     id : 'id',
428                                     fields : [
429                                         {
430                                             'name': 'id',
431                                             'type': 'int'
432                                         },
433                                         {
434                                             'name': 'ltype',
435                                             'type': 'string'
436                                         },
437                                         {
438                                             'name': 'lkey',
439                                             'type': 'string'
440                                         },
441                                         {
442                                             'name': 'inlang',
443                                             'type': 'string'
444                                         },
445                                         {
446                                             'name': 'lval',
447                                             'type': 'string'
448                                         }
449                                     ]
450                                 }
451                             },
452                             toolbar : {
453                                 xtype: 'Toolbar',
454                                 xns: Roo,
455                                 items : [
456                                     {
457                                         xtype: 'ComboBox',
458                                         xns: Roo.form,
459                                         listeners : {
460                                             render : function (_self)
461                                             {
462                                               _this.langtypeCombo = _self;
463                                             },
464                                             select : function (combo, record, index)
465                                             {
466                                               _this.langgrid.getDataSource().reload(); 
467                                             }
468                                         },
469                                         displayField : 'lval',
470                                         editable : false,
471                                         emptyText : "Select Translation of",
472                                         mode : 'local',
473                                         selectOnFocus : true,
474                                         triggerAction : 'all',
475                                         typeAhead : false,
476                                         valueField : 'lkey',
477                                         width : 200,
478                                         store : {
479                                             xtype: 'SimpleStore',
480                                             xns: Roo.data,
481                                             data : [
482                                                [ 'l', 'Language Names' ],
483                                                [ 'c', 'Country Names' ],
484                                                 [ 'm', 'Currency Names' ]
485                                             ],
486                                             fields : ['lkey','lval']
487                                         }
488                                     },
489                                     {
490                                         xtype: 'ComboBox',
491                                         xns: Roo.form,
492                                         listeners : {
493                                             select : function (combo, record, index)
494                                             {
495                                               _this.langgrid.getDataSource().reload(); 
496                                             },
497                                             render : function (_self)
498                                             {
499                                               _this.langgridCombo=_self;
500                                             }
501                                         },
502                                         displayField : 'ldisp',
503                                         editable : false,
504                                         emptyText : "Select Language",
505                                         mode : 'local',
506                                         selectOnFocus : true,
507                                         triggerAction : 'all',
508                                         typeAhead : false,
509                                         valueField : 'lang',
510                                         width : 200,
511                                         store : {
512                                             xtype: 'SimpleStore',
513                                             xns: Roo.data,
514                                             fields : ['lang', 'ldisp'],
515                                             data : [                                                [ 'zh_HK' , '\u7E41\u4E2D - Trad. Chin. (HK)' ],                         [ 'zh_CN', '\u7C21\u4E2D - Simp. Chin.' ]                     ]
516                                         }
517                                     }
518                                 ]
519                             },
520                             colModel : [
521                                 {
522                                     xtype: 'ColumnModel',
523                                     xns: Roo.grid,
524                                     dataIndex : 'lkey',
525                                     header : 'Code',
526                                     width : 50,
527                                     renderer : function(v) { return String.format('{0}', v); }
528                                 },
529                                 {
530                                     xtype: 'ColumnModel',
531                                     xns: Roo.grid,
532                                     dataIndex : 'lval_en',
533                                     header : 'English',
534                                     width : 150,
535                                     renderer : function(v) { return String.format('{0}', v); }
536                                 },
537                                 {
538                                     xtype: 'ColumnModel',
539                                     xns: Roo.grid,
540                                     dataIndex : 'lval',
541                                     header : 'Translation',
542                                     width : 200,
543                                     renderer : function(v) { return String.format('{0}', v); },
544                                     editor : {
545                                         xtype: 'GridEditor',
546                                         xns: Roo.grid,
547                                         field : {
548                                             xtype: 'TextField',
549                                             xns: Roo.form
550                                         }
551                                     }
552                                 }
553                             ]
554                         }
555                     }
556                 ],
557                 center : {
558                     xtype: 'LayoutRegion',
559                     xns: Roo,
560                     alwaysShowTabs : true,
561                     tabPosition : 'top'
562                 }
563             }
564         });
565         this.layout = this.panel.layout;
566
567     }
568 });