/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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
function POPUP(cb, cbattr) {
    this.popup_states = new Array();
    this.popup_callback = new Array();
    this.popup_rewidth_callback = new Array();
    this.popup_reheight_callback = new Array();
    this.popup_on_callbacks = new Array();
    this.popup_off_callbacks = new Array();
    this.current_height = new Array();
    this.popups = new Array();
    this.modules = new Array();
    this.controls = new Array();
    this.popups_width = 300;
    this.num_opened = 0;

    this.super_popup = false;

    this.resizable = null;
    
    if (typeof cb != "undefined") this.RegisterCallback(cb,cbattr);
}

POPUP.prototype.RegisterPopup = function(module) {
    this.popups.push(module);
    this.controls[module] = new Array();
    this.popup_states[module] = 0;
}

POPUP.prototype.RegisterControlsModule = function(module, cmod) {
    if (typeof this.controls[module] == "undefined") {
	this.RegisterPopup(module);
    }

    this.modules[module] = cmod;
}

POPUP.prototype.RegisterControl = function(module, control) {
    if (typeof this.controls[module] == "undefined") {
	this.RegisterPopup(module);
    }
    
    this.controls[module].push(control);
}

POPUP.prototype.FindControl = function(control) {
    for (var i = 0; i < this.popups.length; i++) {
        var popup = this.popups[i];
	if (typeof this.controls[popup] != "undefind") {
	    for (var j = 0; j < this.controls[popup].length; j++) {
		if (this.controls[popup][j] == control) {
		    return popup;
		}
	    }
	}
    }
    return false;
}

POPUP.prototype.OpenControl = function(control) {
    var popup = this.FindControl(control);
    var module = this.modules[popup];
    
    if ((popup)&&(module)) {
	this.Open(popup);
	module.Open(control);
    }
}


POPUP.prototype.TryFixedSizeMode = function(sidebar, popup, geometry_node) {
    this.super_popup = false;
    
    var node = domGetLastChildByName(sidebar, "div");
    if (!node) return;
    
    if (!domGetFirstChildByName(node, "table")) {
	node = domGetLastChildByName(node, "div");
	if (!node) return;
	
	var subnodes = node.getElementsByTagName("table");
	if ((!subnodes)||(!subnodes.length))
	    alert("problem detecting popups structure");
    }
    this.super_node = node;

    var switch_node = document.getElementById("popup_switch_" + popup);
    nodes = switch_node.getElementsByTagName("button");
    if ((!nodes)||(!nodes.length)) {
	alert("problem detecting popups structure");
	return;
    }
    
    this.geometry_nodes = new Array();
    
    if (geometry_node) {
	node = document.getElementById(geometry_node);
	if (!node) {
	    alert("Invalid geometry_node is supplied");
	    return;
	}
	this.geometry_nodes.push(node);
    }

    this.super_button = nodes[0];
    this.super_popup = popup;
}


POPUP.prototype.RegisterOnCallback = function (module, cb, cbattr, call_once) {
    if (typeof this.popup_on_callbacks[module] == "undefined")
	this.popup_on_callbacks[module] = new Array();
	
    if (typeof call_once == "undefined") call_once = false;
    
    this.popup_on_callbacks[module].push({ 'cb': cb, 'cbattr': cbattr, 'once': call_once });
}

POPUP.prototype.RegisterOffCallback = function(module, cb, cbattr) {
    if (typeof this.popup_off_callbacks[module] == "undefined")
	this.popup_off_callbacks[module] = new Array();
    
    this.popup_off_callbacks[module].push({ 'cb': cb, 'cbattr': cbattr });
}

POPUP.prototype.RegisterCallback = function(cb, cbattr) {
	this.popup_callback.push ({ 'cb': cb, 'cbattr': cbattr });
}

POPUP.prototype.RegisterReWidthCallback = function(cb, cbattr) {
	this.popup_rewidth_callback.push ({ 'cb': cb, 'cbattr': cbattr });
}

POPUP.prototype.RegisterReHeightCallback = function(cb, cbattr) {
	this.popup_reheight_callback.push ({ 'cb': cb, 'cbattr': cbattr });
}

POPUP.prototype.GetEncompasingNode = function(node) {
//    return node.parentNode.parentNode.parentNode.parentNode.parentNode;
    return node.parentNode.parentNode.parentNode.parentNode;
}

POPUP.prototype.RunReWidthCallbacksFunction = function(self) {
    return function() {
	for (var i = 0; i < self.popup_rewidth_callback.length; i++) {
    	    var cb = self.popup_rewidth_callback[i];
    	    cb.cb(cb.cbattr);
	}
    }
}

POPUP.prototype.RunReHeightCallbacksFunction = function(self) {
    return function() {
	for (var i = 0; i < self.popup_reheight_callback.length; i++) {
    	    var cb = self.popup_reheight_callback[i];
    	    cb.cb(cb.cbattr);
	}
    }
}

POPUP.prototype.RunReWidthCallbacks = function() {
    setTimeout(this.RunReWidthCallbacksFunction(this), adei.cfg.parse_delay);
}

POPUP.prototype.RunReHeightCallbacks = function() {
    setTimeout(this.RunReHeightCallbacksFunction(this), adei.cfg.parse_delay);
}


POPUP.prototype.UpdateGeometry = function(module) {
    this.UpdateGlobalGeometry();
    
    with (this) {
	var node = document.getElementById("popup_" + module);
	var switch_node = document.getElementById("popup_switch_" + module);

	    /* Table fills not all available space, we can't fix it by width
	    attribute in HTML since it will prevent hiding. So, fixing here */
	var tbl_node = this.GetEncompasingNode(node);
	
	if (node) {
	    var cur_width_value = tbl_node.offsetWidth;
	    
	    if (cur_width_value > this.popups_width) {
		this.popups_width = cur_width_value;

//		for (var popup in this.popup_states) {
		for (var i = 0; i < this.popups.length; i++) {
		    var popup = this.popups[i];
		    if (this.popup_states[popup]) {
			var popup_node = document.getElementById("popup_" + popup);
			var popup_tbl_node = this.GetEncompasingNode(node);
			if (popup_node) {
//			    if (popup_tbl_node.offsetWidth < this.popups_width) {
				domSetMinWidth(popup_node, this.popups_width, false, popup_tbl_node.parentNode);
//			    }
			}
		    }
		}

		if (this.num_opened) { /* otherwise calling in Open */
		    this.RunReWidthCallbacks();
		}
	    } else if (cur_width_value < this.popups_width) {
		domSetMinWidth(node, this.popups_width, false, tbl_node.parentNode);
	    }
	}
	
	if ((node)&&(switch_node)&&(module!=this.super_popup)) {
	    var a = switch_node.getElementsByTagName("button")[0];
	    if (a) {
		var new_height_value = node.parentNode.offsetHeight; // td
		if (!this.current_height[module]) this.current_height[module] = a.offsetHeight;
				
		if (this.current_height[module] < new_height_value) { 
		    this.current_height[module] = new_height_value;
		    domSetMinHeight(a, new_height_value, false, a.parentNode); //td checking
		    this.RunReHeightCallbacks();
		}
	    }
	}

    }
}

POPUP.prototype.Open = function (module) {
    if (!this.popup_states[module]) {
	this.Switch(module);
    }
}

POPUP.prototype.Close = function (module) {
    if (this.popup_states[module]) {
	this.Switch(module);
    }
}

POPUP.prototype.Switch = function (module) {
 with (this) {
    if (typeof this.popup_states[module] == "undefined") {
	this.RegisterPopup(module);
    }

    if (this.popup_states[module]) {
	if (client.isKonqueror()) {
		// domHide is not working properly in Konqueror 
	    var node = document.getElementById("popup_" + module);
	    if (node) {
		var tdnode = node.parentNode;
//		node.style.witdth = "0px";
		tdnode.style.width = "0px";
//		tdnode.style.display = "none";
	    }
	}
	
	domHide("popup_" + module);

	this.popup_states[module] = 0;

        if (typeof this.popup_off_callbacks[module] != "undefined") {
	    for (var i = 0; i < this.popup_off_callbacks[module].length; i++) {
    		var cb = this.popup_off_callbacks[module][i];
    		cb.cb(cb.cbattr, false);
	    }
	}
	
	this.num_opened--;

	if (!this.num_opened) this.RunReWidthCallbacks();
    } else {
	domShow("popup_" + module);

	if (client.isKonqueror()) {
		// domHide is not working properly in Konqueror 
	    var node = document.getElementById("popup_" + module);
	    if (node) {
		var tdnode = node.parentNode;
		tdnode.style.width = "1px";
	    }
	}


	this.UpdateGeometry(module);
	popup_states[module] = 1;

        if (typeof this.popup_on_callbacks[module] != "undefined") {
	    for (var i = 0; i < this.popup_on_callbacks[module].length; i++) {
    		var cb = this.popup_on_callbacks[module][i];
    		cb.cb(cb.cbattr, true);
		if (cb.once) {
		    this.popup_on_callbacks[module].splice(i,1);
		    i = i - 1;
		}
	    }

	}


	if (!this.num_opened) this.RunReWidthCallbacks();
	this.num_opened++;
    }
    
    for (var i = 0; i < popup_callback.length; i++) {
	var cb = popup_callback[i];
	cb.cb(cb.cbattr);
    }
 }
}

POPUP.prototype.RunCallbacks = function() {
 with (this) {
    for (var i = 0; i < popup_callback.length; i++) {
	var cb = popup_callback[i];
	cb.cb(cb.cbattr);
    }
 }
}

POPUP.prototype.UpdateGlobalGeometry = function(height, vend) {
    if (!this.super_popup) return;
    
    if (vend) this.global_end = vend;
    else if (this.global_end) vend = this.global_end;
    else return;

    var mboffset = domGetNodeOffset(this.super_node);
    var real_size = vend - mboffset[1];

    var mboffset = domGetNodeOffset(this.super_button);
    var new_size = vend - mboffset[1];
    domSetHeight(this.super_button, new_size, true, this.super_node, real_size);

    if (!this.popup_states['controls']) return;

    for (var i = 0; i < this.geometry_nodes.length; ++i) {
	var node = this.geometry_nodes[i];
	var mboffset = domGetNodeOffset(node);

	var new_size = vend - mboffset[1];
	domSetHeight(node, new_size, true, this.super_node, real_size);
    }
}


function popupUpdateGeometryCallback(me, submodule) {
    me.popup.UpdateGeometry(me.module);
}