Pman.Tab.AdminLogEvents.bjs
[Pman.Admin] / Pman.Tab.AdminTranslations.js
index 04ec78d..47ac3cf 100644 (file)
@@ -58,8 +58,6 @@ Pman.Tab.AdminTranslations = new Roo.util.Observable({
                         grid : {
                             xtype: 'EditorGrid',
                             xns: Roo.grid,
-                            autoExpandColumn : 'txt',
-                            loadMask : true,
                             listeners : {
                                 render : function() { 
                                     _this.grid = this; 
@@ -150,7 +148,9 @@ Pman.Tab.AdminTranslations = new Roo.util.Observable({
                                     saveRec.defer(1000, _this, [ e.record ]);
                                 }
                             },
+                            autoExpandColumn : 'txt',
                             clicksToEdit : 1,
+                            loadMask : true,
                             dataSource : {
                                 xtype: 'Store',
                                 xns: Roo.data,
@@ -217,7 +217,7 @@ Pman.Tab.AdminTranslations = new Roo.util.Observable({
                                             xns: Roo.data,
                                             data : (function() {             
                                                     var modlist = [];             
-                                                    AppModules = typeof(AppModules) == 'undefined' ? [] : AppModules;
+                                                    AppModules = typeof(AppModules) == 'undefined' ? '' : AppModules;
                                                     Roo.each( AppModules.split(','), function(mod) {            
                                                              modlist.push( [ mod ] );            
                                                   });             
@@ -277,9 +277,9 @@ Pman.Tab.AdminTranslations = new Roo.util.Observable({
                                 {
                                     xtype: 'ColumnModel',
                                     xns: Roo.grid,
+                                    dataIndex : 'txt',
                                     header : 'Translated (Click to Edit)',
                                     width : 150,
-                                    dataIndex : 'txt',
                                     renderer : function(v,x,r) {                                                   var c = '#666';                         if (r.get('updated') < r.get('origupdated')) {                             c = 'red';                         }                                                  return '<div style="color:' + c+ '">' + Ext.util.Format.htmlEncode(v) + '</div>';                     },
                                     editor : {
                                         xtype: 'GridEditor',
@@ -309,9 +309,9 @@ Pman.Tab.AdminTranslations = new Roo.util.Observable({
                         fitToframe : true,
                         region : 'center',
                         tableName : 'i18n',
-                        title : "i18n",
+                        title : "Languages and Countries",
                         grid : {
-                            xtype: 'Grid',
+                            xtype: 'EditorGrid',
                             xns: Roo.grid,
                             listeners : {
                                 render : function() 
@@ -322,21 +322,103 @@ Pman.Tab.AdminTranslations = new Roo.util.Observable({
                                        this.ds.load({});
                                     }
                                 },
-                                rowdblclick : function (_self, rowIndex, e)
+                                afteredit : function (e)
                                 {
-                                    if (!_this.dialog) return;
-                                    _this.dialog.show( this.getDataSource().getAt(rowIndex), function() {
-                                        _this.grid.footer.onClick('first');
-                                    }); 
-                                }
+                                    var saveRec  = function(rec)
+                                    {
+                                        var g = _this.grid;
+                                
+                                        //g.getView().el.mask('Saving');
+                                        Ext.Ajax.request({
+                                            url : baseURL + '/Roo/I18n.php',
+                                            method: 'POST',
+                                            params : {
+                                                id : rec.get('id'),
+                                                lval : rec.get('lval')
+                                            },
+                                            success : function()
+                                            {
+                                                //g.getView().el.unmask();
+                                                //g.getDataSource().reload();
+                                            },
+                                            failure : function()
+                                            {
+                                                Ext.Msg.alert("Error", "There was a problem saving the data - try reloading");
+                                               // g.getView().el.unmask();
+                                            }
+                                            
+                                    });
+                                        };
+                                    
+                                    saveRec.defer(1000, _this, [ e.record ]);
+                                },
+                                beforeedit : function(e) {
+                                    console.log('beforeedit');
+                                    //if (e.record.get('origtxt').indexOf('<') > -1) {
+                                                       // console.log("HTML EDITOR!!");
+                                             
+                                            //    return false;
+                                            //}
+                                            if (e.record.get('lval').replace(/\s+/, '').length) {
+                                                return true;
+                                            }
+                                            
+                                            
+                                            var tl = _this.langgridCombo.getValue();
+                                          
+                                            tl = (tl == 'zh_HK') ? 'zh-TW' : tl; 
+                                            tl = tl.replace('_', '-');
+                                            var rec = e.record;
+                                            
+                                            
+                                            
+                                            Pman.gtranslate(e.record.get('lval_en'), 'en', tl, function(result) { 
+                                                if (typeof(result) == 'object') { //error
+                                                    return; 
+                                                   }
+                                                
+                                                if (_this.grid.activeEditor) {
+                                                    _this.grid.activeEditor.setValue(result);
+                                                } else {
+                                                    rec.set('lval',result);
+                                                    //_this.saveRec(rec);
+                                                }
+                                
+                                                //
+                                                
+                                                
+                                                //console.log(result.translation);
+                                            });
+                                            
+                                           
+                                            
+                                            return true;
+                                        }
                             },
-                            autoExpandColumn : 'ltype',
+                            autoExpandColumn : 'lval',
+                            clicksToEdit : 1,
                             loadMask : true,
                             dataSource : {
                                 xtype: 'Store',
                                 xns: Roo.data,
+                                listeners : {
+                                    beforeload : function (_self, options)
+                                    {
+                                       options  =options ||  {};
+                                       options.params =options.params|| {};
+                                       options.params.ltype = _this.langtypeCombo.getValue();
+                                       options.params.inlang = _this.langgridCombo.getValue();
+                                       options.params['query[_with_en]'] = 1;
+                                       if (!options.params.ltype.length || !options.params.inlang.length) {
+                                           return false;
+                                       }
+                                       
+                                       options.params.limit = 9999;
+                                       
+                                    }
+                                },
                                 remoteSort : true,
-                                sortInfo : { field : 'ltype', direction: 'ASC' },
+                                sortInfo : { field : 'lkey', direction: 'ASC' },
                                 proxy : {
                                     xtype: 'HttpProxy',
                                     xns: Roo.data,
@@ -373,67 +455,70 @@ Pman.Tab.AdminTranslations = new Roo.util.Observable({
                                     ]
                                 }
                             },
-                            footer : {
-                                xtype: 'PagingToolbar',
-                                xns: Roo,
-                                pageSize : 25,
-                                displayInfo : true,
-                                displayMsg : "Displaying i18n{0} - {1} of {2}",
-                                emptyMsg : "No i18n found"
-                            },
                             toolbar : {
                                 xtype: 'Toolbar',
                                 xns: Roo,
                                 items : [
                                     {
-                                        xtype: 'Button',
-                                        xns: Roo.Toolbar,
-                                        text : "Add",
-                                        cls : 'x-btn-text-icon',
-                                        icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
+                                        xtype: 'ComboBox',
+                                        xns: Roo.form,
                                         listeners : {
-                                            click : function()
+                                            render : function (_self)
                                             {
-                                                if (!_this.dialog) return;
-                                                _this.dialog.show( { id : 0 } , function() {
-                                                    _this.grid.footer.onClick('first');
-                                               }); 
-                                            }
-                                        }
-                                    },
-                                    {
-                                        xtype: 'Button',
-                                        xns: Roo.Toolbar,
-                                        text : "Edit",
-                                        cls : 'x-btn-text-icon',
-                                        icon : Roo.rootURL + 'images/default/tree/leaf.gif',
-                                        listeners : {
-                                            click : function()
+                                              _this.langtypeCombo = _self;
+                                            },
+                                            select : function (combo, record, index)
                                             {
-                                                var s = _this.grid.getSelectionModel().getSelections();
-                                                if (!s.length || (s.length > 1))  {
-                                                    Roo.MessageBox.alert("Error", s.length ? "Select only one Row" : "Select a Row");
-                                                    return;
-                                                }
-                                                if (!_this.dialog) return;
-                                                _this.dialog.show(s[0].data, function() {
-                                                    _this.grid.footer.onClick('first');
-                                                }); 
-                                                
+                                              _this.langgrid.getDataSource().reload(); 
                                             }
+                                        },
+                                        displayField : 'lval',
+                                        editable : false,
+                                        emptyText : "Select Translation of",
+                                        mode : 'local',
+                                        selectOnFocus : true,
+                                        triggerAction : 'all',
+                                        typeAhead : false,
+                                        valueField : 'lkey',
+                                        width : 200,
+                                        store : {
+                                            xtype: 'SimpleStore',
+                                            xns: Roo.data,
+                                            data : [
+                                               [ 'l', 'Language Names' ],
+                                               [ 'c', 'Country Names' ],
+                                                [ 'm', 'Currency Names' ]
+                                            ],
+                                            fields : ['lkey','lval']
                                         }
                                     },
                                     {
-                                        xtype: 'Button',
-                                        xns: Roo.Toolbar,
-                                        text : "Delete",
-                                        cls : 'x-btn-text-icon',
-                                        icon : rootURL + '/Pman/templates/images/trash.gif',
+                                        xtype: 'ComboBox',
+                                        xns: Roo.form,
                                         listeners : {
-                                            click : function()
+                                            select : function (combo, record, index)
+                                            {
+                                              _this.langgrid.getDataSource().reload(); 
+                                            },
+                                            render : function (_self)
                                             {
-                                                 Pman.genericDelete(_this, 'i18n'); 
+                                              _this.langgridCombo=_self;
                                             }
+                                        },
+                                        displayField : 'ldisp',
+                                        editable : false,
+                                        emptyText : "Select Language",
+                                        mode : 'local',
+                                        selectOnFocus : true,
+                                        triggerAction : 'all',
+                                        typeAhead : false,
+                                        valueField : 'lang',
+                                        width : 200,
+                                        store : {
+                                            xtype: 'SimpleStore',
+                                            xns: Roo.data,
+                                            fields : ['lang', 'ldisp'],
+                                            data : [                                                [ 'zh_HK' , '\u7E41\u4E2D - Trad. Chin. (HK)' ],                         [ 'zh_CN', '\u7C21\u4E2D - Simp. Chin.' ]                     ]
                                         }
                                     }
                                 ]
@@ -442,42 +527,34 @@ Pman.Tab.AdminTranslations = new Roo.util.Observable({
                                 {
                                     xtype: 'ColumnModel',
                                     xns: Roo.grid,
-                                    header : 'Id',
-                                    width : 75,
-                                    dataIndex : 'id',
-                                    renderer : function(v) { return String.format('{0}', v); }
-                                },
-                                {
-                                    xtype: 'ColumnModel',
-                                    xns: Roo.grid,
-                                    header : 'Ltype',
-                                    width : 200,
-                                    dataIndex : 'ltype',
-                                    renderer : function(v) { return String.format('{0}', v); }
-                                },
-                                {
-                                    xtype: 'ColumnModel',
-                                    xns: Roo.grid,
-                                    header : 'Lkey',
-                                    width : 200,
                                     dataIndex : 'lkey',
+                                    header : 'Code',
+                                    width : 50,
                                     renderer : function(v) { return String.format('{0}', v); }
                                 },
                                 {
                                     xtype: 'ColumnModel',
                                     xns: Roo.grid,
-                                    header : 'Inlang',
-                                    width : 200,
-                                    dataIndex : 'inlang',
+                                    dataIndex : 'lval_en',
+                                    header : 'English',
+                                    width : 150,
                                     renderer : function(v) { return String.format('{0}', v); }
                                 },
                                 {
                                     xtype: 'ColumnModel',
                                     xns: Roo.grid,
-                                    header : 'Lval',
-                                    width : 200,
                                     dataIndex : 'lval',
-                                    renderer : function(v) { return String.format('{0}', v); }
+                                    header : 'Translation',
+                                    width : 200,
+                                    renderer : function(v) { return String.format('{0}', v); },
+                                    editor : {
+                                        xtype: 'GridEditor',
+                                        xns: Roo.grid,
+                                        field : {
+                                            xtype: 'TextField',
+                                            xns: Roo.form
+                                        }
+                                    }
                                 }
                             ]
                         }