diff --git a/code/DataObjectManager.php b/code/DataObjectManager.php
index c877d02..1f6cc67 100644
--- a/code/DataObjectManager.php
+++ b/code/DataObjectManager.php
@@ -2,12 +2,12 @@
class DataObjectManager extends ComplexTableField
{
-
+
protected static $allow_assets_override = true;
protected static $allow_css_override = false;
public static $popup_width = 640;
protected static $confirm_delete = true;
-
+
protected $template = "DataObjectManager";
protected $start = "0";
protected $per_page = "10";
@@ -32,8 +32,8 @@ class DataObjectManager extends ComplexTableField
public $singleTitle;
public $hasNested = false;
public $isNested = false;
-
-
+
+
public $actions = array(
@@ -52,11 +52,11 @@ class DataObjectManager extends ComplexTableField
static $url_handlers = array(
'duplicate/$ID' => 'handleDuplicate'
);
-
-
+
+
public $popupClass = "DataObjectManager_Popup";
public $templatePopup = "DataObjectManager_popup";
-
+
public static function allow_assets_override($bool)
{
if($bool) {
@@ -66,27 +66,27 @@ public static function allow_assets_override($bool)
else
DataObject::remove_extension("Folder","AssetManagerFolder");
}
-
+
public static function allow_css_override($bool)
{
self::$allow_css_override = $bool;
}
-
+
public static function set_popup_width($width)
{
self::$popup_width = $width;
}
-
+
public static function set_confirm_delete($bool)
{
self::$confirm_delete = $bool;
}
-
- function __construct($controller, $name = null, $sourceClass = null, $fieldList = null, $detailFormFields = null, $sourceFilter = "", $sourceSort = null, $sourceJoin = "")
+
+ function __construct($controller, $name = null, $sourceClass = null, $fieldList = null, $detailFormFields = null, $sourceFilter = "", $sourceSort = null, $sourceJoin = "")
{
if(!class_exists("ComplexTableField_ItemRequest"))
die(""._t('DataObjectManager.ERROR','Error').": "._t('DataObjectManager.SILVERSTRIPEVERSION','DataObjectManager requires Silverstripe version 2.3 or higher.'));
-
+
// If no name is given, search the has_many for the first relation.
if($name === null && $sourceClass === null) {
if($has_manys = $controller->stat('has_many')) {
@@ -98,7 +98,7 @@ function __construct($controller, $name = null, $sourceClass = null, $fieldList
}
}
$SNG = singleton($sourceClass);
-
+
if($fieldList === null) {
$diff = array_diff($SNG->summaryFields(),singleton('DataObject')->summaryFields());
@@ -119,11 +119,11 @@ function __construct($controller, $name = null, $sourceClass = null, $fieldList
if(self::$allow_css_override)
Requirements::css('dataobject_manager/css/dataobjectmanager_override.css');
Requirements::javascript(THIRDPARTY_DIR.'/jquery-livequery/jquery.livequery.js');
- Requirements::javascript('dataobject_manager/javascript/facebox.js');
+ Requirements::javascript('dataobject_manager/javascript/facebox.js');
Requirements::javascript('dataobject_manager/javascript/dom_jquery_ui.js');
Requirements::javascript('dataobject_manager/javascript/tooltip.js');
Requirements::javascript('dataobject_manager/javascript/dataobject_manager.js');
-
+
$this->filter_empty_string = '-- '._t('DataObjectManager.NOFILTER','No filter').' --';
if($this->sourceSort) {
@@ -144,12 +144,12 @@ function __construct($controller, $name = null, $sourceClass = null, $fieldList
$this->per_page = $_REQUEST['ctf'][$this->Name()]['per_page'];
$this->showAll = $_REQUEST['ctf'][$this->Name()]['showall'];
$this->search = $_REQUEST['ctf'][$this->Name()]['search'];
- $this->filter = $_REQUEST['ctf'][$this->Name()]['filter'];
+ $this->filter = $_REQUEST['ctf'][$this->Name()]['filter'];
$this->sort = $_REQUEST['ctf'][$this->Name()]['sort'];
$this->sort_dir = $_REQUEST['ctf'][$this->Name()]['sort_dir'];
}
-
-
+
+
$this->setPageSize($this->per_page);
$this->loadSort();
$this->loadSourceFilter();
@@ -170,27 +170,27 @@ function __construct($controller, $name = null, $sourceClass = null, $fieldList
public function setClickToToggle($bool) {
$this->clickToToggle = $bool;
}
-
+
public function setSourceFilter($filter)
{
$this->sourceFilter = $filter;
}
-
+
public function setUseViewAll($bool)
{
$this->use_view_all = $bool;
}
-
+
public function setPerPageMap($values)
{
$this->per_page_map = $values;
}
-
+
public function setPluralTitle($title)
{
$this->pluralTitle = $title;
}
-
+
public function setWideMode($bool)
{
$this->hasNested = $bool;
@@ -200,29 +200,29 @@ public function PluralTitle()
{
return $this->pluralTitle ? $this->pluralTitle : $this->AddTitle()."s";
}
-
-
+
+
protected function loadSort()
{
- if($this->ShowAll())
+ if($this->ShowAll())
$this->setPageSize(999);
-
- if($this->Sortable() && (!isset($_REQUEST['ctf'][$this->Name()]['sort']) || $_REQUEST['ctf'][$this->Name()]['sort'] == "SortOrder")) {
+
+ $frontendSort = empty($_REQUEST['ctf'][$this->Name()]['sort'])
+ ? null
+ : $_REQUEST['ctf'][$this->Name()]['sort'];
+ if($this->Sortable() && (empty($frontendSort) || $frontendSort == "SortOrder")) {
$this->sort = "SortOrder";
$this->sourceSort = "\"SortOrder\" ASC";
- }
- elseif(isset($_REQUEST['ctf'][$this->Name()]['sort']) && !empty($_REQUEST['ctf'][$this->Name()]['sort'])) {
- $this->sourceSort = "\"" . $_REQUEST['ctf'][$this->Name()]['sort'] . "\" " . $this->sort_dir;
- }
- elseif($sort = singleton($this->sourceClass())->stat('default_sort')) {
+ } elseif($frontendSort) {
+ $this->sourceSort = "\"$frontendSort\" {$this->sort_dir}";
+ } elseif($sort = singleton($this->sourceClass())->stat('default_sort')) {
$this->sourceSort = $sort;
- }
- else {
+ } else {
$this->sourceSort = "Created DESC";
}
}
-
+
protected function loadSourceFilter()
{
$filter_string = "";
@@ -231,15 +231,19 @@ protected function loadSourceFilter()
$field = substr($this->filter, 0, $break);
$value = substr($this->filter, $break+1, strlen($this->filter) - strlen($field));
$filter_string = $field . "='$value'";
- }
+ }
$search_string = "";
if(!empty($this->search)) {
$search = array();
- $SNG = singleton($this->sourceClass);
+ $SNG = singleton($this->sourceClass);
foreach(parent::Headings() as $field) {
- if($SNG->hasDatabaseField($field->Name))
- $search[] = "UPPER({$this->sourceClass}.$field->Name) LIKE '%".Convert::raw2sql(strtoupper($this->search))."%'";
+ // If the source class doesn't own this field, then its parent might.
+ while(!$SNG->hasOwnTableDatabaseField($field->Name) && $parentKls = get_parent_class($SNG->class)) {
+ $SNG = singleton($parentKls);
+ }
+ if($SNG->hasDatabaseField($field->Name))
+ $search[] = "UPPER({$SNG->class}.$field->Name) LIKE '%".Convert::raw2sql(strtoupper($this->search))."%'";
}
if(!empty($search)) {
$search_string = "(".implode(" OR ", $search).")";
@@ -248,15 +252,15 @@ protected function loadSourceFilter()
$and = (!empty($this->filter) && !empty($this->search)) ? " AND " : "";
$source_filter = $filter_string.$and.$search_string;
if(!$this->sourceFilter) $this->sourceFilter = $source_filter;
- else if($this->sourceFilter && !empty($source_filter)) $this->sourceFilter .= " AND " . $source_filter;
+ else if($this->sourceFilter && !empty($source_filter)) $this->sourceFilter .= " AND " . $source_filter;
}
-
+
public function handleItem($request) {
return new DataObjectManager_ItemRequest($this, $request->param('ID'));
}
public function getQueryString($params = array())
- {
+ {
$start = isset($params['start'])? $params['start'] : $this->start;
$per_page = isset($params['per_page'])? $params['per_page'] : $this->per_page;
$show_all = isset($params['show_all'])? $params['show_all'] : $this->showAll;
@@ -266,7 +270,7 @@ public function getQueryString($params = array())
$search = isset($params['search'])? $params['search'] : $this->search;
return "ctf[{$this->Name()}][start]={$start}&ctf[{$this->Name()}][per_page]={$per_page}&ctf[{$this->Name()}][showall]={$show_all}&ctf[{$this->Name()}][sort]={$sort}&ctf[{$this->Name()}][sort_dir]={$sort_dir}&ctf[{$this->Name()}][search]={$search}&ctf[{$this->Name()}][filter]={$filter}";
}
-
+
public function getSetting($setting)
{
if($this->$setting) {
@@ -274,7 +278,7 @@ public function getSetting($setting)
}
return Object::get_static($this->class,DOMUtil::to_underscore($setting));
}
-
+
function FieldHolder()
{
if(!$this->controller->ID && $this->isNested)
@@ -282,7 +286,7 @@ function FieldHolder()
return parent::FieldHolder();
}
-
+
public function HasSearch() {
$SNG = singleton($this->sourceClass);
foreach(parent::Headings() as $field) {
@@ -292,17 +296,17 @@ public function HasSearch() {
}
return false;
}
-
+
public function Headings()
{
$headings = array();
foreach($this->fieldList as $fieldName => $fieldTitle) {
- if(isset($_REQUEST['ctf'][$this->Name()]['sort_dir']))
+ if(!empty($_REQUEST['ctf'][$this->Name()]['sort_dir']))
$dir = $_REQUEST['ctf'][$this->Name()]['sort_dir'] == "ASC" ? "DESC" : "ASC";
- else
- $dir = "ASC";
+ else
+ $dir = "ASC";
$headings[] = new ArrayData(array(
- "Name" => $fieldName,
+ "Name" => $fieldName,
"Title" => ($this->sourceClass) ? singleton($this->sourceClass)->fieldLabel($fieldTitle) : $fieldTitle,
"IsSortable" => singleton($this->sourceClass)->hasDatabaseField($fieldName),
"SortLink" => $this->RelativeLink(array(
@@ -310,72 +314,72 @@ public function Headings()
'sort' => $fieldName
)),
"SortDirection" => $dir,
- "IsSorted" => (isset($_REQUEST['ctf'][$this->Name()]['sort'])) && ($_REQUEST['ctf'][$this->Name()]['sort'] == $fieldName),
+ "IsSorted" => (!empty($_REQUEST['ctf'][$this->Name()]['sort'])) && ($_REQUEST['ctf'][$this->Name()]['sort'] == $fieldName),
"ColumnWidthCSS" => !empty($this->column_widths) ? sprintf("style='width:%f%%;'",($this->column_widths[$fieldName] - 0.1)) : ""
));
}
return new DataObjectSet($headings);
}
-
+
function saveComplexTableField($data, $form, $params) {
$className = $this->sourceClass();
$childData = new $className();
$form->saveInto($childData);
try {
$childData->write();
- }
+ }
catch(ValidationException $e) {
$form->sessionMessage($e->getResult()->message(), 'bad');
return Director::redirectBack();
- }
+ }
if($childData->many_many()) {
$form->saveInto($childData);
$childData->write();
- }
+ }
$form->sessionMessage(sprintf(_t('DataObjectManager.ADDEDNEW','Added new %s successfully'),$this->SingleTitle()), 'good');
if($form->getFileFields() || $form->getNestedDOMs()) {
$form->clearMessage();
- Director::redirect(Controller::join_links($this->BaseLink(),'item', $childData->ID, 'edit'));
+ Director::redirect(Controller::join_links($this->BaseLink(),'item', $childData->ID, 'edit'));
}
else Director::redirectBack();
}
-
- function setSourceID($val) {
- if (is_numeric($val)) {
- $this->sourceID = $val;
+
+ function setSourceID($val) {
+ if (is_numeric($val)) {
+ $this->sourceID = $val;
$this->hasCustomSourceID = true;
- }
- }
-
+ }
+ }
+
function sourceID() {
if ($this->hasCustomSourceID) {
return $this->sourceID;
}
-
+
if($this->isNested)
- return $this->controller->ID;
- $idField = $this->form->dataFieldByName('ID');
- return ($idField && is_numeric($idField->Value())) ? $idField->Value() : (isset($_REQUEST['ctf']['ID']) ? $_REQUEST['ctf']['ID'] : null);
- }
-
-
+ return $this->controller->ID;
+ $idField = $this->form->dataFieldByName('ID');
+ return ($idField && is_numeric($idField->Value())) ? $idField->Value() : (isset($_REQUEST['ctf']['ID']) ? $_REQUEST['ctf']['ID'] : null);
+ }
+
+
protected function getRawDetailFields($childData)
{
- if(is_a($this->detailFormFields,"Fieldset"))
+ if(is_a($this->detailFormFields,"Fieldset"))
$fields = $this->detailFormFields;
else {
if(!is_string($this->detailFormFields)) $this->detailFormFields = "getCMSFields";
$functioncall = $this->detailFormFields;
if(!$childData->hasMethod($functioncall)) $functioncall = "getCMSFields";
-
+
$fields = $childData->{$functioncall}($this);
}
- return $fields;
+ return $fields;
}
-
+
public function getCustomFieldsFor($childData) {
$fields = $this->getRawDetailFields($childData);
foreach($fields as $field) {
@@ -384,17 +388,17 @@ public function getCustomFieldsFor($childData) {
}
return $fields;
}
-
+
function AddForm($childID = null)
{
$form = parent::AddForm($childID);
- $actions = new FieldSet();
+ $actions = new FieldSet();
$titles = array();
if($files = $form->getFileFields()) {
foreach($files as $field) $titles[] = DOMUtil::readable_class($field->Title());
}
if($doms = $form->getNestedDOMs())
- foreach($doms as $field) $titles[] = $field->PluralTitle();
+ foreach($doms as $field) $titles[] = $field->PluralTitle();
if(empty($titles))
$text = _t('DataObjectManager.SAVE','Save');
elseif(sizeof($titles) > 3) {
@@ -408,7 +412,7 @@ function AddForm($childID = null)
$actions->push(
$saveAction = new FormAction("saveComplexTableField", $text)
- );
+ );
$saveAction->addExtraClass('save');
$form->setActions($actions);
$form->Fields()->insertFirst(new LiteralField('open','
'));
@@ -421,80 +425,80 @@ function AddForm($childID = null)
public function ClickToToggle() {
return $this->clickToToggle;
}
-
+
public function Link($action = null)
{
return Controller::join_links(parent::Link($action),'?'.$this->getQueryString());
}
-
+
public function BaseLink()
{
return parent::Link();
}
-
+
public function CurrentLink()
{
return $this->Link();
- }
-
+ }
+
public function RelativeLink($params = array())
{
return Controller::join_links(parent::Link(),'?'.$this->getQueryString($params));
- }
+ }
public function FirstLink()
{
return parent::FirstLink() ? $this->RelativeLink(array('start' => '0')) : false;
}
-
+
public function PrevLink()
{
$start = ($this->start - $this->pageSize < 0) ? 0 : $this->start - $this->pageSize;
return parent::PrevLink() ? $this->RelativeLink(array('start' => $start)) : false;
}
-
+
public function NextLink()
{
$currentStart = isset($_REQUEST['ctf'][$this->Name()]['start']) ? $_REQUEST['ctf'][$this->Name()]['start'] : 0;
$start = ($currentStart + $this->pageSize < $this->TotalCount()) ? $currentStart + $this->pageSize : $this->TotalCount() % $this->pageSize > 0;
return parent::NextLink() ? $this->RelativeLink(array('start' => $start)) : false;
}
-
+
public function LastLink()
{
$pageSize = ($this->TotalCount() % $this->pageSize > 0) ? $this->TotalCount() % $this->pageSize : $this->pageSize;
$start = $this->TotalCount() - $pageSize;
return parent::LastLink() ? $this->RelativeLink(array('start' => $start)) : false;
}
-
+
public function ShowAllLink()
{
return $this->RelativeLink(array('show_all' => '1'));
}
-
+
public function PaginatedLink()
{
return $this->RelativeLink(array('show_all' => '0'));
}
public function AddLink() {
- return Controller::join_links($this->BaseLink(), 'add');
+ return Controller::join_links($this->BaseLink(), 'add?cacheb=' . time());
}
-
+
public function ShowAll()
{
return $this->showAll == "1";
}
-
+
public function Paginated()
{
return $this->showAll == "0";
}
-
+
public function Sortable()
{
return DataObject::has_extension($this->sourceClass(), 'SortableDataObject');
}
-
+
public function setFilter($field, $label, $map, $default = null)
{
if(is_array($map)) {
@@ -512,7 +516,7 @@ public function HasFilter()
{
return !empty($this->filter_map);
}
-
+
public function FilterDropdown()
{
$map = $this->filter_empty_string ? array($this->RelativeLink(array('filter' => '')) => $this->filter_empty_string) : array();
@@ -523,7 +527,7 @@ public function FilterDropdown()
$dropdown = new DropdownField('Filter',$this->filter_label . " (
"._t('DataObjectManager.REFRESH','refresh').")", $map, $value);
return $dropdown->FieldHolder();
}
-
+
public function PerPageDropdown()
{
$map = array();
@@ -542,62 +546,62 @@ public function SearchValue()
{
return !empty($this->search) ? $this->search : false;
}
-
+
public function AddTitle()
{
return $this->addTitle ? $this->addTitle : DOMUtil::readable_class($this->Title());
}
-
+
public function SingleTitle()
{
return $this->singleTitle ? $this->singleTitle : DOMUtil::readable_class($this->AddTitle());
}
-
+
public function setAddTitle($title)
{
$this->addTitle = $title;
}
-
+
public function setSingleTitle($title)
{
$this->singleTitle = $title;
}
-
+
public function getColumnWidths()
{
return $this->column_widths;
}
-
+
public function setColumnWidths($widths)
{
if(is_array($widths)) {
$total = 0;
foreach($widths as $name => $value) $total += $value;
- if($total != 100)
+ if($total != 100)
die('
DataObjectManager::setColumnWidths():' . sprintf(_t('DataObjectManager.TOTALNOT100','Column widths must total 100 and not %s'), $total));
else
$this->column_widths = $widths;
}
}
-
+
public function setFilterEmptyString($str)
{
$this->filter_empty_string = $str;
}
-
+
public function addPermission($perm)
{
if(!in_array($perm,$this->permissions))
$this->permissions[] = $perm;
}
-
+
public function removePermission($perm)
{
$key = array_search($perm,$this->permissions);
if($key !== false)
unset($this->permissions[$key]);
}
-
+
public function NestedType()
{
if($this->hasNested)
@@ -607,46 +611,46 @@ public function NestedType()
else
return "";
}
-
+
public function handleDuplicate($request)
{
return new DataObjectManager_ItemRequest($this,$request->param('ID'));
}
-
+
public function setPopupWidth($val)
{
$this->popupWidth = $val;
}
-
+
public function setConfirmDelete($bool)
{
$this->confirmDelete = $bool;
}
-
+
public function PopupWidth()
{
return $this->popupWidth ? $this->popupWidth : self::$popup_width;
}
-
+
public function ConfirmDelete()
{
return $this->getSetting('confirmDelete');
}
-
-
+
+
}
class DataObjectManager_Item extends ComplexTableField_Item {
- function __construct(DataObject $item, DataObjectManager $parent)
+ function __construct(DataObject $item, DataObjectManager $parent)
{
parent::__construct($item, $parent);
}
-
+
function Link() {
return Controller::join_links($this->parent->BaseLink(), 'item', $this->item->ID);
}
-
+
function Fields() {
$fields = parent::Fields();
$widths = $this->parent->getColumnWidths();
@@ -655,21 +659,21 @@ function Fields() {
$field->ColumnWidthCSS = sprintf("style='width:%f%%;'",($widths[$field->Name] - 0.1));
}
}
- return $fields;
+ return $fields;
}
-
+
public function CanViewOrEdit()
{
return $this->parent->Can('view') || $this->parent->Can('edit');
}
-
+
public function ViewOrEdit()
{
if($this->CanViewOrEdit())
return $this->parent->Can('edit') ? "edit" : "view";
return false;
}
-
+
public function ViewOrEdit_i18n()
{
if($res = $this->ViewOrEdit()) {
@@ -677,7 +681,7 @@ public function ViewOrEdit_i18n()
}
return null;
}
-
+
public function EditLink()
{
return Controller::join_links($this->Link(), "edit","?".$this->parent->getQueryString());
@@ -695,12 +699,12 @@ public function CustomActions()
}
return false;
}
-
+
public function PopupWidth()
{
return $this->parent->PopupWidth();
}
-
+
public function Actions()
{
$actions = new DataObjectSet();
@@ -708,18 +712,21 @@ public function Actions()
$action = false;
switch($perm) {
case "edit":
+ if(!$this->item->canEdit()) continue;
case "view":
+ if(!$this->item->canView()) continue;
$actions->push(new DataObjectManagerAction(
$this->ViewOrEdit_i18n(),
$this->EditLink(),
"popup",
"dataobject_manager/images/page_white_{$this->ViewOrEdit()}.png",
"editlink" ,
- $this->parent->PopupWidth()
+ $this->parent->PopupWidth()
));
break;
-
+
case "delete":
+ if(!$this->item->canDelete()) continue;
$actions->push(new DataObjectManagerAction(
_t('DataObjectManager.DELETE','Delete'),
$this->DeleteLink(),
@@ -729,8 +736,9 @@ public function Actions()
$this->parent->getSetting('confirmDelete') ? "confirm" : null
));
break;
-
+
case "duplicate":
+ if(!$this->item->canCreate()) continue;
$actions->push(new DataObjectManagerAction(
_t('DataObjectManager.DUPLICATE','Duplicate'),
$this->DuplicateLink(),
@@ -762,29 +770,30 @@ public function dosort()
list($ownerClass, $className) = explode("-",$className);
}
$many_many = ((is_numeric($this->urlParams['OtherID'])) && SortableDataObject::is_sortable_many_many($className));
- foreach($_POST as $group => $map) {
+ foreach($_POST as $group => $map) {
if(substr($group, 0, 7) == "record-") {
if($many_many) {
- $controllerID = $this->urlParams['OtherID'];
+ $controllerID = $this->urlParams['OtherID'];
$candidates = singleton($ownerClass)->many_many();
if(is_array($candidates)) {
foreach($candidates as $name => $class)
- if($class == $className) {
+ if($class == $className and substr($group, -strlen($name)-1) == '_'.$name) {
$relationName = $name;
break;
}
}
if(!isset($relationName)) return false;
- list($parentClass, $componentClass, $parentField, $componentField, $table) = singleton($ownerClass)->many_many($relationName);
- foreach($map as $sort => $id)
- DB::query("UPDATE \"$table\" SET \"SortOrder\" = $sort WHERE \"{$className}ID\" = $id AND \"{$ownerClass}ID\" = $controllerID");
+ list($parentClass, $componentClass, $parentField, $componentField, $table) = singleton($ownerClass)->many_many($relationName);
+ foreach($map as $sort => $id) {
+ DB::query("UPDATE \"$table\" SET \"SortOrder\" = $sort WHERE \"{$componentField}\" = $id AND \"{$parentField}\" = $controllerID");
+ }
}
else {
foreach($map as $sort => $id) {
$obj = DataObject::get_by_id($className, $id);
$obj->SortOrder = $sort;
$obj->write();
- }
+ }
}
break;
}
@@ -813,7 +822,7 @@ function __construct($controller, $name, $fields, $validator, $readonly, $dataOb
// added prototype.js to provide support for TreeDropdownField
Requirements::javascript(THIRDPARTY_DIR.'/prototype/prototype.js');
Requirements::javascript(THIRDPARTY_DIR.'/jquery/jquery.js');
- Requirements::javascript(THIRDPARTY_DIR.'/jquery-livequery/jquery.livequery.js');
+ Requirements::javascript(THIRDPARTY_DIR.'/jquery-livequery/jquery.livequery.js');
Requirements::block(THIRDPARTY_DIR.'/behaviour.js');
Requirements::block(SAPPHIRE_DIR.'/javascript/Validator.js');
Requirements::clear(THIRDPARTY_DIR.'/behavior.js');
@@ -837,30 +846,30 @@ function __construct($controller, $name, $fields, $validator, $readonly, $dataOb
$this->dataObject->getRequirementsForPopup();
}
Requirements::javascript('dataobject_manager/javascript/dataobjectmanager_popup.js');
-
-
- $actions = new FieldSet();
+
+
+ $actions = new FieldSet();
if(!$readonly) {
$actions->push(
$saveAction = new FormAction("saveComplexTableField", _t('DataObjectManager.SAVE','Save'))
- );
+ );
$saveAction->addExtraClass('save');
}
-
+
parent::__construct($controller, $name, $fields, $actions, $validator);
if ($this->validator instanceof Validator) {
$this->validator->setJavascriptValidationHandler('none');
- }
+ }
else {
$this->unsetValidator();
}
-
+
if($this->getNestedDOMs()) {
Requirements::javascript(THIRDPARTY_DIR.'/jquery-livequery/jquery.livequery.js');
Requirements::javascript('dataobject_manager/javascript/dom_jquery_ui.js');
- Requirements::javascript('dataobject_manager/javascript/tooltip.js');
+ Requirements::javascript('dataobject_manager/javascript/tooltip.js');
Requirements::javascript('dataobject_manager/javascript/dataobject_manager.js');
}
$this->NestedController = $this->controller->isNested;
@@ -869,7 +878,7 @@ function __construct($controller, $name, $fields, $validator, $readonly, $dataOb
function FieldHolder() {
return $this->renderWith('ComplexTableField_Form');
}
-
+
public function getFileFields()
{
$file_fields = array();
@@ -877,9 +886,9 @@ public function getFileFields()
if($field instanceof FileIFrameField || $field instanceof ImageField)
$file_fields[] = $field;
}
- return !empty($file_fields)? $file_fields : false;
+ return !empty($file_fields)? $file_fields : false;
}
-
+
public function getNestedDOMs()
{
$dom_fields = array();
@@ -899,21 +908,21 @@ public function getNestedDOMs()
}
}
}
- return !empty($dom_fields)? $dom_fields : false;
+ return !empty($dom_fields)? $dom_fields : false;
}
-
-
+
+
}
-class DataObjectManager_ItemRequest extends ComplexTableField_ItemRequest
+class DataObjectManager_ItemRequest extends ComplexTableField_ItemRequest
{
public $isNested = false;
protected $itemList;
protected $currentIndex;
-
- function __construct($ctf, $itemID)
+
+ function __construct($ctf, $itemID)
{
parent::__construct($ctf, $itemID);
$this->isNested = $this->ctf->isNested;
@@ -923,9 +932,9 @@ function __construct($ctf, $itemID)
}
}
- function Link()
+ function Link()
{
- return Controller::join_links($this->ctf->BaseLink() , 'item', $this->itemID);
+ return Controller::join_links($this->ctf->BaseLink() , 'item', $this->itemID);
}
function saveComplexTableField($data, $form, $request) {
@@ -933,7 +942,7 @@ function saveComplexTableField($data, $form, $request) {
$form->saveInto($dataObject);
try {
$dataObject->write();
- }
+ }
catch(ValidationException $e) {
$form->sessionMessage($e->getResult()->message(), 'bad');
return Director::redirectBack();
@@ -946,12 +955,12 @@ function saveComplexTableField($data, $form, $request) {
$componentSet = $parentRecord->getManyManyComponents($relationName);
$componentSet->add($dataObject);
}
-
+
$form->sessionMessage(sprintf(_t('DataObjectManager.SAVED','Saved %s successfully'),$this->ctf->SingleTitle()), 'good');
Director::redirectBack();
}
-
+
function DetailForm($childID = null)
{
$form = parent::DetailForm($childID);
@@ -964,7 +973,7 @@ function DetailForm($childID = null)
}
return $form;
}
-
+
function edit() {
if(!$this->ctf->Can('view') && !$this->ctf->Can('edit'))
return false;
@@ -973,16 +982,16 @@ function edit() {
echo $this->renderWith($this->ctf->templatePopup);
}
-
+
public function duplicate()
{
if(!$this->ctf->Can('duplicate'))
return false;
$this->methodName = "duplicate";
-
+
echo $this->renderWith(array('DataObjectManager_duplicate'));
}
-
+
public function DuplicateForm()
{
return new Form(
@@ -1001,7 +1010,7 @@ public function DuplicateForm()
)
);
}
-
+
public function doDuplicate($data,$form)
{
if($obj = $this->dataObj()) {
@@ -1017,7 +1026,7 @@ public function doDuplicate($data,$form)
if($related_objects = $obj->$name()) {
foreach($related_objects as $related_obj) {
$o = $related_obj->duplicate(false);
- $o->$ownerID = $new->ID;
+ $o->$ownerID = $new->ID;
$o->write();
}
}
@@ -1037,7 +1046,7 @@ public function doDuplicate($data,$form)
}
$new->write();
}
- }
+ }
}
$ret = "$i " . _t('DataObjectManager.DUPLICATESCREATED','duplicate(s) created');
if(isset($data['Relations']) && $data['Relations'] == "1") $ret .= ", " . _t('DataObjectManager.WITHRELATIONS','with relations included');
@@ -1047,13 +1056,13 @@ public function doDuplicate($data,$form)
$form->sessionMessage(_t('DataObjectManager.ERRORDUPLICATING','There was an error duplicating the object.'),'bad');
Director::redirectBack();
}
-
-
+
+
protected function getPrevID()
{
return $this->itemList[$this->currentIndex - 1];
}
-
+
protected function getNextID()
{
return $this->itemList[$this->currentIndex + 1];
@@ -1065,40 +1074,40 @@ function NextRecordLink()
if(!$this->itemList || $this->currentIndex == sizeof($this->itemList)-1) return false;
return Controller::join_links($this->ctf->BaseLink() , 'item/' . $this->getNextID().'/edit',"?".$this->ctf->getQueryString());
}
-
+
function PrevRecordLink()
{
if(!$this->itemList || $this->currentIndex == 0) return false;
return Controller::join_links($this->ctf->BaseLink() , 'item/' . $this->getPrevID().'/edit',"?".$this->ctf->getQueryString());
}
-
-
+
+
function HasPagination()
{
return $this->NextRecordLink() || $this->PrevRecordLink();
}
-
+
function HasDuplicate()
{
return $this->ctf->Can('duplicate');
}
-
+
function SingleTitle()
{
return $this->ctf->SingleTitle();
}
-
+
function DuplicateLink()
{
return Controller::join_links($this->ctf->BaseLink(),'duplicate'.$this->itemID);
}
-
+
function HasRelated()
{
$has_many = singleton($this->ctf->SourceClass())->has_many();
return is_array($has_many) && !empty($has_many);
}
-
+
}
class DataObjectManagerAction extends ViewableData
@@ -1109,13 +1118,13 @@ class DataObjectManagerAction extends ViewableData
'refresh' => 'refresh-button',
'window' => 'window-link'
);
-
+
public $Title;
public $Behaviour;
public $ActionClass;
public $Link;
public $IconURL;
-
+
public function __construct($title, $link, $behaviour = "popup", $icon = null, $class = null, $rel = null) {
parent::__construct();
$this->Title = $title;
@@ -1148,12 +1157,12 @@ public static function readable_list($array)
return implode(', ', $array).", $and $last";
}
}
-
+
public static function readable_class($string)
{
- return ucwords(trim(strtolower(ereg_replace('([A-Z])',' \\1',$string))));
+ return ucwords(trim(strtolower(ereg_replace('([A-Z])',' \\1',$string))));
}
-
+
/**
* Translates a camel case string into a string with underscores (e.g. firstName -> first_name)
* @param string $str String in camel case format
@@ -1164,7 +1173,7 @@ public static function to_underscore($str) {
$func = create_function('$c', 'return "_" . strtolower($c[1]);');
return preg_replace_callback('/([A-Z])/', $func, $str);
}
-
+
/**
* Translates a string with underscores into camel case (e.g. first_name -> firstName)
* @param string $str String in underscore format
@@ -1178,7 +1187,5 @@ public static function to_camel_case($str, $capitalise_first_char = false) {
$func = create_function('$c', 'return strtoupper($c[1]);');
return preg_replace_callback('/_([a-z])/', $func, $str);
}
-
-}
-
+}
diff --git a/code/FileDataObjectManager.php b/code/FileDataObjectManager.php
index de1c08f..e87e2e0 100644
--- a/code/FileDataObjectManager.php
+++ b/code/FileDataObjectManager.php
@@ -10,6 +10,7 @@ class FileDataObjectManager extends DataObjectManager
public static $upgrade_video = true;
public static $upgrade_image = true;
public static $upload_limit = "40";
+ public static $copy_on_import = true;
public $view;
public $default_view = "grid";
@@ -18,6 +19,7 @@ class FileDataObjectManager extends DataObjectManager
protected $limitFileTypes;
protected $uploadLimit;
protected $allowUploadFolderSelection = true;
+ protected $allowDragDrop = true;
protected $enableUploadDebugging = false;
public $hasDataObject = true;
public $importClass = "File";
@@ -43,7 +45,7 @@ class FileDataObjectManager extends DataObjectManager
public $uploadifyField = "MultipleFileUploadField";
- public $copyOnImport = true;
+ public $copyOnImport;
public function __construct($controller, $name = null, $sourceClass = null, $fileFieldName = null, $fieldList = null, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "")
{
@@ -195,6 +197,16 @@ public function getUploadLimit()
return $this->getSetting('uploadLimit');
}
+ public function setCopyOnImport($bool)
+ {
+ $this->copyOnImport = $bool;
+ }
+
+ public function getCopyOnImport()
+ {
+ return $this->getSetting('copyOnImport');
+ }
+
public function setBrowseButtonText($text)
{
$this->browseButtonText = $text;
@@ -215,6 +227,11 @@ public function allowUploadFolderSelection()
$this->allowUploadFolderSelection = true;
}
+ public function allowDragDrop()
+ {
+ return $this->allowDragDrop ? true : false;
+ }
+
public function enableUploadDebugging()
{
$this->enableUploadDebugging = true;
@@ -427,7 +444,7 @@ public function saveUploadifyForm($data, $form)
if($file = DataObject::get_by_id("File", (int) $id)) {
$upload_folder = $form->Fields()->fieldByName('UploadedFiles')->uploadFolder;
$folder_id = Folder::findOrMake($upload_folder)->ID;
- if($this->copyOnImport && ($file->ParentID != $folder_id)) {
+ if($this->getCopyOnImport() && ($file->ParentID != $folder_id)) {
$new_file_path = $upload_folder.'/'.$file->Name;
copy($file->getFullPath(), BASE_PATH.'/'.ASSETS_DIR.'/'.$new_file_path);
$clone = new $file_class();
diff --git a/code/HasManyDataObjectManager.php b/code/HasManyDataObjectManager.php
index 07af4e2..3cf4f1c 100644
--- a/code/HasManyDataObjectManager.php
+++ b/code/HasManyDataObjectManager.php
@@ -140,6 +140,7 @@ function ExtraData() {
$inputId = $this->id() . '_' . $this->htmlListEndName;
return <<
+