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 Roo.namespace('Pman.Tab');
6
7 Pman.Tab.CmsTranslateTemplates = new Roo.XComponent({
8
9  _strings : {
10   '0a52da7a03a6de3beefe54f8c03ad80d' :"Original",
11   '0b8d92bc19b720bb1065649535463409' :"Translations",
12   '9d1ead73e678fa2f51a70a933b0bf017' :"Not Found",
13   '6dd08874f83507e9c7b23f1a46b7fa7c' :"Translation",
14   'e2f9d206562d8f5ea421ad51100f7151' :"Displaying petition_entry{0} - {1} of {2}",
15   'dc00a593c8be0a664ba934335b093154' :"Translate Templates",
16   '4d1c8263ba1036754f8db14a98f9f006' :"Reload",
17   'f2a6c498fb90ee345d997f888fce3b18' :"Delete",
18   '03c2e7e41ffc181a4e84080b4710e81e' :"New",
19   '193cfc9be3b995831c6af2fea6650e60' :"Page"
20  },
21
22   part     :  ["Cms", "TranslateTemplates" ],
23   order    : '800-Pman.Tab.CmsTranslateTemplates',
24   region   : 'center',
25   parent   : 'Pman.Tab.Cms',
26   name     : "Pman.Tab.CmsTranslateTemplates",
27   disabled : false, 
28   permname : '', 
29   _tree : function()
30   {
31    var _this = this;
32    var MODULE = this;
33    return {
34    layout : {
35     west : {
36      '|xns' : 'Roo',
37      split : true,
38      width : 200,
39      xns : Roo,
40      xtype : 'LayoutRegion'
41     },
42     center : {
43      '|xns' : 'Roo',
44      xns : Roo,
45      xtype : 'LayoutRegion'
46     },
47     '|xns' : 'Roo',
48     xns : Roo,
49     xtype : 'BorderLayout',
50     items : [
51      {
52       toolbar : {
53        '|xns' : 'Roo',
54        xns : Roo,
55        xtype : 'Toolbar',
56        items : [
57         {
58          '|xns' : 'Roo.Toolbar',
59          text : _this._strings['03c2e7e41ffc181a4e84080b4710e81e'],
60          xns : Roo.Toolbar,
61          xtype : 'Button',
62          listeners : {
63           click : function (_self, e)
64            {
65                Pman.Dialog.CmsLanguagePick.show( {  }, function(lang) {
66                    
67                    new Pman.Request({
68                        url : baseURL + '/Roo/cms_templatestr',
69                        method : 'GET',
70                        params : {
71                            _rescan : lang
72                        }, 
73                        success : function()
74                        {
75                            _this.treepanel.tree.getRootNode().reload();
76                        }
77                    });
78                
79                });
80                
81            }
82          }
83         },
84         {
85          '|xns' : 'Roo.Toolbar',
86          text : _this._strings['f2a6c498fb90ee345d997f888fce3b18'],
87          xns : Roo.Toolbar,
88          xtype : 'Button',
89          listeners : {
90           click : function (_self, e)
91            {
92                var tree = _this.treepanel.tree;
93                var sn  = tree.getSelectionModel().getSelectedNode();
94            
95                if (!sn || sn.id.split('/').length > 1) {
96                    Roo.MessageBox.alert("Error", "Select a language");
97                    return;
98                }
99                Roo.log(sn);return;
100                 Roo.MessageBox.confirm("Confirm", "Are sure you want to delete the language", function (v){
101                        if (v != 'yes') {
102                            return;
103                        }
104                        Roo.MessageBox.alert("Not yet", "not done yet");
105                        return;
106                        Roo.Ajax.request({
107                            url : baseURL + '/Roo/cms_language.php',
108                            method: 'POST',
109                            params : {
110                                _delete : _t.selectedNode.id 
111                            },
112                            success : function()
113                            {
114                               _this.treepanel.tree.getRootNode().reload();
115                                //g.getDataSource().reload();
116                            },
117                            failure : function()
118                            {
119                                Roo.MessageBox.alert("Error", 
120                                    "There was a problem saving the data - try reloading");
121                                
122                            }
123                            
124                        });
125                        
126                        
127                        
128                        
129                    });
130            }
131          }
132         },
133         {
134          '|xns' : 'Roo.Toolbar',
135          text : _this._strings['4d1c8263ba1036754f8db14a98f9f006'],
136          xns : Roo.Toolbar,
137          xtype : 'Button',
138          listeners : {
139           click : function (_self, e)
140            {
141                _this.treepanel.tree.getRootNode().reload();
142                
143            }
144          }
145         }
146        ]
147
148       },
149       tree : {
150        loader : {
151         '|xns' : 'Roo.tree',
152         baseParams : { _tree : 1 },
153         dataUrl : baseURL + '/Roo/cms_templatestr',
154         requestMethod : 'GET',
155         xns : Roo.tree,
156         xtype : 'TreeLoader',
157         listeners : {
158          beforeload : function (This, node, callback)
159           {
160               // set some params.
161               Roo.log(node);
162               this.baseParams._tree = 1;
163               
164               //this.baseParams.category = node.attributes.category;
165           },
166          loadexception : function (This, node, response)
167           {
168               Roo.MessageBox.alert("Error", "Problem loading tree");
169           }
170         }
171        },
172        root : {
173         '|xns' : 'Roo.tree',
174         id : 'transtree',
175         text : _this._strings['0b8d92bc19b720bb1065649535463409'],
176         xns : Roo.tree,
177         xtype : 'AsyncTreeNode'
178        },
179        selModel : {
180         '|xns' : 'Roo.tree',
181         xns : Roo.tree,
182         xtype : 'DefaultSelectionModel',
183         listeners : {
184          selectionchange : function (_self, node)
185           {
186               Roo.log(node);
187               
188               //if (node.id.split('/').length < 2) {
189               //    return;
190              // }
191               (function() {
192                   _this.grid.footer.onClick('first');
193               }).defer(100);
194               
195           }
196         }
197        },
198        '|xns' : 'Roo.tree',
199        containerScroll : false,
200        rootVisible : true,
201        xns : Roo.tree,
202        xtype : 'TreePanel',
203        items : [
204
205        ]
206
207       },
208       '|xns' : 'Roo',
209       region : 'west',
210       xns : Roo,
211       xtype : 'TreePanel',
212       listeners : {
213        render : function (_self)
214         {
215             _this.treepanel = _self;
216         }
217       },
218       items : [
219
220       ]
221
222      },
223      {
224       grid : {
225        footer : {
226         '|xns' : 'Roo',
227         displayInfo : true,
228         displayMsg : _this._strings['e2f9d206562d8f5ea421ad51100f7151'],
229         emptyMsg : _this._strings['9d1ead73e678fa2f51a70a933b0bf017'],
230         pageSize : 100,
231         xns : Roo,
232         xtype : 'PagingToolbar'
233        },
234        dataSource : {
235         proxy : {
236          '|xns' : 'Roo.data',
237          method : 'GET',
238          url : baseURL + '/Roo/cms_templatestr.php',
239          xns : Roo.data,
240          xtype : 'HttpProxy'
241         },
242         reader : {
243          '|xns' : 'Roo.data',
244          fields : [
245              {
246                  'name': 'id',
247                  'type': 'int'
248              },
249              {
250                  'name': 'shortname',
251                  'type': 'string'
252              },
253             
254          ],
255          id : 'id',
256          root : 'data',
257          totalProperty : 'total',
258          xns : Roo.data,
259          xtype : 'JsonReader'
260         },
261         '|xns' : 'Roo.data',
262         remoteSort : true,
263         sortInfo : { field : 'shortname', direction: 'ASC' },
264         xns : Roo.data,
265         xtype : 'Store',
266         listeners : {
267          beforeload : function (_self, o)
268           {
269              
270               var sn = _this.treepanel.tree.getSelectionModel().getSelectedNode();
271           
272               if (!sn) { // || (sn.id.split('/').length < 2)) {
273                  
274                   _this.grid.ds.removeAll();
275                   return false;
276               }
277               Roo.log("load?");
278               var ar = sn.attributes.id * 1;//.split('/');
279               Roo.log(sn);
280               
281               o.params = o.params || {};
282               o.params.lang = sn.parentNode.attributes.id;
283               o.params.template_id = sn.attributes.id;
284               if(sn.attributes.on_table){
285                   o.params.on_table = sn.attributes.on_table;
286               }
287               o.params.sort= 'src_id_txt';
288               o.params.dir = 'ASC';
289           },
290          update : function (_self, rec, operation)
291           {
292               Roo.log(operation);
293               
294               if (operation != 'commit') {
295                   return;
296               }
297               
298           
299               _this.grid.getView().el.mask("Saving");
300               new Pman.Request({
301                   url : baseURL + '/Roo/cms_templatestr',
302                   method: 'POST',
303                   params : {
304                       id : rec.get('id'),
305                       txt : rec.get('txt')
306                   },
307                   success : function()
308                   {
309                       _this.grid.getView().el.unmask();
310                           //g.getDataSource().reload();
311                   },
312                   failure : function()
313                   {
314                       _this.grid.getView().el.unmask();
315                       Roo.MessageBox.alert("Error", "There was a problem saving the data - try reloading");
316                    }
317                       
318               });
319               
320           }
321         },
322         items : [
323
324         ]
325
326        },
327        '|xns' : 'Roo.grid',
328        autoExpandColumn : 'txt',
329        clicksToEdit : 1,
330        loadMask : true,
331        xns : Roo.grid,
332        xtype : 'EditorGrid',
333        colModel : [
334          {
335           '|xns' : 'Roo.grid',
336           dataIndex : 'src_id_txt',
337           header : _this._strings['0a52da7a03a6de3beefe54f8c03ad80d'],
338           renderer : function(v,x,r) { 
339           
340            var c = '#666';
341                   if (r.data.updated  < r.data.src_id_origupdated) {
342                       c = 'red';
343                   }
344                   
345           //        return '<div style="color:'+c+'";>' +r.data.tableid + ':' + v + '</div>';
346                   return String.format('<div style="color:'+c+'";>{0}</div>', v)
347           
348           },
349           width : 200,
350           xns : Roo.grid,
351           xtype : 'ColumnModel'
352          },
353 {
354           editor : {
355            field : {
356             '|xns' : 'Roo.form',
357             allowBlank : false,
358             xns : Roo.form,
359             xtype : 'TextField'
360            },
361            '|xns' : 'Roo.grid',
362            xns : Roo.grid,
363            xtype : 'GridEditor',
364            items : [
365
366            ]
367
368           },
369           '|xns' : 'Roo.grid',
370           dataIndex : 'txt',
371           header : _this._strings['6dd08874f83507e9c7b23f1a46b7fa7c'],
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           width : 200,
384           xns : Roo.grid,
385           xtype : 'ColumnModel',
386           items : [
387
388           ]
389
390          }
391        ],
392        listeners : {
393         afteredit : function (e)
394          {
395              e.record.commit();
396          },
397         beforeedit : function (e)
398          {   
399              /*if (e.record.data.src_id_txt.indexOf('<') > -1) {
400                 // console.log("HTML EDITOR!!");
401                  Pman.Dialog.CmsTranslateEditor.show(e.record);
402                  return false;
403              }*/
404              
405              var str=e.record.data.src_id_txt;
406              var patt=/{(.*?)}/g;
407              
408              Roo.log(str.length);
409              
410              
411              if(patt.test(str)){
412                  e.cancel = true;
413                  Pman.Dialog.CmsTranslateTemplates.show(e.record.data, function(v){
414                      Roo.log(v);
415                      e.value = v.txt;
416                      e.record.set('txt', v.txt);
417                      e.record.commit();
418                  });
419                  /*
420                  Roo.MessageBox.prompt('WARNING', 'This text is with {TEMPLATE VARIABLE}, PLEASE BE CAREFUL EDITING. What\'s change? '+str, function(btn, text){
421                      if (btn == 'ok'){
422                          e.value = text;
423                          e.record.set('txt', text);
424                          e.record.commit();
425                      }
426                  });*/
427                  return;
428              }
429              
430              if(str.length > 150){
431                  e.cancel = true;
432                  Pman.Dialog.CmsTranslateTemplates.show(e.record.data, function(v){
433                      e.value = v.txt;
434                      e.record.set('txt', v.txt);
435                      e.record.commit();
436                  });
437                  /*
438                  Roo.MessageBox.prompt('WARNING', 'This text is with {TEMPLATE VARIABLE}, PLEASE BE CAREFUL EDITING. What\'s change? '+str, function(btn, text){
439                      if (btn == 'ok'){
440                          e.value = text;
441                          e.record.set('txt', text);
442                          e.record.commit();
443                      }
444                  });*/
445                  return;
446              }
447              
448          
449              if (e.record.data.txt.replace(/\s+/, '').length) {
450                  return true;
451              }
452              
453              var tl = _this.treepanel.tree.getSelectionModel().getSelectedNode().parentNode.attributes.id;
454              // mapping?
455              
456              tl = (tl == 'zh_HK') ? 'zh-TW' : tl;
457              
458              if (tl == 'en' && !e.value.length) {
459          
460                  e.value = e.record.data.src_id_txt;
461                  e.record.set('txt', e.record.data.src_id_txt);
462                  return true;
463              }
464              
465              Pman.GoogleTranslate(e.record.data.src_id_txt, "en", tl, function(result) {
466                 // Roo.log(result);
467                  _this.grid.activeEditor.setValue(result);
468                  //console.log(result.translation);
469              });
470              
471          
472              
473              return true;
474          },
475         render : function() 
476          {
477              _this.grid = this; 
478              //_this.dialog = Pman.Dialog.FILL_IN
479              if (_this.panel.active) {
480                  this.footer.onClick('first');
481                // this.ds.onc.onClick('first');
482              }
483          },
484         rowdblclick : function (_self, rowIndex, e)
485          {
486              if (!_this.dialog) return;
487              _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {
488                  _this.grid.footer.onClick('first');
489              }); 
490          }
491        },
492        items : [
493
494        ]
495
496       },
497       '|xns' : 'Roo',
498       background : false,
499       fitContainer : true,
500       fitToframe : true,
501       region : 'center',
502       tableName : 'Page',
503       title : _this._strings['193cfc9be3b995831c6af2fea6650e60'],
504       xns : Roo,
505       xtype : 'GridPanel',
506       listeners : {
507        activate : function() {
508             _this.panel = this;
509             if (_this.grid) {
510                 _this.grid.footer.onClick('first');
511             }
512         }
513       },
514       items : [
515
516       ]
517
518      }
519     ]
520
521    },
522    '|xns' : 'Roo',
523    region : 'center',
524    title : _this._strings['dc00a593c8be0a664ba934335b093154'],
525    xns : Roo,
526    xtype : 'NestedLayoutPanel',
527    items : [
528
529    ]
530
531   };  }
532 });