1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 16:52:41 +01:00

Use responsive form elements in Ponder create view

Summary: Use flexible form and application side nav.

Test Plan: {F19525}

Reviewers: pieter, starruler

Reviewed By: pieter

CC: aran

Maniphest Tasks: T1644

Differential Revision: https://secure.phabricator.com/D3511
This commit is contained in:
epriestley 2012-09-30 20:09:18 -07:00
parent 27c97571c0
commit 9d87510ff3

View file

@ -22,108 +22,79 @@ final class PonderQuestionAskController extends PonderController {
$request = $this->getRequest(); $request = $this->getRequest();
$user = $request->getUser(); $user = $request->getUser();
if ($request->isFormPost()) {
return $this->handlePost();
}
return $this->showForm();
}
private function handlePost() {
$request = $this->getRequest();
$user = $request->getUser();
$errors = array();
$title = $request->getStr('title');
$content = $request->getStr('content');
// form validation
if (phutil_utf8_strlen($title) < 1 || phutil_utf8_strlen($title) > 255) {
$errors[] = "Please enter a title (1-255 characters)";
}
if ($errors) {
return $this->showForm($errors, $title, $content);
}
// no validation errors -> save it
$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_WEB,
array(
'ip' => $request->getRemoteAddr(),
));
$question = id(new PonderQuestion()) $question = id(new PonderQuestion())
->setTitle($title)
->setContent($content)
->setAuthorPHID($user->getPHID()) ->setAuthorPHID($user->getPHID())
->setContentSource($content_source)
->setVoteCount(0) ->setVoteCount(0)
->setAnswerCount(0) ->setAnswerCount(0)
->setHeat(0.0) ->setHeat(0.0);
->save();
PhabricatorSearchPonderIndexer::indexQuestion($question); $errors = array();
$e_title = true;
if ($request->isFormPost()) {
$question->setTitle($request->getStr('title'));
$question->setContent($request->getStr('content'));
return id(new AphrontRedirectResponse()) $len = phutil_utf8_strlen($question->getTitle());
->setURI('/Q'.$question->getID()); if ($len < 1) {
} $errors[] = pht('Title must not be empty.');
$e_title = pht('Required');
} else if ($len > 255) {
$errors[] = pht('Title is too long.');
$e_title = pht('Too Long');
}
private function showForm( if (!$errors) {
$errors = null, $content_source = PhabricatorContentSource::newForSource(
$title = "", PhabricatorContentSource::SOURCE_WEB,
$content = "", array(
$id = null) { 'ip' => $request->getRemoteAddr(),
));
$question->setContentSource($content_source);
$question->save();
require_celerity_resource('ponder-core-view-css'); PhabricatorSearchPonderIndexer::indexQuestion($question);
require_celerity_resource('phabricator-remarkup-css');
require_celerity_resource('ponder-post-css'); return id(new AphrontRedirectResponse())
->setURI('/Q'.$question->getID());
}
}
$request = $this->getRequest();
$user = $request->getUser();
$error_view = null; $error_view = null;
if ($errors) { if ($errors) {
$error_view = id(new AphrontErrorView()) $error_view = id(new AphrontErrorView())
->setTitle('Form Errors') ->setTitle('Form Errors')
->setErrors($errors); ->setErrors($errors);
} }
$form = new AphrontFormView(); $header = id(new PhabricatorHeaderView())->setHeader(pht('Ask Question'));
$form->setUser($user);
$form->setAction('/ponder/question/ask/'); $form = id(new AphrontFormView())
$form ->setUser($user)
->setFlexible(true)
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
->setLabel('Title') ->setLabel(pht('Question'))
->setName('title') ->setName('title')
->setValue($title)) ->setValue($question->getTitle())
->setError($e_title))
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setName('content') ->setName('content')
->setID('content') ->setID('content')
->setValue($content) ->setValue($question->getContent())
->setLabel("Question")) ->setLabel(pht('Description')))
->appendChild( ->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->setValue('Ask Away!')); ->setValue('Ask Away!'));
$panel = id(new AphrontPanelView()) $preview =
->addClass("ponder-panel")
->setHeader("Your Question:")
->appendChild($error_view)
->appendChild($form);
$panel->appendChild(
'<div class="aphront-panel-flush">'. '<div class="aphront-panel-flush">'.
'<div id="question-preview">'. '<div id="question-preview">'.
'<span class="aphront-panel-preview-loading-text">'. '<span class="aphront-panel-preview-loading-text">'.
'Loading question preview...'. pht('Loading question preview...').
'</span>'. '</span>'.
'</div>'. '</div>'.
'</div>' '</div>';
);
Javelin::initBehavior( Javelin::initBehavior(
'ponder-feedback-preview', 'ponder-feedback-preview',
@ -134,9 +105,23 @@ final class PonderQuestionAskController extends PonderController {
'question_id' => null 'question_id' => null
)); ));
return $this->buildStandardPageResponse( $nav = $this->buildSideNavView($question);
array($panel), $nav->selectFilter($question->getID() ? null : 'question/ask');
array('title' => 'Ask a Question')
$nav->appendChild(
array(
$header,
$error_view,
$form,
$preview,
));
return $this->buildApplicationPage(
$nav,
array(
'device' => true,
'title' => 'Ask a Question',
)
); );
} }