1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 05:50: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',
'PhabricatorMailImplementationTestAdapter' => 'applications/metamta/adapter/PhabricatorMailImplementationTestAdapter.php',
'PhabricatorMailReplyHandler' => 'applications/metamta/replyhandler/PhabricatorMailReplyHandler.php',
'PhabricatorMailingListsController' => 'applications/mailinglists/controller/PhabricatorMailingListsController.php',
'PhabricatorMailingListsEditController' => 'applications/mailinglists/controller/PhabricatorMailingListsEditController.php',
'PhabricatorMailingListsListController' => 'applications/mailinglists/controller/PhabricatorMailingListsListController.php',
'PhabricatorMainMenuGroupView' => 'view/page/menu/PhabricatorMainMenuGroupView.php',
@ -2331,8 +2332,9 @@ phutil_register_library_map(array(
'PhabricatorMailImplementationPHPMailerLiteAdapter' => 'PhabricatorMailImplementationAdapter',
'PhabricatorMailImplementationSendGridAdapter' => 'PhabricatorMailImplementationAdapter',
'PhabricatorMailImplementationTestAdapter' => 'PhabricatorMailImplementationAdapter',
'PhabricatorMailingListsEditController' => 'PhabricatorController',
'PhabricatorMailingListsListController' => 'PhabricatorController',
'PhabricatorMailingListsController' => 'PhabricatorController',
'PhabricatorMailingListsEditController' => 'PhabricatorMailingListsController',
'PhabricatorMailingListsListController' => 'PhabricatorMailingListsController',
'PhabricatorMainMenuGroupView' => 'AphrontView',
'PhabricatorMainMenuIconView' => '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
final class PhabricatorMailingListsEditController
extends PhabricatorController {
extends PhabricatorMailingListsController {
private $id;
@ -25,6 +25,8 @@ final class PhabricatorMailingListsEditController
$e_name = true;
$errors = array();
$crumbs = $this->buildApplicationCrumbs($this->buildSideNavView());
$request = $this->getRequest();
if ($request->isFormPost()) {
$list->setName($request->getStr('name'));
@ -35,22 +37,22 @@ final class PhabricatorMailingListsEditController
$e_name = null;
if (!strlen($list->getEmail())) {
$e_email = 'Required';
$errors[] = 'Email is required.';
$e_email = pht('Required');
$errors[] = pht('Email is required.');
}
if (!strlen($list->getName())) {
$e_name = 'Required';
$errors[] = 'Name is required.';
$e_name = pht('Required');
$errors[] = pht('Name is required.');
} else if (preg_match('/[ ,]/', $list->getName())) {
$e_name = 'Invalid';
$errors[] = 'Name must not contain spaces or commas.';
$e_name = pht('Invalid');
$errors[] = pht('Name must not contain spaces or commas.');
}
if ($list->getURI()) {
if (!PhabricatorEnv::isValidWebResource($list->getURI())) {
$e_uri = 'Invalid';
$errors[] = 'Mailing list URI must point to a valid web page.';
$e_uri = pht('Invalid');
$errors[] = pht('Mailing list URI must point to a valid web page.');
}
}
@ -60,8 +62,8 @@ final class PhabricatorMailingListsEditController
return id(new AphrontRedirectResponse())
->setURI($this->getApplicationURI());
} catch (AphrontQueryDuplicateKeyException $ex) {
$e_email = 'Duplicate';
$errors[] = 'Another mailing list already uses that address.';
$e_email = pht('Duplicate');
$errors[] = pht('Another mailing list already uses that address.');
}
}
}
@ -69,7 +71,7 @@ final class PhabricatorMailingListsEditController
$error_view = null;
if ($errors) {
$error_view = id(new AphrontErrorView())
->setTitle('Form Errors')
->setTitle(pht('Form Errors'))
->setErrors($errors);
}
@ -84,24 +86,24 @@ final class PhabricatorMailingListsEditController
$form
->appendChild(
id(new AphrontFormTextControl())
->setLabel('Email')
->setLabel(pht('Email'))
->setName('email')
->setValue($list->getEmail())
->setCaption('Email will be delivered to this address.')
->setCaption(pht('Email will be delivered to this address.'))
->setError($e_email))
->appendChild(
id(new AphrontFormTextControl())
->setLabel('Name')
->setLabel(pht('Name'))
->setName('name')
->setError($e_name)
->setCaption('Human-readable display and autocomplete name.')
->setCaption(pht('Human-readable display and autocomplete name.'))
->setValue($list->getName()))
->appendChild(
id(new AphrontFormTextControl())
->setLabel('URI')
->setLabel(pht('URI'))
->setName('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()))
->appendChild(
id(new AphrontFormStaticControl())
@ -109,26 +111,39 @@ final class PhabricatorMailingListsEditController
->setValue(nonempty($list->getPHID(), '-')))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue('Save')
->setValue(pht('Save'))
->addCancelButton($this->getApplicationURI()));
$panel = new AphrontPanelView();
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 {
$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->setWidth(AphrontPanelView::WIDTH_FORM);
$panel->setNoBackground();
return $this->buildApplicationPage(
array(
$crumbs,
$error_view,
$panel,
),
array(
'title' => 'Edit Mailing List',
'title' => pht('Edit Mailing List'),
'device' => true,
));
}

View file

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