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                             autoExpandColumn : 'txt',
62                             loadMask : true,
63                             listeners : {
64                                 render : function() { 
65                                     _this.grid = this; 
66                                     //_this.dialog = Pman.Dialog.FILL_IN
67                                     if (_this.panel.active) {
68                                       _this.grid.getDataSource().reload(); 
69                                     }
70                                 },
71                                 beforeedit : function(e) {
72                                     console.log('beforeedit');
73                                     //if (e.record.get('origtxt').indexOf('<') > -1) {
74                                                        // console.log("HTML EDITOR!!");
75                                                      
76                                                     //    return false;
77                                                     //}
78                                                     if (e.record.get('txt').replace(/\s+/, '').length) {
79                                                         return true;
80                                                     }
81                                                     if (e.record.get('suggest').length) {
82                                                         e.record.set('txt', e.record.get('suggest'));
83                                                     //    _this.saveRec(e.record);
84                                                         return;
85                                                     }
86                                                     
87                                                     
88                                                     
89                                                    
90                                                     var tl = e.record.get('id').split('/')[0];
91                                                   
92                                                     tl = (tl == 'zh_HK') ? 'zh-TW' : tl; 
93                                                     tl = tl.replace('_', '-');
94                                                     var rec = e.record;
95                                                     
96                                                     
97                                                     
98                                                     Pman.gtranslate(e.record.get('origtxt'), 'en', tl, function(result) { 
99                                                         if (typeof(result) == 'object') { //error
100                                                             return; 
101                                                            }
102                                                         
103                                                         if (_this.grid.activeEditor) {
104                                                             _this.grid.activeEditor.setValue(result);
105                                                         } else {
106                                                             rec.set('txt',result);
107                                                             //_this.saveRec(rec);
108                                                         }
109                                 
110                                                         //
111                                                         
112                                                         
113                                                         //console.log(result.translation);
114                                                     });
115                                                     
116                                                    
117                                                     
118                                                     return true;
119                                                 },
120                                 afteredit : function (e)
121                                 {
122                                     var saveRec  = function(rec)
123                                     {
124                                         var g = _this.grid;
125                                 
126                                         //g.getView().el.mask('Saving');
127                                         Ext.Ajax.request({
128                                             url : baseURL + '/Admin/Translations.php',
129                                             method: 'POST',
130                                             params : {
131                                                 id : rec.get('id'),
132                                                 txt : rec.get('txt'),
133                                                 lang :  _this.langCombo.getValue(),
134                                                 module :  _this.modCombo.getValue()
135                                             },
136                                             success : function()
137                                             {
138                                                 //g.getView().el.unmask();
139                                                 //g.getDataSource().reload();
140                                             },
141                                             failure : function()
142                                             {
143                                                 Ext.Msg.alert("Error", "There was a problem saving the data - try reloading");
144                                                // g.getView().el.unmask();
145                                             }
146                                             
147                                     });
148                                         };
149                                     
150                                     saveRec.defer(1000, _this, [ e.record ]);
151                                 }
152                             },
153                             clicksToEdit : 1,
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                                             fields : ['module'],
219                                             data : (function() {             var modlist = [];             Roo.each( AppModules.split(','), function(mod) {            
220                                                      modlist.push( [ mod ] );             });             return modlist;         })()
221                                         }
222                                     },
223                                     {
224                                         xtype: 'ComboBox',
225                                         xns: Roo.form,
226                                         listeners : {
227                                             select : function (combo, record, index)
228                                             {
229                                               _this.grid.getDataSource().reload(); 
230                                             },
231                                             render : function (_self)
232                                             {
233                                               _this.langCombo=_self;
234                                             }
235                                         },
236                                         valueField : 'lang',
237                                         displayField : 'ldisp',
238                                         width : 200,
239                                         typeAhead : false,
240                                         editable : false,
241                                         mode : 'local',
242                                         triggerAction : 'all',
243                                         emptyText : "Select Language",
244                                         selectOnFocus : true,
245                                         store : {
246                                             xtype: 'SimpleStore',
247                                             xns: Roo.data,
248                                             fields : ['lang', 'ldisp'],
249                                             data : [                                                [ 'zh_HK' , '\u7E41\u4E2D - Trad. Chin. (HK)' ],                         [ 'zh_CN', '\u7C21\u4E2D - Simp. Chin.' ]                     ]
250                                         }
251                                     }
252                                 ]
253                             },
254                             colModel : [
255                                 {
256                                     xtype: 'ColumnModel',
257                                     xns: Roo.grid,
258                                     header : 'Name',
259                                     width : 150,
260                                     dataIndex : 'colname',
261                                     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>';                                              }
262                                 },
263                                 {
264                                     xtype: 'ColumnModel',
265                                     xns: Roo.grid,
266                                     header : 'Original',
267                                     width : 300,
268                                     dataIndex : 'origtxt',
269                                     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>';                                              }
270                                 },
271                                 {
272                                     xtype: 'ColumnModel',
273                                     xns: Roo.grid,
274                                     header : 'Translated (Click to Edit)',
275                                     width : 150,
276                                     dataIndex : 'txt',
277                                     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>';                     },
278                                     editor : {
279                                         xtype: 'GridEditor',
280                                         xns: Roo.grid,
281                                         field : {
282                                             xtype: 'TextField',
283                                             xns: Roo.form
284                                         }
285                                     }
286                                 }
287                             ]
288                         }
289                     },
290                     {
291                         xtype: 'GridPanel',
292                         xns: Roo,
293                         listeners : {
294                             activate : function() {
295                                 _this.langpanel = this;
296                                 if (_this.langgrid) {
297                                     _this.langgrid.ds.load({});
298                                 }
299                             }
300                         },
301                         background : true,
302                         fitContainer : true,
303                         fitToframe : true,
304                         region : 'center',
305                         tableName : 'i18n',
306                         title : "i18n",
307                         grid : {
308                             xtype: 'Grid',
309                             xns: Roo.grid,
310                             listeners : {
311                                 render : function() 
312                                 {
313                                     _this.langgrid = this; 
314                                     //_this.dialog = Pman.Dialog.FILL_IN
315                                     if (_this.langpanel.active) {
316                                        this.ds.load({});
317                                     }
318                                 },
319                                 rowdblclick : function (_self, rowIndex, e)
320                                 {
321                                     if (!_this.dialog) return;
322                                     _this.dialog.show( this.getDataSource().getAt(rowIndex), function() {
323                                         _this.grid.footer.onClick('first');
324                                     }); 
325                                 }
326                             },
327                             autoExpandColumn : 'ltype',
328                             loadMask : true,
329                             dataSource : {
330                                 xtype: 'Store',
331                                 xns: Roo.data,
332                                 remoteSort : true,
333                                 sortInfo : { field : 'ltype', direction: 'ASC' },
334                                 proxy : {
335                                     xtype: 'HttpProxy',
336                                     xns: Roo.data,
337                                     method : 'GET',
338                                     url : baseURL + '/Roo/i18n.php'
339                                 },
340                                 reader : {
341                                     xtype: 'JsonReader',
342                                     xns: Roo.data,
343                                     totalProperty : 'total',
344                                     root : 'data',
345                                     id : 'id',
346                                     fields : [
347                                         {
348                                             'name': 'id',
349                                             'type': 'int'
350                                         },
351                                         {
352                                             'name': 'ltype',
353                                             'type': 'string'
354                                         },
355                                         {
356                                             'name': 'lkey',
357                                             'type': 'string'
358                                         },
359                                         {
360                                             'name': 'inlang',
361                                             'type': 'string'
362                                         },
363                                         {
364                                             'name': 'lval',
365                                             'type': 'string'
366                                         }
367                                     ]
368                                 }
369                             },
370                             footer : {
371                                 xtype: 'PagingToolbar',
372                                 xns: Roo,
373                                 pageSize : 25,
374                                 displayInfo : true,
375                                 displayMsg : "Displaying i18n{0} - {1} of {2}",
376                                 emptyMsg : "No i18n found"
377                             },
378                             toolbar : {
379                                 xtype: 'Toolbar',
380                                 xns: Roo,
381                                 items : [
382                                     {
383                                         xtype: 'Button',
384                                         xns: Roo.Toolbar,
385                                         text : "Add",
386                                         cls : 'x-btn-text-icon',
387                                         icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
388                                         listeners : {
389                                             click : function()
390                                             {
391                                                 if (!_this.dialog) return;
392                                                 _this.dialog.show( { id : 0 } , function() {
393                                                     _this.grid.footer.onClick('first');
394                                                }); 
395                                             }
396                                         }
397                                     },
398                                     {
399                                         xtype: 'Button',
400                                         xns: Roo.Toolbar,
401                                         text : "Edit",
402                                         cls : 'x-btn-text-icon',
403                                         icon : Roo.rootURL + 'images/default/tree/leaf.gif',
404                                         listeners : {
405                                             click : function()
406                                             {
407                                                 var s = _this.grid.getSelectionModel().getSelections();
408                                                 if (!s.length || (s.length > 1))  {
409                                                     Roo.MessageBox.alert("Error", s.length ? "Select only one Row" : "Select a Row");
410                                                     return;
411                                                 }
412                                                 if (!_this.dialog) return;
413                                                 _this.dialog.show(s[0].data, function() {
414                                                     _this.grid.footer.onClick('first');
415                                                 }); 
416                                                 
417                                             }
418                                         }
419                                     },
420                                     {
421                                         xtype: 'Button',
422                                         xns: Roo.Toolbar,
423                                         text : "Delete",
424                                         cls : 'x-btn-text-icon',
425                                         icon : rootURL + '/Pman/templates/images/trash.gif',
426                                         listeners : {
427                                             click : function()
428                                             {
429                                                  Pman.genericDelete(_this, 'i18n'); 
430                                             }
431                                         }
432                                     }
433                                 ]
434                             },
435                             colModel : [
436                                 {
437                                     xtype: 'ColumnModel',
438                                     xns: Roo.grid,
439                                     header : 'Id',
440                                     width : 75,
441                                     dataIndex : 'id',
442                                     renderer : function(v) { return String.format('{0}', v); }
443                                 },
444                                 {
445                                     xtype: 'ColumnModel',
446                                     xns: Roo.grid,
447                                     header : 'Ltype',
448                                     width : 200,
449                                     dataIndex : 'ltype',
450                                     renderer : function(v) { return String.format('{0}', v); }
451                                 },
452                                 {
453                                     xtype: 'ColumnModel',
454                                     xns: Roo.grid,
455                                     header : 'Lkey',
456                                     width : 200,
457                                     dataIndex : 'lkey',
458                                     renderer : function(v) { return String.format('{0}', v); }
459                                 },
460                                 {
461                                     xtype: 'ColumnModel',
462                                     xns: Roo.grid,
463                                     header : 'Inlang',
464                                     width : 200,
465                                     dataIndex : 'inlang',
466                                     renderer : function(v) { return String.format('{0}', v); }
467                                 },
468                                 {
469                                     xtype: 'ColumnModel',
470                                     xns: Roo.grid,
471                                     header : 'Lval',
472                                     width : 200,
473                                     dataIndex : 'lval',
474                                     renderer : function(v) { return String.format('{0}', v); }
475                                 }
476                             ]
477                         }
478                     }
479                 ],
480                 center : {
481                     xtype: 'LayoutRegion',
482                     xns: Roo,
483                     alwaysShowTabs : true,
484                     tabPosition : 'top'
485                 }
486             }
487         });
488         this.layout = this.panel.layout;
489
490     }
491 });