includes/clientside/sbedit.js
changeset 1 fe660c52c48f
child 80 cb7dde69c301
equal deleted inserted replaced
0:902822492a68 1:fe660c52c48f
       
     1 var disenable_currentBlock;
       
     2 function ajaxDisenableBlock(id)
       
     3 {
       
     4   disenable_currentBlock = document.getElementById('disabled_'+id);
       
     5   ajaxGet(makeUrlNS('Special', 'EditSidebar', 'action=disenable&ajax=true&noheaders&id='+id), function()
       
     6     {
       
     7       if(ajax.readyState == 4)
       
     8       {
       
     9         if(ajax.responseText == 'GOOD')
       
    10         {
       
    11           if(disenable_currentBlock.style.display == 'none')
       
    12           {
       
    13             disenable_currentBlock.style.display = 'inline';
       
    14           }
       
    15           else
       
    16           {
       
    17             disenable_currentBlock.style.display = 'none';
       
    18           }
       
    19         } 
       
    20         else
       
    21         {
       
    22           document.getElementById('ajaxEditContainer').innerHTML = ajax.responseText;
       
    23         }
       
    24       }
       
    25     });
       
    26 }
       
    27 
       
    28 var delete_currentBlock;
       
    29 function ajaxDeleteBlock(id, oElm)
       
    30 {
       
    31   delete_currentBlock = { 0 : id, 1 : oElm };
       
    32   ajaxGet(makeUrlNS('Special', 'EditSidebar', 'action=delete&ajax=true&noheaders&id='+id), function()
       
    33     {
       
    34       if(ajax.readyState == 4)
       
    35       {
       
    36         if(ajax.responseText == 'GOOD')
       
    37         {
       
    38           e = delete_currentBlock[1];
       
    39           e = e.parentNode.parentNode;
       
    40           e.parentNode.removeChild(e);
       
    41         } 
       
    42         else
       
    43         {
       
    44           document.getElementById('ajaxEditContainer').innerHTML = ajax.responseText;
       
    45         }
       
    46       }
       
    47     });
       
    48 }
       
    49 
       
    50 var blockEdit_current;
       
    51 function ajaxEditBlock(id, oElm)
       
    52 {
       
    53   blockEdit_current = { 0 : id, 1 : oElm };
       
    54   ajaxGet(makeUrlNS('Special', 'EditSidebar', 'action=getsource&noheaders&id='+id), function()
       
    55     {
       
    56       if(ajax.readyState == 4)
       
    57       {
       
    58         id = blockEdit_current[0];
       
    59         oElm = blockEdit_current[1];
       
    60         var thediv = document.createElement('div');
       
    61         //if(!oElm.id) oElm.id = 'autoEditButton_'+Math.floor(Math.random() * 100000);
       
    62         oElm = oElm.parentNode;
       
    63         o = fetch_offset(oElm);
       
    64         d = fetch_dimensions(oElm);
       
    65         top = o['top'] + d['h'] + 'px';
       
    66         left = o['left'] + 'px';
       
    67         thediv.style.top = top;
       
    68         thediv.style.left = left;
       
    69         thediv.style.position = 'absolute';
       
    70         thediv.className = 'mdg-comment';
       
    71         thediv.style.margin = '0';
       
    72         if(ajax.responseText == 'HOUSTON_WE_HAVE_A_PLUGIN')
       
    73         {
       
    74           thediv.innerHTML = '<h3>This block cannot be edited.</h3><p>This is a plugin block, and cannot be edited.</p><p><a href="#" onclick="this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode); return false;">close</a></p>';
       
    75         }
       
    76         else
       
    77         {
       
    78           ta = document.createElement('textarea');
       
    79           ta.rows = '15';
       
    80           ta.cols = '50';
       
    81           ta.innerHTML = ajax.responseText;
       
    82           thediv.appendChild(ta);
       
    83           b = document.createElement('br');
       
    84           thediv.appendChild(b);
       
    85           thediv.innerHTML += '<a href="#" onclick="ajaxSaveBlock(this, \''+id+'\'); return false;">save</a>  |  <a href="#" onclick="if(confirm(\'Do you really want to discard your changes?\')) this.parentNode.parentNode.removeChild(this.parentNode); return false;">cancel</a>';
       
    86         }
       
    87         body = document.getElementsByTagName('body');
       
    88         body = body[0];
       
    89         body.appendChild(thediv);
       
    90       }
       
    91     });
       
    92 }
       
    93 
       
    94 var blockSave_current;
       
    95 function ajaxSaveBlock(oElm, id)
       
    96 {
       
    97   taContent = escape(oElm.previousSibling.previousSibling.value);
       
    98   taContent = taContent.replace(unescape('%0A'), '%0A');
       
    99   taContent = taContent.replace('+', '%2B');
       
   100   blockSave_current = { 0 : id, 1 : oElm };
       
   101   ajaxPost(makeUrlNS('Special', 'EditSidebar', 'noheaders&action=save&id='+id), 'content='+taContent, function()
       
   102     {
       
   103       if(ajax.readyState == 4)
       
   104       {
       
   105         id   = blockSave_current[0];
       
   106         oElm = blockSave_current[1];
       
   107         eval(ajax.responseText);
       
   108         if(status == 'GOOD')
       
   109         {
       
   110           parent = document.getElementById('disabled_'+id).parentNode.parentNode;
       
   111           oElm.parentNode.parentNode.removeChild(oElm.parentNode);
       
   112           content = content.replace('%a', unescape('%0A'));
       
   113           parent.firstChild.nextSibling.nextSibling.nextSibling.innerHTML = content; // $content is set in ajax.responseText
       
   114         }
       
   115         else
       
   116         {
       
   117           alert(status);
       
   118         }
       
   119       }
       
   120     });
       
   121 }
       
   122