1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-23 15:22:41 +01:00

Inset view controller for inset elements of forms.

Summary:
T937 suggests 'inset' could have its own view controller.

It has the following methods:
 - setTitle         for title
 - setRightbutton   if you have to place something (preferably a button)
                    on the right side of the form
 - setDescription   if you want to describe what it does
 - setContent       for the main content
 - addDivAttributes REALLY not sure about this one but it had to be included
                    because of a single controller (see owners/controller/edit/PhabricatorOwnersEditController.php:238)
 - appendChild      works as usual if your form is complex but you still want to remove
                    ->appendChild('<div class..') ->appendChild('</div>');

It might be an overkill so maybe some could be dropped:
 - addDivAttributes() and just rewrite how PhabricatorOwnersEditController.php works
 - setContent() and use appendChild for the main content?

Test Plan:
 - Looked at the controllers in phabricator
 - Changed the controller
 - Opened the page in another tab
 - If something didnd't look the same I fixed it.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, epriestley

Differential Revision: https://secure.phabricator.com/D1926
This commit is contained in:
Hafsteinn Baldvinsson 2012-03-15 17:10:19 -07:00 committed by epriestley
parent 7c67b5e600
commit fffc1e51d0
13 changed files with 243 additions and 123 deletions

View file

@ -34,6 +34,7 @@ phutil_register_library_map(array(
'AphrontFormDividerControl' => 'view/form/control/divider', 'AphrontFormDividerControl' => 'view/form/control/divider',
'AphrontFormDragAndDropUploadControl' => 'view/form/control/draganddropupload', 'AphrontFormDragAndDropUploadControl' => 'view/form/control/draganddropupload',
'AphrontFormFileControl' => 'view/form/control/file', 'AphrontFormFileControl' => 'view/form/control/file',
'AphrontFormInsetView' => 'view/form/inset',
'AphrontFormLayoutView' => 'view/form/layout', 'AphrontFormLayoutView' => 'view/form/layout',
'AphrontFormMarkupControl' => 'view/form/control/markup', 'AphrontFormMarkupControl' => 'view/form/control/markup',
'AphrontFormPasswordControl' => 'view/form/control/password', 'AphrontFormPasswordControl' => 'view/form/control/password',
@ -935,6 +936,7 @@ phutil_register_library_map(array(
'AphrontFormDividerControl' => 'AphrontFormControl', 'AphrontFormDividerControl' => 'AphrontFormControl',
'AphrontFormDragAndDropUploadControl' => 'AphrontFormControl', 'AphrontFormDragAndDropUploadControl' => 'AphrontFormControl',
'AphrontFormFileControl' => 'AphrontFormControl', 'AphrontFormFileControl' => 'AphrontFormControl',
'AphrontFormInsetView' => 'AphrontView',
'AphrontFormLayoutView' => 'AphrontView', 'AphrontFormLayoutView' => 'AphrontView',
'AphrontFormMarkupControl' => 'AphrontFormControl', 'AphrontFormMarkupControl' => 'AphrontFormControl',
'AphrontFormPasswordControl' => 'AphrontFormControl', 'AphrontFormPasswordControl' => 'AphrontFormControl',

View file

@ -165,34 +165,31 @@ final class HeraldRuleController extends HeraldController {
"This <strong>${rule_type_name}</strong> rule triggers for " . "This <strong>${rule_type_name}</strong> rule triggers for " .
"<strong>${content_type_name}</strong>.")) "<strong>${content_type_name}</strong>."))
->appendChild( ->appendChild(
'<h1>Conditions</h1>'. id(new AphrontFormInsetView())
'<div class="aphront-form-inset">'. ->setTitle('Conditions')
'<div style="float: right;">'. ->setRightButton(javelin_render_tag(
javelin_render_tag(
'a', 'a',
array( array(
'href' => '#', 'href' => '#',
'class' => 'button green', 'class' => 'button green',
'sigil' => 'create-condition', 'sigil' => 'create-condition',
'mustcapture' => true, 'mustcapture' => true
), ),
'Create New Condition'). 'Create New Condition'))
'</div>'. ->setDescription(
'<p>When '.$must_match_selector.' these conditions are met:</p>'. 'When '.$must_match_selector .
'<div style="clear: both;"></div>'. ' these conditions are met:')
javelin_render_tag( ->setContent(javelin_render_tag(
'table', 'table',
array( array(
'sigil' => 'rule-conditions', 'sigil' => 'rule-conditions',
'class' => 'herald-condition-table', 'class' => 'herald-condition-table'
), ),
''). '')))
'</div>')
->appendChild( ->appendChild(
'<h1>Action</h1>'. id(new AphrontFormInsetView())
'<div class="aphront-form-inset">'. ->setTitle('Action')
'<div style="float: right;">'. ->setRightButton(javelin_render_tag(
javelin_render_tag(
'a', 'a',
array( array(
'href' => '#', 'href' => '#',
@ -200,20 +197,16 @@ final class HeraldRuleController extends HeraldController {
'sigil' => 'create-action', 'sigil' => 'create-action',
'mustcapture' => true, 'mustcapture' => true,
), ),
'Create New Action'). 'Create New Action'))
'</div>'. ->setDescription('Take these actions '.$repetition_selector.
'<p>'. ' this rule matches:')
'Take these actions '.$repetition_selector.' this rule matches:'. ->setContent(javelin_render_tag(
'</p>'.
'<div style="clear: both;"></div>'.
javelin_render_tag(
'table', 'table',
array( array(
'sigil' => 'rule-actions', 'sigil' => 'rule-actions',
'class' => 'herald-action-table', 'class' => 'herald-action-table',
), ),
''). '')))
'</div>')
->appendChild( ->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->setValue('Save Rule') ->setValue('Save Rule')

View file

@ -28,6 +28,7 @@ phutil_require_module('phabricator', 'view/form/control/markup');
phutil_require_module('phabricator', 'view/form/control/submit'); phutil_require_module('phabricator', 'view/form/control/submit');
phutil_require_module('phabricator', 'view/form/control/text'); phutil_require_module('phabricator', 'view/form/control/text');
phutil_require_module('phabricator', 'view/form/error'); phutil_require_module('phabricator', 'view/form/error');
phutil_require_module('phabricator', 'view/form/inset');
phutil_require_module('phabricator', 'view/layout/panel'); phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phutil', 'markup'); phutil_require_module('phutil', 'markup');

View file

@ -104,10 +104,9 @@ final class ManiphestBatchEditController extends ManiphestController {
$form->appendChild('<p>These tasks will be edited:</p>'); $form->appendChild('<p>These tasks will be edited:</p>');
$form->appendChild($list); $form->appendChild($list);
$form->appendChild( $form->appendChild(
'<h1>Actions</h1>'. id(new AphrontFormInsetView())
'<div class="aphront-form-inset">'. ->setTitle('Actions')
'<div style="float: right;">'. ->setRightButton(javelin_render_tag(
javelin_render_tag(
'a', 'a',
array( array(
'href' => '#', 'href' => '#',
@ -115,17 +114,14 @@ final class ManiphestBatchEditController extends ManiphestController {
'sigil' => 'add-action', 'sigil' => 'add-action',
'mustcapture' => true, 'mustcapture' => true,
), ),
'Add Another Action'). 'Add Another Action'))
'</div>'. ->setContent(javelin_render_tag(
'<div style="clear: both;"></div>'.
javelin_render_tag(
'table', 'table',
array( array(
'sigil' => 'maniphest-batch-actions', 'sigil' => 'maniphest-batch-actions',
'class' => 'maniphest-batch-actions-table', 'class' => 'maniphest-batch-actions-table',
), ),
''). '')))
'</div>')
->appendChild( ->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->setValue('Update Tasks') ->setValue('Update Tasks')

View file

@ -20,6 +20,7 @@ phutil_require_module('phabricator', 'infrastructure/javelin/markup');
phutil_require_module('phabricator', 'view/control/tokenizer'); phutil_require_module('phabricator', 'view/control/tokenizer');
phutil_require_module('phabricator', 'view/form/base'); phutil_require_module('phabricator', 'view/form/base');
phutil_require_module('phabricator', 'view/form/control/submit'); phutil_require_module('phabricator', 'view/form/control/submit');
phutil_require_module('phabricator', 'view/form/inset');
phutil_require_module('phabricator', 'view/layout/panel'); phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phutil', 'markup'); phutil_require_module('phutil', 'markup');

View file

@ -233,10 +233,10 @@ final class PhabricatorOwnersEditController
? 'enabled' ? 'enabled'
: 'disabled')) : 'disabled'))
->appendChild( ->appendChild(
'<h1>Paths</h1>'. id(new AphrontFormInsetView())
'<div class="aphront-form-inset" id="path-editor">'. ->setTitle('Paths')
'<div style="float: right;">'. ->addDivAttributes(array('id' => 'path-editor'))
javelin_render_tag( ->setRightButton(javelin_render_tag(
'a', 'a',
array( array(
'href' => '#', 'href' => '#',
@ -244,19 +244,16 @@ final class PhabricatorOwnersEditController
'sigil' => 'addpath', 'sigil' => 'addpath',
'mustcapture' => true, 'mustcapture' => true,
), ),
'Add New Path'). 'Add New Path'))
'</div>'. ->setDescription('Specify the files and directories which comprise '.
'<p>Specify the files and directories which comprise this '. 'this package.')
'package.</p>'. ->setContent(javelin_render_tag(
'<div style="clear: both;"></div>'.
javelin_render_tag(
'table', 'table',
array( array(
'class' => 'owners-path-editor-table', 'class' => 'owners-path-editor-table',
'sigil' => 'paths', 'sigil' => 'paths',
), ),
''). '')))
'</div>')
->appendChild( ->appendChild(
id(new AphrontFormTextAreaControl()) id(new AphrontFormTextAreaControl())
->setLabel('Description') ->setLabel('Description')

View file

@ -23,6 +23,7 @@ phutil_require_module('phabricator', 'view/form/control/text');
phutil_require_module('phabricator', 'view/form/control/textarea'); phutil_require_module('phabricator', 'view/form/control/textarea');
phutil_require_module('phabricator', 'view/form/control/tokenizer'); phutil_require_module('phabricator', 'view/form/control/tokenizer');
phutil_require_module('phabricator', 'view/form/error'); phutil_require_module('phabricator', 'view/form/error');
phutil_require_module('phabricator', 'view/form/inset');
phutil_require_module('phabricator', 'view/layout/panel'); phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phutil', 'utils'); phutil_require_module('phutil', 'utils');

View file

@ -258,11 +258,9 @@ final class PhabricatorProjectProfileEditController
->setError($e_image) ->setError($e_image)
->setCaption('Supported formats: '.implode(', ', $supported_formats))) ->setCaption('Supported formats: '.implode(', ', $supported_formats)))
->appendChild( ->appendChild(
'<h1>Resources</h1>'. id(new AphrontFormInsetView())
'<input type="hidden" name="resources" id="resources" />'. ->setTitle('Resources')
'<div class="aphront-form-inset">'. ->setRightButton(javelin_render_tag(
'<div style="float: right;">'.
javelin_render_tag(
'a', 'a',
array( array(
'href' => '#', 'href' => '#',
@ -270,18 +268,15 @@ final class PhabricatorProjectProfileEditController
'sigil' => 'add-resource', 'sigil' => 'add-resource',
'mustcapture' => true, 'mustcapture' => true,
), ),
'Add New Resource'). 'Add New Resource'))
'</div>'. ->addHiddenInput('resources', 'resources')
'<p></p>'. ->setContent(javelin_render_tag(
'<div style="clear: both;"></div>'.
javelin_render_tag(
'table', 'table',
array( array(
'sigil' => 'resources', 'sigil' => 'resources',
'class' => 'project-resource-table', 'class' => 'project-resource-table',
), ),
''). '')))
'</div>')
->appendChild( ->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->addCancelButton('/project/view/'.$project->getID().'/') ->addCancelButton('/project/view/'.$project->getID().'/')

View file

@ -31,6 +31,7 @@ phutil_require_module('phabricator', 'view/form/control/text');
phutil_require_module('phabricator', 'view/form/control/textarea'); phutil_require_module('phabricator', 'view/form/control/textarea');
phutil_require_module('phabricator', 'view/form/control/tokenizer'); phutil_require_module('phabricator', 'view/form/control/tokenizer');
phutil_require_module('phabricator', 'view/form/error'); phutil_require_module('phabricator', 'view/form/error');
phutil_require_module('phabricator', 'view/form/inset');
phutil_require_module('phabricator', 'view/layout/panel'); phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phutil', 'utils'); phutil_require_module('phutil', 'utils');

View file

@ -389,13 +389,12 @@ final class PhabricatorRepositoryEditController
$form $form
->appendChild( ->appendChild(
'<h1>Basics</h1><div class="aphront-form-inset">') id(new AphrontFormInsetView())
->appendChild( ->setTitle('Basics')
id(new AphrontFormStaticControl()) ->appendChild(id(new AphrontFormStaticControl())
->setLabel('Repository Name') ->setLabel('Repository Name')
->setValue($repository->getName())) ->setValue($repository->getName()))
->appendChild( ->appendChild(id(new AphrontFormSelectControl())
id(new AphrontFormSelectControl())
->setName('tracking') ->setName('tracking')
->setLabel('Tracking') ->setLabel('Tracking')
->setOptions(array( ->setOptions(array(
@ -405,12 +404,10 @@ final class PhabricatorRepositoryEditController
->setValue( ->setValue(
$repository->isTracked() $repository->isTracked()
? 'enabled' ? 'enabled'
: 'disabled')) : 'disabled')));
->appendChild('</div>');
$form->appendChild( $inset = new AphrontFormInsetView();
'<h1>Remote URI</h1>'. $inset->setTitle('Remote URI');
'<div class="aphront-form-inset">');
$clone_command = null; $clone_command = null;
$fetch_command = null; $fetch_command = null;
@ -435,7 +432,7 @@ final class PhabricatorRepositoryEditController
'Enter the URI to clone this repository from. It should look '. 'Enter the URI to clone this repository from. It should look '.
'something like <tt>ssh://user@host.com/hg/example</tt>'; 'something like <tt>ssh://user@host.com/hg/example</tt>';
} }
$form->appendChild( $inset->appendChild(
'<p class="aphront-form-instructions">'.$instructions.'</p>'); '<p class="aphront-form-instructions">'.$instructions.'</p>');
} else if ($is_svn) { } else if ($is_svn) {
$instructions = $instructions =
@ -444,12 +441,12 @@ final class PhabricatorRepositoryEditController
'the value in the <tt>Repository Root</tt> field. It should be a URI '. 'the value in the <tt>Repository Root</tt> field. It should be a URI '.
'and look like <tt>http://svn.example.org/svn/</tt> or '. 'and look like <tt>http://svn.example.org/svn/</tt> or '.
'<tt>svn+ssh://svn.example.com/svnroot/</tt>'; '<tt>svn+ssh://svn.example.com/svnroot/</tt>';
$form->appendChild( $inset->appendChild(
'<p class="aphront-form-instructions">'.$instructions.'</p>'); '<p class="aphront-form-instructions">'.$instructions.'</p>');
$uri_label = 'Repository Root'; $uri_label = 'Repository Root';
} }
$form $inset
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
->setName('uri') ->setName('uri')
@ -458,14 +455,14 @@ final class PhabricatorRepositoryEditController
->setValue($repository->getDetail('remote-uri')) ->setValue($repository->getDetail('remote-uri'))
->setError($e_uri)); ->setError($e_uri));
$form->appendChild( $inset->appendChild(
'<div class="aphront-form-instructions">'. '<div class="aphront-form-instructions">'.
'If you want to connect to this repository over SSH, enter the '. 'If you want to connect to this repository over SSH, enter the '.
'username and private key to use. You can leave these fields blank if '. 'username and private key to use. You can leave these fields blank if '.
'the repository does not use SSH.'. 'the repository does not use SSH.'.
'</div>'); '</div>');
$form $inset
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
->setName('ssh-login') ->setName('ssh-login')
@ -490,7 +487,7 @@ final class PhabricatorRepositoryEditController
'look for a private key.')); 'look for a private key.'));
if ($has_http_support) { if ($has_http_support) {
$form $inset
->appendChild( ->appendChild(
'<div class="aphront-form-instructions">'. '<div class="aphront-form-instructions">'.
'If you want to connect to this repository over HTTP Basic Auth, '. 'If you want to connect to this repository over HTTP Basic Auth, '.
@ -509,7 +506,7 @@ final class PhabricatorRepositoryEditController
->setValue($repository->getDetail('http-pass'))); ->setValue($repository->getDetail('http-pass')));
} }
$form $inset
->appendChild( ->appendChild(
'<div class="aphront-form-important">'. '<div class="aphront-form-important">'.
'To test your authentication configuration, <strong>save this '. 'To test your authentication configuration, <strong>save this '.
@ -523,33 +520,32 @@ final class PhabricatorRepositoryEditController
'from it.'. 'from it.'.
'</div>'); '</div>');
$form->appendChild('</div>'); $form->appendChild($inset);
$form->appendChild( $inset = new AphrontFormInsetView();
'<h1>Importing Repository Information</h1>'. $inset->setTitle('Repository Information');
'<div class="aphront-form-inset">');
if ($has_local) { if ($has_local) {
$form->appendChild( $inset->appendChild(
'<p class="aphront-form-instructions">Select a path on local disk '. '<p class="aphront-form-instructions">Select a path on local disk '.
'which the daemons should <tt>'.$clone_command.'</tt> the repository '. 'which the daemons should <tt>'.$clone_command.'</tt> the repository '.
'into. This must be readable and writable by the daemons, and '. 'into. This must be readable and writable by the daemons, and '.
'readable by the webserver. The daemons will <tt>'.$fetch_command. 'readable by the webserver. The daemons will <tt>'.$fetch_command.
'</tt> and keep this repository up to date.</p>'); '</tt> and keep this repository up to date.</p>');
$form->appendChild( $inset->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
->setName('path') ->setName('path')
->setLabel('Local Path') ->setLabel('Local Path')
->setValue($repository->getDetail('local-path')) ->setValue($repository->getDetail('local-path'))
->setError($e_path)); ->setError($e_path));
} else if ($is_svn) { } else if ($is_svn) {
$form->appendChild( $inset->appendChild(
'<p class="aphront-form-instructions">If you only want to parse one '. '<p class="aphront-form-instructions">If you only want to parse one '.
'subpath of the repository, specify it here, relative to the '. 'subpath of the repository, specify it here, relative to the '.
'repository root (e.g., <tt>trunk/</tt> or <tt>projects/wheel/</tt>). '. 'repository root (e.g., <tt>trunk/</tt> or <tt>projects/wheel/</tt>). '.
'If you want to parse multiple subdirectories, create a separate '. 'If you want to parse multiple subdirectories, create a separate '.
'Phabricator repository for each one.</p>'); 'Phabricator repository for each one.</p>');
$form->appendChild( $inset->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
->setName('svn-subpath') ->setName('svn-subpath')
->setLabel('Subpath') ->setLabel('Subpath')
@ -561,7 +557,7 @@ final class PhabricatorRepositoryEditController
$branch_filter_str = implode( $branch_filter_str = implode(
', ', ', ',
array_keys($repository->getDetail('branch-filter', array()))); array_keys($repository->getDetail('branch-filter', array())));
$form $inset
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
->setName('branch-filter') ->setName('branch-filter')
@ -573,7 +569,7 @@ final class PhabricatorRepositoryEditController
'Example: <tt>master, release</tt>')); 'Example: <tt>master, release</tt>'));
} }
$form $inset
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
->setName('frequency') ->setName('frequency')
@ -583,11 +579,10 @@ final class PhabricatorRepositoryEditController
'Number of seconds daemon should sleep between requests. Larger '. 'Number of seconds daemon should sleep between requests. Larger '.
'numbers reduce load but also decrease responsiveness.')); 'numbers reduce load but also decrease responsiveness.'));
$form->appendChild('</div>'); $form->appendChild($inset);
$form->appendChild( $inset = new AphrontFormInsetView();
'<h1>Application Configuration</h1>'. $inset->setTitle('Application Configuration');
'<div class="aphront-form-inset">');
if ($has_branches) { if ($has_branches) {
@ -598,7 +593,7 @@ final class PhabricatorRepositoryEditController
$default_branch_name = 'master'; $default_branch_name = 'master';
} }
$form $inset
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
->setName('default-branch') ->setName('default-branch')
@ -612,7 +607,7 @@ final class PhabricatorRepositoryEditController
'Default branch to show in Diffusion.')); 'Default branch to show in Diffusion.'));
} }
$form $inset
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
->setName('default-owners-path') ->setName('default-owners-path')
@ -623,7 +618,7 @@ final class PhabricatorRepositoryEditController
'/')) '/'))
->setCaption('Default path in Owners tool.')); ->setCaption('Default path in Owners tool.'));
$form $inset
->appendChild( ->appendChild(
id(new AphrontFormSelectControl()) id(new AphrontFormSelectControl())
->setName('herald-disabled') ->setName('herald-disabled')
@ -643,7 +638,7 @@ final class PhabricatorRepositoryEditController
->selectSymbolsWithoutLoading(); ->selectSymbolsWithoutLoading();
$parsers = ipull($parsers, 'name', 'name'); $parsers = ipull($parsers, 'name', 'name');
$form $inset
->appendChild( ->appendChild(
'<p class="aphront-form-instructions">If you extend the commit '. '<p class="aphront-form-instructions">If you extend the commit '.
'message format, you can provide a new parser which will extract '. 'message format, you can provide a new parser which will extract '.
@ -661,7 +656,7 @@ final class PhabricatorRepositoryEditController
'PhabricatorRepositoryDefaultCommitMessageDetailParser'))); 'PhabricatorRepositoryDefaultCommitMessageDetailParser')));
if ($is_svn) { if ($is_svn) {
$form $inset
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
->setName('uuid') ->setName('uuid')
@ -670,7 +665,7 @@ final class PhabricatorRepositoryEditController
->setCaption('Repository UUID from <tt>svn info</tt>.')); ->setCaption('Repository UUID from <tt>svn info</tt>.'));
} }
$form->appendChild('</div>'); $form->appendChild($inset);
$form $form
->appendChild( ->appendChild(

View file

@ -20,6 +20,7 @@ phutil_require_module('phabricator', 'view/form/control/submit');
phutil_require_module('phabricator', 'view/form/control/text'); phutil_require_module('phabricator', 'view/form/control/text');
phutil_require_module('phabricator', 'view/form/control/textarea'); phutil_require_module('phabricator', 'view/form/control/textarea');
phutil_require_module('phabricator', 'view/form/error'); phutil_require_module('phabricator', 'view/form/error');
phutil_require_module('phabricator', 'view/form/inset');
phutil_require_module('phabricator', 'view/layout/panel'); phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phabricator', 'view/layout/sidenav'); phutil_require_module('phabricator', 'view/layout/sidenav');

View file

@ -0,0 +1,123 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class AphrontFormInsetView extends AphrontView {
private $title;
private $description;
private $rightButton;
private $content;
private $hidden = array();
private $divAttributes;
public function setTitle($title) {
$this->title = $title;
return $this;
}
public function setDescription($description) {
$this->description = $description;
return $this;
}
public function setRightButton($button) {
$this->rightButton = $button;
return $this;
}
public function setContent($content) {
$this->content = $content;
return $this;
}
public function addHiddenInput($key, $value) {
if (is_array($value)) {
foreach ($value as $hidden_key => $hidden_value) {
$this->hidden[] = array($key.'['.$hidden_key.']', $hidden_value);
}
} else {
$this->hidden[] = array($key, $value);
}
return $this;
}
public function addDivAttributes(array $attributes) {
$this->divAttributes = $attributes;
return $this;
}
public function render() {
$title = $hidden_inputs = $right_button = $desc = $content = '';
if ($this->title) {
$title = '<h1>'.phutil_escape_html($this->title).'</h1>';
}
$hidden_inputs = array();
foreach ($this->hidden as $inp) {
list($key, $value) = $inp;
$hidden_inputs[] = phutil_render_tag(
'input',
array(
'type' => 'hidden',
'name' => $key,
'value' => $value,
));
}
$hidden_inputs = implode("\n", $hidden_inputs);
if ($this->rightButton) {
$right_button = phutil_render_tag(
'div',
array(
'style' => 'float: right;',
),
$this->rightButton);
}
if ($this->description) {
$desc = phutil_render_tag(
'p',
array(),
$this->description);
if ($right_button) {
$desc .= '<div style="clear: both;"></div>';
}
}
$div_attributes = $this->divAttributes;
$classes = array('aphront-form-inset');
if (isset($div_attributes['class'])) {
$classes[] = $div_attributes['class'];
}
$div_attributes['class'] = implode(' ', $classes);
if ($this->content) {
$content = $this->content;
}
return $title.phutil_render_tag(
'div',
$div_attributes,
$hidden_inputs.$right_button.$desc.$content.$this->renderChildren());
}
}

View file

@ -0,0 +1,14 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'view/base');
phutil_require_module('phutil', 'markup');
phutil_require_source('AphrontFormInsetView.php');