diff --git a/code/controllers/AssetAdmin.php b/code/controllers/AssetAdmin.php
index 21e2c7e8..e85a2f15 100644
--- a/code/controllers/AssetAdmin.php
+++ b/code/controllers/AssetAdmin.php
@@ -160,7 +160,12 @@ JS
$addFolderBtn = new LiteralField(
'AddFolderButton',
sprintf(
- '%s',
+ '%s',
+ Controller::join_links($this->Link('AddForm'), '?' . http_build_query(array(
+ 'action_doAdd' => 1,
+ 'ParentID' => $folder->ID,
+ 'SecurityID' => $form->getSecurityToken()->getValue()
+ ))),
Controller::join_links($this->Link('addfolder'), '?ParentID=' . $folder->ID),
_t('Folder.AddFolderButton', 'Add folder')
)
@@ -335,9 +340,9 @@ JS
$fields->dataFieldByName('ParentID')->setValue($this->request->getVar('ParentID'));
$form->setFields($fields);
- $form->addExtraClass('cms-edit-form');
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
- $form->addExtraClass('center ' . $this->BaseCSSClasses());
+ // TODO Can't merge $FormAttributes in template at the moment
+ $form->addExtraClass('cms-add-form cms-edit-form cms-panel-padded center ' . $this->BaseCSSClasses());
return $form;
}
@@ -358,20 +363,23 @@ JS
singleton($class)->hasExtension('Hierarchy')
&& isset($data['ParentID'])
&& is_numeric($data['ParentID'])
+ && $data['ParentID']
) {
$parentRecord = DataObject::get_by_id($class, $data['ParentID']);
if(
$parentRecord->hasMethod('canAddChildren')
&& !$parentRecord->canAddChildren()
) return Security::permissionFailure($this);
+ } else {
+ $parentRecord = null;
}
$parent = (isset($data['ParentID']) && is_numeric($data['ParentID'])) ? (int)$data['ParentID'] : 0;
$name = (isset($data['Name'])) ? basename($data['Name']) : _t('AssetAdmin.NEWFOLDER',"NewFolder");
- if(!isset($parentRecord) || !$parentRecord->ID) $parent = 0;
+ if(!$parentRecord || !$parentRecord->ID) $parent = 0;
// Get the folder to be created
- if(isset($parentRecord->ID)) $filename = $parentRecord->FullPath . $name;
+ if($parentRecord && $parentRecord->ID) $filename = $parentRecord->FullPath . $name;
else $filename = ASSETS_PATH . '/' . $name;
// Actually create
@@ -397,14 +405,10 @@ JS
mkdir($record->FullPath);
chmod($record->FullPath, Filesystem::$file_create_mask);
- if($this->isAjax()) {
- $link = Controller::join_links($this->Link('show'), $record->ID);
- $this->getResponse()->addHeader('X-ControllerURL', $link);
- $form = $this->getEditForm($record->ID);
- return $form->forTemplate();
- } else {
- return $this->redirect(Controller::join_links($this->Link('show'), $record->ID));
- }
+ $parentID = $parentRecord ? $parentRecord->ID : 'root';
+ $link = Controller::join_links($this->Link('show'), $parentID);
+ $this->getResponse()->addHeader('X-ControllerURL', $link);
+ return $this->redirect($link);
}
/**
@@ -563,6 +567,14 @@ JS
)));
}
+ // If we're adding a folder, note that in breadcrumbs as well
+ if($this->request->param('Action') == 'addfolder') {
+ $items->push(new ArrayData(array(
+ 'Title' => _t('Folder.AddFolderButton', 'Add folder'),
+ 'Link' => false
+ )));
+ }
+
// TODO Remove once ViewableData->First()/Last() is fixed
foreach($items as $i => $item) $item->iteratorProperties($i, $items->Count());
diff --git a/javascript/AssetAdmin.js b/javascript/AssetAdmin.js
index 3da0126c..ddd72658 100644
--- a/javascript/AssetAdmin.js
+++ b/javascript/AssetAdmin.js
@@ -52,6 +52,22 @@
}
});
+ /**
+ * Prompt for a new foldername, rather than using dedicated form.
+ * Better usability, but less flexibility in terms of inputs and validation.
+ * Mainly necessary because AssetAdmin->AddForm() returns don't play nicely
+ * with the nested AssetAdmin->EditForm() DOM structures.
+ */
+ $('.AssetAdmin .cms-add-folder-link').entwine({
+ onclick: function(e) {
+ var name = prompt(ss.i18n._t('Folder.Name'));
+ if(!name) return false;
+
+ this.closest('.cms-container').loadPanel(this.data('url') + '&Name=' + name);
+ return false;
+ }
+ });
+
/**
* Class: #Form_SyncForm
*/
diff --git a/javascript/lang/en_US.js b/javascript/lang/en_US.js
index 7124a7cb..1b98091f 100644
--- a/javascript/lang/en_US.js
+++ b/javascript/lang/en_US.js
@@ -35,6 +35,7 @@ if(typeof(ss) == 'undefined' || typeof(ss.i18n) == 'undefined') {
'SecurityAdmin.BATCHACTIONSDELETECONFIRM': "Do you really want to delete %s groups?",
'CMSMAIN.AddSearchCriteria': 'Add Criteria',
'WidgetAreaEditor.TOOMANY': 'Sorry, you have reached the maximum number of widgets in this area',
- 'AssetAdmin.ConfirmDelete': 'Do you really want to delete this folder and all contained files?'
+ 'AssetAdmin.ConfirmDelete': 'Do you really want to delete this folder and all contained files?',
+ 'Folder.Name': 'Foldername'
});
}