Project

General

Profile

Download (5.88 KB) Statistics
| Branch: | Revision:
1
// dojo.provide('evd.tunnel');
2

    
3
// dojo.require('evd.uid');
4

    
5
// dojo.require('dijit.Dialog');
6
// dojo.require('dijit.form.Button');
7
// dojo.require('dijit.form.Form');
8
// dojo.require('dijit.form.TextBox');
9
// dojo.require('dojox.NodeList.delegate');
10

    
11
// dojo.require('java.applet');
12

    
13
// (function(/* Window */$){
14

    
15
// var archive = '/stabile/static/applet/evd.jar',
16

    
17
//     id = uid(),
18
//     start_args,
19
//     start_node,
20
//     local_port = 8240,
21
    
22
//     code = 'Tunnel',
23
//     callback = 'tunnel.javatrigger',
24
//     connected = false,
25
//     password = '',
26
    
27
//     port_dialog = null,
28
    
29
//     // EVENTS
30
//     INJECT = 'tunnel:inject',
31
//     INIT = 'tunnel:init',
32
//     DESTROY = 'tunnel:destroy',
33
//     BIND_ERROR = 'tunnel:bind_error',
34
//     PASSWORD_ERROR = 'tunnel:password_error',
35
//     CONNECTED = 'tunnel:connected';
36
    
37
//     // event handlers.
38
// dojo.subscribe(DESTROY, function(obj){
39
//     connected = false;
40
//     function doIt(){
41
//         dojo.destroy(id);
42
//     }
43
//     // otherwise browser begins to hang on several requests...?
44
//     setTimeout(doIt, 0);
45
// });
46

    
47
// dojo.subscribe(PASSWORD_ERROR, function(obj){
48
//     dojo.destroy(id);
49

    
50
//     getPassword();
51

    
52
//     dojo.query('#tunnel-password-form').onsubmit(function(e){
53
//         e.preventDefault();                                     
54
//         password = this.password.value;
55
                                 
56
//         start(start_node, start_args);
57
//         password_dialog.hide();
58
//     });
59
// });
60

    
61
// dojo.subscribe(BIND_ERROR, function(obj){
62
//     dojo.destroy(id);
63
//     getPort();
64
// });
65

    
66
// dojo.subscribe(INIT, function(){
67
//     connected = true;
68
// });
69

    
70
// function javatrigger(eventname, id, msg){
71
//     function f(){
72
//         dojo.publish('tunnel:' + eventname, [{id:id,msg:msg}]);
73
//     }
74
//     setTimeout(f, 0);
75
// }
76

    
77
// function start(node, args){
78
//     console.log('evd::start', node, dojo.byId(node), args);
79
    
80
//     dojo.publish(tunnel.INJECT);
81
//     start_args = args;
82
//     start_node = node;
83
    
84
//     if(!connected){
85

    
86
//         $.applet.inject(node, {
87
//             archive: archive, 
88
//             id: id,
89
//             code: code,
90
//             callback: callback,
91
//             local_port: local_port,
92
//             password: password,
93
//             remote_port: args.remote_port,                                         
94
//             remote_ip: args.remote_ip,
95
//             username: args.username,
96
//             host: args.host
97
//         });
98
//     }
99
//     else{
100
//         dojo.publish(tunnel.INIT);
101
//         dojo.publish(tunnel.CONNECTED);
102
//     }
103
// }
104

    
105
// var password_dialog = function(){
106

    
107
//     var dialog = new dijit.Dialog({
108
//         title: "Enter password",
109
//         style: "width: 250px"
110
//     });
111

    
112
//     var content = [
113
//         '<div id="tunnel-password-form" dojoType="dijit.form.Form" style="text-align:center">',
114
//         '    <div>',
115
//         '        Password:',
116
//         '        <input id="tunnel-password" type="password" name="password" dojoType="dijit.form.TextBox" style="width:100px"/>',
117
//         '    </div>',
118
//         '    <div style="margin-top:5px;">',
119
//         '        <button type="submit" dojoType="dijit.form.Button">OK</button>',
120
//         '    </div>',
121
//         '</div>'].join('');
122
//     dialog.set('content', content);
123
//     return dialog;
124
//  }();
125

    
126
// function getPortDialog(){
127
//     if(!port_dialog){
128
//         return new dijit.Dialog({
129
//             style: "width: 300px"
130
//         });
131
//     }
132
//     return port_dialog;
133
// }
134
    
135
// function setPortDialogContents(){
136
//     var new_port = Number(local_port) + 1;
137

    
138
//     var content = [
139
//         '<div id="tunnel-port-form" dojoType="dijit.form.Form" style="text-align:center">',
140
//         '    <div>',
141
//         '        A free local port:',
142
//         '        <input id="port" type="port" name="port" dojoType="dijit.form.TextBox" style="width:100px" value="' + new_port + '" />',
143
//         '    </div>',
144
//         '    <div style="margin-top:5px;">',
145
//         '        <button type="submit" dojoType="dijit.form.Button">OK</button>',
146
//         '    </div>',
147
//         '</div>'].join('');
148
//     port_dialog.set('title','local port ' + local_port + ' is busy');
149
//     port_dialog.set('content', content);
150
// }
151

    
152
// function addPortDialogSubmitHandler(){
153
//     dojo.connect(dojo.byId('tunnel-port-form'), "onsubmit", function(e){
154
//         e.preventDefault();                    
155
//         local_port = this.port.value;
156
//         port_dialog.hide();
157
//         start(start_node, start_args);
158
//     });
159
// }
160

    
161
// function getPassword(){
162
//     password_dialog.show();
163
// }
164

    
165
// function getPort(){
166
//     port_dialog = getPortDialog();
167
//     setPortDialogContents();
168
//     port_dialog.show();
169
//     addPortDialogSubmitHandler();
170
// }
171

    
172
// function destroy(){
173
//     lg("tunnel::destroy", "connected", connected);
174
//     if(connected){
175
//         dojo.publish(tunnel.DESTROY);
176
//     }
177
// }
178

    
179
//     // destroy: function(){
180
//     //     lg("tunnel::destroy");
181
//     //     var def = new dojo.Deferred();
182

    
183
//     //     var h = dojo.connect(this, "onDestroy", function(){
184
//     //         dojo.disconnect(h);
185
//     //         def.callback();
186
//     //     });
187

    
188
//     //     if(dojo.isMac && dojo.isFF){
189
//     //         // That bitch doesn't call destroy on the applet when removed from the DOM
190
//     //         if(this._applet){
191
//     //             this._applet.destroy();
192
//     //             this._applet = null;
193
//     //         }
194
//     //     }
195

    
196
//     //     dojo.destroy('tunnel');
197
        
198
//     //     return def;
199
//     // },
200

    
201
// $.tunnel = {
202
//     javatrigger: javatrigger,
203
//     start: start,
204
//     destroy:destroy,
205
//     getLocalPort: function(){return local_port;},
206
    
207
//     // events
208
//     INJECT : INJECT,
209
//     INIT : INIT,
210
//     DESTROY : DESTROY,
211
//     BIND_ERROR : BIND_ERROR,
212
//     PASSWORD_ERROR : PASSWORD_ERROR,
213
//     CONNECTED : CONNECTED
214
// };
215

    
216
// })(window);
(4-4/6)