2014-05-23 19:41:24 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorProjectEditIconController
|
|
|
|
extends PhabricatorProjectController {
|
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = $data['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
|
|
|
$project = id(new PhabricatorProjectQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->executeOne();
|
|
|
|
if (!$project) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$view_uri = '/tag/'.$project->getPrimarySlug().'/';
|
|
|
|
$edit_uri = $this->getApplicationURI('edit/'.$project->getID().'/');
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
2014-06-26 07:01:58 +02:00
|
|
|
$xactions = array();
|
|
|
|
|
2014-05-23 19:41:24 +02:00
|
|
|
$v_icon = $request->getStr('icon');
|
2014-06-26 07:01:58 +02:00
|
|
|
|
2014-05-23 19:41:24 +02:00
|
|
|
$type_icon = PhabricatorProjectTransaction::TYPE_ICON;
|
2014-06-26 07:01:58 +02:00
|
|
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
2014-05-23 19:41:24 +02:00
|
|
|
->setTransactionType($type_icon)
|
2014-06-26 07:01:58 +02:00
|
|
|
->setNewValue($v_icon);
|
|
|
|
|
2014-05-23 19:41:24 +02:00
|
|
|
$editor = id(new PhabricatorProjectTransactionEditor())
|
|
|
|
->setActor($viewer)
|
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->setContinueOnMissingFields(true)
|
|
|
|
->setContinueOnNoEffect(true);
|
|
|
|
|
|
|
|
$editor->applyTransactions($project, $xactions);
|
|
|
|
|
|
|
|
return id(new AphrontReloadResponse())->setURI($edit_uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
require_celerity_resource('project-icon-css');
|
|
|
|
Javelin::initBehavior('phabricator-tooltips');
|
|
|
|
|
|
|
|
$project_icons = PhabricatorProjectIcon::getIconMap();
|
|
|
|
$ii = 0;
|
|
|
|
$buttons = array();
|
|
|
|
foreach ($project_icons as $icon => $label) {
|
|
|
|
$view = id(new PHUIIconView())
|
2014-06-26 07:01:58 +02:00
|
|
|
->setIconFont($icon);
|
2014-05-23 19:41:24 +02:00
|
|
|
|
|
|
|
$aural = javelin_tag(
|
|
|
|
'span',
|
|
|
|
array(
|
|
|
|
'aural' => true,
|
|
|
|
),
|
|
|
|
pht('Choose "%s" Icon', $label));
|
|
|
|
|
|
|
|
if ($icon == $project->getIcon()) {
|
|
|
|
$class_extra = ' selected';
|
|
|
|
} else {
|
|
|
|
$class_extra = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$buttons[] = javelin_tag(
|
|
|
|
'button',
|
|
|
|
array(
|
|
|
|
'class' => 'icon-button'.$class_extra,
|
|
|
|
'name' => 'icon',
|
|
|
|
'value' => $icon,
|
|
|
|
'type' => 'submit',
|
|
|
|
'sigil' => 'has-tooltip',
|
|
|
|
'meta' => array(
|
2014-06-26 07:01:58 +02:00
|
|
|
'tip' => $label,
|
2014-05-23 19:41:24 +02:00
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
$aural,
|
|
|
|
$view,
|
|
|
|
));
|
|
|
|
if ((++$ii % 4) == 0) {
|
|
|
|
$buttons[] = phutil_tag('br');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$buttons = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'icon-grid',
|
|
|
|
),
|
|
|
|
$buttons);
|
|
|
|
|
2014-06-26 07:01:58 +02:00
|
|
|
return $this->newDialog()
|
2014-05-23 19:41:24 +02:00
|
|
|
->setTitle(pht('Choose Project Icon'))
|
2014-06-26 17:50:01 +02:00
|
|
|
->appendChild($buttons)
|
2014-05-23 19:41:24 +02:00
|
|
|
->addCancelButton($edit_uri);
|
|
|
|
}
|
|
|
|
}
|