diff --git a/apps/qubit/modules/informationobject/actions/indexAction.class.php b/apps/qubit/modules/informationobject/actions/indexAction.class.php
index 2ac500f56d..b2c1c98647 100644
--- a/apps/qubit/modules/informationobject/actions/indexAction.class.php
+++ b/apps/qubit/modules/informationobject/actions/indexAction.class.php
@@ -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))
{
diff --git a/apps/qubit/modules/informationobject/actions/renameAction.class.php b/apps/qubit/modules/informationobject/actions/renameAction.class.php
index ff4acda848..577e383fa5 100644
--- a/apps/qubit/modules/informationobject/actions/renameAction.class.php
+++ b/apps/qubit/modules/informationobject/actions/renameAction.class.php
@@ -17,81 +17,95 @@
* along with Access to Memory (AtoM). If not, see .
*/
-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)
@@ -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;
@@ -125,8 +139,6 @@ private function updateResource()
digitalObjectRegenDerivativesTask::regenerateDerivatives($digitalObject);
}
- $resource->save();
-
- return $resource;
+ $this->resource->save();
}
}
diff --git a/apps/qubit/modules/informationobject/templates/_actions.php b/apps/qubit/modules/informationobject/templates/_actions.php
index 65574bfc01..74b910ef5e 100644
--- a/apps/qubit/modules/informationobject/templates/_actions.php
+++ b/apps/qubit/modules/informationobject/templates/_actions.php
@@ -28,7 +28,7 @@
-
- $resource, 'renameForm' => $renameForm)) ?>
diff --git a/apps/qubit/modules/informationobject/templates/_renameModal.php b/apps/qubit/modules/informationobject/templates/_renameModal.php
deleted file mode 100644
index 7119b16ac9..0000000000
--- a/apps/qubit/modules/informationobject/templates/_renameModal.php
+++ /dev/null
@@ -1,53 +0,0 @@
-addJavaScript('renameModal'); ?>
-addJavaScript('description'); ?>
-
-
+
+
+
+ renderFormTag(url_for(array('module' => 'informationobject', 'action' => 'rename', 'slug' => $resource->slug)), array('id' => 'rename-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.'))) ?>
+
+
+
+
+ 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) ?>
+
+ digitalObjects) > 0): ?>
+
+
+
+
+ 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) ?>
+
+
+
+
+
+
+ 'informationobject', 'action' => 'browse'), array('class' => 'c-btn c-btn-delete')) ?>
+
+
+
+
+
+
+
+
diff --git a/js/description.js b/js/description.js
index 972412f1ba..1ae4bc040e 100644
--- a/js/description.js
+++ b/js/description.js
@@ -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()
diff --git a/js/renameModal.js b/js/rename.js
similarity index 55%
rename from js/renameModal.js
rename to js/rename.js
index dee14002fa..103d638332 100644
--- a/js/renameModal.js
+++ b/js/rename.js
@@ -6,8 +6,13 @@
// Fetch a slug preview for a given title
function fetchSlugPreview(title, callback)
{
+ // Assemble slug preview URL
+ var urlParts = window.location.href.split('/');
+ urlParts.pop();
+ var slugPreviewUrl = urlParts.join('/') + '/slugPreview';
+
$.ajax({
- 'url': window.location.href + '/slugPreview',
+ 'url': slugPreviewUrl,
'data': {'title': title},
'type': 'GET',
'cache': false,
@@ -21,20 +26,23 @@
}
$(function() {
+
+ // Place cursor in first field of form
+ $('#rename-form input:text:visible:first').focus();
+
// Create references to selectors
- var $renameModal = $('#renameModal');
+ var $renameForm = $('#rename-form');
var $fields = {};
var $fieldCheckboxes = {};
for (var index in fields) {
var field = fields[index];
- $fields[field] = $('#rename_' + field);
+ $fields[field] = $('#' + field);
$fieldCheckboxes[field] = $('#rename_enable_' + field);
}
- $renameModalSubmit = $('#renameModalSubmit');
- $renameModalCancel = $('#renameModalCancel');
+ $renameFormSubmit = $('#rename-form-submit');
// Cycle through fields and disable them if their corresponding checkbox isn't checked
function enableFields() {
@@ -44,79 +52,58 @@
}
}
- // Hide modal and submit form data
- function submit() {
- $renameModal.modal('hide');
- $("#renameModalForm").submit();
+ function updateSlugPreview() {
+ fetchSlugPreview($fields['title'].val(), function(err, slug) {
+ if (err) {
+ alert('Error fetching slug preview.');
+ } else {
+ $fields['slug'].val(slug);
+ }
+ });
}
- // When no AJAX requests are pending, hide modal and submit form data
+ // When no AJAX requests are pending, submit form data
function trySubmit() {
if (asyncOpInProgress) {
setTimeout(trySubmit, 1000);
} else {
- submit();
+ $renameForm.submit();
}
}
// Enable/disable fields according to initial checkbox values
enableFields();
- // Auto-focus on the first field
- $renameModal.on('shown', function () {
- $('input:text:visible:first', this).focus();
- });
-
// Submit when users hits the enter key
- $renameModal.on('keypress', function (e) {
+ $renameForm.on('keypress', function (e) {
if (e.keyCode == 13) {
+ updateSlugPreview();
trySubmit();
}
});
// Keep track of whether async requests are in progress
- $renameModal.ajaxStart(function() {
+ $renameForm.ajaxStart(function() {
asyncOpInProgress = true;
});
- $renameModal.ajaxStop(function() {
+ $renameForm.ajaxStop(function() {
asyncOpInProgress = false;
});
- // Add click handlers
- $renameModal.bind('show', function() {
- // Enable/disable fields when checkboxes clicked
- $('#renameModal form input[type=checkbox]').click(function(e) {
- enableFields();
- });
-
- // Simulate submit button
- $renameModalSubmit.click(function(e) {
- trySubmit();
- });
-
- // Hide form if cancel clicked
- $renameModalCancel.click(function(e) {
- $renameModal.modal('hide');
- });
+ // Enable/disable fields when checkboxes clicked
+ $('#rename-form input[type=checkbox]').click(function(e) {
+ enableFields();
});
- // Remove click handlers when modal's hidden
- $renameModal.bind('hide', function() {
- $renameModalSubmit.unbind();
- $renameModalCancel.unbind();
- $('#renameModal form input[type=checkbox]').unbind();
+ // Simulate submit button
+ $renameFormSubmit.click(function(e) {
+ trySubmit();
});
// If title changes, update slug
$fields['title'].change(function() {
- fetchSlugPreview($fields['title'].val(), function(err, slug) {
- if (err) {
- alert('Error fetching slug preview.');
- } else {
- $fields['slug'].val(slug);
- }
- });
+ updateSlugPreview();
});
});
diff --git a/lib/form/InformationObjectRenameForm.class.php b/lib/form/InformationObjectRenameForm.class.php
deleted file mode 100644
index aaa1727ab1..0000000000
--- a/lib/form/InformationObjectRenameForm.class.php
+++ /dev/null
@@ -1,62 +0,0 @@
-.
- */
-
-/**
- * Information Object module - rename modal form definition
- *
- * @package AccesstoMemory
- * @subpackage informationobject
- * @author Mike Cantelon