31 }); |
31 }); |
32 } |
32 } |
33 |
33 |
34 // Miscellaneous AJAX applets |
34 // Miscellaneous AJAX applets |
35 |
35 |
36 window.ajaxProtect = function(l) { |
36 window.ajaxProtect = function(existing_level) |
|
37 { |
37 // IE <6 pseudo-compatibility |
38 // IE <6 pseudo-compatibility |
38 if ( KILL_SWITCH ) |
39 if ( KILL_SWITCH ) |
39 return true; |
40 return true; |
40 load_component('l10n'); |
41 |
41 |
42 // touch this variable to allow it to be used in child functions |
42 if(shift) { |
43 void(existing_level); |
43 r = 'NO_REASON'; |
44 |
44 } else { |
45 load_component(['messagebox', 'jquery', 'jquery-ui', 'l10n', 'fadefilter', 'flyin']); |
45 r = prompt($lang.get('ajax_protect_prompt_reason')); |
46 |
46 if(!r || r=='') return; |
47 // preload language |
47 } |
48 $lang.get('meta_meta'); |
48 setAjaxLoading(); |
49 |
49 document.getElementById('protbtn_0').style.textDecoration = 'none'; |
50 var mp = miniPrompt(function(parent) |
50 document.getElementById('protbtn_1').style.textDecoration = 'none'; |
51 { |
51 document.getElementById('protbtn_2').style.textDecoration = 'none'; |
52 var icon_full = gen_sprite_html(cdnPath + '/images/protect-icons.png', 22, 22, 0, 0); |
52 document.getElementById('protbtn_'+l).style.textDecoration = 'underline'; |
53 var icon_semi = gen_sprite_html(cdnPath + '/images/protect-icons.png', 22, 22, 22, 0); |
53 ajaxPost(stdAjaxPrefix+'&_mode=protect', 'reason='+ajaxEscape(r)+'&level='+l, function(ajax) { |
54 var icon_none = gen_sprite_html(cdnPath + '/images/protect-icons.png', 22, 22, 44, 0); |
54 if ( ajax.readyState == 4 && ajax.status == 200 ) { |
55 |
55 unsetAjaxLoading(); |
56 $(parent).append('<h3>' + $lang.get('onpage_protect_heading') + '</h3>'); |
56 if(ajax.responseText == 'good') |
57 $(parent).append('<p>' + $lang.get('onpage_protect_msg_select_level') + '</p>'); |
57 return true; |
58 |
58 // check for JSON error response |
59 $(parent).append('<div class="protectlevel"><label><input type="radio" id="protect_level_1" name="protect_level" /> ' + icon_full + ' ' + $lang.get('onpage_protect_btn_full') + '</label></div>'); |
59 var response = String(ajax.responseText + ''); |
60 $(parent).append('<div class="protectlevel_hint" id="protect_level_1_hint">' + $lang.get('onpage_protect_btn_full_hint') + '</div>'); |
60 if ( response.substr(0, 1) == '{' ) |
61 $(parent).append('<div class="protectlevel"><label><input type="radio" id="protect_level_2" name="protect_level" /> ' + icon_semi + ' ' + $lang.get('onpage_protect_btn_semi') + '</label></div>'); |
61 { |
62 $(parent).append('<div class="protectlevel_hint" id="protect_level_2_hint">' + $lang.get('onpage_protect_btn_semi_hint') + '</div>'); |
62 response = parseJSON(response); |
63 $(parent).append('<div class="protectlevel"><label><input type="radio" id="protect_level_0" name="protect_level" /> ' + icon_none + ' ' + $lang.get('onpage_protect_btn_none') + '</label></div>'); |
63 if ( response.mode == 'error' ) |
64 $(parent).append('<div class="protectlevel_hint" id="protect_level_0_hint">' + $lang.get('onpage_protect_btn_none_hint') + '</div>'); |
64 { |
65 |
65 alert(response.error); |
66 $(parent).append('<table class="protectreason"><tr><td valign="top">' + $lang.get('onpage_protect_lbl_reason') + '</td><td><input id="protect_reason" size="30" type="text" /><br /><small>' + $lang.get('onpage_protect_lbl_reason_hint') + '</small></td></tr></table>'); |
66 return true; |
67 |
67 } |
68 $(parent).append('<p class="buttons"><a class="submitbutton abutton abutton_green" style="font-weight: bold;" href="#" onclick="ajaxProtectSubmit(this); return false;">' + $lang.get('onpage_protect_btn_submit') + '</a> <a class="submitbutton abutton" href="#" onclick="miniPromptDestroy(this); return false;">' + $lang.get('etc_cancel') + '</a></p>'); |
68 } |
69 |
69 alert(ajax.responseText); |
70 $('.protectlevel', parent).css('line-height', '22px'); |
|
71 $('h3', parent).css('text-align', 'center'); |
|
72 $('.protectlevel_hint', parent) |
|
73 .css('font-size', 'smaller') |
|
74 .css('margin-left', '52px') |
|
75 .hide(); |
|
76 $('p.buttons', parent).css('margin-top', '15px').css('text-align', 'center'); |
|
77 |
|
78 if ( typeof(existing_level) == 'number' ) |
|
79 { |
|
80 $('#protect_level_' + existing_level, parent).attr('checked', 'checked'); |
|
81 $('#protect_level_' + existing_level + '_hint', parent).show(); |
|
82 $('#protect_level_' + existing_level, parent).parent().append(' <small><span style="color: #050; background-color: #eee; padding: 0 4px;">' + $lang.get('onpage_protect_lbl_current') + '</span></small>'); |
|
83 } |
|
84 |
|
85 $('input:radio', parent).click(function() |
|
86 { |
|
87 var mp = miniPromptGetParent(this); |
|
88 $('.protectlevel_hint:visible', mp).hide('blind', 150); |
|
89 $('#' + this.id + '_hint').show('blind', 150); |
|
90 $('#protect_reason').focus(); |
|
91 }); |
|
92 $('input:text', parent).keyup(function(e) |
|
93 { |
|
94 if ( e.keyCode == 13 ) |
|
95 ajaxProtectSubmit(this); |
|
96 }); |
|
97 }); |
|
98 } |
|
99 |
|
100 window.ajaxProtectSubmit = function(el) |
|
101 { |
|
102 var mp = miniPromptGetParent(el); |
|
103 |
|
104 var reason = trim($('#protect_reason', mp).attr('value')); |
|
105 if ( reason == '' ) |
|
106 { |
|
107 var oldbg = $('#protect_reason').css('background-color'); |
|
108 if ( jQuery.fx.off ) |
|
109 { |
|
110 $('#protect_reason').css('background-color', '#a00'); |
|
111 setTimeout(function() |
|
112 { |
|
113 $('#protect_reason').css('background-color', oldbg); |
|
114 }, 1000); |
70 } |
115 } |
71 }, true); |
116 else |
|
117 { |
|
118 $('#protect_reason').css('background-color', '#a00').animate({ backgroundColor: oldbg }, 1000); |
|
119 } |
|
120 return false; |
|
121 } |
|
122 |
|
123 var level = 0; |
|
124 if ( $('#protect_level_1', mp).attr('checked') ) |
|
125 level = 1; |
|
126 if ( $('#protect_level_2', mp).attr('checked') ) |
|
127 level = 2; |
|
128 |
|
129 var whitey = whiteOutMiniPrompt(mp); |
|
130 $.post(stdAjaxPrefix + '&_mode=protect', { level: level, reason: reason }, function(response, statustext) |
|
131 { |
|
132 if ( response.success ) |
|
133 { |
|
134 whiteOutReportSuccess(whitey); |
|
135 setTimeout(function() |
|
136 { |
|
137 miniPromptDestroy(mp); |
|
138 }, 1250); |
|
139 // update protect button |
|
140 var btn = $('#tb_ajax_protect_btn').get(0); |
|
141 btn.level = level; |
|
142 btn.setAttribute('onclick', null); |
|
143 btn.onclick = null; |
|
144 $(btn).click(function() |
|
145 { |
|
146 ajaxProtect(this.level); |
|
147 return false; |
|
148 }); |
|
149 var status = ''; |
|
150 switch(level) |
|
151 { |
|
152 case 1: status = $lang.get('onpage_btn_protect_on'); break; |
|
153 case 0: status = $lang.get('onpage_btn_protect_off'); break; |
|
154 case 2: status = $lang.get('onpage_btn_protect_semi'); break; |
|
155 } |
|
156 $('#tb_ajax_protect_status').text(status); |
|
157 } |
|
158 else |
|
159 { |
|
160 whiteOutReportFailure(whitey); |
|
161 alert($lang.get('page_err_' + response.error)); |
|
162 } |
|
163 }, 'json'); |
72 } |
164 } |
73 |
165 |
74 window.ajaxRename = function() |
166 window.ajaxRename = function() |
75 { |
167 { |
76 // IE <6 pseudo-compatibility |
168 // IE <6 pseudo-compatibility |