1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 22:10:55 +01:00

Moderize Mailing Lists

Summary: Attempting to learn how to 'modernize' apps so I can update things. Adds a sidenav, crumbs, and views.

Test Plan: Tested creating lists on web and mobile.

Reviewers: epriestley, btrahan

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4598
This commit is contained in:
Chad Little 2013-01-23 16:36:21 -08:00
parent b3fa5492b4
commit 9b8288886f
4 changed files with 101 additions and 32 deletions

View file

@ -942,6 +942,7 @@ phutil_register_library_map(array(
'PhabricatorMailImplementationSendGridAdapter' => 'applications/metamta/adapter/PhabricatorMailImplementationSendGridAdapter.php', 'PhabricatorMailImplementationSendGridAdapter' => 'applications/metamta/adapter/PhabricatorMailImplementationSendGridAdapter.php',
'PhabricatorMailImplementationTestAdapter' => 'applications/metamta/adapter/PhabricatorMailImplementationTestAdapter.php', 'PhabricatorMailImplementationTestAdapter' => 'applications/metamta/adapter/PhabricatorMailImplementationTestAdapter.php',
'PhabricatorMailReplyHandler' => 'applications/metamta/replyhandler/PhabricatorMailReplyHandler.php', 'PhabricatorMailReplyHandler' => 'applications/metamta/replyhandler/PhabricatorMailReplyHandler.php',
'PhabricatorMailingListsController' => 'applications/mailinglists/controller/PhabricatorMailingListsController.php',
'PhabricatorMailingListsEditController' => 'applications/mailinglists/controller/PhabricatorMailingListsEditController.php', 'PhabricatorMailingListsEditController' => 'applications/mailinglists/controller/PhabricatorMailingListsEditController.php',
'PhabricatorMailingListsListController' => 'applications/mailinglists/controller/PhabricatorMailingListsListController.php', 'PhabricatorMailingListsListController' => 'applications/mailinglists/controller/PhabricatorMailingListsListController.php',
'PhabricatorMainMenuGroupView' => 'view/page/menu/PhabricatorMainMenuGroupView.php', 'PhabricatorMainMenuGroupView' => 'view/page/menu/PhabricatorMainMenuGroupView.php',
@ -2331,8 +2332,9 @@ phutil_register_library_map(array(
'PhabricatorMailImplementationPHPMailerLiteAdapter' => 'PhabricatorMailImplementationAdapter', 'PhabricatorMailImplementationPHPMailerLiteAdapter' => 'PhabricatorMailImplementationAdapter',
'PhabricatorMailImplementationSendGridAdapter' => 'PhabricatorMailImplementationAdapter', 'PhabricatorMailImplementationSendGridAdapter' => 'PhabricatorMailImplementationAdapter',
'PhabricatorMailImplementationTestAdapter' => 'PhabricatorMailImplementationAdapter', 'PhabricatorMailImplementationTestAdapter' => 'PhabricatorMailImplementationAdapter',
'PhabricatorMailingListsEditController' => 'PhabricatorController', 'PhabricatorMailingListsController' => 'PhabricatorController',
'PhabricatorMailingListsListController' => 'PhabricatorController', 'PhabricatorMailingListsEditController' => 'PhabricatorMailingListsController',
'PhabricatorMailingListsListController' => 'PhabricatorMailingListsController',
'PhabricatorMainMenuGroupView' => 'AphrontView', 'PhabricatorMainMenuGroupView' => 'AphrontView',
'PhabricatorMainMenuIconView' => 'AphrontView', 'PhabricatorMainMenuIconView' => 'AphrontView',
'PhabricatorMainMenuSearchView' => 'AphrontView', 'PhabricatorMainMenuSearchView' => 'AphrontView',

View file

@ -0,0 +1,37 @@
<?php
abstract class PhabricatorMailingListsController extends PhabricatorController {
public function buildSideNavView($filter = null, $for_app = false) {
$user = $this->getRequest()->getUser();
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
$nav->addLabel(pht('Mailing Lists'));
$nav->addFilter('/', pht('All Lists'));
$nav->selectFilter($filter, '/');
if ($for_app) {
$nav->addFilter('edit/', pht('Create List'));
}
return $nav;
}
public function buildApplicationMenu() {
return $this->buildSideNavView(null, true)->getMenu();
}
public function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
$crumbs->addAction(
id(new PhabricatorMenuItemView())
->setName(pht('Create List'))
->setHref($this->getApplicationURI('edit/'))
->setIcon('create'));
return $crumbs;
}
}

View file

@ -1,7 +1,7 @@
<?php <?php
final class PhabricatorMailingListsEditController final class PhabricatorMailingListsEditController
extends PhabricatorController { extends PhabricatorMailingListsController {
private $id; private $id;
@ -25,6 +25,8 @@ final class PhabricatorMailingListsEditController
$e_name = true; $e_name = true;
$errors = array(); $errors = array();
$crumbs = $this->buildApplicationCrumbs($this->buildSideNavView());
$request = $this->getRequest(); $request = $this->getRequest();
if ($request->isFormPost()) { if ($request->isFormPost()) {
$list->setName($request->getStr('name')); $list->setName($request->getStr('name'));
@ -35,22 +37,22 @@ final class PhabricatorMailingListsEditController
$e_name = null; $e_name = null;
if (!strlen($list->getEmail())) { if (!strlen($list->getEmail())) {
$e_email = 'Required'; $e_email = pht('Required');
$errors[] = 'Email is required.'; $errors[] = pht('Email is required.');
} }
if (!strlen($list->getName())) { if (!strlen($list->getName())) {
$e_name = 'Required'; $e_name = pht('Required');
$errors[] = 'Name is required.'; $errors[] = pht('Name is required.');
} else if (preg_match('/[ ,]/', $list->getName())) { } else if (preg_match('/[ ,]/', $list->getName())) {
$e_name = 'Invalid'; $e_name = pht('Invalid');
$errors[] = 'Name must not contain spaces or commas.'; $errors[] = pht('Name must not contain spaces or commas.');
} }
if ($list->getURI()) { if ($list->getURI()) {
if (!PhabricatorEnv::isValidWebResource($list->getURI())) { if (!PhabricatorEnv::isValidWebResource($list->getURI())) {
$e_uri = 'Invalid'; $e_uri = pht('Invalid');
$errors[] = 'Mailing list URI must point to a valid web page.'; $errors[] = pht('Mailing list URI must point to a valid web page.');
} }
} }
@ -60,8 +62,8 @@ final class PhabricatorMailingListsEditController
return id(new AphrontRedirectResponse()) return id(new AphrontRedirectResponse())
->setURI($this->getApplicationURI()); ->setURI($this->getApplicationURI());
} catch (AphrontQueryDuplicateKeyException $ex) { } catch (AphrontQueryDuplicateKeyException $ex) {
$e_email = 'Duplicate'; $e_email = pht('Duplicate');
$errors[] = 'Another mailing list already uses that address.'; $errors[] = pht('Another mailing list already uses that address.');
} }
} }
} }
@ -69,7 +71,7 @@ final class PhabricatorMailingListsEditController
$error_view = null; $error_view = null;
if ($errors) { if ($errors) {
$error_view = id(new AphrontErrorView()) $error_view = id(new AphrontErrorView())
->setTitle('Form Errors') ->setTitle(pht('Form Errors'))
->setErrors($errors); ->setErrors($errors);
} }
@ -84,24 +86,24 @@ final class PhabricatorMailingListsEditController
$form $form
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
->setLabel('Email') ->setLabel(pht('Email'))
->setName('email') ->setName('email')
->setValue($list->getEmail()) ->setValue($list->getEmail())
->setCaption('Email will be delivered to this address.') ->setCaption(pht('Email will be delivered to this address.'))
->setError($e_email)) ->setError($e_email))
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
->setLabel('Name') ->setLabel(pht('Name'))
->setName('name') ->setName('name')
->setError($e_name) ->setError($e_name)
->setCaption('Human-readable display and autocomplete name.') ->setCaption(pht('Human-readable display and autocomplete name.'))
->setValue($list->getName())) ->setValue($list->getName()))
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
->setLabel('URI') ->setLabel(pht('URI'))
->setName('uri') ->setName('uri')
->setError($e_uri) ->setError($e_uri)
->setCaption('Optional link to mailing list archives or info.') ->setCaption(pht('Optional link to mailing list archives or info.'))
->setValue($list->getURI())) ->setValue($list->getURI()))
->appendChild( ->appendChild(
id(new AphrontFormStaticControl()) id(new AphrontFormStaticControl())
@ -109,26 +111,39 @@ final class PhabricatorMailingListsEditController
->setValue(nonempty($list->getPHID(), '-'))) ->setValue(nonempty($list->getPHID(), '-')))
->appendChild( ->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->setValue('Save') ->setValue(pht('Save'))
->addCancelButton($this->getApplicationURI())); ->addCancelButton($this->getApplicationURI()));
$panel = new AphrontPanelView(); $panel = new AphrontPanelView();
if ($list->getID()) { if ($list->getID()) {
$panel->setHeader('Edit Mailing List'); $panel->setHeader(pht('Edit Mailing List'));
$crumbs->addCrumb(
id(new PhabricatorCrumbView())
->setName(pht('Edit Mailing List'))
->setHref($this->getApplicationURI('/edit/'.$list->getID().'/'))
);
} else { } else {
$panel->setHeader('Create New Mailing List'); $panel->setHeader(pht('Create Mailing List'));
$crumbs->addCrumb(
id(new PhabricatorCrumbView())
->setName(pht('Create Mailing List'))
->setHref($this->getApplicationURI('/edit/'))
);
} }
$panel->appendChild($form); $panel->appendChild($form);
$panel->setWidth(AphrontPanelView::WIDTH_FORM); $panel->setWidth(AphrontPanelView::WIDTH_FORM);
$panel->setNoBackground();
return $this->buildApplicationPage( return $this->buildApplicationPage(
array( array(
$crumbs,
$error_view, $error_view,
$panel, $panel,
), ),
array( array(
'title' => 'Edit Mailing List', 'title' => pht('Edit Mailing List'),
'device' => true,
)); ));
} }

View file

@ -1,7 +1,7 @@
<?php <?php
final class PhabricatorMailingListsListController final class PhabricatorMailingListsListController
extends PhabricatorController { extends PhabricatorMailingListsController {
public function processRequest() { public function processRequest() {
$request = $this->getRequest(); $request = $this->getRequest();
@ -24,6 +24,8 @@ final class PhabricatorMailingListsListController
$pager->getOffset(), $pager->getPageSize() + 1); $pager->getOffset(), $pager->getPageSize() + 1);
$data = $pager->sliceResults($data); $data = $pager->sliceResults($data);
$nav = $this->buildSideNavView('all');
$lists = $list->loadAllFromArray($data); $lists = $list->loadAllFromArray($data);
$rows = array(); $rows = array();
@ -37,15 +39,15 @@ final class PhabricatorMailingListsListController
'class' => 'button grey small', 'class' => 'button grey small',
'href' => $this->getApplicationURI('/edit/'.$list->getID().'/'), 'href' => $this->getApplicationURI('/edit/'.$list->getID().'/'),
), ),
'Edit'), pht('Edit')),
); );
} }
$table = new AphrontTableView($rows); $table = new AphrontTableView($rows);
$table->setHeaders( $table->setHeaders(
array( array(
'Name', pht('Name'),
'Email', pht('Email'),
'', '',
)); ));
$table->setColumnClasses( $table->setColumnClasses(
@ -55,16 +57,29 @@ final class PhabricatorMailingListsListController
'action', 'action',
)); ));
$crumbs = $this->buildApplicationCrumbs($this->buildSideNavView());
$crumbs->addCrumb(
id(new PhabricatorCrumbView())
->setName(pht('All Lists'))
->setHref($this->getApplicationURI())
);
$nav->setCrumbs($crumbs);
$panel = new AphrontPanelView(); $panel = new AphrontPanelView();
$panel->appendChild($table); $panel->appendChild($table);
$panel->setHeader('Mailing Lists'); $panel->setHeader(pht('Mailing Lists'));
$panel->setCreateButton('Add New List', $this->getApplicationURI('/edit/'));
$panel->appendChild($pager); $panel->appendChild($pager);
$panel->setNoBackground();
$nav->appendChild($panel);
return $this->buildApplicationPage( return $this->buildApplicationPage(
$panel,
array( array(
'title' => 'Mailing Lists', $nav,
),
array(
'title' => pht('Mailing Lists'),
'device' => true,
)); ));
} }
} }