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