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']; return $_REQUEST['ID'];
} elseif (is_numeric($this->urlParams['ID'])) { } elseif (is_numeric($this->urlParams['ID'])) {
return $this->urlParams['ID']; return $this->urlParams['ID'];
} elseif(is_numeric(Session::get("{$this->class}.currentPage"))) {
return Session::get("{$this->class}.currentPage");
} else { } else {
return "root"; return "root";
} }
@ -58,6 +56,7 @@ class AssetAdmin extends LeftAndMain {
if(!file_exists(ASSETS_PATH)) Filesystem::makeFolder(ASSETS_PATH); if(!file_exists(ASSETS_PATH)) Filesystem::makeFolder(ASSETS_PATH);
Requirements::javascript(CMS_DIR . "/javascript/AssetAdmin.js"); 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::css(CMS_DIR . "/css/AssetAdmin.css");
Requirements::customScript(<<<JS Requirements::customScript(<<<JS
@ -176,7 +175,7 @@ JS
'div', 'div',
array( array(
'class' => 'cms-tree', 'class' => 'cms-tree',
'data-url' => $this->Link('getsubtree'), 'data-url-tree' => $this->Link('getsubtree'),
'data-url-savetreenode' => $this->Link('savetreenode') 'data-url-savetreenode' => $this->Link('savetreenode')
), ),
$this->SiteTreeAsUL() $this->SiteTreeAsUL()
@ -195,10 +194,38 @@ JS
return $form; 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() { public function AddForm() {
$form = parent::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; return $form;
} }
@ -226,7 +253,7 @@ JS
&& !$parentRecord->canAddChildren() && !$parentRecord->canAddChildren()
) return Security::permissionFailure($this); ) return Security::permissionFailure($this);
} }
$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(!isset($parentRecord) || !$parentRecord->ID) $parent = 0;
@ -242,7 +269,8 @@ JS
$record = new Folder(); $record = new Folder();
$record->ParentID = $parent; $record->ParentID = $parent;
$record->Name = $record->Title = basename($filename);
// Ensure uniqueness // Ensure uniqueness
$i = 2; $i = 2;
$baseFilename = substr($record->Filename, 0, -1) . '-'; $baseFilename = substr($record->Filename, 0, -1) . '-';
@ -257,10 +285,9 @@ JS
mkdir($record->FullPath); mkdir($record->FullPath);
chmod($record->FullPath, Filesystem::$file_create_mask); chmod($record->FullPath, Filesystem::$file_create_mask);
// Used in TinyMCE inline folder creation if($this->isAjax()) {
if(isset($data['returnID'])) { $link = Controller::join_links($this->Link('show'), $record->ID);
return $record->ID; $this->getResponse()->addHeader('X-ControllerURL', $link);
} else if($this->isAjax()) {
$form = $this->getEditForm($record->ID); $form = $this->getEditForm($record->ID);
return $form->forTemplate(); return $form->forTemplate();
} else { } else {