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.footer.onClick('first');
209                                       // this.ds.onc.onClick('first');
210                                     }
211                                 },
212                                 rowdblclick : function (_self, rowIndex, e)
213                                 {
214                                     if (!_this.dialog) return;
215                                     _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {
216                                         _this.grid.footer.onClick('first');
217                                     }); 
218                                 },
219                                 beforeedit : function (e)
220                                 {   
221                                     Roo.log('in1?');
222                                     
223                                     if (e.record.data.src_id_txt.indexOf('<') > -1) {
224                                        // console.log("HTML EDITOR!!");
225                                         Pman.Dialog.CmsTranslateEditor.show(e.record);
226                                         return false;
227                                     }
228                                     
229                                     Roo.log('in2?');
230                                     var str=e.record.data.src_id_txt;
231                                     var patt=/{(.*?)}/g;
232                                     
233                                     if(patt.test(str)){
234                                         Roo.MessageBox.prompt('WARNING', 'This text is with {TEMPLATE VARIABLE}, PLEASE BE CAREFUL EDITING. What\'s change? '+str, function(btn, text){
235                                             if (btn == 'ok'){
236                                                 e.value = text;
237                                                 e.record.set('txt', text);
238                                             }
239                                         });
240                                         return true;
241                                     }
242                                     
243                                     if (e.record.data.txt.replace(/\s+/, '').length) {
244                                         return true;
245                                     }
246                                     Roo.log('in3?');
247                                     
248                                     var tl = _this.treepanel.tree.getSelectionModel().getSelectedNode().parentNode.attributes.id;
249                                     // mapping?
250                                     
251                                     Roo.log(e);
252                                     Roo.log(tl);
253                                     
254                                     
255                                     tl = (tl == 'zh_HK') ? 'zh-TW' : tl;
256                                     
257                                     if (tl == 'en' && !e.value.length) {
258                                 
259                                         e.value = e.record.data.src_id_txt;
260                                         e.record.set('txt', e.record.data.src_id_txt);
261                                         return true;
262                                     }
263                                     
264                                     Pman.GoogleTranslate(e.record.data.src_id_txt, "en", tl, function(result) {
265                                        // Roo.log(result);
266                                         _this.grid.activeEditor.setValue(result);
267                                         //console.log(result.translation);
268                                     });
269                                     
270                                 
271                                     
272                                     return true;
273                                 },
274                                 afteredit : function (e)
275                                 {
276                                     e.record.commit();
277                                 }
278                             },
279                             autoExpandColumn : 'txt',
280                             clicksToEdit : 1,
281                             loadMask : true,
282                             footer : {
283                                 xtype: 'PagingToolbar',
284                                 xns: Roo,
285                                 displayInfo : true,
286                                 displayMsg : "Displaying petition_entry{0} - {1} of {2}",
287                                 emptyMsg : "Not Found",
288                                 pageSize : 25
289                             },
290                             dataSource : {
291                                 xtype: 'Store',
292                                 xns: Roo.data,
293                                 listeners : {
294                                     update : function (_self, rec, operation)
295                                     {
296                                         Roo.log(operation);
297                                         
298                                         if (operation != 'commit') {
299                                             return;
300                                         }
301                                         
302                                     
303                                         _this.grid.getView().el.mask("Saving");
304                                         new Pman.Request({
305                                             url : baseURL + '/Roo/cms_templatestr',
306                                             method: 'POST',
307                                             params : {
308                                                 id : rec.get('id'),
309                                                 txt : rec.get('txt')
310                                             },
311                                             success : function()
312                                             {
313                                                 _this.grid.getView().el.unmask();
314                                                     //g.getDataSource().reload();
315                                             },
316                                             failure : function()
317                                             {
318                                                 _this.grid.getView().el.unmask();
319                                                 Roo.MessageBox.alert("Error", "There was a problem saving the data - try reloading");
320                                              }
321                                                 
322                                         });
323                                         
324                                     },
325                                     beforeload : function (_self, o)
326                                     {
327                                        
328                                         var sn = _this.treepanel.tree.getSelectionModel().getSelectedNode();
329                                     
330                                         if (!sn) { // || (sn.id.split('/').length < 2)) {
331                                            
332                                             _this.grid.ds.removeAll();
333                                             return false;
334                                         }
335                                         Roo.log("load?");
336                                         var ar = sn.attributes.id * 1;//.split('/');
337                                         
338                                         o.params = o.params || {};
339                                         o.params.lang = sn.parentNode.attributes.id;
340                                         o.params.template_id = sn.attributes.id;
341                                         o.params.sort= 'src_id_txt';
342                                         o.params.dir = 'ASC';
343                                     }
344                                 },
345                                 remoteSort : true,
346                                 sortInfo : { field : 'shortname', direction: 'ASC' },
347                                 proxy : {
348                                     xtype: 'HttpProxy',
349                                     xns: Roo.data,
350                                     method : 'GET',
351                                     url : baseURL + '/Roo/cms_templatestr.php'
352                                 },
353                                 reader : {
354                                     xtype: 'JsonReader',
355                                     xns: Roo.data,
356                                     id : 'id',
357                                     root : 'data',
358                                     totalProperty : 'total',
359                                     fields : [
360                                         {
361                                             'name': 'id',
362                                             'type': 'int'
363                                         },
364                                         {
365                                             'name': 'shortname',
366                                             'type': 'string'
367                                         },
368                                        
369                                     ]
370                                 }
371                             },
372                             colModel : [
373                                 {
374                                     xtype: 'ColumnModel',
375                                     xns: Roo.grid,
376                                     dataIndex : 'src_id_txt',
377                                     header : 'Original',
378                                     width : 200,
379                                     renderer : function(v,x,r) { 
380                                     
381                                      var c = '#666';
382                                             if (r.data.updated  < r.data.src_id_origupdated) {
383                                                 c = 'red';
384                                             }
385                                             
386                                     //        return '<div style="color:'+c+'";>' +r.data.tableid + ':' + v + '</div>';
387                                             return String.format('<div style="color:'+c+'";>{0}</div>', v)
388                                     
389                                     }
390                                 },
391                                 {
392                                     xtype: 'ColumnModel',
393                                     xns: Roo.grid,
394                                     dataIndex : 'txt',
395                                     header : 'Translation',
396                                     width : 200,
397                                     renderer : function(v,x,r) { 
398                                     
399                                      var c = '#666';
400                                             if (r.data.updated  < r.data.src_id_updated) {
401                                                 c = 'red';
402                                             }
403                                             
404                                     //        return '<div style="color:'+c+'";>' +r.data.tableid + ':' + v + '</div>';
405                                             return String.format('<div style="color:'+c+'";>{0}</div>', v)
406                                     
407                                     },
408                                     editor : {
409                                         xtype: 'GridEditor',
410                                         xns: Roo.grid,
411                                         field : {
412                                             xtype: 'TextField',
413                                             xns: Roo.form,
414                                             allowBlank : false
415                                         }
416                                     }
417                                 }
418                             ]
419                         }
420                     }
421                 ],
422                 west : {
423                     xtype: 'LayoutRegion',
424                     xns: Roo,
425                     split : true,
426                     width : 200
427                 },
428                 center : {
429                     xtype: 'LayoutRegion',
430                     xns: Roo
431                 }
432             }
433         };
434     }
435 });