<script src="js/dojo/dojo.js" type="text/javascript"
   djConfig="parseOnLoad: true"></script>
<script type="text/javascript">
var span;
var tr;
var td;

dojo.addOnLoad(initTable);
function initTable(){
 dojo.forEach(
  dojo.query(".ajaxspan"),
  function(spantag){
   dojo.connect(spantag, 'onmouseover',this,'bggreen');
   dojo.connect(spantag, 'onmouseout',this,'bgnormal');
   dojo.connect(spantag, 'onclick', this, 'textChange');
  }
 );
}

function textChange(event){
 span = event.target;
 td = span.parentNode;
 tr = td.parentNode;
 var node = dojo.doc.createElement("input");
 dojo.attr(node,"type","text");
 dojo.attr(node,"id",tr.id);
 dojo.attr(node,"name",span.id);
 dojo.attr(node,"value",span.innerHTML);
 dojo.connect(node,"onblur",this,"saveTextChange")
 td.innerHTML = "";
 td.appendChild(node);
 node.focus();    
}

function saveTextChange(event){
 var node = event.target;
 if(dojo.trim(node.value)!=dojo.trim(span.innerHTML)&&node.value!=""){
  dojo.byId("ajaxmsg").innerHTML = "正在更新..."
  dojo.xhrPost({
   url:"show/console/newsTypeAjax",
   load:function(data,ioArgs){
    if("200"==ioArgs.xhr.status){
     span.innerHTML = node.value;
     td.innerHTML = "";
     span.style.backgroundColor="";
     td.appendChild(span);
     clearNode() 
     dojo.byId("ajaxmsg").innerHTML = "";
    }
   },
   error:function(data,ioArgs){
    dojo.byId("ajaxmsg").innerHTML = "更新失败:"+data;
    td.innerHTML = "";
    span.style.backgroundColor="";
    td.appendChild(child);
    clearNode()
   },
   content: getTextParams(node)
  });
 }else{
  td.innerHTML = "";
  span.style.backgroundColor="";
  td.appendChild(span); 
  clearNode()   
 }   
}

function getTextParams(node){
 if("desc"==node.name){
  return {
   "id":node.id,"name":node.value,"tag":"desc"
  }
 }
 if("cont"==node.name){
  return {
   "id":node.id,"name":node.value,"tag":"cont"
  }
 }
}

function clearNode(){
 span = null;
 tr = null;
 td = null;
}

function bggreen(event){
   event.target.style.backgroundColor="#CCCCCC";
}
function bgnormal(event){
 event.target.style.backgroundColor="";
}

</script>


<table width="100%" height="58"  style="border: solid 1px #EEF8F9"cellpadding="0" cellspacing="0" id="listTable">
    
<c:forEach items="${msg}" var="newstype">    
  <tr id="${newstype.news_type_id}">
  
    <td width="30%" height="28" class="font_name">
 <span id="cont" class="ajaxspan">
 ${newstype.news_type_name} 
 </span> 
 </td>
    <td width="46%" class="font_name">
 <span id="desc" class="ajaxspan">
  ${newstype.news_type_description}
 </span> 
 </td>
  </tr>
 </c:forEach> 
 
  <tr>
    <td height="28" colspan="2" class="font_name">&nbsp;</td>
    <td class="font_name">&nbsp;</td>
  </tr>
</table>