随笔-6  评论-0  文章-3  trackbacks-0

//ajax support
var J = { 
 request: function(url, param, onComplete) {  
  new Ajax.Request(
         url,
         {
          method: 'post',
          parameters: param,
          onComplete: function(request) {
           var o = eval('(' + request.responseText + ')');
     if(null != o.exception) {
      Load.off();
      Msg.exception(o.exception);  
     } else {
            (onComplete || Prototype.emptyFunction)(o);
           }
           o = null;
    },
          onLoading: function(request) {
     Load.on();
    },
    onLoaded: function(request) {
     Load.off();
    }
         }
     );
   },
 
   update: function(url, param, container) {  
    new Ajax.Updater(
    container,
    url,
    {
     method: 'post',
     asynchronous: true,
     evalScripts: true,
    parameters: param,
    onLoading: function(request) {
     Load.on();
    },
    onLoaded: function(request) {
     Load.off();
    }
   }
  );
   } 
};

 


var Msg = {
 exceptionLayer:null,
 exceptionLayerMessage:null,
 exceptionLayerStackTrace:null,
 init: function() {
  var s = [];
  s[s.length] = '<div id="exceptionLayer" name="exceptionLayer" style="position:absolute;z-index:101;display:none;width:100%;height:100%;text-align:center;top:0;left:0;padding-top:100;">';
  s[s.length] = '<div class="font_exception" style="width:600;border:1px solid #FF0000;background-color:#FFFF00;padding:10px;filter:alpha(opacity=90)progid:DXImageTransform.Microsoft.Fade(duration=0.2)progid:DXImageTransform.Microsoft.Shadow(color=#777777,direction=135,strength=3);">';
  s[s.length] = '<div style="width:100%;height:22;text-align:left;">Exception occur:</div>';
  s[s.length] = '<div id="exceptionLayerMessage" name="exceptionLayerMessage" style="font-weight:bold;width:100%;height:50;overflow:auto;text-align:left;">&nbsp;</div>';
  s[s.length] = '<div style="width:100%;height:22;text-align:right;padding-top:5;"><input type="button" style="width:120;" value="Close" class="font_exception" style="border:1px solid #FF0000;" onclick="Msg.exceptionOff();" />&nbsp;<input type="button" style="width:120;" value="Detail >>" class="font_exception" style="border:1px solid #FF0000;" onclick="Msg.switchExceptionLayerStackTrace();" /></div>';
  s[s.length] = '<div id="exceptionLayerStackTrace" name="exceptionLayerStackTrace" style="width:100%;height:300;padding-top:5;overflow:auto;text-align:left;display:none;">&nbsp;</div>';
  s[s.length] = '</div>';
  s[s.length] = '</div>';  
  document.writeln(s.join(''));
  s = null;
  this.exceptionLayer = document.all.exceptionLayer;   
  this.exceptionLayerMessage = $('exceptionLayerMessage');
  this.exceptionLayerStackTrace = $('exceptionLayerStackTrace');
 },
 exception: function(e) {    
    Cover.on();
    this.exceptionLayerStackTrace.style.display = 'none';
    this.exceptionLayer.style.display = 'block';    
    this.exceptionLayerMessage.innerHTML = '<xmp>' + e.message + '</xmp>';
    this.exceptionLayerStackTrace.innerHTML = '<xmp>' + e.stackTrace + '</xmp>';
   },
   switchExceptionLayerStackTrace: function() {   
    event.srcElement.value = ('Detail >>'==event.srcElement.value) ? 'Detail <<' : 'Detail >>';
    this.exceptionLayerStackTrace.style.display = ('none'==this.exceptionLayerStackTrace.style.display) ? 'block' : 'none';
   },
   exceptionOff: function() {
    Cover.off();
    this.exceptionLayer.style.display = 'none';
   }
}
Msg.init();

 


var Cover = {
 coverLayer:null,
 init: function() {
  document.writeln('<iframe id="coverLayer" name="coverLayer" frameborder="no" style="position:absolute;width:100%;height:100%;top:0;left:0;z-index:100;display:none;margin:0;padding:0;filter:alpha(opacity=10);"></iframe>');
  window.frames.coverLayer.document.close();
  this.coverLayer = document.all.coverLayer;
 },
 on: function() {
  this.coverLayer.style.display = 'block';
 },
 off: function() {
  this.coverLayer.style.display = 'none';
 }
};
Cover.init();

 


var Load = {
 loadLayer: null,
 init: function() {
  document.writeln('<div id="loadLayer" name="loadLayer" style="position:absolute;z-index:101;display:none;width:200;height:20;right:10;bottom:10;font-size:12px;font-family:Verdana,Simsun;background-color:#FFFF00;border:1px solid #FF0000;padding:2;cursor:hand;filter:progid:DXImageTransform.Microsoft.Fade(duration=0.2)progid:DXImageTransform.Microsoft.Shadow(color=#777777,direction=135,strength=3);" onclick="Load.off();" title="close"><span class="loader">&nbsp;</span>&nbsp;loading...</div>');
  this.loadLayer = document.all.loadLayer;
 },
 on: function() {
  Cover.on();
  this.loadLayer.style.display = 'block';
  window.status = 'loading...';
 },
 off: function() {
  Cover.off();
  this.loadLayer.style.display = 'none';
  window.status = 'loaded!';
 }
};
Load.init();









//css
.loader {
 border:0; 
 width:16;
 height:16;
 background: url(../image/loader.gif) no-repeat 0em 0em;
}
.font_exception {
 color: #A90101;
 font-size: 12px; 
 font-family: Verdana, Simsun;
}










//usage
function initAbstractEntityType() {
 J.request(
        'findAbstractEntityType.html',
        '',
        onInitAbstractEntityType
    );
}

function onInitAbstractEntityType(o) {
 var xtree = o.xtree;
 var item = null;
 for(var i = 0; i<xtree.length; i++ ) {
  item = xtree[i];
  //sText, sXmlSrc, sAction, eParent, sIcon, sOpenIcon
  tree.add(
   new WebFXLoadTreeItem(
    item.text + ' ' + item.name,
    'findEntityType.html?invokeType=tree&abstractEntityTypeId=' + item.id,
    'javascript:findEntityTypeByAbstractEntityTypeId(' + item.id + ');'
   )
  );
 }
 item = null;
 xtree = null;
}






//request.responseText
{
 entityTypes:[
<#if entityTypes ? exists><#list entityTypes as entityType>
  {id:'${(entityType.id)?if_exists}', text:'${(entityType.text)?if_exists}', name:'${(entityType.name)?if_exists}'}<#if entityType_has_next>,</#if>
</#list></#if>
 ]
}

//exception
{
 exception: {
  message:'${(Request["_exception_message_"])?if_exists?j_string}',
  stackTrace:'${(Request["_exception_stack_trace_"])?if_exists?j_string}'
 }
}

posted on 2006-11-22 22:35 frogfool 阅读(472) 评论(0)  编辑  收藏 所属分类: Ajax

只有注册用户登录后才能发表评论。


网站导航: