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: '' 
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: 'GridPanel',
35             xns: Roo,
36             listeners : {
37                 activate : function() {
38                     _this.panel = this;
39                     if (_this.grid) {
40                        _this.grid.getDataSource().reload(); 
41                     }
42                 }
43             },
44             background : true,
45             fitContainer : true,
46             fitToframe : true,
47             region : 'center',
48             title : "Translate App",
49             grid : {
50                 xtype: 'EditorGrid',
51                 xns: Roo.grid,
52                 autoExpandColumn : 'txt',
53                 loadMask : true,
54                 listeners : {
55                     render : function() { 
56                         _this.grid = this; 
57                         //_this.dialog = Pman.Dialog.FILL_IN
58                         if (_this.panel.active) {
59                           _this.grid.getDataSource().reload(); 
60                         }
61                     },
62                     beforeedit : function(e) {
63                         console.log('beforeedit');
64                         //if (e.record.get('origtxt').indexOf('<') > -1) {
65                                            // console.log("HTML EDITOR!!");
66                                          
67                                         //    return false;
68                                         //}
69                                         if (e.record.get('txt').replace(/\s+/, '').length) {
70                                             return true;
71                                         }
72                                         if (e.record.get('suggest').length) {
73                                             e.record.set('txt', e.record.get('suggest'));
74                                         //    _this.saveRec(e.record);
75                                             return;
76                                         }
77                                         
78                                         
79                                         
80                                        
81                                         var tl = e.record.get('id').split('/')[0];
82                                       
83                                         tl = (tl == 'zh_HK') ? 'zh-TW' : tl; 
84                                         tl = tl.replace('_', '-');
85                                         var rec = e.record;
86                                         
87                                         
88                                         
89                                         Pman.gtranslate(e.record.get('origtxt'), 'en', tl, function(result) { 
90                                             if (typeof(result) == 'object') { //error
91                                                 return; 
92                                                }
93                                             
94                                             if (_this.grid.activeEditor) {
95                                                 _this.grid.activeEditor.setValue(result);
96                                             } else {
97                                                 rec.set('txt',result);
98                                                 //_this.saveRec(rec);
99                                             }
100                     
101                                             //
102                                             
103                                             
104                                             //console.log(result.translation);
105                                         });
106                                         
107                                        
108                                         
109                                         return true;
110                                     },
111                     afteredit : function (e)
112                     {
113                         var saveRec  = function(rec)
114                         {
115                             var g = _this.grid;
116                     
117                             //g.getView().el.mask('Saving');
118                             Ext.Ajax.request({
119                                 url : baseURL + '/Admin/Translations.php',
120                                 method: 'POST',
121                                 params : {
122                                     id : rec.get('id'),
123                                     txt : rec.get('txt'),
124                                     lang :  _this.langCombo.getValue(),
125                                     module :  _this.modCombo.getValue()
126                                 },
127                                 success : function()
128                                 {
129                                     //g.getView().el.unmask();
130                                     //g.getDataSource().reload();
131                                 },
132                                 failure : function()
133                                 {
134                                     Ext.Msg.alert("Error", "There was a problem saving the data - try reloading");
135                                    // g.getView().el.unmask();
136                                 }
137                                 
138                         });
139                             };
140                         
141                         saveRec.defer(1000, _this, [ e.record ]);
142                     }
143                 },
144                 clicksToEdit : 1,
145                 dataSource : {
146                     xtype: 'Store',
147                     xns: Roo.data,
148                     reader : Pman.Readers.Category,
149                     listeners : {
150                         beforeload : function (_self, opts)
151                         {
152                         
153                                                 if (!_this.langCombo || !_this.langCombo.getValue().length) {
154                                                     return false;
155                                                 }
156                                                 if (!_this.modCombo || !_this.modCombo.getValue().length) {
157                                                     return false;
158                                                 }
159                                                 opts.params = {
160                                                     lang :  _this.langCombo.getValue(),
161                                                     module :  _this.modCombo.getValue()
162                                                 };
163                         }
164                     },
165                     proxy : {
166                         xtype: 'HttpProxy',
167                         xns: Roo.data,
168                         method : 'GET',
169                         url : baseURL + '/Admin/Translations.php'
170                     },
171                     reader : {
172                         xtype: 'JsonReader',
173                         xns: Roo.data,
174                         root : 'data',
175                         totalProperty : 'total',
176                         id : 'id',
177                         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'                  ]
178                     }
179                 },
180                 toolbar : {
181                     xtype: 'Toolbar',
182                     xns: Roo,
183                     items : [
184                         {
185                             xtype: 'ComboBox',
186                             xns: Roo.form,
187                             listeners : {
188                                 render : function (_self)
189                                 {
190                                   _this.modCombo = _self;
191                                 },
192                                 select : function (combo, record, index)
193                                 {
194                                   _this.grid.getDataSource().reload(); 
195                                 }
196                             },
197                             valueField : 'module',
198                             displayField : 'module',
199                             width : 200,
200                             typeAhead : false,
201                             editable : false,
202                             mode : 'local',
203                             triggerAction : 'all',
204                             emptyText : "Select Module",
205                             selectOnFocus : true,
206                             store : {
207                                 xtype: 'SimpleStore',
208                                 xns: Roo.data,
209                                 fields : ['module'],
210                                 data : (function() {             var modlist = [];             Roo.each( AppModules.split(','), function(mod) {            
211                                          modlist.push( [ mod ] );             });             return modlist;         })()
212                             }
213                         },
214                         {
215                             xtype: 'ComboBox',
216                             xns: Roo.form,
217                             listeners : {
218                                 select : function (combo, record, index)
219                                 {
220                                   _this.grid.getDataSource().reload(); 
221                                 },
222                                 render : function (_self)
223                                 {
224                                   _this.langCombo=_self;
225                                 }
226                             },
227                             valueField : 'lang',
228                             displayField : 'ldisp',
229                             width : 200,
230                             typeAhead : false,
231                             editable : false,
232                             mode : 'local',
233                             triggerAction : 'all',
234                             emptyText : "Select Language",
235                             selectOnFocus : true,
236                             store : {
237                                 xtype: 'SimpleStore',
238                                 xns: Roo.data,
239                                 fields : ['lang', 'ldisp'],
240                                 data : [                                                [ 'zh_HK' , '\u7E41\u4E2D - Trad. Chin. (HK)' ],                         [ 'zh_CN', '\u7C21\u4E2D - Simp. Chin.' ]                     ]
241                             }
242                         }
243                     ]
244                 },
245                 colModel : [
246                     {
247                         xtype: 'ColumnModel',
248                         xns: Roo.grid,
249                         header : 'Name',
250                         width : 150,
251                         dataIndex : 'colname',
252                         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>';                                              }
253                     },
254                     {
255                         xtype: 'ColumnModel',
256                         xns: Roo.grid,
257                         header : 'Original',
258                         width : 300,
259                         dataIndex : 'origtxt',
260                         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>';                                              }
261                     },
262                     {
263                         xtype: 'ColumnModel',
264                         xns: Roo.grid,
265                         header : 'Translated (Click to Edit)',
266                         width : 150,
267                         dataIndex : 'txt',
268                         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>';                     },
269                         editor : {
270                             xtype: 'GridEditor',
271                             xns: Roo.grid,
272                             field : {
273                                 xtype: 'TextField',
274                                 xns: Roo.form
275                             }
276                         }
277                     }
278                 ]
279             }
280         });
281         this.layout = this.panel.layout;
282
283     }
284 });