This repository was archived by the owner on Dec 26, 2023. It is now read-only.
forked from feincms/feincms
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpage_toolbox.js
More file actions
209 lines (176 loc) · 5.25 KB
/
Copy pathpage_toolbox.js
File metadata and controls
209 lines (176 loc) · 5.25 KB
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
/* All things javascript specific for the classic page change list */
/* 25b6: black right-pointing triangle, 25bc: black down-pointing triangle,
25b7: white right-pointing triangle, 25BD: white down-pointing triangle */
var expand_sym = '\u25B7';
var collapse_sym = '\u25BD';
var feincms_page_open_list;
var page = function(item_id) { return tree_structure[item_id]; }
var recolor_lines = function()
{
$('tbody tr').removeClass('row1').removeClass('row2');
$('tbody tr:visible:even').addClass('row1');
$('tbody tr:visible:odd').addClass('row2');
}
/* show all immediate children, then open all children that are marked as open */
var open_subtree = function(item_id)
{
var p = page(item_id)
if(p.children.length == 0)
return;
p.ptr.html(collapse_sym);
$.each(p.children, function(i, id)
{
pp = page(id)
if(pp.ptr)
{
pp.row.show();
if(pp.open)
open_subtree(id);
}
});
}
/* hide all descendants */
var close_subtree = function(item_id)
{
var p = page(item_id)
if(!p.id || !p.children || p.children.length == 0)
return false;
p.ptr.html(expand_sym);
$.each(p.descendants, function(i, id)
{
var pp = page(id);
if(pp.ptr)
pp.row.hide()
});
}
/* Click handler */
var page_tree_handler = function(item_id)
{
var p = page(item_id);
if(!p.id || !p.children || p.children.length == 0)
return false;
var open = p.open;
p.open = !open;
if(open)
{
close_subtree(item_id);
feincms_page_open_list = feincms_page_open_list.filter(function(o) { return o != item_id });
}
else
{
open_subtree(item_id);
feincms_page_open_list.push(item_id);
}
/* Do I really want that? */
recolor_lines();
return false;
}
/* Clean out tree_structure: Remove non existant parents, children, descendants */
var tree_structure_clean = function()
{
feincms_page_open_list = $.cookie('feincms_page_open_list');
/* Keep a list of open pages to save state across reloads */
if(feincms_page_open_list) {
var lst = feincms_page_open_list.split(',');
feincms_page_open_list = [];
for(var i=0; i<lst.length; i++)
feincms_page_open_list.push(parseInt(lst[i]));
} else
feincms_page_open_list = [];
$(window).unload(function(){
$.cookie('feincms_page_open_list', feincms_page_open_list.join(','));
});
for(k in tree_structure)
{
var p = page(k);
/* Precompute object links for no object-id lookups later */
m = $('#page_marker-' + k);
if(m.length)
{
p.ptr = m;
p.row = m.parents('tr:first');
}
else /* row not present in changelist, throw node away */
{
tree_structure[k] = { }
}
}
/* Clean out tree_structure: Remove non existant parents, children, descendants */
for(k in tree_structure)
{
var p = page(k);
if(p.parent && !page(p.parent).ptr)
p.parent = null
if(p.descendants)
p.descendants = $.grep(p.descendants, function(o) { return page(o).ptr; });
if(p.children)
{
p.children = $.grep(p.children, function(o) { return page(o).ptr; });
if(p.children.length)
p.ptr.html(expand_sym);
}
}
for(i in feincms_page_open_list)
{
var item_id = feincms_page_open_list[i];
var p = page(item_id);
// pages could have been deleted
if(p) p.open = true;
}
}
var close_entire_tree = function()
{
for(k in tree_structure)
{
close_subtree(k);
}
feincms_page_open_list = []
recolor_lines();
}
var open_entire_tree = function()
{
feincms_page_open_list = []
for(k in tree_structure)
{
if(page(k) && page(k).children)
{
open_subtree(k);
feincms_page_open_list.push(k);
}
}
recolor_lines();
}
/* Cut/Copy/Paste support */
// FIXME: This changes the site structure and would need to refresh at least the
// tree_structure (if not more, eg. page filter). Easy way out: reload the page.
var cut_item_pk = null;
function cut_item(pk, elem) {
var row = $(elem.parentNode.parentNode);
if(row.hasClass('cut')) {
cut_item_pk = null;
$('a.paste_target').hide();
row.removeClass('cut');
} else {
cut_item_pk = pk;
$('a.paste_target').show();
$('tr').removeClass('cut');
row.addClass('cut').find('a.paste_target').hide();
}
return false;
}
function paste_item(pk, position) {
if(!cut_item_pk)
return false;
$.post('.', {
'__cmd': 'move_node',
'position': position,
'cut_item': cut_item_pk,
'pasted_on': pk
}, function(data) {
if(data == 'OK')
window.location.reload();
else
alert(data);
});
return false;
}