ENHANCEMENT New "add folder" logic for AssetAdmin

This commit is contained in:
Ingo Schommer 2012-02-23 18:39:05 +01:00
parent 71c7664c95
commit c7c2a2c409

View File

@ -41,8 +41,6 @@ class AssetAdmin extends LeftAndMain {
return $_REQUEST['ID'];
} elseif (is_numeric($this->urlParams['ID'])) {
return $this->urlParams['ID'];
} elseif(is_numeric(Session::get("{$this->class}.currentPage"))) {
return Session::get("{$this->class}.currentPage");
} else {
return "root";
}
@ -58,6 +56,7 @@ class AssetAdmin extends LeftAndMain {
if(!file_exists(ASSETS_PATH)) Filesystem::makeFolder(ASSETS_PATH);
Requirements::javascript(CMS_DIR . "/javascript/AssetAdmin.js");
Requirements::add_i18n_javascript(CMS_DIR . '/javascript/lang', false, true);
Requirements::css(CMS_DIR . "/css/AssetAdmin.css");
Requirements::customScript(<<<JS
@ -176,7 +175,7 @@ JS
'div',
array(
'class' => 'cms-tree',
'data-url' => $this->Link('getsubtree'),
'data-url-tree' => $this->Link('getsubtree'),
'data-url-savetreenode' => $this->Link('savetreenode')
),
$this->SiteTreeAsUL()
@ -196,9 +195,37 @@ JS
return $form;
}
public function addfolder($request) {
$obj = $this->customise(array(
'EditForm' => $this->AddForm()
));
if($this->isAjax()) {
// Rendering is handled by template, which will call EditForm() eventually
$content = $obj->renderWith($this->getTemplatesWithSuffix('_Content'));
} else {
$content = $obj->renderWith($this->getViewer('show'));
}
return $content;
}
public function AddForm() {
$form = parent::AddForm();
$form->Actions()->fieldByName('action_doAdd')->setTitle(_t('AssetAdmin.ActionAdd', 'Add folder'));
$folder = singleton('Folder');
$form->Actions()->fieldByName('action_doAdd')
->setTitle(_t('AssetAdmin.ActionAdd', 'Add folder'))
->setAttribute('data-icon', 'accept');
$fields = $folder->getCMSFields();
$fields->replaceField('Name', new TextField("Name", _t('File.Name')));
$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());
return $form;
}
@ -242,6 +269,7 @@ JS
$record = new Folder();
$record->ParentID = $parent;
$record->Name = $record->Title = basename($filename);
// Ensure uniqueness
$i = 2;
@ -257,10 +285,9 @@ JS
mkdir($record->FullPath);
chmod($record->FullPath, Filesystem::$file_create_mask);
// Used in TinyMCE inline folder creation
if(isset($data['returnID'])) {
return $record->ID;
} else if($this->isAjax()) {
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 {