fix html editor
[roojs1] / roojs-ui-debug.js
index a35452e..1b33c47 100644 (file)
@@ -23375,7 +23375,10 @@ Roo.extend(Roo.form.ComboBox, Roo.form.TriggerField, {
     onLoadException : function()
     {
         this.collapse();
-        Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
+        Roo.log(this.store.reader.jsonData);
+        if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
+            Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
+        }
         
         
     },
@@ -24521,7 +24524,7 @@ Roo.form.HtmlEditor = Roo.extend(Roo.form.Field, {
     syncValue : function(){
         if(this.initialized){
             var bd = (this.doc.body || this.doc.documentElement);
-            this.cleanUpPaste();
+            //this.cleanUpPaste();
             var html = bd.innerHTML;
             if(Roo.isSafari){
                 var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
@@ -24699,7 +24702,7 @@ Roo.form.HtmlEditor = Roo.extend(Roo.form.Field, {
     onEditorEvent : function(e){
         this.fireEvent('editorevent', this, e);
       //  this.updateToolbar();
-        this.syncValue();
+        this.syncValue(); //we can not sync so often.. sync cleans, so this breaks stuff
     },
 
     insertTag : function(tg)
@@ -24793,6 +24796,7 @@ Roo.form.HtmlEditor = Roo.extend(Roo.form.Field, {
                     break;
                     case 'u':
                         cmd = 'underline';
+                        break;
                     case 'v':
                         this.cleanUpPaste.defer(100, this);
                         return;
@@ -25095,11 +25099,28 @@ Roo.form.HtmlEditor = Roo.extend(Roo.form.Field, {
     cleanUpPaste :  function()
     {
         // cleans up the whole document..
-      //  console.log('cleanuppaste');
+         Roo.log('cleanuppaste');
         this.cleanUpChildren(this.doc.body);
+        var clean = this.cleanWordChars(this.doc.body.innerHTML);
+        if (clean != this.doc.body.innerHTML) {
+            this.doc.body.innerHTML = clean;
+        }
         
+    },
+    
+    cleanWordChars : function(input) {
+        var he = Roo.form.HtmlEditor;
+    
+        var output = input;
+        Roo.each(he.swapCodes, function(sw) { 
         
+            var swapper = new RegExp("\\u" + sw[0].toString(16), "g"); // hex codes
+            output = output.replace(swapper, sw[1]);
+        });
+        return output;
     },
+    
+    
     cleanUpChildren : function (n)
     {
         if (!n.childNodes.length) {
@@ -25132,7 +25153,16 @@ Roo.form.HtmlEditor = Roo.extend(Roo.form.Field, {
             return;
             
         }
-        if (Roo.form.HtmlEditor.remove.indexOf(node.tagName.toLowerCase()) > -1) {
+        
+        var remove_keep_children= Roo.form.HtmlEditor.remove.indexOf(node.tagName.toLowerCase()) > -1;
+        
+        // remove <a name=....> as rendering on yahoo mailer is bored with this.
+        
+        if (node.tagName.toLowerCase() == 'a' && !node.hasAttribute('href')) {
+            remove_keep_children = true;
+        }
+        
+        if (remove_keep_children) {
             this.cleanUpChildren(node);
             // inserts everything just before this node...
             while (node.childNodes.length) {
@@ -25207,10 +25237,17 @@ Roo.form.HtmlEditor = Roo.extend(Roo.form.Field, {
                 cleanStyle(a.name,a.value);
             }
             /// clean up MS crap..
+            // tecnically this should be a list of valid class'es..
+            
+            
             if (a.name == 'class') {
                 if (a.value.match(/^Mso/)) {
                     node.className = '';
                 }
+                
+                if (a.value.match(/body/)) {
+                    node.className = '';
+                }
             }
             
             // style cleanup!?
@@ -25321,7 +25358,19 @@ Roo.form.HtmlEditor.cwhite= [
         'font-size'
 ];
 
-// <script type="text/javascript">
+
+Roo.form.HtmlEditor.swapCodes   =[ 
+    [    8211, "--" ], 
+    [    8212, "--" ], 
+    [    8216,  "'" ],  
+    [    8217, "'" ],  
+    [    8220, '"' ],  
+    [    8221, '"' ],  
+    [    8226, "*" ],  
+    [    8230, "..." ]
+]; 
+
+    // <script type="text/javascript">
 /*
  * Based on
  * Ext JS Library 1.1.1
@@ -26824,7 +26873,7 @@ clientValidation  Boolean          Applies to submit only.  Pass true to call fo
             // show an error message if no failed handler is set..
             if (!this.hasListener('actionfailed')) {
                 Roo.MessageBox.alert("Error",
-                    typeof(action.result.errorMsg) != 'undefined' ?
+                    (typeof(action.result) != 'undefined' && typeof(action.result.errorMsg) != 'undefined') ?
                         action.result.errorMsg :
                         "Saving Failed, please check your entries"
                 );
@@ -29211,7 +29260,10 @@ Roo.extend(Roo.form.ComboCheck, Roo.form.ComboBox, {
         var ar = [] ;
         
         try {
-            Roo.log(this.value);
+            //Roo.log(this.value);
+            if (typeof(this.value) == 'undefined') {
+                return [];
+            }
             var ar = Roo.decode(this.value);
             return  ar instanceof Array ? ar : []; //?? valid?
             
@@ -30226,7 +30278,7 @@ layout.addxtype({
             xitems = cfg.items;
             delete cfg.items;
         }
-        
+        var nb = false;
         
         switch(cfg.xtype) 
         {
@@ -30267,7 +30319,7 @@ layout.addxtype({
                 ret = new Roo[cfg.xtype](layout, cfg); // new panel!!!!!
                 //console.log('adding nested layout panel '  + cfg.toSource());
                 this.add(region, ret);
-                
+                nb = {}; /// find first...
                 break;
                 
             case 'GridPanel': 
@@ -30308,10 +30360,37 @@ layout.addxtype({
         }
         this.beginUpdate();
         // add children..
+        var region = '';
+        var abn = {};
         Roo.each(xitems, function(i)  {
-            ret.addxtype(i);
+            region = nb && i.region ? i.region : false;
+            
+            var add = ret.addxtype(i);
+           
+            if (region) {
+                nb[region] = nb[region] == undefined ? 0 : nb[region]+1;
+                if (!i.background) {
+                    abn[region] = nb[region] ;
+                }
+            }
+            
         });
         this.endUpdate();
+
+        // make the last non-background panel active..
+        //if (nb) { Roo.log(abn); }
+        if (nb) {
+            
+            for(var r in abn) {
+                region = this.getRegion(r);
+                if (region) {
+                    // tried using nb[r], but it does not work..
+                     
+                    region.showPanel(abn[r]);
+                   
+                }
+            }
+        }
         return ret;
         
     }
@@ -36658,6 +36737,7 @@ Roo.extend(Roo.grid.RowSelectionModel, Roo.grid.AbstractSelectionModel,  {
  * This class provides the basic implementation for cell selection in a grid.
  * @constructor
  * @param {Object} config The object containing the configuration of this model.
+ * @cfg {Boolean} enter_is_tab Enter behaves the same as tab. (eg. goes to next cell) default: false
  */
 Roo.grid.CellSelectionModel = function(config){
     Roo.apply(this, config);
@@ -36691,12 +36771,21 @@ Roo.grid.CellSelectionModel = function(config){
                <li>o.cell: An array of [rowIndex, columnIndex]</li>
                </ul>
             */
-           "selectionchange" : true
+           "selectionchange" : true,
+        /**
+            * @event tabend
+            * Fires when the tab (or enter) was pressed on the last editable cell
+            * You can use this to trigger add new row.
+            * @param {SelectionModel} this
+            */
+           "tabend" : true
     });
     Roo.grid.CellSelectionModel.superclass.constructor.call(this);
 };
 
 Roo.extend(Roo.grid.CellSelectionModel, Roo.grid.AbstractSelectionModel,  {
+    
+    enter_is_tab: false,
 
     /** @ignore */
     initEvents : function(){
@@ -36825,41 +36914,52 @@ Roo.extend(Roo.grid.CellSelectionModel, Roo.grid.AbstractSelectionModel,  {
         var k = e.getKey(), r = s.cell[0], c = s.cell[1];
         var newCell;
 
+      
+
         switch(k){
             case e.TAB:
                 // handled by onEditorKey
                 if (g.isEditor && g.editing) {
                     return;
                 }
-                if(e.shiftKey){
-                     newCell = walk(r, c-1, -1);
-                }else{
-                     newCell = walk(r, c+1, 1);
+                if(e.shiftKey) {
+                    newCell = walk(r, c-1, -1);
+                } else {
+                    newCell = walk(r, c+1, 1);
                 }
-             break;
-             case e.DOWN:
-                 newCell = walk(r+1, c, 1);
-             break;
-             case e.UP:
-                 newCell = walk(r-1, c, -1);
-             break;
-             case e.RIGHT:
-                 newCell = walk(r, c+1, 1);
-             break;
-             case e.LEFT:
-                 newCell = walk(r, c-1, -1);
-             break;
-             case e.ENTER:
-                 if(g.isEditor && !g.editing){
-                    g.startEditing(r, c);
-                    e.stopEvent();
-                    return;
+                break;
+            
+            case e.DOWN:
+               newCell = walk(r+1, c, 1);
+                break;
+            
+            case e.UP:
+                newCell = walk(r-1, c, -1);
+                break;
+            
+            case e.RIGHT:
+                newCell = walk(r, c+1, 1);
+                break;
+            
+            case e.LEFT:
+                newCell = walk(r, c-1, -1);
+                break;
+            
+            case e.ENTER:
+                
+                if(g.isEditor && !g.editing){
+                   g.startEditing(r, c);
+                   e.stopEvent();
+                   return;
                 }
+                
+                
              break;
         };
         if(newCell){
             this.select(newCell[0], newCell[1]);
             e.stopEvent();
+            
         }
     },
 
@@ -36878,18 +36978,24 @@ Roo.extend(Roo.grid.CellSelectionModel, Roo.grid.AbstractSelectionModel,  {
      */
     onEditorKey : function(field, e){
         
-        var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
+        var k = e.getKey(),
+            newCell,
+            g = this.grid,
+            ed = g.activeEditor,
+            forward = false;
         ///Roo.log('onEditorKey' + k);
-        if (!ed) {
-            
-            
-            
+        
+        
+        if (this.enter_is_tab && k == e.ENTER) {
+            k = e.TAB;
         }
+        
         if(k == e.TAB){
             if(e.shiftKey){
                 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
             }else{
                 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
+                forward = true;
             }
             
             e.stopEvent();
@@ -36906,6 +37012,9 @@ Roo.extend(Roo.grid.CellSelectionModel, Roo.grid.AbstractSelectionModel,  {
         if(newCell){
             //Roo.log('next cell after edit');
             g.startEditing.defer(100, g, [newCell[0], newCell[1]]);
+        } else if (forward) {
+            // tabbed past last
+            this.fireEvent.defer(100, this, ['tabend',this]);
         }
     }
 });/*