/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
function GRAPHCONTROL(showid,showcontrolsdiv,imgdiv,windowref,graphimg,emaildiv,sensordiv){
    this.showhidebutton = document.getElementById(showcontrolsdiv);
    this.controls = document.getElementById(showid);
    this.imgdiv = document.getElementById(imgdiv);
    this.graphimg = document.getElementById(graphimg);
    this.emaildiv = document.getElementById(emaildiv);
    this.sensordiv = document.getElementById(sensordiv);
    var num = 0;
    this.win = windowref;
    this.path;
    Event.observe(this.showhidebutton,'click', this.showhide.bindAsEventListener(this));
    Event.observe(this.controls, 'click', this.showhide.bindAsEventListener(this));
}
GRAPHCONTROL.prototype.showhide = function(ev){
    if (this.num == 1){
        this.controls.style.visibility = 'visible';
        this.num=0;
    }else{
        this.controls.style.visibility = 'hidden';
        this.num=1;
    }
    this.StopPropagation(ev);
}
GRAPHCONTROL.prototype.StopPropagation = function(ev){
    if (!ev) var ev = window.event;
    if (ev)if (ev.cancelBubble)ev.cancelBubble = true;
    if (ev)if (ev.stopPropagation) ev.stopPropagation();

}
GRAPHCONTROL.prototype.sendEmail = function(){
    try{
        var	props = "url="+ window.location;
        props += "&from="+ document.getElementById('from').value;
        props += "&to="+document.getElementById('tomail').value;
        props += "&message="+document.getElementById('message').value;
        props += "&attachement=" + this.path;
        props += "&task=Send";
        props = props.replace('#','&');
        new Ajax.Request(
            adei.GetServiceURL('email',props),
    	    {
		method: 'get',
		onSuccess: this.MailSent(this),
		onFailure: this.MailFail(this)
    	    }
        );
    } catch (err) {
        alert("FAILED : "+ err);
    }
}


GRAPHCONTROL.prototype.MailSent = function(graphcontrol) {
    return function(transport) {
        if (!transport && !transport.responseText) alert("Unexpected content received");
        else alert("Success : " + transport.responseText);
    }
}

GRAPHCONTROL.prototype.MailFail = function(graphcontrol) {
    return function(transport) {
        alert("No data was returned by the service");
    }
}

GRAPHCONTROL.prototype.openMailForm = function() {
    var serviceurl = adei.GetService('email');
    this.emaildiv.style.visibility = 'visible';
    adei.UpdateDIV('emailform',serviceurl,'email');
}

GRAPHCONTROL.prototype.closediv = function(type) {
    if (type=='imgdiv')this.imgdiv.style.visibility = 'hidden';
    if (type=='emailform')this.emaildiv.style.visibility = 'hidden';
    if (type=='sensordiv')this.sensordiv.style.visibility = 'hidden';
    this.StopPropagation();
}

GRAPHCONTROL.prototype.getSensors = function(){
    if (this.sensordiv) {
        var serviceurl = adei.GetService('email');
        serviceurl += "&"+adei.config.GetProps();
        serviceurl += "&task=getSensorList";
        this.sensordiv.style.visibility = 'visible';
        adei.UpdateDIV('sensorlist',serviceurl,'sensorlist',true);
    }
}

GRAPHCONTROL.prototype.loadImage = function(){
    var props = adei.config.GetProps();
    props += "&width=1024&height=640&task=genpic";
    try{
        new Ajax.Request(
            adei.GetServiceURL('email',props),
    	    {
		method: 'get',
		onSuccess: this.getFilePath(this),
		onFailure: this.failed(this)
    	    }
        );
        this.openMailForm();
    } catch (err) {
        alert("Request Failed : "+ err);
    }
}

GRAPHCONTROL.prototype.failed = function(graphcontrol) {
    return function(transport) {
        alert("Request returned onFailure : " + transport.responseText);
    }
}
GRAPHCONTROL.prototype.getFilePath = function(self) {
    return function(transport) {
        if (!transport && !transport.responseText) alert("Request returned no content");
        else{
            if (transport.responseText=='FAIL') alert("Creating temporary folder for image failed");
            else self.path = transport.responseText;
        }
    }
}

GRAPHCONTROL.prototype.genIMG = function(ev) {
    this.StopPropagation();
    this.loadImage();
}

GRAPHCONTROL.prototype.UseWindow = function(prop) {
    switch (prop){
    case "centerzoomin":
        this.win.window.CenterZoomIn();
        break;
    case "centerzoomout":
        this.win.window.CenterZoomOut();
        break;
    case "moveright":
        this.win.window.MoveRight();
        break;
    case "moveleft":
        this.win.window.MoveLeft();
        break;
    case "moveup":
        this.win.window.MoveUp();
        break;
    case "movedown":
        this.win.window.MoveDown();
        break;
    }
    this.StopPropagation();
}