Page MenuHomePhabricator

D16302.diff
No OneTemporary

D16302.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1626,8 +1626,6 @@
'PHUIFormIconSetControl' => 'view/form/control/PHUIFormIconSetControl.php',
'PHUIFormInsetView' => 'view/form/PHUIFormInsetView.php',
'PHUIFormLayoutView' => 'view/form/PHUIFormLayoutView.php',
- 'PHUIFormMultiSubmitControl' => 'view/form/control/PHUIFormMultiSubmitControl.php',
- 'PHUIFormPageView' => 'view/form/PHUIFormPageView.php',
'PHUIHandleListView' => 'applications/phid/view/PHUIHandleListView.php',
'PHUIHandleTagListView' => 'applications/phid/view/PHUIHandleTagListView.php',
'PHUIHandleView' => 'applications/phid/view/PHUIHandleView.php',
@@ -1653,7 +1651,6 @@
'PHUIObjectItemListExample' => 'applications/uiexample/examples/PHUIObjectItemListExample.php',
'PHUIObjectItemListView' => 'view/phui/PHUIObjectItemListView.php',
'PHUIObjectItemView' => 'view/phui/PHUIObjectItemView.php',
- 'PHUIPagedFormView' => 'view/form/PHUIPagedFormView.php',
'PHUIPagerView' => 'view/phui/PHUIPagerView.php',
'PHUIPinboardItemView' => 'view/phui/PHUIPinboardItemView.php',
'PHUIPinboardView' => 'view/phui/PHUIPinboardView.php',
@@ -2974,7 +2971,6 @@
'PhabricatorPHPASTApplication' => 'applications/phpast/application/PhabricatorPHPASTApplication.php',
'PhabricatorPHPConfigSetupCheck' => 'applications/config/check/PhabricatorPHPConfigSetupCheck.php',
'PhabricatorPHPMailerConfigOptions' => 'applications/config/option/PhabricatorPHPMailerConfigOptions.php',
- 'PhabricatorPagedFormUIExample' => 'applications/uiexample/examples/PhabricatorPagedFormUIExample.php',
'PhabricatorPagerUIExample' => 'applications/uiexample/examples/PhabricatorPagerUIExample.php',
'PhabricatorPassphraseApplication' => 'applications/passphrase/application/PhabricatorPassphraseApplication.php',
'PhabricatorPasswordAuthProvider' => 'applications/auth/provider/PhabricatorPasswordAuthProvider.php',
@@ -6189,8 +6185,6 @@
'PHUIFormIconSetControl' => 'AphrontFormControl',
'PHUIFormInsetView' => 'AphrontView',
'PHUIFormLayoutView' => 'AphrontView',
- 'PHUIFormMultiSubmitControl' => 'AphrontFormControl',
- 'PHUIFormPageView' => 'AphrontView',
'PHUIHandleListView' => 'AphrontTagView',
'PHUIHandleTagListView' => 'AphrontTagView',
'PHUIHandleView' => 'AphrontView',
@@ -6216,7 +6210,6 @@
'PHUIObjectItemListExample' => 'PhabricatorUIExample',
'PHUIObjectItemListView' => 'AphrontTagView',
'PHUIObjectItemView' => 'AphrontTagView',
- 'PHUIPagedFormView' => 'AphrontView',
'PHUIPagerView' => 'AphrontView',
'PHUIPinboardItemView' => 'AphrontView',
'PHUIPinboardView' => 'AphrontView',
@@ -7730,7 +7723,6 @@
'PhabricatorPHPASTApplication' => 'PhabricatorApplication',
'PhabricatorPHPConfigSetupCheck' => 'PhabricatorSetupCheck',
'PhabricatorPHPMailerConfigOptions' => 'PhabricatorApplicationConfigOptions',
- 'PhabricatorPagedFormUIExample' => 'PhabricatorUIExample',
'PhabricatorPagerUIExample' => 'PhabricatorUIExample',
'PhabricatorPassphraseApplication' => 'PhabricatorApplication',
'PhabricatorPasswordAuthProvider' => 'PhabricatorAuthProvider',
diff --git a/src/applications/uiexample/examples/PhabricatorPagedFormUIExample.php b/src/applications/uiexample/examples/PhabricatorPagedFormUIExample.php
deleted file mode 100644
--- a/src/applications/uiexample/examples/PhabricatorPagedFormUIExample.php
+++ /dev/null
@@ -1,71 +0,0 @@
-<?php
-
-final class PhabricatorPagedFormUIExample extends PhabricatorUIExample {
-
- public function getName() {
- return pht('Form (Paged)');
- }
-
- public function getDescription() {
- return pht(
- 'Use %s to render forms with multiple pages.',
- hsprintf('<tt>PHUIPagedFormView</tt>'));
- }
-
- public function renderExample() {
- $request = $this->getRequest();
- $user = $request->getUser();
-
-
- $page1 = id(new PHUIFormPageView())
- ->setPageName(pht('Page 1'))
- ->addControl(
- id(new AphrontFormTextControl())
- ->setName('page1')
- ->setLabel(pht('Page 1')));
-
- $page2 = id(new PHUIFormPageView())
- ->setPageName(pht('Page 2'))
- ->addControl(
- id(new AphrontFormTextControl())
- ->setName('page2')
- ->setLabel(pht('Page 2')));
-
- $page3 = id(new PHUIFormPageView())
- ->setPageName(pht('Page 3'))
- ->addControl(
- id(new AphrontFormTextControl())
- ->setName('page3')
- ->setLabel(pht('Page 3')));
-
- $page4 = id(new PHUIFormPageView())
- ->setPageName(pht('Page 4'))
- ->addControl(
- id(new AphrontFormTextControl())
- ->setName('page4')
- ->setLabel(pht('Page 4')));
-
- $form = new PHUIPagedFormView();
- $form->setUser($user);
-
- $form->addPage('page1', $page1);
- $form->addPage('page2', $page2);
- $form->addPage('page3', $page3);
- $form->addPage('page4', $page4);
-
- if ($request->isFormPost()) {
- $form->readFromRequest($request);
- if ($form->isComplete()) {
- return id(new AphrontDialogView())
- ->setUser($user)
- ->setTitle(pht('Form Complete'))
- ->appendChild(pht('You submitted the form. Well done!'))
- ->addCancelButton($request->getRequestURI(), pht('Again!'));
- }
- } else {
- $form->readFromObject(null);
- }
-
- return $form;
- }
-}
diff --git a/src/view/form/PHUIFormPageView.php b/src/view/form/PHUIFormPageView.php
deleted file mode 100644
--- a/src/view/form/PHUIFormPageView.php
+++ /dev/null
@@ -1,221 +0,0 @@
-<?php
-
-/**
- * @concrete-extensible
- */
-class PHUIFormPageView extends AphrontView {
-
- private $key;
- private $form;
- private $controls = array();
- private $content = array();
- private $values = array();
- private $isValid;
- private $validateFormPageCallback;
- private $adjustFormPageCallback;
- private $pageErrors = array();
- private $pageName;
-
-
- public function setPageName($page_name) {
- $this->pageName = $page_name;
- return $this;
- }
-
- public function getPageName() {
- return $this->pageName;
- }
-
- public function addPageError($page_error) {
- $this->pageErrors[] = $page_error;
- return $this;
- }
-
- public function getPageErrors() {
- return $this->pageErrors;
- }
-
- public function setAdjustFormPageCallback($adjust_form_page_callback) {
- $this->adjustFormPageCallback = $adjust_form_page_callback;
- return $this;
- }
-
- public function setValidateFormPageCallback($validate_form_page_callback) {
- $this->validateFormPageCallback = $validate_form_page_callback;
- return $this;
- }
-
- public function addInstructions($text, $before = null) {
- $tag = phutil_tag(
- 'div',
- array(
- 'class' => 'aphront-form-instructions',
- ),
- $text);
-
- $append = true;
- if ($before !== null) {
- for ($ii = 0; $ii < count($this->content); $ii++) {
- if ($this->content[$ii] instanceof AphrontFormControl) {
- if ($this->content[$ii]->getName() == $before) {
- array_splice($this->content, $ii, 0, array($tag));
- $append = false;
- break;
- }
- }
- }
- }
-
- if ($append) {
- $this->content[] = $tag;
- }
-
- return $this;
- }
-
- public function addRemarkupInstructions($remarkup, $before = null) {
- $remarkup = new PHUIRemarkupView($this->getUser(), $remarkup);
- return $this->addInstructions($remarkup, $before);
- }
-
- public function addControl(AphrontFormControl $control) {
- $name = $control->getName();
-
- if (!strlen($name)) {
- throw new Exception(pht('Form control has no name!'));
- }
-
- if (isset($this->controls[$name])) {
- throw new Exception(
- pht("Form page contains duplicate control with name '%s'!", $name));
- }
-
- $this->controls[$name] = $control;
- $this->content[] = $control;
- $control->setFormPage($this);
-
- return $this;
- }
-
- public function getControls() {
- return $this->controls;
- }
-
- public function getControl($name) {
- if (empty($this->controls[$name])) {
- throw new Exception(pht("No page control '%s'!", $name));
- }
- return $this->controls[$name];
- }
-
- protected function canAppendChild() {
- return false;
- }
-
- public function setPagedFormView(PHUIPagedFormView $view, $key) {
- if ($this->key) {
- throw new Exception(pht('This page is already part of a form!'));
- }
- $this->form = $view;
- $this->key = $key;
- return $this;
- }
-
- public function adjustFormPage() {
- if ($this->adjustFormPageCallback) {
- call_user_func($this->adjustFormPageCallback, $this);
- }
- return $this;
- }
-
- protected function validateFormPage() {
- if ($this->validateFormPageCallback) {
- return call_user_func($this->validateFormPageCallback, $this);
- }
- return true;
- }
-
- public function getKey() {
- return $this->key;
- }
-
- public function render() {
- return $this->content;
- }
-
- public function getForm() {
- return $this->form;
- }
-
- public function getRequestKey($key) {
- return $this->getForm()->getRequestKey('p:'.$this->key.':'.$key);
- }
-
- public function validateObjectType($object) {
- return true;
- }
-
- public function validateResponseType($response) {
- return true;
- }
-
- protected function validateControls() {
- $result = true;
- foreach ($this->getControls() as $name => $control) {
- if (!$control->isValid()) {
- $result = false;
- break;
- }
- }
-
- return $result;
- }
-
- public function isValid() {
- if ($this->isValid === null) {
- $this->isValid = $this->validateControls() && $this->validateFormPage();
- }
- return $this->isValid;
- }
-
- public function readFromRequest(AphrontRequest $request) {
- foreach ($this->getControls() as $name => $control) {
- $control->readValueFromRequest($request);
- }
-
- return $this;
- }
-
- public function readFromObject($object) {
- foreach ($this->getControls() as $name => $control) {
- if (is_array($object)) {
- $control->readValueFromDictionary($object);
- }
- }
-
- return $this;
- }
-
- public function writeToResponse($response) {
- return $this;
- }
-
- public function readSerializedValues(AphrontRequest $request) {
- foreach ($this->getControls() as $name => $control) {
- $key = $this->getRequestKey($name);
- $control->readSerializedValue($request->getStr($key));
- }
-
- return $this;
- }
-
- public function getSerializedValues() {
- $dict = array();
- foreach ($this->getControls() as $name => $control) {
- $key = $this->getRequestKey($name);
- $dict[$key] = $control->getSerializedValue();
- }
- return $dict;
- }
-
-}
diff --git a/src/view/form/PHUIPagedFormView.php b/src/view/form/PHUIPagedFormView.php
deleted file mode 100644
--- a/src/view/form/PHUIPagedFormView.php
+++ /dev/null
@@ -1,279 +0,0 @@
-<?php
-
-/**
- * @task page Managing Pages
- */
-final class PHUIPagedFormView extends AphrontView {
-
- private $name = 'pages';
- private $pages = array();
- private $selectedPage;
- private $choosePage;
- private $nextPage;
- private $prevPage;
- private $complete;
- private $cancelURI;
-
- protected function canAppendChild() {
- return false;
- }
-
-
-/* -( Managing Pages )----------------------------------------------------- */
-
-
- /**
- * @task page
- */
- public function addPage($key, PHUIFormPageView $page) {
- if (isset($this->pages[$key])) {
- throw new Exception(pht("Duplicate page with key '%s'!", $key));
- }
- $this->pages[$key] = $page;
- $page->setPagedFormView($this, $key);
-
- $this->selectedPage = null;
- $this->complete = null;
-
- return $this;
- }
-
-
- /**
- * @task page
- */
- public function getPage($key) {
- if (!$this->pageExists($key)) {
- throw new Exception(pht("No page '%s' exists!", $key));
- }
- return $this->pages[$key];
- }
-
-
- /**
- * @task page
- */
- public function pageExists($key) {
- return isset($this->pages[$key]);
- }
-
-
- /**
- * @task page
- */
- protected function getPageIndex($key) {
- $page = $this->getPage($key);
-
- $index = 0;
- foreach ($this->pages as $target_page) {
- if ($page === $target_page) {
- break;
- }
- $index++;
- }
-
- return $index;
- }
-
-
- /**
- * @task page
- */
- protected function getPageByIndex($index) {
- foreach ($this->pages as $page) {
- if (!$index) {
- return $page;
- }
- $index--;
- }
-
- throw new Exception(pht("Requesting out-of-bounds page '%s'.", $index));
- }
-
- protected function getLastIndex() {
- return count($this->pages) - 1;
- }
-
- protected function isFirstPage(PHUIFormPageView $page) {
- return ($this->getPageIndex($page->getKey()) === 0);
-
- }
-
- protected function isLastPage(PHUIFormPageView $page) {
- return ($this->getPageIndex($page->getKey()) === (count($this->pages) - 1));
- }
-
- public function getSelectedPage() {
- return $this->selectedPage;
- }
-
- public function readFromObject($object) {
- return $this->processForm($is_request = false, $object);
- }
-
- public function writeToResponse($response) {
- foreach ($this->pages as $page) {
- $page->validateResponseType($response);
- $response = $page->writeToResponse($page);
- }
-
- return $response;
- }
-
- public function readFromRequest(AphrontRequest $request) {
- $this->choosePage = $request->getStr($this->getRequestKey('page'));
- $this->nextPage = $request->getStr('__submit__');
- $this->prevPage = $request->getStr('__back__');
-
- return $this->processForm($is_request = true, $request);
- }
-
- public function setName($name) {
- $this->name = $name;
- return $this;
- }
-
-
- public function getValue($page, $key, $default = null) {
- return $this->getPage($page)->getValue($key, $default);
- }
-
- public function setValue($page, $key, $value) {
- $this->getPage($page)->setValue($key, $value);
- return $this;
- }
-
- private function processForm($is_request, $source) {
- if ($this->pageExists($this->choosePage)) {
- $selected = $this->getPage($this->choosePage);
- } else {
- $selected = $this->getPageByIndex(0);
- }
-
- $is_attempt_complete = false;
- if ($this->prevPage) {
- $prev_index = $this->getPageIndex($selected->getKey()) - 1;
- $index = max(0, $prev_index);
- $selected = $this->getPageByIndex($index);
- } else if ($this->nextPage) {
- $next_index = $this->getPageIndex($selected->getKey()) + 1;
- if ($next_index > $this->getLastIndex()) {
- $is_attempt_complete = true;
- }
- $index = min($this->getLastIndex(), $next_index);
- $selected = $this->getPageByIndex($index);
- }
-
- $validation_error = false;
- $found_selected = false;
- foreach ($this->pages as $key => $page) {
- if ($is_request) {
- if ($key === $this->choosePage) {
- $page->readFromRequest($source);
- } else {
- $page->readSerializedValues($source);
- }
- } else {
- $page->readFromObject($source);
- }
-
- if (!$found_selected) {
- $page->adjustFormPage();
- }
-
- if ($page === $selected) {
- $found_selected = true;
- }
-
- if (!$found_selected || $is_attempt_complete) {
- if (!$page->isValid()) {
- $selected = $page;
- $validation_error = true;
- break;
- }
- }
- }
-
- if ($is_attempt_complete && !$validation_error) {
- $this->complete = true;
- } else {
- $this->selectedPage = $selected;
- }
-
- return $this;
- }
-
- public function isComplete() {
- return $this->complete;
- }
-
- public function getRequestKey($key) {
- return $this->name.':'.$key;
- }
-
- public function setCancelURI($cancel_uri) {
- $this->cancelURI = $cancel_uri;
- return $this;
- }
-
- public function getCancelURI() {
- return $this->cancelURI;
- }
-
- public function render() {
- $form = id(new AphrontFormView())
- ->setUser($this->getUser());
-
- $selected_page = $this->getSelectedPage();
- if (!$selected_page) {
- throw new Exception(pht('No selected page!'));
- }
-
- $form->addHiddenInput(
- $this->getRequestKey('page'),
- $selected_page->getKey());
-
- $errors = array();
-
- foreach ($this->pages as $page) {
- if ($page == $selected_page) {
- $errors = $page->getPageErrors();
- continue;
- }
- foreach ($page->getSerializedValues() as $key => $value) {
- $form->addHiddenInput($key, $value);
- }
- }
-
- $submit = id(new PHUIFormMultiSubmitControl());
-
- if (!$this->isFirstPage($selected_page)) {
- $submit->addBackButton();
- } else if ($this->getCancelURI()) {
- $submit->addCancelButton($this->getCancelURI());
- }
-
- if ($this->isLastPage($selected_page)) {
- $submit->addSubmitButton(pht('Save'));
- } else {
- $submit->addSubmitButton(pht('Continue')." \xC2\xBB");
- }
-
- $form->appendChild($selected_page);
- $form->appendChild($submit);
-
- $box = id(new PHUIObjectBoxView())
- ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
- ->setFormErrors($errors)
- ->setForm($form);
-
- if ($selected_page->getPageName()) {
- $header = id(new PHUIHeaderView())
- ->setHeader($selected_page->getPageName());
- $box->setHeader($header);
- }
-
- return $box;
- }
-
-}
diff --git a/src/view/form/control/AphrontFormControl.php b/src/view/form/control/AphrontFormControl.php
--- a/src/view/form/control/AphrontFormControl.php
+++ b/src/view/form/control/AphrontFormControl.php
@@ -11,7 +11,6 @@
private $id;
private $controlID;
private $controlStyle;
- private $formPage;
private $required;
private $hidden;
private $classes;
@@ -132,21 +131,6 @@
return $this;
}
- public function setFormPage(PHUIFormPageView $page) {
- if ($this->formPage) {
- throw new Exception(pht('This control is already a member of a page!'));
- }
- $this->formPage = $page;
- return $this;
- }
-
- public function getFormPage() {
- if ($this->formPage === null) {
- throw new Exception(pht('This control does not have a page!'));
- }
- return $this->formPage;
- }
-
public function setDisabled($disabled) {
$this->disabled = $disabled;
return $this;
diff --git a/src/view/form/control/PHUIFormMultiSubmitControl.php b/src/view/form/control/PHUIFormMultiSubmitControl.php
deleted file mode 100644
--- a/src/view/form/control/PHUIFormMultiSubmitControl.php
+++ /dev/null
@@ -1,61 +0,0 @@
-<?php
-
-final class PHUIFormMultiSubmitControl extends AphrontFormControl {
-
- private $buttons = array();
-
- public function addBackButton($label = null) {
- if ($label === null) {
- $label = "\xC2\xAB ".pht('Back');
- }
- return $this->addButton('__back__', $label, 'grey');
- }
-
- public function addSubmitButton($label) {
- return $this->addButton('__submit__', $label);
- }
-
- public function addCancelButton($uri, $label = null) {
- if ($label === null) {
- $label = pht('Cancel');
- }
-
- $this->buttons[] = phutil_tag(
- 'a',
- array(
- 'class' => 'grey button',
- 'href' => $uri,
- ),
- $label);
-
- return $this;
- }
-
- public function addButtonView(PHUIButtonView $button) {
- $this->buttons[] = $button;
- return $this;
- }
-
- public function addButton($name, $label, $class = null) {
- $this->buttons[] = javelin_tag(
- 'input',
- array(
- 'type' => 'submit',
- 'name' => $name,
- 'value' => $label,
- 'class' => $class,
- 'sigil' => 'alternate-submit-button',
- 'disabled' => $this->getDisabled() ? 'disabled' : null,
- ));
- return $this;
- }
-
- protected function getCustomControlClass() {
- return 'phui-form-control-multi-submit';
- }
-
- protected function renderInput() {
- return array_reverse($this->buttons);
- }
-
-}

File Metadata

Mime Type
text/plain
Expires
Sat, Sep 21, 5:48 AM (21 h, 15 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6624973
Default Alt Text
D16302.diff (20 KB)

Event Timeline