Pman.Tab.CmsTranslateTemplates.bjs
[Pman.Cms] / Pman.Tab.CmsTranslateTemplates.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Pman.Tab.CmsTranslateTemplates = new Roo.XComponent({
6     part     :  ["Cms","TranslateTemplates"],
7     order    : '800-Pman.Tab.CmsTranslateTemplates',
8     region   : 'center',
9     parent   : 'Pman.Tab.Cms',
10     name     : "Pman.Tab.CmsTranslateTemplates",
11     disabled : false, 
12     permname : '', 
13     _tree : function()
14     {
15         var _this = this;
16         var MODULE = this;
17         return {
18             xtype: 'NestedLayoutPanel',
19             xns: Roo,
20             region : 'center',
21             title : "Translate Templates",
22             layout : {
23                 xtype: 'BorderLayout',
24                 xns: Roo,
25                 items : [
26                     {
27                         xtype: 'TreePanel',
28                         xns: Roo,
29                         listeners : {
30                             render : function (_self)
31                             {
32                                 _this.treepanel = _self;
33                             }
34                         },
35                         region : 'west',
36                         toolbar : {
37                             xtype: 'Toolbar',
38                             xns: Roo,
39                             items : [
40                                 {
41                                     xtype: 'Button',
42                                     xns: Roo.Toolbar,
43                                     listeners : {
44                                         click : function (_self, e)
45                                         {
46                                             Pman.Dialog.CmsLanguagePick.show( {  }, function(lang) {
47                                                 
48                                                 new Pman.Request({
49                                                     url : baseURL + '/Roo/cms_templatestr',
50                                                     method : 'GET',
51                                                     params : {
52                                                        
53                                                         lang : lang
54                                                     }, 
55                                                     success : function()
56                                                     {
57                                         
58                                                         _this.treepanel.tree.getRootNode().reload();
59                                                     
60                                                     }
61                                                 });
62                                             
63                                             });
64                                             
65                                         }
66                                     },
67                                     text : "New"
68                                 },
69                                 {
70                                     xtype: 'Button',
71                                     xns: Roo.Toolbar,
72                                     listeners : {
73                                         click : function (_self, e)
74                                         {
75                                             var tree = _this.treepanel.tree;
76                                             var sn  = tree.getSelectionModel().getSelectedNode();
77                                             if (!sn || sn.id.split('/').length > 1) {
78                                                 Roo.MessageBox.alert("Error", "Select a language");
79                                                 return;
80                                             }
81                                             
82                                              Roo.MessageBox.confirm("Confirm", "Are sure you want to delete the language", function (v){
83                                                     if (v != 'yes') {
84                                                         return;
85                                                     }
86                                                     Roo.MessageBox.alert("Not yet", "not done yet");
87                                                     return;
88                                                     Roo.Ajax.request({
89                                                         url : baseURL + '/Roo/cms_language.php',
90                                                         method: 'POST',
91                                                         params : {
92                                                             _delete : _t.selectedNode.id 
93                                                         },
94                                                         success : function()
95                                                         {
96                                                            _this.treepanel.tree.getRootNode().reload();
97                                                             //g.getDataSource().reload();
98                                                         },
99                                                         failure : function()
100                                                         {
101                                                             Roo.MessageBox.alert("Error", 
102                                                                 "There was a problem saving the data - try reloading");
103                                                             
104                                                         }
105                                                         
106                                                     });
107                                                     
108                                                     
109                                                     
110                                                     
111                                                 });
112                                         }
113                                     },
114                                     text : "Delete"
115                                 },
116                                 {
117                                     xtype: 'Button',
118                                     xns: Roo.Toolbar,
119                                     listeners : {
120                                         click : function (_self, e)
121                                         {
122                                             _this.treepanel.tree.getRootNode().reload();
123                                             
124                                         }
125                                     },
126                                     text : "Reload"
127                                 }
128                             ]
129                         },
130                         tree : {
131                             xtype: 'TreePanel',
132                             xns: Roo.tree,
133                             containerScroll : false,
134                             rootVisible : true,
135                             loader : {
136                                 xtype: 'TreeLoader',
137                                 xns: Roo.tree,
138                                 listeners : {
139                                     beforeload : function (This, node, callback)
140                                     {
141                                         // set some params.
142                                         Roo.log(node);
143                                         this.baseParams._tree = 1;
144                                         
145                                         //this.baseParams.category = node.attributes.category;
146                                     },
147                                     loadexception : function (This, node, response)
148                                     {
149                                         Roo.MessageBox.alert("Error", "Problem loading tree");
150                                     }
151                                 },
152                                 requestMethod : 'GET',
153                                 baseParams : { _tree : 1 },
154                                 dataUrl : baseURL + '/Roo/cms_templatestr'
155                             },
156                             root : {
157                                 xtype: 'AsyncTreeNode',
158                                 xns: Roo.tree,
159                                 id : 'transtree',
160                                 text : "Translations"
161                             },
162                             selModel : {
163                                 xtype: 'DefaultSelectionModel',
164                                 xns: Roo.tree,
165                                 listeners : {
166                                     selectionchange : function (_self, node)
167                                     {
168                                         Roo.log(node);
169                                         
170                                         //if (node.id.split('/').length < 2) {
171                                         //    return;
172                                        // }
173                                         (function() {
174                                             _this.grid.ds.load({});
175                                         }).defer(100);
176                                         
177                                     }
178                                 }
179                             }
180                         }
181                     },
182                     {
183                         xtype: 'GridPanel',
184                         xns: Roo,
185                         listeners : {
186                             activate : function() {
187                                 _this.panel = this;
188                                 if (_this.grid) {
189                                     _this.grid.footer.onClick('first');
190                                 }
191                             }
192                         },
193                         background : false,
194                         fitContainer : true,
195                         fitToframe : true,
196                         region : 'center',
197                         tableName : 'Page',
198                         title : "Page",
199                         grid : {
200                             xtype: 'EditorGrid',
201                             xns: Roo.grid,
202                             listeners : {
203                                 render : function() 
204                                 {
205                                     _this.grid = this; 
206                                     //_this.dialog = Pman.Dialog.FILL_IN
207                                     //if (_this.panel.active) {
208                                       // this.ds.onc.onClick('first');
209                                     //}
210                                 },
211                                 rowdblclick : function (_self, rowIndex, e)
212                                 {
213                                     if (!_this.dialog) return;
214                                     _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {
215                                         _this.grid.footer.onClick('first');
216                                     }); 
217                                 },
218                                 beforeedit : function (e)
219                                 {
220                                     if (e.record.data.src_id_txt.indexOf('<') > -1) {
221                                        // console.log("HTML EDITOR!!");
222                                         Pman.Dialog.CmsTranslateEditor.show(e.record);
223                                         return false;
224                                     }
225                                     if (e.record.data.txt.replace(/\s+/, '').length) {
226                                         return true;
227                                     }
228                                     var tl = _this.treepanel.tree.getSelectionModel().getSelectedNode().parentNode.attributes.id;
229                                     // mapping?
230                                     tl = (tl == 'zh_HK') ? 'zh-TW' : tl;
231                                     
232                                     if (tl == 'en' && !e.value.length) {
233                                 
234                                         e.value =  e.record.data.src_id_txt;
235                                         e.record.set('txt', e.record.data.src_id_txt);
236                                         return true;
237                                     }    
238                                     Roo.log(tl);
239                                     Pman.GoogleTranslate(e.record.data.src_id_txt, "en", tl, function(result) {
240                                        // Roo.log(result);
241                                         _this.grid.activeEditor.setValue(result);
242                                         //console.log(result.translation);
243                                     });
244                                     
245                                 
246                                     
247                                     return true;
248                                 },
249                                 afteredit : function (e)
250                                 {
251                                     e.record.commit();
252                                 }
253                             },
254                             autoExpandColumn : 'txt',
255                             clicksToEdit : 1,
256                             loadMask : true,
257                             footer : {
258                                 xtype: 'PagingToolbar',
259                                 xns: Roo,
260                                 displayInfo : true,
261                                 pageSize : 25
262                             },
263                             dataSource : {
264                                 xtype: 'Store',
265                                 xns: Roo.data,
266                                 listeners : {
267                                     update : function (_self, rec, operation)
268                                     {
269                                         Roo.log(operation);
270                                         
271                                         if (operation != 'commit') {
272                                             return;
273                                         }
274                                         
275                                     
276                                         _this.grid.getView().el.mask("Saving");
277                                         new Pman.Request({
278                                             url : baseURL + '/Roo/cms_templatestr',
279                                             method: 'POST',
280                                             params : {
281                                                 id : rec.get('id'),
282                                                 txt : rec.get('txt')
283                                             },
284                                             success : function()
285                                             {
286                                                 _this.grid.getView().el.unmask();
287                                                     //g.getDataSource().reload();
288                                             },
289                                             failure : function()
290                                             {
291                                                 _this.grid.getView().el.unmask();
292                                                 Roo.MessageBox.alert("Error", "There was a problem saving the data - try reloading");
293                                              }
294                                                 
295                                         });
296                                         
297                                     },
298                                     beforeload : function (_self, o)
299                                     {
300                                        
301                                         var sn = _this.treepanel.tree.getSelectionModel().getSelectedNode();
302                                     
303                                         if (!sn) { // || (sn.id.split('/').length < 2)) {
304                                            
305                                             _this.grid.ds.removeAll();
306                                             return false;
307                                         }
308                                         Roo.log("load?");
309                                         var ar = sn.attributes.id * 1;//.split('/');
310                                         
311                                         o.params = o.params || {};
312                                         o.params.lang = sn.parentNode.attributes.id;
313                                         o.params.template_id = sn.attributes.id;
314                                         o.params.sort= 'src_id_txt';
315                                         o.params.dir = 'ASC';
316                                     }
317                                 },
318                                 remoteSort : true,
319                                 sortInfo : { field : 'shortname', direction: 'ASC' },
320                                 proxy : {
321                                     xtype: 'HttpProxy',
322                                     xns: Roo.data,
323                                     method : 'GET',
324                                     url : baseURL + '/Roo/cms_templatestr.php'
325                                 },
326                                 reader : {
327                                     xtype: 'JsonReader',
328                                     xns: Roo.data,
329                                     id : 'id',
330                                     root : 'data',
331                                     totalProperty : 'total',
332                                     fields : [
333                                         {
334                                             'name': 'id',
335                                             'type': 'int'
336                                         },
337                                         {
338                                             'name': 'shortname',
339                                             'type': 'string'
340                                         },
341                                        
342                                     ]
343                                 }
344                             },
345                             colModel : [
346                                 {
347                                     xtype: 'ColumnModel',
348                                     xns: Roo.grid,
349                                     dataIndex : 'src_id_txt',
350                                     header : 'Original',
351                                     width : 200,
352                                     renderer : function(v,x,r) { 
353                                     
354                                      var c = '#666';
355                                             if (r.data.updated  < r.data.src_id_origupdated) {
356                                                 c = 'red';
357                                             }
358                                             
359                                     //        return '<div style="color:'+c+'";>' +r.data.tableid + ':' + v + '</div>';
360                                             return String.format('<div style="color:'+c+'";>{0}</div>', v)
361                                     
362                                     }
363                                 },
364                                 {
365                                     xtype: 'ColumnModel',
366                                     xns: Roo.grid,
367                                     dataIndex : 'txt',
368                                     header : 'Translation',
369                                     width : 200,
370                                     renderer : function(v,x,r) { 
371                                     
372                                      var c = '#666';
373                                             if (r.data.updated  < r.data.src_id_updated) {
374                                                 c = 'red';
375                                             }
376                                             
377                                     //        return '<div style="color:'+c+'";>' +r.data.tableid + ':' + v + '</div>';
378                                             return String.format('<div style="color:'+c+'";>{0}</div>', v)
379                                     
380                                     },
381                                     editor : {
382                                         xtype: 'GridEditor',
383                                         xns: Roo.grid,
384                                         field : {
385                                             xtype: 'TextField',
386                                             xns: Roo.form,
387                                             allowBlank : false
388                                         }
389                                     }
390                                 }
391                             ]
392                         }
393                     }
394                 ],
395                 west : {
396                     xtype: 'LayoutRegion',
397                     xns: Roo,
398                     split : true,
399                     width : 200
400                 },
401                 center : {
402                     xtype: 'LayoutRegion',
403                     xns: Roo
404                 }
405             }
406         };
407     }
408 });