1 var disenable_currentBlock; |
1 addOnloadHook(function() |
2 function ajaxDisenableBlock(id) |
2 { |
3 { |
3 load_component(['jquery', 'jquery-ui']); |
4 disenable_currentBlock = document.getElementById('disabled_'+id); |
4 $('.sbedit-column').sortable({ |
5 ajaxGet(makeUrlNS('Special', 'EditSidebar', 'action=disenable&ajax=true&noheaders&id='+id), function() |
5 handle: '.sbedit-handle', |
6 { |
6 connectWith: '.sbedit-column', |
7 if ( ajax.readyState == 4 && ajax.status == 200 ) |
7 stop: function() |
8 { |
8 { |
9 if(ajax.responseText == 'GOOD') |
9 ajaxUpdateSidebarOrder(); |
10 { |
10 } |
11 if(disenable_currentBlock.style.display == 'none') |
11 }); |
12 { |
12 }); |
13 disenable_currentBlock.style.display = 'inline'; |
13 |
|
14 function serialize_sidebar() |
|
15 { |
|
16 var columns = {}; |
|
17 var i = 0; |
|
18 $('.sbedit-column').each(function(i, e) |
|
19 { |
|
20 var arr = $(e).sortable('toArray'); |
|
21 for ( var j = 0; j < arr.length; j++ ) |
|
22 arr[j] = parseInt(arr[j].replace(/^block:/, '')); |
|
23 |
|
24 i++; |
|
25 columns[i] = arr; |
|
26 }); |
|
27 return toJSONString(columns); |
|
28 } |
|
29 |
|
30 function sbedit_open_editor(a) |
|
31 { |
|
32 if ( auth_level < USER_LEVEL_ADMIN ) |
|
33 { |
|
34 load_component('login'); |
|
35 ajaxDynamicReauth(function(sid) |
|
36 { |
|
37 sbedit_open_editor(a); |
|
38 }, USER_LEVEL_ADMIN); |
|
39 return false; |
|
40 } |
|
41 load_component(['fadefilter', 'l10n']); |
|
42 var shade = darken(true, 50, 'sbedit-shade'); |
|
43 $(shade).css('z-index', 0); |
|
44 var parent = sbedit_get_parent(a); |
|
45 var offset = $(parent).offset(); |
|
46 var top = (( getHeight() ) / 2) - 200 + getScrollOffset(); |
|
47 var box = $(parent) |
|
48 .clone() |
|
49 .empty() |
|
50 .attr('id', 'sb_blockedit') |
|
51 .addClass('sbedit-float') |
|
52 .css('height', $(parent).height()) |
|
53 .css('top', offset.top) |
|
54 .css('left', offset.left) |
|
55 .appendTo('body') |
|
56 .animate({ width: 500, height: 400, top: top, left: (getWidth() / 2) - 250 }, 400, function() |
|
57 { |
|
58 var whitey = whiteOutElement(this); |
|
59 $(this).append('<textarea style="width: 100%; height: 90%;"></textarea>'); |
|
60 $(this).append('<p style="text-align: center;"><a href="#" onclick="sbedit_edit_save(this); return false;">' + $lang.get('etc_save_changes') + '</a> | <a href="#" onclick="sbedit_edit_cancel(this); return false;">' + $lang.get('etc_cancel') + '</a></p>'); |
|
61 $.get(makeUrlNS('Special', 'EditSidebar', 'action=getsource&noheaders&id=' + this.item_id), {}, function(response, statustext) |
|
62 { |
|
63 $('textarea', box).attr('value', response); |
|
64 $(whitey).remove(); |
|
65 }, 'html'); |
|
66 }) |
|
67 .get(0); |
|
68 box.parentdiv = parent; |
|
69 box.item_id = parseInt($(parent).attr('id').replace(/^block:/, '')); |
|
70 } |
|
71 |
|
72 function sbedit_edit_save(a) |
|
73 { |
|
74 var box = a.parentNode.parentNode; |
|
75 var parent = box.parentdiv; |
|
76 var whitey = whiteOutElement(box); |
|
77 $.post(makeUrlNS('Special', 'EditSidebar', 'noheaders&action=save&id=' + box.item_id), { content: $('textarea', box).attr('value') }, function(response, statustext) |
|
78 { |
|
79 whiteOutReportSuccess(whitey); |
|
80 setTimeout(function() |
|
81 { |
|
82 sbedit_close_editor(parent, box); |
|
83 }, 1250); |
|
84 }, 'html'); |
|
85 } |
|
86 |
|
87 function sbedit_edit_cancel(a) |
|
88 { |
|
89 var box = a.parentNode.parentNode; |
|
90 var parent = box.parentdiv; |
|
91 |
|
92 sbedit_close_editor(parent, box); |
|
93 } |
|
94 |
|
95 function sbedit_close_editor(parent, box) |
|
96 { |
|
97 var offset = $(parent).offset(); |
|
98 $(box).empty().animate( |
|
99 { |
|
100 width: $(parent).width(), |
|
101 height: $(parent).height(), |
|
102 top: offset.top, |
|
103 left: offset.left, |
|
104 }, 400, function() |
|
105 { |
|
106 $(this).css('background-color', '#f70').fadeOut(1000, function() { $(this).remove(); }); |
|
107 enlighten(true, 'sbedit-shade'); |
|
108 }); |
|
109 } |
|
110 |
|
111 function sbedit_delete_block(a) |
|
112 { |
|
113 var parent = sbedit_get_parent(a); |
|
114 load_component(['messagebox', 'fadefilter', 'flyin', 'l10n']); |
|
115 var mp = miniPromptMessage({ |
|
116 title: $lang.get('sbedit_msg_delete_confirm_title'), |
|
117 message: $lang.get('sbedit_msg_delete_confirm_body'), |
|
118 buttons: [ |
|
119 { |
|
120 text: $lang.get('sbedit_btn_delete_confirm'), |
|
121 color: 'red', |
|
122 onclick: function() |
|
123 { |
|
124 var mp = miniPromptGetParent(this); |
|
125 sbedit_delete_block_s2(mp.target_block); |
|
126 miniPromptDestroy(this); |
|
127 return false; |
|
128 }, |
|
129 style: { |
|
130 fontWeight: 'bold' |
14 } |
131 } |
15 else |
132 }, |
16 { |
133 { |
17 disenable_currentBlock.style.display = 'none'; |
134 text: $lang.get('etc_cancel'), |
|
135 onclick: function() |
|
136 { |
|
137 miniPromptDestroy(this); |
|
138 return false; |
18 } |
139 } |
19 } |
|
20 else |
|
21 { |
|
22 document.getElementById('ajaxEditContainer').innerHTML = ajax.responseText; |
|
23 } |
140 } |
24 } |
141 ] |
25 }); |
142 }); |
26 } |
143 mp.target_block = parent; |
27 |
144 } |
28 var delete_currentBlock; |
145 |
29 function ajaxDeleteBlock(id, oElm) |
146 function sbedit_delete_block_s2(box) |
30 { |
147 { |
31 delete_currentBlock = { 0 : id, 1 : oElm }; |
148 var parent = box; |
32 ajaxGet(makeUrlNS('Special', 'EditSidebar', 'action=delete&ajax=true&noheaders&id='+id), function() |
149 var id = parseInt($(parent).attr('id').replace(/^block:/, '')); |
33 { |
150 var whitey = whiteOutElement(parent); |
34 if ( ajax.readyState == 4 && ajax.status == 200 ) |
151 |
35 { |
152 $.get(makeUrlNS('Special', 'EditSidebar', 'action=delete&ajax=true&noheaders&id=' + id), function(response, statustext) |
36 if(ajax.responseText == 'GOOD') |
153 { |
37 { |
154 if ( response == 'GOOD' ) |
38 e = delete_currentBlock[1]; |
155 { |
39 e = e.parentNode.parentNode; |
156 whiteOutReportSuccess(whitey); |
40 e.parentNode.removeChild(e); |
157 setTimeout(function() |
41 } |
158 { |
42 else |
159 $(parent) |
43 { |
160 .hide('blind', { duration: 500 }, function() |
44 document.getElementById('ajaxEditContainer').innerHTML = ajax.responseText; |
161 { |
45 } |
162 $(this).remove(); |
46 } |
163 ajaxUpdateSidebarOrder(); |
47 }); |
164 }); |
48 } |
165 }, 1250); |
49 |
166 } |
50 var blockEdit_current; |
167 else |
51 function ajaxEditBlock(id, oElm) |
168 { |
52 { |
169 whiteOutReportFailure(whitey); |
53 blockEdit_current = { 0 : id, 1 : oElm }; |
170 alert(response); |
54 ajaxGet(makeUrlNS('Special', 'EditSidebar', 'action=getsource&noheaders&id='+id), function() |
171 } |
55 { |
172 }, 'html'); |
56 if ( ajax.readyState == 4 && ajax.status == 200 ) |
173 } |
57 { |
174 |
58 id = blockEdit_current[0]; |
175 function sbedit_rename_block(a) |
59 oElm = blockEdit_current[1]; |
176 { |
60 var thediv = document.createElement('div'); |
177 var parent = sbedit_get_parent(a); |
61 //if(!oElm.id) oElm.id = 'autoEditButton_'+Math.floor(Math.random() * 100000); |
178 $('div.sbedit-handle > span', parent).hide(); |
62 oElm = oElm.parentNode; |
179 var input = $('div.sbedit-handle > input', parent).show().focus().select().keyup(function(e) |
63 var magic = $(oElm).Top() + $(oElm).Height(); |
180 { |
64 var top = String(magic); |
181 switch(e.keyCode) |
65 top = top + 'px'; |
182 { |
66 left = $(oElm).Left() + 'px'; |
183 case 13: |
67 thediv.style.top = top; |
184 // enter |
68 thediv.style.left = left; |
185 var whitey = whiteOutElement(this.parentNode); |
69 thediv.style.position = 'absolute'; |
186 var me = this; |
70 thediv.className = 'mdg-comment'; |
187 var id = parseInt($(parent).attr('id').replace(/^block:/, '')); |
71 thediv.style.margin = '0'; |
188 $.post(makeUrlNS('Special', 'EditSidebar', 'ajax&noheaders&action=rename&id='+id), { newname: $(this).attr('value') }, function(response, statustext) |
72 if(ajax.responseText == 'HOUSTON_WE_HAVE_A_PLUGIN') |
189 { |
73 { |
190 if ( response == 'GOOD' ) |
74 thediv.innerHTML = '<h3>' + $lang.get('sbedit_msg_cant_edit_plugin_title') + '</h3><p>' + $lang.get('sbedit_msg_cant_edit_plugin_body', { close_link: 'a href="#" onclick="this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode); return false;"' }) + '</p>'; |
191 { |
75 } |
192 whiteOutReportSuccess(whitey); |
76 else |
193 setTimeout(function() |
77 { |
194 { |
78 ta = document.createElement('textarea'); |
195 $(me).hide(); |
79 ta.rows = '15'; |
196 $('span', me.parentNode).show().text(me.value); |
80 ta.cols = '50'; |
197 }, 1250); |
81 ta.innerHTML = ajax.responseText; |
198 } |
82 thediv.appendChild(ta); |
199 else |
83 b = document.createElement('br'); |
200 { |
84 thediv.appendChild(b); |
201 alert(response); |
85 thediv.innerHTML += '<a href="#" onclick="ajaxSaveBlock(this, \''+id+'\'); return false;">' + $lang.get('sbedit_btn_edit_save') + '</a> | <a href="#" onclick="if(confirm(\'' + $lang.get('sbedit_msg_discard_confirm') + '\')) this.parentNode.parentNode.removeChild(this.parentNode); return false;">' + $lang.get('sbedit_btn_edit_cancel') + '</a>'; |
202 whiteOutReportFailure(whitey); |
86 } |
203 } |
87 body = document.getElementsByTagName('body'); |
204 }, 'html'); |
88 body = body[0]; |
205 break; |
89 body.appendChild(thediv); |
206 case 27: |
90 } |
207 // escape |
91 }); |
208 this.value = this.origvalue; |
92 } |
209 $(this).hide(); |
93 |
210 $('span', this.parentNode).show(); |
94 var blockSave_current; |
211 break; |
95 function ajaxSaveBlock(oElm, id) |
212 } |
96 { |
213 }).get(0); |
97 taContent = escape(oElm.previousSibling.previousSibling.value); |
214 input.origvalue = input.value; |
98 taContent = taContent.replace(unescape('%0A'), '%0A'); |
215 } |
99 taContent = taContent.replace('+', '%2B'); |
216 |
100 blockSave_current = { 0 : id, 1 : oElm }; |
217 function sbedit_disenable_block(a) |
101 ajaxPost(makeUrlNS('Special', 'EditSidebar', 'noheaders&action=save&id='+id), 'content='+taContent, function() |
218 { |
102 { |
219 var parent = sbedit_get_parent(a); |
103 if ( ajax.readyState == 4 && ajax.status == 200 ) |
220 var whitey = whiteOutElement(parent); |
104 { |
221 $.get(makeUrlNS('Special', 'EditSidebar', 'action=disenable&ajax=true&noheaders&id=' + parseInt($(parent).attr('id').replace(/^block:/, ''))), {}, function(response, statustext) |
105 id = blockSave_current[0]; |
222 { |
106 oElm = blockSave_current[1]; |
223 if ( response == 'GOOD' ) |
107 eval(ajax.responseText); |
224 { |
108 if(status == 'GOOD') |
225 whiteOutReportSuccess(whitey); |
109 { |
226 $(parent).toggleClass('disabled'); |
110 var _id = 'disabled_' + String(id); |
227 } |
111 var parent = document.getElementById(_id).parentNode.parentNode; |
228 else |
112 oElm.parentNode.parentNode.removeChild(oElm.parentNode); |
229 { |
113 content = content.replace('%a', unescape('%0A')); |
230 whiteOutReportFailure(whitey); |
114 var obj = ( IE ) ? parent.firstChild.nextSibling.nextSibling : parent.firstChild.nextSibling.nextSibling.nextSibling; |
231 alert(response); |
115 if ( obj ) |
232 } |
116 obj.innerHTML = content; // $content is set in ajax.responseText |
233 }, 'html'); |
117 } |
234 } |
118 else |
235 |
119 { |
236 function sbedit_get_parent(a) |
120 alert(status); |
237 { |
121 } |
238 var o = a.parentNode; |
122 } |
239 while ( !$(o).hasClass('sbedit-block') ) |
123 }); |
240 o = o.parentNode; |
124 } |
241 |
125 |
242 return o; |
126 function ajaxRenameSidebarStage1(parent, id) |
243 } |
127 { |
244 |
128 var oldname = parent.firstChild.nodeValue; |
245 function ajaxUpdateSidebarOrder() |
129 parent.removeChild(parent.firstChild); |
246 { |
130 parent.ondblclick = function() {}; |
247 setAjaxLoading(); |
131 parent._idcache = id; |
248 var ser = serialize_sidebar(); |
132 var input = document.createElement('input'); |
249 $.post(makeUrlNS('Special', 'EditSidebar', 'update_order'), { order: ser }, function(response, statustext) |
133 input.type = 'text'; |
250 { |
134 input.sbedit_id = id; |
251 var msg = document.createElement('div'); |
135 input.oldvalue = oldname; |
252 $(msg) |
136 input.onkeyup = function(e) |
253 .addClass('info-box-mini') |
137 { |
254 .text('Sidebar order saved.') |
138 if ( typeof(e) != 'object' ) |
255 .css('position', 'fixed') |
139 return false; |
256 .css('bottom', 1) |
140 if ( !e.keyCode ) |
257 .appendTo('body') |
141 return false; |
258 .css('left', ( getWidth() / 2 ) - ( $(msg).width() / 2 )); |
142 if ( e.keyCode == 13 ) |
259 setTimeout(function() |
143 { |
260 { |
144 ajaxRenameSidebarStage2(this); |
261 $(msg).fadeOut(500, function() { $(this).remove(); }); |
145 } |
262 }, 1000); |
146 if ( e.keyCode == 27 ) |
263 unsetAjaxLoading(); |
147 { |
264 }, 'json'); |
148 ajaxRenameSidebarCancel(this); |
265 } |
149 } |
266 |
150 }; |
|
151 input.onblur = function() |
|
152 { |
|
153 ajaxRenameSidebarCancel(this); |
|
154 }; |
|
155 input.value = oldname; |
|
156 input.style.fontSize = '7pt'; |
|
157 parent.appendChild(input); |
|
158 input.focus(); |
|
159 } |
|
160 |
|
161 function ajaxRenameSidebarStage2(input) |
|
162 { |
|
163 var newname = input.value; |
|
164 var id = input.sbedit_id; |
|
165 var parent = input.parentNode; |
|
166 parent.removeChild(input); |
|
167 parent.appendChild(document.createTextNode(( newname == '' ? '<Unnamed>' : newname ))); |
|
168 parent.ondblclick = function() { ajaxRenameSidebarStage1(this, this._idcache); return false; }; |
|
169 var img = document.createElement('img'); |
|
170 img.src = scriptPath + '/images/loading.gif'; |
|
171 parent.appendChild(img); |
|
172 newname = ajaxEscape(newname); |
|
173 ajaxPost(makeUrlNS('Special', 'EditSidebar', 'ajax&noheaders&action=rename&id='+id), 'newname=' +newname, function() |
|
174 { |
|
175 if ( ajax.readyState == 4 && ajax.status == 200 ) |
|
176 { |
|
177 parent.removeChild(img); |
|
178 if ( ajax.responseText != 'GOOD' ) |
|
179 new messagebox(MB_OK|MB_ICONSTOP, 'Error renaming block', ajax.responseText); |
|
180 } |
|
181 }); |
|
182 } |
|
183 |
|
184 function ajaxRenameSidebarCancel(input) |
|
185 { |
|
186 var newname = input.oldvalue; |
|
187 var id = input.sbedit_id; |
|
188 var parent = input.parentNode; |
|
189 parent.removeChild(input); |
|
190 parent.appendChild(document.createTextNode(newname)); |
|
191 parent.ondblclick = function() { ajaxRenameSidebarStage1(this, this._idcache); return false; }; |
|
192 } |
|
193 |
|