diff -r 1e40b33f2e3e -r c949e82b8f49 includes/clientside/static/ajax.js
--- a/includes/clientside/static/ajax.js Mon Apr 13 12:32:36 2009 -0400
+++ b/includes/clientside/static/ajax.js Mon Apr 13 14:43:28 2009 -0400
@@ -33,42 +33,134 @@
// Miscellaneous AJAX applets
-window.ajaxProtect = function(l) {
+window.ajaxProtect = function(existing_level)
+{
// IE <6 pseudo-compatibility
if ( KILL_SWITCH )
return true;
- load_component('l10n');
+
+ // touch this variable to allow it to be used in child functions
+ void(existing_level);
+
+ load_component(['messagebox', 'jquery', 'jquery-ui', 'l10n', 'fadefilter', 'flyin']);
+
+ // preload language
+ $lang.get('meta_meta');
- if(shift) {
- r = 'NO_REASON';
- } else {
- r = prompt($lang.get('ajax_protect_prompt_reason'));
- if(!r || r=='') return;
+ var mp = miniPrompt(function(parent)
+ {
+ var icon_full = gen_sprite_html(cdnPath + '/images/protect-icons.png', 22, 22, 0, 0);
+ var icon_semi = gen_sprite_html(cdnPath + '/images/protect-icons.png', 22, 22, 22, 0);
+ var icon_none = gen_sprite_html(cdnPath + '/images/protect-icons.png', 22, 22, 44, 0);
+
+ $(parent).append('
' + $lang.get('onpage_protect_heading') + '
');
+ $(parent).append('' + $lang.get('onpage_protect_msg_select_level') + '
');
+
+ $(parent).append('');
+ $(parent).append('' + $lang.get('onpage_protect_btn_full_hint') + '
');
+ $(parent).append('');
+ $(parent).append('' + $lang.get('onpage_protect_btn_semi_hint') + '
');
+ $(parent).append('');
+ $(parent).append('' + $lang.get('onpage_protect_btn_none_hint') + '
');
+
+ $(parent).append('');
+
+ $(parent).append('' + $lang.get('onpage_protect_btn_submit') + ' ' + $lang.get('etc_cancel') + '
');
+
+ $('.protectlevel', parent).css('line-height', '22px');
+ $('h3', parent).css('text-align', 'center');
+ $('.protectlevel_hint', parent)
+ .css('font-size', 'smaller')
+ .css('margin-left', '52px')
+ .hide();
+ $('p.buttons', parent).css('margin-top', '15px').css('text-align', 'center');
+
+ if ( typeof(existing_level) == 'number' )
+ {
+ $('#protect_level_' + existing_level, parent).attr('checked', 'checked');
+ $('#protect_level_' + existing_level + '_hint', parent).show();
+ $('#protect_level_' + existing_level, parent).parent().append(' ' + $lang.get('onpage_protect_lbl_current') + '');
+ }
+
+ $('input:radio', parent).click(function()
+ {
+ var mp = miniPromptGetParent(this);
+ $('.protectlevel_hint:visible', mp).hide('blind', 150);
+ $('#' + this.id + '_hint').show('blind', 150);
+ $('#protect_reason').focus();
+ });
+ $('input:text', parent).keyup(function(e)
+ {
+ if ( e.keyCode == 13 )
+ ajaxProtectSubmit(this);
+ });
+ });
+}
+
+window.ajaxProtectSubmit = function(el)
+{
+ var mp = miniPromptGetParent(el);
+
+ var reason = trim($('#protect_reason', mp).attr('value'));
+ if ( reason == '' )
+ {
+ var oldbg = $('#protect_reason').css('background-color');
+ if ( jQuery.fx.off )
+ {
+ $('#protect_reason').css('background-color', '#a00');
+ setTimeout(function()
+ {
+ $('#protect_reason').css('background-color', oldbg);
+ }, 1000);
+ }
+ else
+ {
+ $('#protect_reason').css('background-color', '#a00').animate({ backgroundColor: oldbg }, 1000);
+ }
+ return false;
}
- setAjaxLoading();
- document.getElementById('protbtn_0').style.textDecoration = 'none';
- document.getElementById('protbtn_1').style.textDecoration = 'none';
- document.getElementById('protbtn_2').style.textDecoration = 'none';
- document.getElementById('protbtn_'+l).style.textDecoration = 'underline';
- ajaxPost(stdAjaxPrefix+'&_mode=protect', 'reason='+ajaxEscape(r)+'&level='+l, function(ajax) {
- if ( ajax.readyState == 4 && ajax.status == 200 ) {
- unsetAjaxLoading();
- if(ajax.responseText == 'good')
- return true;
- // check for JSON error response
- var response = String(ajax.responseText + '');
- if ( response.substr(0, 1) == '{' )
+
+ var level = 0;
+ if ( $('#protect_level_1', mp).attr('checked') )
+ level = 1;
+ if ( $('#protect_level_2', mp).attr('checked') )
+ level = 2;
+
+ var whitey = whiteOutMiniPrompt(mp);
+ $.post(stdAjaxPrefix + '&_mode=protect', { level: level, reason: reason }, function(response, statustext)
+ {
+ if ( response.success )
{
- response = parseJSON(response);
- if ( response.mode == 'error' )
+ whiteOutReportSuccess(whitey);
+ setTimeout(function()
+ {
+ miniPromptDestroy(mp);
+ }, 1250);
+ // update protect button
+ var btn = $('#tb_ajax_protect_btn').get(0);
+ btn.level = level;
+ btn.setAttribute('onclick', null);
+ btn.onclick = null;
+ $(btn).click(function()
+ {
+ ajaxProtect(this.level);
+ return false;
+ });
+ var status = '';
+ switch(level)
{
- alert(response.error);
- return true;
+ case 1: status = $lang.get('onpage_btn_protect_on'); break;
+ case 0: status = $lang.get('onpage_btn_protect_off'); break;
+ case 2: status = $lang.get('onpage_btn_protect_semi'); break;
}
+ $('#tb_ajax_protect_status').text(status);
}
- alert(ajax.responseText);
- }
- }, true);
+ else
+ {
+ whiteOutReportFailure(whitey);
+ alert($lang.get('page_err_' + response.error));
+ }
+ }, 'json');
}
window.ajaxRename = function()