-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added UploadField subclass to save into serialized DBField
- Loading branch information
1 parent
bcc1afa
commit cd45bb2
Showing
7 changed files
with
127 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.ui-sortable .preview img { | ||
cursor: move; | ||
} | ||
|
||
.zauberfisch\\serializeddataobject\\form\\sortableupload .ui-sortable-helper { | ||
background-color: #fff !important; | ||
border: 1px solid #b3b3b3 !important; | ||
border-left: 0 !important; | ||
border-right: 0 !important; | ||
-webkit-box-shadow: 0px 9px 5px -5px rgba(0, 0, 0, 0.3); | ||
-moz-box-shadow: 0px 9px 5px -5px rgba(0, 0, 0, 0.3); | ||
box-shadow: 0px 9px 5px -5px rgba(0, 0, 0, 0.3); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
;(function($) { | ||
$(function(){ | ||
$.entwine('ss', function($) { | ||
$(".zauberfisch\\\\serializeddataobject\\\\form\\\\sortableupload.ss-uploadfield ul.ss-uploadfield-files").entwine({ | ||
onmatch: function() { | ||
// enable sorting functionality | ||
var self = this, | ||
rootForm = this.closest('form'); | ||
self.sortable({ | ||
handle: ".ss-uploadfield-item-preview", | ||
axis: "y", | ||
start: function(event, ui){ | ||
// remove overflow on container | ||
ui.item.data("oldPosition", ui.item.index()); | ||
self.css("overflow", "hidden"); | ||
}, | ||
stop: function(event, ui){ | ||
// restore overflow | ||
self.css("overflow", "auto"); | ||
//rootForm.addClass('changed'); | ||
} | ||
}); | ||
this._super(); | ||
}, | ||
onunmatch: function(){ | ||
// clean up | ||
try { | ||
$(this).sortable("destroy"); | ||
} catch(e){} | ||
this._super(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}(jQuery)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.ui-sortable .preview img { | ||
cursor: move; | ||
} | ||
|
||
.zauberfisch\\serializeddataobject\\form\\sortableupload .ui-sortable-helper { | ||
background-color: #fff !important; | ||
border: 1px solid #b3b3b3 !important; | ||
border-left: 0 !important; | ||
border-right: 0 !important; | ||
-webkit-box-shadow: 0px 9px 5px -5px rgba(0, 0, 0, 0.3); | ||
-moz-box-shadow: 0px 9px 5px -5px rgba(0, 0, 0, 0.3); | ||
box-shadow: 0px 9px 5px -5px rgba(0, 0, 0, 0.3); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace zauberfisch\SerializedDataObject\Form; | ||
|
||
/** | ||
* @author Zauberfisch | ||
*/ | ||
class SortableUploadField extends UploadField { | ||
public function Field($properties = []) { | ||
\Requirements::javascript(SERIALIZED_DATAOBJECT_DIR . '/javascript/SortableUploadField.js'); | ||
//\Requirements::css(SERIALIZED_DATAOBJECT_DIR . '/scss/SortableUploadField.scss'); | ||
\Requirements::css(SERIALIZED_DATAOBJECT_DIR . '/css/SortableUploadField.scss.css'); | ||
return parent::Field($properties); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace zauberfisch\SerializedDataObject\Form; | ||
|
||
use zauberfisch\SerializedDataObject\DataList; | ||
use zauberfisch\SerializedDataObject\DBField\DataListField; | ||
|
||
/** | ||
* @author Zauberfisch | ||
*/ | ||
class UploadField extends \UploadField { | ||
protected function getSerializableList($ids) { | ||
return new DataList(\File::get()->byIDs($ids)->toArray()); | ||
} | ||
|
||
/** | ||
* @param \DataObjectInterface|\DataObject $record | ||
* @return $this | ||
*/ | ||
public function saveInto(\DataObjectInterface $record) { | ||
$fieldName = $this->getName(); | ||
if (!$fieldName) { | ||
return $this; | ||
} | ||
if ($record->hasField($fieldName)) { | ||
$info = $record->db($fieldName); | ||
if ($info == DataListField::class) { | ||
// Get details to save | ||
$value = $this->getSerializableList($this->getItemIDs()); | ||
$dbValue = new DataListField(); | ||
$dbValue->setValue($value, null, true); | ||
$record->setField($fieldName, $dbValue); | ||
} | ||
} else { | ||
parent::saveInto($record); | ||
} | ||
return $this; | ||
} | ||
|
||
public function setValue($value, $record = null) { | ||
if (is_string($value) && $value) { | ||
$dbField = new DataListField(); | ||
$dbField->setValue($value, null, true); | ||
$value = $dbField->getValue(); | ||
return parent::setValue(null, $value); | ||
} | ||
return parent::setValue($value, $record); | ||
} | ||
} |