Poll plugin: make the polling response form submit via AJAX and return the results.

Now, any form marked with 'ajax' class will get the simple FormXHR treatment. Should help cut down on code that just adds that into individual forms.
This commit is contained in:
Brion Vibber 2011-03-08 13:45:51 -08:00
parent ba1ada2880
commit 90f1cfcfc0
5 changed files with 30 additions and 4 deletions

View File

@ -1380,6 +1380,16 @@ var SN = { // StatusNet
});
},
/**
* Set up any generic 'ajax' form so it submits via AJAX with auto-replacement.
*/
AjaxForms: function() {
$('form.ajax').live('submit', function() {
SN.U.FormXHR($(this));
return false;
});
},
/**
* Add logic to any file upload forms to handle file size limits,
* on browsers that support basic FileAPI.
@ -1416,6 +1426,7 @@ var SN = { // StatusNet
* don't start them loading until after DOM-ready time!
*/
$(document).ready(function(){
SN.Init.AjaxForms();
SN.Init.UploadForms();
if ($('.'+SN.C.S.FormNotice).length > 0) {
SN.Init.NoticeForm();

2
js/util.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -83,7 +83,7 @@ class PollResponseForm extends Form
function formClass()
{
return 'form_settings';
return 'form_settings ajax';
}
/**

View File

@ -83,7 +83,7 @@ class PollResultForm extends Form
function formClass()
{
return 'form_settings';
return 'form_settings ajax';
}
/**

View File

@ -145,7 +145,22 @@ class RespondPollAction extends Action
return;
}
common_redirect($this->poll->bestUrl(), 303);
if ($this->arg('ajax')) {
header('Content-Type: text/xml;charset=utf-8');
$this->xw->startDocument('1.0', 'UTF-8');
$this->elementStart('html');
$this->elementStart('head');
// TRANS: Page title after sending a poll response.
$this->element('title', null, _m('Poll results'));
$this->elementEnd('head');
$this->elementStart('body');
$form = new PollResultForm($this->poll, $this);
$form->show();
$this->elementEnd('body');
$this->elementEnd('html');
} else {
common_redirect($this->poll->bestUrl(), 303);
}
}
/**