Loading the original form instead of faking up our own. Sorta works but not pretty :D

This commit is contained in:
Brion Vibber 2011-03-04 14:11:11 -08:00
parent b68f8643a2
commit 9689bda21c
2 changed files with 74 additions and 24 deletions

View File

@ -269,6 +269,31 @@ class NewnoticeAction extends Action
$this->elementEnd('html'); $this->elementEnd('html');
} }
/**
* Show an Ajax-y notice form
*
* Goes back to the browser, where it's shown in a popup.
*
* @param string $msg Message to show
*
* @return void
*/
function ajaxShowForm()
{
$this->startHTML('text/xml;charset=utf-8', true);
$this->elementStart('head');
$this->element('title', null, _('New notice'));
$this->elementEnd('head');
$this->elementStart('body');
$form = new NoticeForm($this);
$form->show();
$this->elementEnd('body');
$this->elementEnd('html');
}
/** /**
* Formerly page output * Formerly page output
* *
@ -286,8 +311,12 @@ class NewnoticeAction extends Action
function showForm($msg=null) function showForm($msg=null)
{ {
if ($msg && $this->boolean('ajax')) { if ($this->boolean('ajax')) {
if ($msg) {
$this->ajaxErrorMsg($msg); $this->ajaxErrorMsg($msg);
} else {
$this->ajaxShowForm();
}
return; return;
} }

View File

@ -553,13 +553,54 @@ var SN = { // StatusNet
// See if the form's already open... // See if the form's already open...
var replyForm = $('.notice-reply-form', list); var replyForm = $('.notice-reply-form', list);
if (replyForm.length == 0) {
var nextStep = function() {
// Override...?
replyForm.find('input[name=inreplyto]').val(id);
// Set focus...
var text = replyForm.find('textarea');
if (text.length == 0) {
throw "No textarea";
}
var replyto = '';
if (initialText) {
replyto = initialText + ' ';
}
text.val(replyto + text.val().replace(RegExp(replyto, 'i'), ''));
text.data('initialText', $.trim(initialText + ''));
text.focus();
if (text[0].setSelectionRange) {
var len = text.val().length;
text[0].setSelectionRange(len,len);
}
};
if (replyForm.length > 0) {
// Update the existing form...
nextStep();
} else {
// Remove placeholder if any // Remove placeholder if any
$('li.notice-reply-placeholder').remove(); $('li.notice-reply-placeholder').remove();
// Create the reply form entry at the end // Create the reply form entry at the end
var replyItem = $('li.notice-reply', list); var replyItem = $('li.notice-reply', list);
if (replyItem.length == 0) { if (replyItem.length == 0) {
var url = $('#form_notice').attr('action');
replyItem = $('<li class="notice-reply"></li>');
$.get(url, {ajax: 1}, function(data, textStatus, xhr) {
var formEl = document._importNode($('form', data)[0], true);
replyItem.append(formEl);
list.append(replyItem);
var form = replyForm = $(formEl);
SN.U.NoticeLocationAttach(form);
SN.U.FormNoticeXHR(form);
SN.U.FormNoticeEnhancements(form);
SN.U.NoticeDataAttach(form);
nextStep();
});
/*
replyItem = $('<li class="notice-reply">' + replyItem = $('<li class="notice-reply">' +
'<form class="notice-reply-form" method="post">' + '<form class="notice-reply-form" method="post">' +
'<textarea name="status_textarea"></textarea>' + '<textarea name="status_textarea"></textarea>' +
@ -570,7 +611,6 @@ var SN = { // StatusNet
'</div>' + '</div>' +
'</form>' + '</form>' +
'</li>'); '</li>');
var baseForm = $('#form_notice'); var baseForm = $('#form_notice');
replyForm = replyItem.find('form'); replyForm = replyItem.find('form');
replyForm.attr('action', baseForm.attr('action')); replyForm.attr('action', baseForm.attr('action'));
@ -630,28 +670,9 @@ var SN = { // StatusNet
event.preventDefault(); event.preventDefault();
return false; return false;
}); });
*/
} }
} }
// Override...?
replyForm.find('input[name=inreplyto]').val(id);
// Set focus...
var text = replyForm.find('textarea');
if (text.length == 0) {
throw "No textarea";
}
var replyto = '';
if (initialText) {
replyto = initialText + ' ';
}
text.val(replyto + text.val().replace(RegExp(replyto, 'i'), ''));
text.data('initialText', $.trim(initialText + ''));
text.focus();
if (text[0].setSelectionRange) {
var len = text.val().length;
text[0].setSelectionRange(len,len);
}
}, },
/** /**