-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunctions.js
145 lines (130 loc) · 3.99 KB
/
functions.js
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
/**
* This file is part of RLO-Plan.
*
* Copyright 2009 Tillmann Karras, Josua Grawitter
*
* RLO-Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RLO-Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with RLO-Plan. If not, see <http://www.gnu.org/licenses/>.
*/
function remove(element) {
element.parentNode.removeChild(element);
}
function newElement(type) {
return document.createElement(type);
}
function newCell(value) {
var cell = newElement('td');
cell.innerHTML = value;
return cell;
}
function newButton(caption, action) {
var button = newElement('button');
//button.type = 'button'; // not supported by IE8
button.innerHTML = caption;
button.onclick = function() {
action(this);
};
return button;
}
function newStatus(text, element) {
var status = newElement('span');
status.textContent = text;
element.appendChild(status);
return status;
}
function remove_status(status, xhr) {
var success = false;
if (xhr) {
success = xhr.status == 200;
status.textContent = success ? 'OK' : xhr.responseText;
} else {
status.textContent = 'Konnte nicht gespeichert werden';
}
status.style.background = success ? 'lightgreen' : '#FF8888';
setTimeout(function() {
fade_out(status);
}, 2000, 'JavaScript');
}
function hide_buttons(button) {
button.style.display = 'none';
button.nextSibling.style.display = 'none';
}
function show_buttons(button) {
button.style.display = 'inline-block';
button.nextSibling.style.display = 'inline-block';
}
function send_msg(msg, callback, error_callback) {
function newXHR() {
var xhr = null;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xhr = new ActiveXObject('Microsoft.XMLHTTP');
}
return xhr;
}
var xhr = newXHR();
if (xhr) {
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
callback(xhr);
}
};
// url is defined in the calling html document
// callback used as a boolean value here
xhr.open('POST', url, callback);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.send(msg);
} else {
error_callback ? error_callback() : alert('Diese Funktion erfordert einen neueren Browser.');
}
return xhr;
}
function fade_out(e) {
if (!e.style.opacity) {
e.style.opacity = 1.0;
}
setTimeout(function() {
if (e.style.opacity > 0) {
e.style.opacity -= 0.1;
fade_out(e);
} else {
remove(e);
}
}, 100, 'JavaScript');
}
function make_textbox(cell, i) {
var textbox = newElement('input');
textbox.type = 'text';
textbox.value = cell.textContent;
textbox.maxLength = column_maxLengths[i];
textbox.style.width = column_widths[i];
cell.innerHTML = '';
cell.appendChild(textbox);
}
function make_backup(cell, value) {
var backup = newElement('span');
backup.style.display = 'none';
backup.textContent = value;
cell.appendChild(backup);
}
function cancel_editing(button) {
var saveButton = button.previousSibling;
hide_buttons(saveButton);
show_buttons(saveButton.previousSibling.previousSibling);
var row = button.parentNode.parentNode;
for (var i = 0; i < row.childNodes.length - 1; i++) {
var cell = row.childNodes[i];
cell.textContent = cell.lastChild.textContent;
}
}