includes/clientside/sbedit.js
changeset 179 e858bacb5cfa
parent 80 cb7dde69c301
child 190 88d7a7c2743c
equal deleted inserted replaced
178:fd0e9c7a7b28 179:e858bacb5cfa
   121         }
   121         }
   122       }
   122       }
   123     });
   123     });
   124 }
   124 }
   125 
   125 
       
   126 function ajaxRenameSidebarStage1(parent, id)
       
   127 {
       
   128   var oldname = parent.firstChild.nodeValue;
       
   129   parent.removeChild(parent.firstChild);
       
   130   parent.ondblclick = function() {};
       
   131   parent._idcache = id;
       
   132   var input = document.createElement('input');
       
   133   input.type = 'text';
       
   134   input.sbedit_id = id;
       
   135   input.oldvalue = oldname;
       
   136   input.onkeyup = function(e)
       
   137   {
       
   138     if ( typeof(e) != 'object' )
       
   139       return false;
       
   140     if ( !e.keyCode )
       
   141       return false;
       
   142     if ( e.keyCode == 13 )
       
   143     {
       
   144       ajaxRenameSidebarStage2(this);
       
   145     }
       
   146     if ( e.keyCode == 27 )
       
   147     {
       
   148       ajaxRenameSidebarCancel(this);
       
   149     }
       
   150   };
       
   151   input.onblur = function()
       
   152   {
       
   153     ajaxRenameSidebarCancel(this);
       
   154   };
       
   155   input.value = oldname;
       
   156   input.style.fontSize = '7pt';
       
   157   parent.appendChild(input);
       
   158   input.focus();
       
   159 }
       
   160 
       
   161 function ajaxRenameSidebarStage2(input)
       
   162 {
       
   163   var newname = input.value;
       
   164   var id = input.sbedit_id;
       
   165   var parent = input.parentNode;
       
   166   parent.removeChild(input);
       
   167   parent.appendChild(document.createTextNode(newname));
       
   168   parent.ondblclick = function() { ajaxRenameSidebarStage1(this, this._idcache); return false; };
       
   169   var img = document.createElement('img');
       
   170   img.src = scriptPath + '/images/loading.gif';
       
   171   parent.appendChild(img);
       
   172   newname = ajaxEscape(newname);
       
   173   ajaxPost(makeUrlNS('Special', 'EditSidebar', 'ajax&noheaders&action=rename&id='+id), 'newname=' +newname, function()
       
   174     {
       
   175       if ( ajax.readyState == 4 )
       
   176       {
       
   177         parent.removeChild(img);
       
   178         if ( ajax.responseText != 'GOOD' )
       
   179           new messagebox(MB_OK|MB_ICONSTOP, 'Error renaming block', ajax.responseText);
       
   180       }
       
   181     });
       
   182 }
       
   183 
       
   184 function ajaxRenameSidebarCancel(input)
       
   185 {
       
   186   var newname = input.oldvalue;
       
   187   var id = input.sbedit_id;
       
   188   var parent = input.parentNode;
       
   189   parent.removeChild(input);
       
   190   parent.appendChild(document.createTextNode(newname));
       
   191   parent.ondblclick = function() { ajaxRenameSidebarStage1(this, this._idcache); return false; };
       
   192 }
       
   193