2011-02-16 22:14:09 -08:00
|
|
|
<?php
|
|
|
|
|
2012-03-13 16:21:04 -07:00
|
|
|
final class PhabricatorObjectSelectorDialog {
|
2011-02-16 22:14:09 -08:00
|
|
|
|
2011-02-17 14:32:01 -08:00
|
|
|
private $user;
|
|
|
|
private $filters = array();
|
|
|
|
private $handles = array();
|
|
|
|
private $cancelURI;
|
|
|
|
private $submitURI;
|
|
|
|
private $searchURI;
|
2011-05-16 11:43:39 -07:00
|
|
|
private $selectedFilter;
|
2012-04-03 18:34:55 -07:00
|
|
|
private $excluded;
|
2011-02-17 14:32:01 -08:00
|
|
|
|
2011-06-14 07:55:04 -07:00
|
|
|
private $title;
|
|
|
|
private $header;
|
|
|
|
private $buttonText;
|
|
|
|
private $instructions;
|
|
|
|
|
2011-02-17 14:32:01 -08:00
|
|
|
public function setUser($user) {
|
|
|
|
$this->user = $user;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setFilters(array $filters) {
|
|
|
|
$this->filters = $filters;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-05-16 11:43:39 -07:00
|
|
|
public function setSelectedFilter($selected_filter) {
|
|
|
|
$this->selectedFilter = $selected_filter;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-04-03 18:34:55 -07:00
|
|
|
public function setExcluded($excluded_phid) {
|
|
|
|
$this->excluded = $excluded_phid;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-02-17 14:32:01 -08:00
|
|
|
public function setHandles(array $handles) {
|
2012-04-03 12:10:45 -07:00
|
|
|
assert_instances_of($handles, 'PhabricatorObjectHandle');
|
2011-02-17 14:32:01 -08:00
|
|
|
$this->handles = $handles;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setCancelURI($cancel_uri) {
|
|
|
|
$this->cancelURI = $cancel_uri;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setSubmitURI($submit_uri) {
|
|
|
|
$this->submitURI = $submit_uri;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setSearchURI($search_uri) {
|
|
|
|
$this->searchURI = $search_uri;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-06-14 07:55:04 -07:00
|
|
|
public function setTitle($title) {
|
|
|
|
$this->title = $title;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setHeader($header) {
|
|
|
|
$this->header = $header;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setButtonText($button_text) {
|
|
|
|
$this->buttonText = $button_text;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setInstructions($instructions) {
|
|
|
|
$this->instructions = $instructions;
|
2011-02-17 14:32:01 -08:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildDialog() {
|
|
|
|
$user = $this->user;
|
|
|
|
|
|
|
|
$filter_id = celerity_generate_unique_node_id();
|
|
|
|
$query_id = celerity_generate_unique_node_id();
|
|
|
|
$results_id = celerity_generate_unique_node_id();
|
|
|
|
$current_id = celerity_generate_unique_node_id();
|
|
|
|
$search_id = celerity_generate_unique_node_id();
|
|
|
|
$form_id = celerity_generate_unique_node_id();
|
|
|
|
|
|
|
|
require_celerity_resource('phabricator-object-selector-css');
|
|
|
|
|
|
|
|
$options = array();
|
|
|
|
foreach ($this->filters as $key => $label) {
|
2013-01-25 05:50:50 -08:00
|
|
|
$options[] = phutil_tag(
|
2011-02-17 14:32:01 -08:00
|
|
|
'option',
|
|
|
|
array(
|
2011-05-16 11:43:39 -07:00
|
|
|
'value' => $key,
|
|
|
|
'selected' => ($key == $this->selectedFilter)
|
|
|
|
? 'selected'
|
|
|
|
: null,
|
2011-02-17 14:32:01 -08:00
|
|
|
),
|
|
|
|
$label);
|
|
|
|
}
|
|
|
|
|
2011-06-14 07:55:04 -07:00
|
|
|
$instructions = null;
|
|
|
|
if ($this->instructions) {
|
2013-02-13 14:50:15 -08:00
|
|
|
$instructions = phutil_tag(
|
|
|
|
'p',
|
|
|
|
array('class' => 'phabricator-object-selector-instructions'),
|
|
|
|
$this->instructions);
|
2011-06-14 07:55:04 -07:00
|
|
|
}
|
|
|
|
|
2013-02-13 14:50:15 -08:00
|
|
|
$search_box = phabricator_form(
|
2011-02-17 14:32:01 -08:00
|
|
|
$user,
|
|
|
|
array(
|
|
|
|
'method' => 'POST',
|
|
|
|
'action' => $this->submitURI,
|
|
|
|
'id' => $search_id,
|
|
|
|
),
|
2013-02-13 14:50:15 -08:00
|
|
|
hsprintf(
|
|
|
|
'<table class="phabricator-object-selector-search">
|
|
|
|
<tr>
|
|
|
|
<td class="phabricator-object-selector-search-filter">%s</td>
|
|
|
|
<td class="phabricator-object-selector-search-text">%s</td>
|
|
|
|
</tr>
|
|
|
|
</table>',
|
Update form styles, implement in many places
Summary:
This creates a common form look and feel across the site. I spent a bit of time working out a number of kinks in our various renderings. Some things:
- Font Styles are correctly applied for form elements now.
- Everything lines up!
- Selects are larger, easier to read, interact.
- Inputs have been squared.
- Consistant CSS applied glow (try it!)
- Improved Mobile Responsiveness
- CSS applied to all form elements, not just Aphront
- Many other minor tweaks.
I tried to hit as many high profile forms as possible in an effort to increase consistency. Stopped for now and will follow up after this lands. I know Evan is not a super fan of the glow, but after working with it for a week, it's way cleaner and responsive than the OS controls. Give it a try.
Test Plan: Tested many applications, forms, mobile and tablet.
Reviewers: epriestley, btrahan
Reviewed By: epriestley
CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D5860
2013-05-07 14:07:06 -07:00
|
|
|
phutil_tag(
|
|
|
|
'select',
|
|
|
|
array('id' => $filter_id),
|
|
|
|
$options),
|
|
|
|
phutil_tag(
|
|
|
|
'input',
|
|
|
|
array(
|
|
|
|
'id' => $query_id,
|
|
|
|
'type' => 'text'))));
|
2013-02-13 14:50:15 -08:00
|
|
|
|
|
|
|
$result_box = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-object-selector-results',
|
|
|
|
'id' => $results_id,
|
|
|
|
),
|
|
|
|
'');
|
|
|
|
|
|
|
|
$attached_box = hsprintf(
|
2011-02-17 14:32:01 -08:00
|
|
|
'<div class="phabricator-object-selector-current">'.
|
|
|
|
'<div class="phabricator-object-selector-currently-attached">'.
|
2013-02-13 14:50:15 -08:00
|
|
|
'<div class="phabricator-object-selector-header">%s</div>'.
|
|
|
|
'<div id="%s"></div>'.
|
|
|
|
'%s'.
|
2011-02-17 14:32:01 -08:00
|
|
|
'</div>'.
|
2013-02-13 14:50:15 -08:00
|
|
|
'</div>',
|
|
|
|
$this->header,
|
|
|
|
$current_id,
|
|
|
|
$instructions);
|
2011-02-17 14:32:01 -08:00
|
|
|
|
|
|
|
$dialog = new AphrontDialogView();
|
|
|
|
$dialog
|
|
|
|
->setUser($this->user)
|
2011-06-14 07:55:04 -07:00
|
|
|
->setTitle($this->title)
|
2011-02-17 14:32:01 -08:00
|
|
|
->setClass('phabricator-object-selector-dialog')
|
|
|
|
->appendChild($search_box)
|
|
|
|
->appendChild($result_box)
|
|
|
|
->appendChild($attached_box)
|
|
|
|
->setRenderDialogAsDiv()
|
|
|
|
->setFormID($form_id)
|
2011-06-14 07:55:04 -07:00
|
|
|
->addSubmitButton($this->buttonText);
|
2011-02-17 14:32:01 -08:00
|
|
|
|
|
|
|
if ($this->cancelURI) {
|
|
|
|
$dialog->addCancelButton($this->cancelURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
$handle_views = array();
|
2011-04-14 18:36:18 -07:00
|
|
|
foreach ($this->handles as $handle) {
|
|
|
|
$phid = $handle->getPHID();
|
2011-02-17 14:32:01 -08:00
|
|
|
$view = new PhabricatorHandleObjectSelectorDataView($handle);
|
|
|
|
$handle_views[$phid] = $view->renderData();
|
|
|
|
}
|
|
|
|
$dialog->addHiddenInput('phids', implode(';', array_keys($this->handles)));
|
|
|
|
|
|
|
|
|
|
|
|
Javelin::initBehavior(
|
|
|
|
'phabricator-object-selector',
|
|
|
|
array(
|
|
|
|
'filter' => $filter_id,
|
|
|
|
'query' => $query_id,
|
|
|
|
'search' => $search_id,
|
|
|
|
'results' => $results_id,
|
|
|
|
'current' => $current_id,
|
|
|
|
'form' => $form_id,
|
2012-04-03 18:34:55 -07:00
|
|
|
'exclude' => $this->excluded,
|
2011-02-17 14:32:01 -08:00
|
|
|
'uri' => $this->searchURI,
|
|
|
|
'handles' => $handle_views,
|
|
|
|
));
|
|
|
|
|
|
|
|
return $dialog;
|
|
|
|
}
|
2011-02-16 22:14:09 -08:00
|
|
|
|
|
|
|
}
|