sweetdev ajaxwindow

/**
* This class simulates the action to trigger an ajax call to an url,
* and show the outputs in an window, which is based on sweetdev window components.
*
*/

function initWindow(name,title,modal,width,height) {
(function beforeInit(name){
var a = document.getElementsByTagName("DIV")[0];
var d = '<div id="'+name+'_container" style="position:absolute;top:-1000px;left:-1000px;" class="" ></div>';
d += '<div id="'+name+'_content"><div id="'+name+'_zone" style="" class="" ></div></div>';
var e = document.createElement("DIV");
e.innerHTML=d;
a.appendChild(e);
})(name);
title = title||"";
width = width||400;
height = height||100;
new SweetDevRia.Window(name,-1,-1,width,height,100,100,-1,-1, null ,modal,false,true);
SweetDevRia.$(name).title = title;
SweetDevRia.$(name).style = "";
SweetDevRia.$(name).styleClass = "";
SweetDevRia.$(name).i18n={};
SweetDevRia.$(name).i18n["closeButton"] = "Close";
SweetDevRia.$(name).i18n["maximizeButton"] = "Maximize";
SweetDevRia.$(name).i18n["minimizeButton"] = "Minimize";
SweetDevRia.$(name).i18n["restoreButton"] = "Restore";
SweetDevRia.$(name).asIframe = true;
SweetDevRia.$(name).canMinimize = false;
SweetDevRia.$(name).canMaximize = false;
SweetDevRia.$(name).canClose = true;
SweetDevRia.$(name).isResizable = true;
SweetDevRia.$(name).displayTitleBar = true;
SweetDevRia.riaComponentParentIds.push (name);
new SweetDevRia.Zone(name+"_zone", false, null, 0, null);
SweetDevRia.riaComponentParentIds.pop ();
SweetDevRia.$(name).render();
return SweetDevRia.$(name);
};
/**
* Common method..
* Get an element's rectangle position in window
* return: object {top:top,left:left,bottom:bottom,right:right}
**/
function getPosition(aLink){
var top = parseInt(SweetDevRia.DomHelper.getY(aLink), 10);
var bottom = top + parseInt(SweetDevRia.DomHelper.getHeight(aLink), 10); //y position, not the same as DOM
var left = parseInt(SweetDevRia.DomHelper.getX(aLink), 10);
var right = left + parseInt(SweetDevRia.DomHelper.getWidth(aLink),0); //x position, not the same as DOM
return {top:top,left:left,bottom:bottom,right:right};
}

function AjaxWindow(name,title,modal){
this.name = name;
this.title = title;
this.modal = modal;
this.content = null;
this.setContent = function(s){
this.content = s;
}
this.window = initWindow(this.name,this.title,this.modal);
this.client = null; //the source element that triggers the ajax event
this.width = this.window.getWidth();
this.height = this.window.getHeight();
this.x = null;
this.y = null;
this.setWidth = function(w){this.width = w};
this.setHeight = function(h){this.height = h};
this.setX = function(x){this.x =x};
this.setY = function(y){this.y =y};
this.getContent = function(){
return document.getElementById(this.name+'_zone');
};
this.beforeOpen = function(t){
this.window.close();
if(!t) t = 'loading...';
this.getContent().innerHTML = t;
};
this.afterOpen = function(t){
var event = event || window.event;
if(event)
this.client = event.srcElement || event.target;
var target = this.client;
if(!t && target) t = target.value;
t = this.content || t;
if(this.x && this.y)
this.window.moveTo(this.x,this.y);
else {
var pos = getPosition(target);
this.window.moveTo(pos.left,pos.bottom);
}
this.window.resizeTo(this.width,this.height);
this.window.getFrame().refreshBorders();
this.getContent().innerHTML = t;
};
this.open = function(){
this.beforeOpen();
this.window.open();
this.afterOpen();
};
this.openNoPrepare = function(){
this.window.open();
};
/**
* Ajax submit
* @param client - client object that triggers the submit
* @param url - submit url
* @param params - parameter object, format {key:value}
**/
this.submit = function(url,params,client){
this.client=client;
var ajaxW = this;
SweetDevRia.ComHelper.genericCall (
url, params, function(){
ajaxW.setContent(this.responseText);
ajaxW.beforeOpen();
ajaxW.openNoPrepare();
ajaxW.afterOpen();
ajaxW.event = null;
});
}
}

/*
example :
var ajaxWindow = new AjaxWindow("ajaxWindow","A window");
ajaxWindow.setHeight(400);

var ajaxWindow2 = new AjaxWindow("anotherAjaxWindow","Another window",true);
ajaxWindow2.setX(ajaxWindow2.window.getCenterOnScreenX());
ajaxWindow2.setY(ajaxWindow2.window.getCenterOnScreenY());

<input type="button" οnclick="ajaxWindow.open();" value="Open window1"/>
<input type="button" οnclick="ajaxWindow2.submit('ajaxform/requesthandler.jsp',{ajaxformvalue:'hello'},this);" value="Open window2"/>

*/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值