aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCallum Macrae <callum@lynxphp.com>2011-07-17 14:57:13 +0100
committerIgor Wiedler <igor@wiedler.ch>2012-03-31 02:00:22 +0200
commitf42f6f19028fab5b047baae0df5004a43e946a30 (patch)
treea2ecaa6eceb5dc43a39481e062e002b6e6d6f537
parent456e56144256f3d14d78b02b397d5f3838f0cfea (diff)
downloadforums-f42f6f19028fab5b047baae0df5004a43e946a30.tar
forums-f42f6f19028fab5b047baae0df5004a43e946a30.tar.gz
forums-f42f6f19028fab5b047baae0df5004a43e946a30.tar.bz2
forums-f42f6f19028fab5b047baae0df5004a43e946a30.tar.xz
forums-f42f6f19028fab5b047baae0df5004a43e946a30.zip
[ticket/10273] Added phpbb.ajaxify_form and converted accept / deny to it.
Also made a few minor improvements to other JavaScript. PHPBB3-10273
-rw-r--r--phpBB/styles/prosilver/template/viewtopic_body.html4
-rw-r--r--phpBB/styles/script.js125
2 files changed, 80 insertions, 49 deletions
diff --git a/phpBB/styles/prosilver/template/viewtopic_body.html b/phpBB/styles/prosilver/template/viewtopic_body.html
index 5571ce07c4..856ee6962c 100644
--- a/phpBB/styles/prosilver/template/viewtopic_body.html
+++ b/phpBB/styles/prosilver/template/viewtopic_body.html
@@ -139,8 +139,8 @@
<p class="rules">
<!-- IF postrow.S_POST_UNAPPROVED -->
{UNAPPROVED_IMG} <strong>{L_POST_UNAPPROVED}</strong> &nbsp;
- <input class="button2" type="button" value="{L_DISAPPROVE}" name="action[disapprove]" /> &nbsp;
- <input class="button1" type="button" value="{L_APPROVE}" name="action[approve]" />
+ <input class="button2" type="submit" value="{L_DISAPPROVE}" name="action[disapprove]" /> &nbsp;
+ <input class="button1" type="submit" value="{L_APPROVE}" name="action[approve]" />
<input type="hidden" name="post_id_list[]" value="{postrow.POST_ID}" />
{S_FORM_TOKEN}
<br /><!-- ENDIF -->
diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js
index 17934ed6ae..5d9b89e386 100644
--- a/phpBB/styles/script.js
+++ b/phpBB/styles/script.js
@@ -1,3 +1,26 @@
+/**
+ * Make some changes to the jQuery core.
+ */
+$.fn.hide = function() {
+ this.animate({opacity: 0}, 300, function() {
+ $(this).css('display', 'none')
+ .css('opacity', 1);
+ });
+}
+$.fn.show = function() {
+ this.css('opacity', 0)
+ .css('display', 'block')
+ .animate({opacity: 1}, 300);
+}
+
+$.fn.remove_old = $.fn.remove;
+$.fn.remove = function() {
+ this.animate({opacity: 0}, 300, function() {
+ $(this).remove_old();
+ });
+}
+
+
var phpbb = {};
/**
@@ -16,14 +39,12 @@ phpbb.alert = function(title, msg) {
{
return true;
}
- div.animate({opacity: 0}, 300, function() {
- div.remove();
- });
+ div.remove();
return false;
});
$('body').append(div);
- div.css('opacity', 0).show().animate({opacity: 1}, 300);
+ div.show();
return div;
}
@@ -37,19 +58,17 @@ phpbb.alert = function(title, msg) {
*/
phpbb.confirm = function(msg, callback) {
var div = $('<div class="jalert"><p>' + msg + '</p>\
- <input type="button" class="jalertbut" value="Yes" />&nbsp;\
- <input type="button" class="jalertbut" value="No" /></div>');
+ <input type="button" class="jalertbut button1" value="Yes" />&nbsp;\
+ <input type="button" class="jalertbut button2" value="No" /></div>');
$('body').append(div);
$('.jalertbut').bind('click', function(event) {
- div.animate({opacity: 0}, 300, function() {
- div.remove();
- });
+ div.remove();
callback(this.value === 'Yes');
return false;
});
- div.css('opacity', 0).show().animate({opacity: 1}, 300);
+ div.show();
return div;
}
@@ -101,12 +120,13 @@ phpbb.confirm_box = function(condition, refresh, callback)
var that = this;
$.get(this.href, function(res) {
res = JSON.parse(res);
+ console.log(res);
phpbb.confirm(res.MESSAGE_TEXT, function(del) {
if (del)
{
var path = res.S_CONFIRM_ACTION;
var data = $('<form>' + res.S_HIDDEN_FIELDS + '</form>').serialize();
- $.post(path, data + '&confirm=Yes', function(res) {
+ $.post(path, data + '&confirm=' + res.YES_VALUE, function(res) {
res = JSON.parse(res);
var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT);
if (typeof callback !== 'undefined')
@@ -135,6 +155,7 @@ phpbb.ajaxify = function(selector, refresh, callback) {
var that = this;
$.get(this.href, function(res) {
res = JSON.parse(res);
+ console.log(res);
var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT);
if (typeof callback !== 'undefined')
{
@@ -146,6 +167,50 @@ phpbb.ajaxify = function(selector, refresh, callback) {
});
}
+/**
+ * AJAXifies a form. This will automatically get the action from the submit.
+ *
+ * @param string condition The element to capture.
+ * @param bool/function refresh If we are sent back a refresh, should it be
+ * acted upon? This can either be true / false / a function.
+ * @param function callback Callback.
+ */
+phpbb.ajaxify_form = function(selector, refresh, callback)
+{
+ $(selector + ' input:submit').click(function(e) {
+ var act = /action\[([a-z]+)\]/.exec(this.name),
+ data = decodeURI($(this).closest('form').serialize()),
+ path = $(this).closest('form').attr('action').replace('&amp;', '&'),
+ that = this;
+
+ if (act)
+ {
+ data += '&action=' + act[1];
+ }
+
+ $.post(path, data, function(res) {
+ res = JSON.parse(res);
+ phpbb.confirm(res.MESSAGE_TEXT, function(del) {
+ if (del)
+ {
+ path = res.S_CONFIRM_ACTION;
+ data = $('<form>' + res.S_HIDDEN_FIELDS + '</form>').serialize();
+ $.post(path, data + '&confirm=' + res.YES_VALUE, function(res) {
+ res = JSON.parse(res);
+ var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT);
+ if (typeof callback !== 'undefined')
+ {
+ callback(that, act[1]);
+ }
+ handle_refresh(res.REFRESH_DATA, refresh, alert);
+ });
+ }
+ });
+ });
+ return false;
+ });
+}
+
//bind the confirm_boxes
var refresh = function(url) {
@@ -177,40 +242,6 @@ phpbb.ajaxify('a[href*="watch=forum"]', false, function(el, res) {
phpbb.ajaxify('a[href*="mode=bump"]');
phpbb.ajaxify('a[href*="mark="]'); //captures topics and forums
-
-
-/**
- * Forms have to be captured manually, as they're all different.
- */
-$('input[name^="action"]').click(function(e) {
- var that = this;
- var path = $(this).parents('form')[0].action.replace('&amp;', '&');
- var action = (this.name === 'action[approve]') ? 'approve' : 'disapprove';
- var data = {
- action: action,
- post_id_list: [$(this).siblings('input[name="post_id_list[]"]')[0].value]
- };
- $.post(path, data, function(res) {
- res = JSON.parse(res);
- phpbb.confirm(res.MESSAGE_TEXT, function(del) {
- if (del)
- {
- path = res.S_CONFIRM_ACTION;
- data = $('<form>' + res.S_HIDDEN_FIELDS + '</form>').serialize();
- $.post(path, data + '&confirm=Yes', function(res) {
- res = JSON.parse(res);
- var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT);
-
- $(that).parents((action === 'approve') ? '.rules' : '.post').remove();
-
- setTimeout(function() {
- alert.hide(300, function() {
- alert.remove();
- });
- }, 5000);
- });
- }
- });
- });
- return false;
+phpbb.ajaxify_form('.mcp_approve', false, function(el, act) {
+ $(el).parents((act === 'approve') ? '.rules' : '.post').remove();
});