var ServerEventListener = Class.create({
initialize: function(id){
if (++ServerEventListener.instance_counter_ > 1){
LogE("Only one instance of ServerEventListener is allowed");
return;
}
var elem = $(id);
if (elem){
this.id_ = elem.getAttribute("id");
elem.JSControl = this;
}
this.src_ = "/srv/WWW/WWWWorker/GetEvent"
this.timer_ = window.setTimeout(this.connect.bind(this), 1000);
Event.observe(window, "unload", this.abort.bind(this));
GDocumentInstance.Subscribe("RELOGIN_COMPLETE", this.OnRelogin, this);
},
ID: function(){ return this.id_; },
SetAttribute: function(nam, val){
if ("src" === nam){
this.src_ = val;
this.stop_timer();
delete this.restart_timeout_;
this.connect();
}
},
SetTabOrder: function(tabbase){ return tabbase; },
Value: function(){ return null; },
SetValue: function(){},
OnRelogin: function() {
this.stop_timer();
if (this.restart_timeout_) delete this.restart_timeout_;
this.connect();
},
connect: function(){
if (this.request_) this.abort();
this.request_ = new Ajax.Request(this.src_, {
"method": "get",
"requestHeaders": {"action-type": "GetEvent"},
"onComplete": this.process.bind(this)
});
},
abort: function(){
if (this.request_){
if (this.request_.transport) this.request_.transport.abort();
delete this.request_;
}
},
process: function(transport){
if ([200, 400].indexOf(transport.status) !== -1 && transport.responseText)
try{
var response = XMLRestore(transport.responseText);
if (response instanceof Exception){
LogE("ERROR " + response.ErrorCode() + ": " + response.Message());
this.reconnect();
}else{
if (!Object.isArray(response)) response = [response];
$A(response).each(this.event, this);
this.connect.bind(this).defer();
if (this.restart_timeout_) delete this.restart_timeout_;
}
}catch(exc){
alert("Server Event ERROR: " + exc.message + ".\n" + transport.responseText);
this.reconnect();
}
else this.reconnect();
},
reconnect: function(){
if (!this.restart_timeout_) this.restart_timeout_ = 4000;
else if(this.restart_timeout_<600000) this.restart_timeout_ = 2 * this.restart_timeout_;
LogL("reconnect in " + (this.restart_timeout_ / 1000) + " sec");
this.stop_timer();
this.timer_ = window.setTimeout(this.connect.bind(this), this.restart_timeout_);
},
stop_timer: function(){
if (this.timer_){
window.clearTimeout(this.timer_);
delete this.timer_;
}
},
event: function(msg){
if (msg) new AEvent(msg.Type, msg.Data, this);
}
});
ServerEventListener.instance_counter_ = 0;
var ProgressBar = Class.create({
initialize: function(id, oManager) {
this.ID=id;
this.oManager=oManager;
this.opacity=".5";
this.showComment=false;
this.element=new Element('DIV', {'class': 'ProgressBar'});
this.element.setStyle({position: 'absolute', top: '-1000px', left: '50%', 'id': this.ID});
document.body.appendChild(this.element);
var ma = function(n,v) { return ' '+n+'="'+AXML.EscapeEntities(v)+'"'; }
var xml='';
var axmlDoc = new AXML();
axmlDoc.Parse(xml);
var oTransformDoc = AXML.TransformDOM(axmlDoc.XML(), GWindowManager.XSL(), true);
ApplyTreeOrString(this.element, oTransformDoc);
this.eleProgressPanel=this.element.down(".PB_ProgressPanel");
this.eleProgressPanel.setStyle({opacity: this.opacity});
this.eleTip=$('TIP_'+this.ID);
this.eleComment=$('CMT_'+this.ID);
this.elePrgText=$('PRG_TXT_'+this.ID);
this.elePrg=$('PRG_'+this.ID);
this.elePin=$('PIN_'+this.ID);
this.interval=parseInt(this.elePrg.readAttribute("interval"));
this.divMouseOverCallback=this.onDivMouseOver.bind(this);
this.divMouseOutCallback=this.onDivMouseOut.bind(this);
this.divClickCallback=this.onDivClick.bind(this);
this.pinClickCallback=this.onPinClick.bind(this);
this.divMouseDownCallback=this.onDivMouseDown.bind(this);
this.divMouseMoveCallback=this.onDivMouseMove.bind(this);
this.divMouseUpCallback=this.onDivMouseUp.bind(this);
this.pinMouseDownCallback=this.onPinMouseDown.bind(this);
this.pinMouseUpCallback=this.onPinMouseUp.bind(this);
this.pinMouseOutCallback=this.onPinMouseOut.bind(this);
this.element.observe('mouseover', this.divMouseOverCallback);
this.element.observe('mouseout', this.divMouseOutCallback);
this.element.observe('click', this.divClickCallback);
this.elePin.observe('click', this.pinClickCallback);
this.elePin.observe('mousedown', this.pinMouseDownCallback);
this.element.observe('mousedown', this.divMouseDownCallback);
},
Update: function(dPosition, iValue, sComment) {
this.elePrgText.update(iValue+'%');
this.elePrg.setStyle({width: iValue+'%'});
this.eleComment.update(sComment);
var viewport=document.viewport.getDimensions();
this.element.setStyle({top: parseInt(viewport.height-this.interval*(dPosition+0))+'px', left: (viewport.width+ProgressBar.BaseOffset)+'px'});
},
PlaceY: function(dPositionY) {
var viewportHeight=document.viewport.getHeight();
this.element.setStyle({top: parseInt(viewportHeight-this.interval*(dPositionY+0))+'px'});
},
PlaceX: function(dPositionX) {
var viewportWidth=document.viewport.getWidth();
this.element.setStyle({left: parseInt(viewportWidth+ProgressBar.BaseOffset)+'px'});
},
Remove: function() {
if(!this.element) return;
document.body.removeChild(this.element);
},
Pin: function() {
this.elePin.addClassName('PB_PinActive');
this.elePin.removeClassName('PB_PinInactive');
this.opacity="1.0";
this.showComment=true;
this.oManager.Pin(this.ID);
this.eleTip.setStyle({display: 'inline'});
$(this.eleProgressPanel).setStyle({opacity: '1'});
},
Unpin: function() {
this.elePin.addClassName('PB_PinInactive');
this.elePin.removeClassName('PB_PinActive');
this.opacity="0.5";
this.showComment=false;
this.oManager.Unpin(this.ID);
},
onDivMouseOver: function(event) {
if(!this.eleComment) return;
this.eleTip.setStyle({display: 'inline'});
$(this.eleProgressPanel).setStyle({opacity: '1'});
},
onDivMouseOut: function(event) {
if(!this.eleComment) return;
if(this.showComment) this.eleTip.setStyle({display: 'inline'});
else this.eleTip.setStyle({display: 'none'});
$(this.eleProgressPanel).setStyle({opacity: this.opacity});
},
onDivClick: function(event) {
},
onPinClick: function(event) {
if(this.showComment) {
this.Unpin();
}
else {
this.Pin();
}
event.stop();
},
onPinMouseDown: function(event) {
this.elePin.observe('mouseup', this.pinMouseUpCallback);
this.elePin.observe('mouseout', this.pinMouseOutCallback);
this.elePin.addClassName('PB_PinButtonPressed');
event.stop();
},
onPinMouseUp: function(event) {
this.elePin.stopObserving('mouseup', this.pinMouseUpCallback);
this.elePin.stopObserving('mouseout', this.pinMouseOutCallback);
this.elePin.removeClassName('PB_PinButtonPressed');
},
onPinMouseOut: function(event) {
this.onPinMouseUp(event);
},
onDivMouseDown: function(event) {
this.element.stopObserving('mouseout', this.divMouseOutCallback);
$(document).observe('mousemove', this.divMouseMoveCallback);
$(document).observe('mouseup', this.divMouseUpCallback);
this.startX=event.pointerX();
},
onDivMouseUp: function(event) {
$(document).stopObserving('mousemove', this.divMouseMoveCallback);
$(document).stopObserving('mouseup', this.divMouseUpCallback);
this.element.observe('mouseout', this.divMouseOutCallback);
},
onDivMouseMove: function(event) {
ProgressBar.BaseOffset+=(event.pointerX()-this.startX);
if(ProgressBar.BaseOffset>0) ProgressBar.BaseOffset=0;
this.startX=event.pointerX();
this.oManager.Refresh();
event.stop();
}
});
ProgressBar.BaseOffset=0;
var ProgressBarMgrClass = Class.create({
initialize: function() {
this.progressMap={};
this.progressArray=[];
SubscribeOnEvent("Progress", "document", this.EventHandler, this);
},
EventHandler: function(evt) {
var data=evt.Data();
if(!data.ID) return;
var progresser=this.getProgresser(data.ID);
if(data.Comment) progresser.Comment=data.Comment;
if(data.Percentage) progresser.Percentage=parseInt(data.Percentage.toString());
if(data.Error=="yes" || data.Error=="true") progresser.Bar.Pin();
if(progresser.Percentage>=100) {
progresser.Bar.Update(progresser.Position, 100, progresser.Comment);
this.deleteProgresser.bind(this, data.ID).delay(1);
}
else progresser.Bar.Update(progresser.Position, progresser.Percentage, progresser.Comment);
// alert("Progress of "+progresser.Comment+" = "+progresser.Percentage);
},
Refresh: function() {
for(var i=0; iindex) --this.progressMap[i];
}
this.progressArray.splice(index, 1);
delete this.progressMap[id];
this.drop.bind(this, index, 0).delay(.1);
}
},
drop: function(iIndex, iStep) {
if(iStep>100) iStep=100;
for(var index=iIndex; index