Skip to content

Commit

Permalink
Changed rename modal to a page. refs #8759
Browse files Browse the repository at this point in the history
Changed the rename modal to a page to simplify code.
  • Loading branch information
mcantelon committed Sep 14, 2015
1 parent 621ffdf commit e51ba17
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,6 @@ public function execute($request)
{
$this->resource = $this->getRoute()->resource;

$this->renameForm = new InformationObjectRenameForm;

// Set rename form values
$this->renameForm->setDefaults(array(
'title' => $this->resource->title,
'slug' => $this->resource->slug,
'filename' => $this->resource->digitalObjects[0]->name
));

// Check that this isn't the root
if (!isset($this->resource->parent))
{
Expand Down
92 changes: 52 additions & 40 deletions apps/qubit/modules/informationobject/actions/renameAction.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,81 +17,95 @@
* along with Access to Memory (AtoM). If not, see <http://www.gnu.org/licenses/>.
*/

class InformationObjectRenameAction extends sfAction
class InformationObjectRenameAction extends DefaultEditAction
{
// Allow modification of title, slug, and digital object filename
public function execute($request)
// Arrays not allowed in class constants
public static
$NAMES = array(
'title',
'slug',
'filename');

protected function earlyExecute()
{
// Return 401 if unauthorized
$this->resource = $this->getRoute()->resource;

// Check user authorization
if (!sfContext::getInstance()->user->isAuthenticated()
|| !QubitAcl::check($this->resource, 'update'))
{
$this->response->setStatusCode(401);
return sfView::NONE;
QubitAcl::forwardUnauthorized();
}
}

// Return 400 if incorrect HTTP method
if ($this->request->getMethod() != 'POST')
protected function addField($name)
{
if (in_array($name, InformationObjectRenameAction::$NAMES))
{
$this->response->setStatusCode(400);
return sfView::NONE;
if ($name == 'filename')
{
$this->form->setDefault($name, $this->resource->digitalObjects[0]->name);
}
else
{
$this->form->setDefault($name, $this->resource[$name]);
}

$this->form->setValidator($name, new sfValidatorString);
$this->form->setWidget($name, new sfWidgetFormInput);
}
}

// Internationalization needed for flash messages
ProjectConfiguration::getActive()->loadHelpers('I18N');

// Handle rename form submission
if (null !== $request->rename)
// Allow modification of title, slug, and digital object filename
public function execute($request)
{
parent::execute($request);

if ($this->request->getMethod() == 'POST')
{
$this->renameForm = new InformationObjectRenameForm;
// Internationalization needed for flash messages
ProjectConfiguration::getActive()->loadHelpers('I18N');

$this->renameForm->bind($request->rename);
$this->form->bind($request->getPostParameters());

if ($this->renameForm->isValid())
{
$resource = $this->updateResource();
if ($this->form->isValid())
{
$this->updateResource();

// Let user know description was updated (and if slug had to be adjusted)
$message = __('Description updated.');

$postedSlug = $this->renameForm->getValue('slug');
$postedSlug = $this->form->getValue('slug');

if ((null !== $postedSlug) && $resource->slug != $postedSlug)
if ((null !== $postedSlug) && $this->resource->slug != $postedSlug)
{
$message .= ' '. __('Slug was adjusted to remove special characters or because it has already been used for another description.');
}

$this->getUser()->setFlash('notice', $message);

$this->redirect(array($resource, 'module' => 'informationobject'));
$this->redirect(array($this->resource, 'module' => 'informationobject'));
}
}
else
{
$this->getUser()->setFlash('error', __('No fields changed.'));

$this->redirect(array($this->getRoute()->resource, 'module' => 'informationobject'));
}
}

private function updateResource()
{
$resource = $this->getRoute()->resource;

$postedTitle = $this->renameForm->getValue('title');
$postedSlug = $this->renameForm->getValue('slug');
$postedFilename = $this->renameForm->getValue('filename');
$postedTitle = $this->form->getValue('title');
$postedSlug = $this->form->getValue('slug');
$postedFilename = $this->form->getValue('filename');

// Update title, if title sent
if (null !== $postedTitle)
{
$resource->title = $postedTitle;
$this->resource->title = $postedTitle;
}

// Attempt to update slug if slug sent
if (null !== $postedSlug)
{
$slug = QubitSlug::getByObjectId($resource->id);
$slug = QubitSlug::getByObjectId($this->resource->id);

// Attempt to change slug if submitted slug's different than current slug
if ($postedSlug != $slug->slug)
Expand All @@ -102,13 +116,13 @@ private function updateResource()
}

// Update digital object filename, if filename sent
if ((null !== $postedFilename) && count($resource->digitalObjects))
if ((null !== $postedFilename) && count($this->resource->digitalObjects))
{
// Parse filename so special characters can be removed
$fileParts = pathinfo($postedFilename);
$filename = QubitSlug::slugify($fileParts['filename']) .'.'. QubitSlug::slugify($fileParts['extension']);

$digitalObject = $resource->digitalObjects[0];
$digitalObject = $this->resource->digitalObjects[0];

// Rename master file
$basePath = sfConfig::get('sf_web_dir') . $digitalObject->path;
Expand All @@ -125,8 +139,6 @@ private function updateResource()
digitalObjectRegenDerivativesTask::regenerateDerivatives($digitalObject);
}

$resource->save();

return $resource;
$this->resource->save();
}
}
4 changes: 1 addition & 3 deletions apps/qubit/modules/informationobject/templates/_actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</a>
<ul class="dropdown-menu">

<li><a href="#" data-toggle="modal" data-target="#renameModal"><?php echo __('Rename') ?></a></li>
<li><?php echo link_to(__('Rename'), array($resource, 'module' => 'informationobject', 'action' => 'rename')) ?></li>

<li class="divider"></li>

Expand Down Expand Up @@ -61,5 +61,3 @@
</ul>

</section>

<?php echo get_partial('informationobject/renameModal', array('resource' => $resource, 'renameForm' => $renameForm)) ?>
53 changes: 0 additions & 53 deletions apps/qubit/modules/informationobject/templates/_renameModal.php

This file was deleted.

64 changes: 64 additions & 0 deletions apps/qubit/modules/informationobject/templates/renameSuccess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php decorate_with('layout_2col.php') ?>

<?php $sf_response->addJavaScript('rename'); ?>
<?php $sf_response->addJavaScript('description'); ?>

<?php slot('sidebar') ?>

<?php include_component('repository', 'contextMenu') ?>

<?php end_slot() ?>

<?php slot('title') ?>

<h1><?php echo __('Rename') ?>: <?php echo $resource->title ?></h1>

<?php end_slot() ?>

<?php slot('content') ?>

<div id="content" class="yui-panel">

<div class="fieldset-wrapper">

<?php echo $form->renderFormTag(url_for(array('module' => 'informationobject', 'action' => 'rename', 'slug' => $resource->slug)), array('id' => 'rename-form')) ?>

<div class="alert"><?php echo __('Use this interface to update the description title, slug (permalink), and/or digital object filename.') ?></div>

<div class="rename-form-field-toggle"><input id="rename_enable_title" type="checkbox" checked="checked" /> <?php echo __('Update title') ?></div>
<br />

<?php echo render_field($form->title
->label(__('Title'))
->help(__('Editing the description title will automatically update the slug field if the "Update slug" checkbox is selected - you can still edit it after.'))) ?>

<div class="rename-form-field-toggle"><input id="rename_enable_slug" type="checkbox" checked="checked" /> <?php echo __('Update slug') ?></div>
<br />

<?php echo render_field($form->slug
->label(__('Slug'))
->help(__('Do not use any special characters or spaces in the slug - only lower case alphanumeric characters (a-z, 0-9) and dashes (-) will be saved. Other characters will be stripped out or replaced. Editing the slug will not automatically update the other fields.')), $resource) ?>

<?php if (count($resource->digitalObjects) > 0): ?>

<div class="rename-form-field-toggle"><input id="rename_enable_filename" type="checkbox" /> <?php echo __('Update filename') ?></div>
<br />

<?php echo render_field($form->filename
->label(__('Filename'))
->help(__('Do not use any special characters or spaces in the filename - only lower case alphanumeric characters (a-z, 0-9) and dashes (-) will be saved. Other characters will be stripped out or replaced. Editing the filename will not automatically update the other fields.')), $resource) ?>

<?php endif; ?>

<section class="actions">
<ul>
<li><a href="#" id="rename-form-submit" class="c-btn c-btn-submit"><?php echo __('Update') ?></a></li>
<li><?php echo link_to(__('Cancel'), array('module' => 'informationobject', 'action' => 'browse'), array('class' => 'c-btn c-btn-delete')) ?></li>
</ul>
</section>

</form>
</div>
</div>

<?php end_slot() ?>
6 changes: 0 additions & 6 deletions js/description.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@
// Specific case for tooltips in YUI dialogs
var $dialog = $this.closest('div.yui-panel');

// If no YUI dialogs found, look for Bootstrap dialogs
if (!$dialog.length)
{
var $dialog = $this.closest('div.modal');
}

if ($dialog.length)
{
var positionateDialog = function()
Expand Down
Loading

0 comments on commit e51ba17

Please sign in to comment.