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