mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
ENHANCEMENT New "add folder" logic for AssetAdmin
This commit is contained in:
parent
71c7664c95
commit
c7c2a2c409
@ -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()
|
||||||
@ -196,9 +195,37 @@ 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;
|
||||||
}
|
}
|
||||||
@ -242,6 +269,7 @@ 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;
|
||||||
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user