Bookmark and poll plugins' custom notice forms now do AJAX submit, with the resulting notice appearing in the timeline.

FormNoticeXHR now is triggered on any form labeled with class 'ajax-notice', so those other than the traditional notice form should work as long as they handle the AJAX submission and return a properly formatted notice.

Things to watch out for:
* to determine whether the resulting notice should show on the current timeline, the JS code needs to be able to check the author and such. Keeping the existing vcard bits helps for this!
* the notice form submission stuff clears out inputs from your form -- test to make sure this behaves correctly
* error messages returned from the thingy _should_ come through, but this needs more testing for consistency
* while form components that aren't in a custom form should just be ignored, this should be tested more. (eg there's no location or attachment box for poll or bookmark plugins)
* NoticeListItem isn't currently reachable via autoloader -- touch NoticeList explicitly before calling into it for now.
This commit is contained in:
Brion Vibber 2011-03-08 15:10:30 -08:00
parent 28809035d0
commit cbf16a4974
9 changed files with 81 additions and 11 deletions

View File

@ -1263,7 +1263,7 @@ var SN = { // StatusNet
var profileLink = $('#nav_profile a').attr('href');
if (profileLink) {
var authorUrl = $(notice).find('.entry-title .author a.url').attr('href');
var authorUrl = $(notice).find('.vcard.author a.url').attr('href');
if (authorUrl == profileLink) {
if (action == 'all' || action == 'showstream') {
// Posts always show on your own friends and profile streams.
@ -1301,7 +1301,7 @@ var SN = { // StatusNet
*/
NoticeForm: function() {
if ($('body.user_in').length > 0) {
$('.'+SN.C.S.FormNotice).each(function() {
$('.ajax-notice').each(function() {
var form = $(this);
SN.U.NoticeLocationAttach(form);
SN.U.FormNoticeXHR(form);

2
js/util.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -132,7 +132,7 @@ class NoticeForm extends Form
function formClass()
{
return 'form_notice';
return 'form_notice ajax-notice';
}
/**

View File

@ -616,12 +616,15 @@ class BookmarkPlugin extends MicroAppPlugin
'height' => AVATAR_MINI_SIZE,
'alt' => $profile->getBestName()));
$out->raw(' ');
$out->raw(' '); // avoid   for AJAX XML compatibility
$out->elementStart('span', 'vcard author'); // hack for belongsOnTimeline; JS needs to be able to find the author
$out->element('a',
array('href' => $profile->profileurl,
array('class' => 'url',
'href' => $profile->profileurl,
'title' => $profile->getBestName()),
$profile->nickname);
$out->elementEnd('span');
}
function entryForm($out)

View File

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

View File

@ -125,6 +125,9 @@ class NewbookmarkAction extends Action
function newBookmark()
{
if ($this->boolean('ajax')) {
StatusNet::setApi(true);
}
try {
if (empty($this->title)) {
throw new ClientException(_('Bookmark must have a title.'));
@ -147,7 +150,37 @@ class NewbookmarkAction extends Action
return;
}
common_redirect($saved->bestUrl(), 303);
if ($this->boolean('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 notice.
$this->element('title', null, _('Notice posted'));
$this->elementEnd('head');
$this->elementStart('body');
$this->showNotice($saved);
$this->elementEnd('body');
$this->elementEnd('html');
} else {
common_redirect($saved->bestUrl(), 303);
}
}
/**
* Output a notice
*
* Used to generate the notice code for Ajax results.
*
* @param Notice $notice Notice that was saved
*
* @return void
*/
function showNotice($notice)
{
class_exists('NoticeList'); // @fixme hack for autoloader
$nli = new NoticeListItem($notice, $this);
$nli->show();
}
/**

View File

@ -216,6 +216,7 @@ class Poll extends Managed_DataObject
array('id' => $p->id));
}
common_log(LOG_DEBUG, "Saving poll: $p->id $p->uri");
$p->insert();
$content = sprintf(_m('Poll: %s %s'),

View File

@ -127,6 +127,9 @@ class NewPollAction extends Action
function newPoll()
{
if ($this->boolean('ajax')) {
StatusNet::setApi(true);
}
try {
if (empty($this->question)) {
throw new ClientException(_('Poll must have a question.'));
@ -147,7 +150,37 @@ class NewPollAction extends Action
return;
}
common_redirect($saved->bestUrl(), 303);
if ($this->boolean('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 notice.
$this->element('title', null, _('Notice posted'));
$this->elementEnd('head');
$this->elementStart('body');
$this->showNotice($saved);
$this->elementEnd('body');
$this->elementEnd('html');
} else {
common_redirect($saved->bestUrl(), 303);
}
}
/**
* Output a notice
*
* Used to generate the notice code for Ajax results.
*
* @param Notice $notice Notice that was saved
*
* @return void
*/
function showNotice($notice)
{
class_exists('NoticeList'); // @fixme hack for autoloader
$nli = new NoticeListItem($notice, $this);
$nli->show();
}
/**
@ -163,7 +196,7 @@ class NewPollAction extends Action
}
$form = new NewPollForm($this,
$this->questions,
$this->question,
$this->options);
$form->show();

View File

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