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()) { $question = id(new PonderQuestion())
return $this->handlePost(); ->setAuthorPHID($user->getPHID())
} ->setVoteCount(0)
->setAnswerCount(0)
return $this->showForm(); ->setHeat(0.0);
}
private function handlePost() {
$request = $this->getRequest();
$user = $request->getUser();
$errors = array(); $errors = array();
$title = $request->getStr('title'); $e_title = true;
$content = $request->getStr('content'); if ($request->isFormPost()) {
$question->setTitle($request->getStr('title'));
$question->setContent($request->getStr('content'));
// form validation $len = phutil_utf8_strlen($question->getTitle());
if (phutil_utf8_strlen($title) < 1 || phutil_utf8_strlen($title) > 255) { if ($len < 1) {
$errors[] = "Please enter a title (1-255 characters)"; $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');
} }
if ($errors) { if (!$errors) {
return $this->showForm($errors, $title, $content);
}
// no validation errors -> save it
$content_source = PhabricatorContentSource::newForSource( $content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_WEB, PhabricatorContentSource::SOURCE_WEB,
array( array(
'ip' => $request->getRemoteAddr(), 'ip' => $request->getRemoteAddr(),
)); ));
$question->setContentSource($content_source);
$question = id(new PonderQuestion()) $question->save();
->setTitle($title)
->setContent($content)
->setAuthorPHID($user->getPHID())
->setContentSource($content_source)
->setVoteCount(0)
->setAnswerCount(0)
->setHeat(0.0)
->save();
PhabricatorSearchPonderIndexer::indexQuestion($question); PhabricatorSearchPonderIndexer::indexQuestion($question);
return id(new AphrontRedirectResponse()) return id(new AphrontRedirectResponse())
->setURI('/Q'.$question->getID()); ->setURI('/Q'.$question->getID());
} }
}
private function showForm(
$errors = null,
$title = "",
$content = "",
$id = null) {
require_celerity_resource('ponder-core-view-css');
require_celerity_resource('phabricator-remarkup-css');
require_celerity_resource('ponder-post-css');
$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',
)
); );
} }