/openshift/adei

To get this branch, use:
bzr branch http://darksoft.org/webbzr/openshift/adei

« back to all changes in this revision

Viewing changes to js/graphcontrol.js

  • Committer: Suren A. Chilingaryan
  • Date: 2011-01-26 02:48:39 UTC
  • mto: This revision was merged to the branch mainline in revision 212.
  • Revision ID: csa@dside.dyndns.org-20110126024839-nv6qp2ie9stmd2dn
Support of Appled devices by Toni Pirhonen

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function GRAPHCONTROL(showid,showcontrolsdiv,imgdiv,windowref,graphimg,emaildiv,sensordiv){
 
2
    this.showhidebutton = document.getElementById(showcontrolsdiv);
 
3
    this.controls = document.getElementById(showid);
 
4
    this.imgdiv = document.getElementById(imgdiv);
 
5
    this.graphimg = document.getElementById(graphimg);
 
6
    this.emaildiv = document.getElementById(emaildiv);
 
7
    this.sensordiv = document.getElementById(sensordiv);
 
8
    var num = 0;
 
9
    this.win = windowref;
 
10
    this.path;
 
11
    Event.observe(this.showhidebutton,'click', this.showhide.bindAsEventListener(this));
 
12
    Event.observe(this.controls, 'click', this.showhide.bindAsEventListener(this));
 
13
}
 
14
GRAPHCONTROL.prototype.showhide = function(ev){
 
15
    if (this.num == 1){
 
16
        this.controls.style.visibility = 'visible';
 
17
        this.num=0;
 
18
    }else{
 
19
        this.controls.style.visibility = 'hidden';
 
20
        this.num=1;
 
21
    }
 
22
    this.StopPropagation(ev);
 
23
}
 
24
GRAPHCONTROL.prototype.StopPropagation = function(ev){
 
25
    if (!ev) var ev = window.event;
 
26
    if (ev)if (ev.cancelBubble)ev.cancelBubble = true;
 
27
    if (ev)if (ev.stopPropagation) ev.stopPropagation();
 
28
 
 
29
}
 
30
GRAPHCONTROL.prototype.sendEmail = function(){
 
31
    try{
 
32
        var     props = "url="+ window.location;
 
33
        props += "&from="+ document.getElementById('from').value;
 
34
        props += "&to="+document.getElementById('tomail').value;
 
35
        props += "&message="+document.getElementById('message').value;
 
36
        props += "&attachement=" + this.path;
 
37
        props += "&task=Send";
 
38
        props = props.replace('#','&');
 
39
        new Ajax.Request(
 
40
            adei.GetServiceURL('email',props),
 
41
            {
 
42
                method: 'get',
 
43
                onSuccess: this.MailSent(this),
 
44
                onFailure: this.MailFail(this)
 
45
            }
 
46
        );
 
47
    } catch (err) {
 
48
        alert("FAILED : "+ err);
 
49
    }
 
50
}
 
51
 
 
52
 
 
53
GRAPHCONTROL.prototype.MailSent = function(graphcontrol) {
 
54
    return function(transport) {
 
55
        if (!transport && !transport.responseText) alert("Unexpected content received");
 
56
        else alert("Success : " + transport.responseText);
 
57
    }
 
58
}
 
59
 
 
60
GRAPHCONTROL.prototype.MailFail = function(graphcontrol) {
 
61
    return function(transport) {
 
62
        alert("No data was returned by the service");
 
63
    }
 
64
}
 
65
 
 
66
GRAPHCONTROL.prototype.openMailForm = function() {
 
67
    var serviceurl = adei.GetService('email');
 
68
    this.emaildiv.style.visibility = 'visible';
 
69
    adei.UpdateDIV('emailform',serviceurl,'email');
 
70
}
 
71
 
 
72
GRAPHCONTROL.prototype.closediv = function(type) {
 
73
    if (type=='imgdiv')this.imgdiv.style.visibility = 'hidden';
 
74
    if (type=='emailform')this.emaildiv.style.visibility = 'hidden';
 
75
    if (type=='sensordiv')this.sensordiv.style.visibility = 'hidden';
 
76
    this.StopPropagation();
 
77
}
 
78
 
 
79
GRAPHCONTROL.prototype.getSensors = function(){
 
80
    if (this.sensordiv) {
 
81
        var serviceurl = adei.GetService('email');
 
82
        serviceurl += "&"+adei.config.GetProps();
 
83
        serviceurl += "&task=getSensorList";
 
84
        this.sensordiv.style.visibility = 'visible';
 
85
        adei.UpdateDIV('sensorlist',serviceurl,'sensorlist',true);
 
86
    }
 
87
}
 
88
 
 
89
GRAPHCONTROL.prototype.loadImage = function(){
 
90
    var props = adei.config.GetProps();
 
91
    props += "&width=1024&height=640&task=genpic";
 
92
    try{
 
93
        new Ajax.Request(
 
94
            adei.GetServiceURL('email',props),
 
95
            {
 
96
                method: 'get',
 
97
                onSuccess: this.getFilePath(this),
 
98
                onFailure: this.failed(this)
 
99
            }
 
100
        );
 
101
        this.openMailForm();
 
102
    } catch (err) {
 
103
        alert("Request Failed : "+ err);
 
104
    }
 
105
}
 
106
 
 
107
GRAPHCONTROL.prototype.failed = function(graphcontrol) {
 
108
    return function(transport) {
 
109
        alert("Request returned onFailure : " + transport.responseText);
 
110
    }
 
111
}
 
112
GRAPHCONTROL.prototype.getFilePath = function(self) {
 
113
    return function(transport) {
 
114
        if (!transport && !transport.responseText) alert("Request returned no content");
 
115
        else{
 
116
            if (transport.responseText=='FAIL') alert("Creating temporary folder for image failed");
 
117
            else self.path = transport.responseText;
 
118
        }
 
119
    }
 
120
}
 
121
 
 
122
GRAPHCONTROL.prototype.genIMG = function(ev) {
 
123
    this.StopPropagation();
 
124
    this.loadImage();
 
125
}
 
126
 
 
127
GRAPHCONTROL.prototype.UseWindow = function(prop) {
 
128
    switch (prop){
 
129
    case "centerzoomin":
 
130
        this.win.window.CenterZoomIn();
 
131
        break;
 
132
    case "centerzoomout":
 
133
        this.win.window.CenterZoomOut();
 
134
        break;
 
135
    case "moveright":
 
136
        this.win.window.MoveRight();
 
137
        break;
 
138
    case "moveleft":
 
139
        this.win.window.MoveLeft();
 
140
        break;
 
141
    case "moveup":
 
142
        this.win.window.MoveUp();
 
143
        break;
 
144
    case "movedown":
 
145
        this.win.window.MoveDown();
 
146
        break;
 
147
    }
 
148
    this.StopPropagation();
 
149
}