Source

webcandy / priv / www / index.html

The default branch has multiple heads

Full commit
<html>
<head>
<!-- 
   by Serge S
   http://bitbucket.org/sunneach/
   September 2008            
-->
<title>YAHTTPClient</title>
<style type="text/css">
.err {color: #AA0000}
</style>

<script>

var respx

var debugm = false
//var debugm = true
var ie = false
var enc = "json"

var _url;
var _enc;
var _reqtype;
var _request;
var _hdr;

function malert(x){if(debugm) alert(x)}
function geto(id){var o=document.getElementById(id);if (!o) o=document.all[id]; return o}
function setV(id,nv,what){if(what == 'h') geto(id).innerHTML = nv;else if(what == 't') geto(id).innerText = nv;else geto(id).value=nv}
function getV(id,what){if(what == 'h') return geto(id).innerHTML;else if(what == 't') return geto(id).innerText;else return geto(id).value}
function check(reqType){setV("reqtype",reqType,true)}
function addCR(hdr){return hdr.replace(/\n/g,"\r")}
function checkenc(encform){enc=encform}


function ajaxFunction()
{  
  setV("res","\n\nWAIT ...",'t')
  setV("hdr","\n\nWAIT ...",'t')
  setV('err','...sending....','h')
  window.status='Sending request...'
  var xmlHttp;
  try
  {  
    xmlHttp=new XMLHttpRequest();   
    malert('got XMLHttpRequest')
  }
  catch (e)
  {       
    try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      malert('got Msxml2.XMLHTTP')
      ie = true
    }
    catch (e)
    {      
       try
       {
           xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
           malert('got Microsoft.XMLHTTP')
           ie = true
       }
       catch (e)
       {
          malert("Your browser does not support AJAX!");
          return false;       
       }
    }
  }
 
  xmlHttp.onreadystatechange=function()
  {
    setV('err','...received....','h')
    window.status='request state changed'
    if(xmlHttp.readyState==4)
    {
         hdr = xmlHttp.status+ "\n" + xmlHttp.getAllResponseHeaders()
         resp = xmlHttp.responseText
         malert(hdr)
         hdr = ie ? addCR(hdr) : hdr
         malert(hdr)
         setV('hdr',hdr,true)
         malert("response from server: " + resp)
         setV('res', resp == '' ? '- EMPTY RESPONSE BODY -':resp,     true)
         setV('err',"Complete",'h')
     }
      window.status='Done'
  }
  malert(encodeURI('={:}check browser')) 
//  if( navigator.appName !='Microsoft Internet Explorer') mal2(navigator.appName+ ":\n"
//                        +'cross-domain request works on IE only!')
  malert('about open') 
  try
  {
    xmlHttp.open(getV('reqtype',true),getV('url',true))
    malert('about header') 
//  
    var sr = getV('request')
    malert("form:\n" + sr)

    var ct
    var rq
    
    if(enc=="json")
    {
      ct =  "application/json";
      rq =  sr
    }
    else
    {
      ct = "application/x-www-form-urlencoded; charset=utf-8"
      ct = "application/x-www-form-urlencoded"
      rq = encodeURI(sr)
    }

    xmlHttp.setRequestHeader("Content-Type", ct);
    xmlHttp.send(rq)
  }
  catch(e)
  {
    setV('err','Server unavailable','h')
    window.status='Done'
    setV('hdr',"- SERVER UNAVAILABLE -",true)
    setV('res',"- SERVER UNAVAILABLE -",true)
  }
}
function dispTrace(istrace) { return istrace ? 'ON' : 'OFF' }
function readTrace() { return (getV('istrace','h') == 'ON') }
function renderTrace(trc) { 
	setV('istrace',dispTrace(trc),'h');
	setV('toggle','Turn ' + dispTrace(!trc))}
function traceToggle(){
	save();
	newstate = ! readTrace()
	renderTrace(newstate)
	setV("url",'/_trace',true);setV("enc",'json',true);
	rt =newstate ? "PUT" : "DELETE";
	setV("reqtype", rt, true);
	renderRadio(rt);
	ajaxFunction()
	jsleep(1);
	restore();
	}
function checkTrace(){  malert("refresh");
	save();
    setV("reqtype","HEAD",true);
	renderRadio("HEAD");
	setV("url",'_trace',true);
	setV("enc",'json',true);
	ajaxFunction();
    renderTrace(('200' == getV('hdr').split("\n")[0]));
	restore();
}
function renderRadio(rt){
  rad = document.myForm.reqt;
  for(i=0;i<rad.length;i++){rad[i].checked = (rad[i].value == rt)}
}
function restore()
{
	setV('url',_url,'true');
	setV('enc',_enc,'true');
	setV('reqtype',_reqtype,'true');
	renderRadio(_reqtype);
	setV('request',_request,'true');
	setV('hdr',_hdr,'true');
}
function save()
{
	_url = getV('url','true');
	_enc = getV('enc','true');
	_reqtype = getV('reqtype','true');
	_request =  getV('request','true');
	_hdr =  getV('hdr','true');
}
function jsleep(s){ s=s*1000; var a=true; var n=new Date(); var w; var sMS=n.getTime(); while(a){ w=new Date(); wMS=w.getTime(); if(wMS-sMS>s) a=false; } }

</script>

</head>

<body onload="checkTrace()">
   <h1>WebCandy Admin</h1>
   <a href="stickynotes.html" target="new">Go directly to Sticky Notes</a>
     <hr>
      TRACE IS <span id='istrace'/>OFF</span>&nbsp;&nbsp;
      <input onclick="checkTrace()" id='refresh' type="button" value='refresh'/>
      <input onclick="traceToggle()" id='toggle' type="button" value='Turn ON'/>
	   &nbsp;&nbsp;<a href="wmtrace" target="new">View Traces</a>

   <hr>
   <form name="myForm" action="javascript:ajaxFunction()">
   <table id="tt">
     <tr><td>URL:          </td><td><input id="url" type="text" size="85" value='/notes'></td></tr>
     <tr><td>REQUEST TYPE: </td>
         <td>
             <input onclick="check(this.value)" name="reqt" type="radio" value='POST'/>POST&nbsp;&nbsp;
             <input onclick="check(this.value)" name="reqt" type="radio" value='GET'/>GET&nbsp;&nbsp;
             <input onclick="check(this.value)" name="reqt" type="radio" value='DELETE'/>DELETE&nbsp;&nbsp;
             <input onclick="check(this.value)" name="reqt" type="radio" value='PUT'/>PUT&nbsp;&nbsp;
             <input onclick="check(this.value)" name="reqt" type="radio" value='HEAD'/>HEAD
         </td>
     </tr>
     <tr><td>Encoding to send:</td>
         <td>
             <input onclick="checkenc(this.value)" name="enc" type="radio" value='json'        />JSON&nbsp;&nbsp;
             <input onclick="checkenc(this.value)" name="enc" type="radio" value='enc'  checked/>x-www-form-urlencoded&nbsp;&nbsp;
         </td>
     </tr>

     <tr><td></td><td><input id="reqtype" type="hidden" value='POST'></td></tr>
     <tr><td>REQUEST BODY:</td><td></td></tr><tr><td colspan="2">
	 <textarea class="code1" id="request" rows="2" cols="80">json={"action":"read_all"}</textarea></td></tr>
     <tr><td></td><td><input type="submit" value="send"/></td></tr>
   </table>
   <hr/>
   RESPONSE: &nbsp;&nbsp; <span class="err" id="err"></span><br/>
   <textarea class="code1" id="res" rows="10" cols="80"></textarea><br/>
   HEADERS:<br/>
   <textarea class="code1" id="hdr" rows="11" cols="80"></textarea><br/>
</body>

</html>