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.footer.onClick('first');
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                                 displayMsg : "Displaying petition_entry{0} - {1} of {2}",
262                                 emptyMsg : "Not Found",
263                                 pageSize : 25
264                             },
265                             dataSource : {
266                                 xtype: 'Store',
267                                 xns: Roo.data,
268                                 listeners : {
269                                     update : function (_self, rec, operation)
270                                     {
271                                         Roo.log(operation);
272                                         
273                                         if (operation != 'commit') {
274                                             return;
275                                         }
276                                         
277                                     
278                                         _this.grid.getView().el.mask("Saving");
279                                         new Pman.Request({
280                                             url : baseURL + '/Roo/cms_templatestr',
281                                             method: 'POST',
282                                             params : {
283                                                 id : rec.get('id'),
284                                                 txt : rec.get('txt')
285                                             },
286                                             success : function()
287                                             {
288                                                 _this.grid.getView().el.unmask();
289                                                     //g.getDataSource().reload();
290                                             },
291                                             failure : function()
292                                             {
293                                                 _this.grid.getView().el.unmask();
294                                                 Roo.MessageBox.alert("Error", "There was a problem saving the data - try reloading");
295                                              }
296                                                 
297                                         });
298                                         
299                                     },
300                                     beforeload : function (_self, o)
301                                     {
302                                        
303                                         var sn = _this.treepanel.tree.getSelectionModel().getSelectedNode();
304                                     
305                                         if (!sn) { // || (sn.id.split('/').length < 2)) {
306                                            
307                                             _this.grid.ds.removeAll();
308                                             return false;
309                                         }
310                                         Roo.log("load?");
311                                         var ar = sn.attributes.id * 1;//.split('/');
312                                         
313                                         o.params = o.params || {};
314                                         o.params.lang = sn.parentNode.attributes.id;
315                                         o.params.template_id = sn.attributes.id;
316                                         o.params.sort= 'src_id_txt';
317                                         o.params.dir = 'ASC';
318                                     }
319                                 },
320                                 remoteSort : true,
321                                 sortInfo : { field : 'shortname', direction: 'ASC' },
322                                 proxy : {
323                                     xtype: 'HttpProxy',
324                                     xns: Roo.data,
325                                     method : 'GET',
326                                     url : baseURL + '/Roo/cms_templatestr.php'
327                                 },
328                                 reader : {
329                                     xtype: 'JsonReader',
330                                     xns: Roo.data,
331                                     id : 'id',
332                                     root : 'data',
333                                     totalProperty : 'total',
334                                     fields : [
335                                         {
336                                             'name': 'id',
337                                             'type': 'int'
338                                         },
339                                         {
340                                             'name': 'shortname',
341                                             'type': 'string'
342                                         },
343                                        
344                                     ]
345                                 }
346                             },
347                             colModel : [
348                                 {
349                                     xtype: 'ColumnModel',
350                                     xns: Roo.grid,
351                                     dataIndex : 'src_id_txt',
352                                     header : 'Original',
353                                     width : 200,
354                                     renderer : function(v,x,r) { 
355                                     
356                                      var c = '#666';
357                                             if (r.data.updated  < r.data.src_id_origupdated) {
358                                                 c = 'red';
359                                             }
360                                             
361                                     //        return '<div style="color:'+c+'";>' +r.data.tableid + ':' + v + '</div>';
362                                             return String.format('<div style="color:'+c+'";>{0}</div>', v)
363                                     
364                                     }
365                                 },
366                                 {
367                                     xtype: 'ColumnModel',
368                                     xns: Roo.grid,
369                                     dataIndex : 'txt',
370                                     header : 'Translation',
371                                     width : 200,
372                                     renderer : function(v,x,r) { 
373                                     
374                                      var c = '#666';
375                                             if (r.data.updated  < r.data.src_id_updated) {
376                                                 c = 'red';
377                                             }
378                                             
379                                     //        return '<div style="color:'+c+'";>' +r.data.tableid + ':' + v + '</div>';
380                                             return String.format('<div style="color:'+c+'";>{0}</div>', v)
381                                     
382                                     },
383                                     editor : {
384                                         xtype: 'GridEditor',
385                                         xns: Roo.grid,
386                                         field : {
387                                             xtype: 'TextField',
388                                             xns: Roo.form,
389                                             allowBlank : false
390                                         }
391                                     }
392                                 }
393                             ]
394                         }
395                     }
396                 ],
397                 west : {
398                     xtype: 'LayoutRegion',
399                     xns: Roo,
400                     split : true,
401                     width : 200
402                 },
403                 center : {
404                     xtype: 'LayoutRegion',
405                     xns: Roo
406                 }
407             }
408         };
409     }
410 });