2012-08-07 20:57:38 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorProjectMembersEditController
|
|
|
|
extends PhabricatorProjectController {
|
|
|
|
|
2012-10-04 23:33:50 +02:00
|
|
|
private $id;
|
|
|
|
|
2012-08-07 20:57:38 +02:00
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = $data['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
2012-08-15 19:44:58 +02:00
|
|
|
$project = id(new PhabricatorProjectQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->executeOne();
|
2012-08-07 20:57:38 +02:00
|
|
|
if (!$project) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
$profile = $project->loadProfile();
|
|
|
|
if (empty($profile)) {
|
|
|
|
$profile = new PhabricatorProjectProfile();
|
|
|
|
}
|
|
|
|
|
|
|
|
$member_phids = $project->loadMemberPHIDs();
|
|
|
|
|
|
|
|
$errors = array();
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$changed_something = false;
|
|
|
|
$member_map = array_fill_keys($member_phids, true);
|
|
|
|
|
|
|
|
$remove = $request->getStr('remove');
|
|
|
|
if ($remove) {
|
|
|
|
if (isset($member_map[$remove])) {
|
|
|
|
unset($member_map[$remove]);
|
|
|
|
$changed_something = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$new_members = $request->getArr('phids');
|
|
|
|
foreach ($new_members as $member) {
|
|
|
|
if (empty($member_map[$member])) {
|
|
|
|
$member_map[$member] = true;
|
|
|
|
$changed_something = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$xactions = array();
|
|
|
|
if ($changed_something) {
|
|
|
|
$xaction = new PhabricatorProjectTransaction();
|
|
|
|
$xaction->setTransactionType(
|
|
|
|
PhabricatorProjectTransactionType::TYPE_MEMBERS);
|
|
|
|
$xaction->setNewValue(array_keys($member_map));
|
|
|
|
$xactions[] = $xaction;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($xactions) {
|
|
|
|
$editor = new PhabricatorProjectEditor($project);
|
2012-10-10 19:18:23 +02:00
|
|
|
$editor->setActor($user);
|
2012-08-07 20:57:38 +02:00
|
|
|
$editor->applyTransactions($xactions);
|
|
|
|
}
|
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI($request->getRequestURI());
|
|
|
|
}
|
|
|
|
|
|
|
|
$member_phids = array_reverse($member_phids);
|
2012-09-05 04:02:56 +02:00
|
|
|
$handles = $this->loadViewerHandles($member_phids);
|
2012-08-07 20:57:38 +02:00
|
|
|
|
|
|
|
$state = array();
|
|
|
|
foreach ($handles as $handle) {
|
|
|
|
$state[] = array(
|
|
|
|
'phid' => $handle->getPHID(),
|
|
|
|
'name' => $handle->getFullName(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-02-13 18:22:14 +01:00
|
|
|
$header_name = pht('Edit Members');
|
|
|
|
$title = pht('Edit Members');
|
2012-08-07 20:57:38 +02:00
|
|
|
|
|
|
|
$list = $this->renderMemberList($handles);
|
|
|
|
|
|
|
|
$form = new AphrontFormView();
|
|
|
|
$form
|
|
|
|
->setUser($user)
|
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 23:07:06 +02:00
|
|
|
->setFlexible(true)
|
2012-08-07 20:57:38 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTokenizerControl())
|
|
|
|
->setName('phids')
|
2013-02-13 18:22:14 +01:00
|
|
|
->setLabel(pht('Add Members'))
|
2012-08-07 20:57:38 +02:00
|
|
|
->setDatasource('/typeahead/common/users/'))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->addCancelButton('/project/view/'.$project->getID().'/')
|
2013-02-13 18:22:14 +01:00
|
|
|
->setValue(pht('Add Members')));
|
2012-08-07 20:57:38 +02:00
|
|
|
$faux_form = id(new AphrontFormLayoutView())
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormInsetView())
|
2013-02-13 18:22:14 +01:00
|
|
|
->setTitle(pht('Current Members (%d)', count($handles)))
|
2012-08-07 20:57:38 +02:00
|
|
|
->appendChild($list));
|
|
|
|
|
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 23:07:06 +02:00
|
|
|
$box = new PHUIBoxView();
|
|
|
|
$box->appendChild($faux_form);
|
|
|
|
$box->setShadow(true);
|
|
|
|
$box->addPadding(PHUI::PADDING_LARGE);
|
|
|
|
$box->addMargin(PHUI::MARGIN_LARGE);
|
2012-08-07 20:57:38 +02:00
|
|
|
|
2013-02-13 18:22:14 +01:00
|
|
|
$crumbs = $this->buildApplicationCrumbs($this->buildSideNavView());
|
|
|
|
$crumbs->addCrumb(
|
|
|
|
id(new PhabricatorCrumbView())
|
|
|
|
->setName($project->getName())
|
2013-02-19 22:33:10 +01:00
|
|
|
->setHref('/project/view/'.$project->getID().'/'));
|
2013-02-13 18:22:14 +01:00
|
|
|
$crumbs->addCrumb(
|
|
|
|
id(new PhabricatorCrumbView())
|
|
|
|
->setName(pht('Edit Members'))
|
2013-02-19 22:33:10 +01:00
|
|
|
->setHref($this->getApplicationURI()));
|
2013-02-13 18:22:14 +01:00
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
2013-07-22 18:01:22 +02:00
|
|
|
array(
|
|
|
|
$crumbs,
|
|
|
|
$form,
|
|
|
|
$box,
|
|
|
|
),
|
2012-08-07 20:57:38 +02:00
|
|
|
array(
|
|
|
|
'title' => $title,
|
2013-02-13 18:22:14 +01:00
|
|
|
'device' => true,
|
2012-08-07 20:57:38 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderMemberList(array $handles) {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
$list = id(new PhabricatorObjectListView())
|
|
|
|
->setHandles($handles);
|
|
|
|
|
|
|
|
foreach ($handles as $handle) {
|
2013-01-18 03:57:09 +01:00
|
|
|
$hidden_input = phutil_tag(
|
2012-08-07 20:57:38 +02:00
|
|
|
'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'remove',
|
|
|
|
'value' => $handle->getPHID(),
|
|
|
|
),
|
|
|
|
'');
|
|
|
|
|
2013-01-25 21:57:17 +01:00
|
|
|
$button = javelin_tag(
|
2012-08-07 20:57:38 +02:00
|
|
|
'button',
|
|
|
|
array(
|
|
|
|
'class' => 'grey',
|
|
|
|
),
|
|
|
|
pht('Remove'));
|
|
|
|
|
|
|
|
$list->addButton(
|
|
|
|
$handle,
|
2013-01-30 20:30:38 +01:00
|
|
|
phabricator_form(
|
2012-08-07 20:57:38 +02:00
|
|
|
$user,
|
|
|
|
array(
|
|
|
|
'method' => 'POST',
|
|
|
|
'action' => $request->getRequestURI(),
|
|
|
|
),
|
2013-01-30 20:30:38 +01:00
|
|
|
array($hidden_input, $button)));
|
2012-08-07 20:57:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
}
|