ENHNANCEMENT Creating folders via (faster) JavaScript prompt in AssetAdmin, implicitly fixing AssetAdmin->doAdd() layout issues after submitting

This commit is contained in:
Ingo Schommer 2012-03-08 17:26:02 +01:00
parent c226554b5a
commit f085583b61
3 changed files with 43 additions and 14 deletions

View File

@ -160,7 +160,12 @@ JS
$addFolderBtn = new LiteralField( $addFolderBtn = new LiteralField(
'AddFolderButton', 'AddFolderButton',
sprintf( sprintf(
'<a class="ss-ui-button ss-ui-action-constructive cms-panel-link" data-icon="add" href="%s">%s</a>', '<a class="ss-ui-button ss-ui-action-constructive cms-add-folder-link" data-icon="add" data-url="%s" href="%s">%s</a>',
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), Controller::join_links($this->Link('addfolder'), '?ParentID=' . $folder->ID),
_t('Folder.AddFolderButton', 'Add folder') _t('Folder.AddFolderButton', 'Add folder')
) )
@ -335,9 +340,9 @@ JS
$fields->dataFieldByName('ParentID')->setValue($this->request->getVar('ParentID')); $fields->dataFieldByName('ParentID')->setValue($this->request->getVar('ParentID'));
$form->setFields($fields); $form->setFields($fields);
$form->addExtraClass('cms-edit-form');
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $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; return $form;
} }
@ -358,20 +363,23 @@ JS
singleton($class)->hasExtension('Hierarchy') singleton($class)->hasExtension('Hierarchy')
&& isset($data['ParentID']) && isset($data['ParentID'])
&& is_numeric($data['ParentID']) && is_numeric($data['ParentID'])
&& $data['ParentID']
) { ) {
$parentRecord = DataObject::get_by_id($class, $data['ParentID']); $parentRecord = DataObject::get_by_id($class, $data['ParentID']);
if( if(
$parentRecord->hasMethod('canAddChildren') $parentRecord->hasMethod('canAddChildren')
&& !$parentRecord->canAddChildren() && !$parentRecord->canAddChildren()
) return Security::permissionFailure($this); ) return Security::permissionFailure($this);
} else {
$parentRecord = null;
} }
$parent = (isset($data['ParentID']) && is_numeric($data['ParentID'])) ? (int)$data['ParentID'] : 0; $parent = (isset($data['ParentID']) && is_numeric($data['ParentID'])) ? (int)$data['ParentID'] : 0;
$name = (isset($data['Name'])) ? basename($data['Name']) : _t('AssetAdmin.NEWFOLDER',"NewFolder"); $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 // 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; else $filename = ASSETS_PATH . '/' . $name;
// Actually create // Actually create
@ -397,14 +405,10 @@ JS
mkdir($record->FullPath); mkdir($record->FullPath);
chmod($record->FullPath, Filesystem::$file_create_mask); chmod($record->FullPath, Filesystem::$file_create_mask);
if($this->isAjax()) { $parentID = $parentRecord ? $parentRecord->ID : 'root';
$link = Controller::join_links($this->Link('show'), $record->ID); $link = Controller::join_links($this->Link('show'), $parentID);
$this->getResponse()->addHeader('X-ControllerURL', $link); $this->getResponse()->addHeader('X-ControllerURL', $link);
$form = $this->getEditForm($record->ID); return $this->redirect($link);
return $form->forTemplate();
} else {
return $this->redirect(Controller::join_links($this->Link('show'), $record->ID));
}
} }
/** /**
@ -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 // TODO Remove once ViewableData->First()/Last() is fixed
foreach($items as $i => $item) $item->iteratorProperties($i, $items->Count()); foreach($items as $i => $item) $item->iteratorProperties($i, $items->Count());

View File

@ -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 * Class: #Form_SyncForm
*/ */

View File

@ -35,6 +35,7 @@ if(typeof(ss) == 'undefined' || typeof(ss.i18n) == 'undefined') {
'SecurityAdmin.BATCHACTIONSDELETECONFIRM': "Do you really want to delete %s groups?", 'SecurityAdmin.BATCHACTIONSDELETECONFIRM': "Do you really want to delete %s groups?",
'CMSMAIN.AddSearchCriteria': 'Add Criteria', 'CMSMAIN.AddSearchCriteria': 'Add Criteria',
'WidgetAreaEditor.TOOMANY': 'Sorry, you have reached the maximum number of widgets in this area', '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'
}); });
} }