Skip to content

Commit

Permalink
WiP updating to SilverStripe 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Zauberfisch committed Oct 5, 2018
1 parent a7e0255 commit 0a7c86e
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 57 deletions.
40 changes: 28 additions & 12 deletions css/ArrayListField.scss.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@
padding-bottom: 10px; }

.zauberfisch\\SerializedDataObject\\Form\\ArrayListField > .middleColumn {
margin-left: 0; }
max-width: 83.33333%; }

.zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.CompositeField {
margin: 0 !important;
padding: 0 !important;
display: block !important; }
.zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.CompositeField > .form__fieldgroup {
margin: 0 !important;
padding: 0 !important;
max-width: none !important;
-webkit-flex: none !important;
flex: none !important; }

.zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.field {
border: 0;
Expand All @@ -18,9 +29,9 @@
border-radius: 3px;
border: 1px solid #CDCCD0;
background: rgba(0, 0, 0, 0.05);
margin: 0 0 10px; }
margin: 0 0 10px !important; }
.zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record {
padding: 20px 10px 10px;
padding: 15px 10px 10px !important;
border-bottom: 1px solid #CDCCD0;
position: relative; }
.zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record:last-child {
Expand All @@ -29,26 +40,31 @@
background: rgba(255, 0, 0, 0.05); }
.zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls {
position: absolute;
right: 5px;
top: 10px; }
.zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls > * {
right: 0;
top: 0;
z-index: 50; }
.zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls > .form__fieldgroup > * {
display: block;
float: left;
margin: 0 5px 0 0; }
.zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls .orderable-handle {
.zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls > .form__fieldgroup button {
background: transparent;
border-radius: none; }
.zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls > .form__fieldgroup .orderable-handle {
height: 22px;
width: 16px;
cursor: move;
background: center center no-repeat url("../images/orderable-handle.png"); }
.zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls .orderable-up, .zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls .orderable-down, .zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls .delete-record {
.zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls > .form__fieldgroup .orderable-up, .zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls > .form__fieldgroup .orderable-down, .zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls > .form__fieldgroup .delete-record {
padding: 2px; }
.zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls .orderable-up:before, .zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls .orderable-down:before, .zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls .delete-record:before {
.zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls > .form__fieldgroup .orderable-up:before, .zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls > .form__fieldgroup .orderable-down:before, .zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls > .form__fieldgroup .delete-record:before {
margin: 0; }
.zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls .orderable-up span, .zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls .orderable-down span, .zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls .delete-record span {
.zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls > .form__fieldgroup .orderable-up span, .zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls > .form__fieldgroup .orderable-down span, .zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls > .form__fieldgroup .delete-record span {
display: none; }
.zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls .orderable-up:hover, .zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls .orderable-down:hover, .zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls .delete-record:hover {
.zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls > .form__fieldgroup .orderable-up:hover, .zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls > .form__fieldgroup .orderable-down:hover, .zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record .controls > .form__fieldgroup .delete-record:hover {
background: transparent;
opacity: .6; }
.zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record:first-child .controls .orderable-up, .zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record:last-child .controls .orderable-down {
.zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record:first-child .controls > .form__fieldgroup .orderable-up,
.zauberfisch\\SerializedDataObject\\Form\\ArrayListField div.record-list .record:last-child .controls > .form__fieldgroup .orderable-down {
cursor: default;
opacity: .4 !important; }
10 changes: 5 additions & 5 deletions javascript/ArrayListField.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function ($) {
$('.zauberfisch\\\\SerializedDataObject\\\\Form\\\\ArrayListField').entwine({
getRecordList: function () {
return this.find('.record-list');
return this.find('.record-list > .form__fieldgroup');
}
});
$('.zauberfisch\\\\SerializedDataObject\\\\Form\\\\ArrayListField *').entwine({
Expand All @@ -23,14 +23,14 @@
},
sortableEnable: function () {
// enable sorting functionality
this.sortable({
this.find('> .form__fieldgroup').sortable({
handle: ".orderable-handle",
axis: "y"
});
},
sortableDisable: function () {
try {
this.sortable("destroy");
this.find('> .form__fieldgroup').sortable("destroy");
} catch (e) {
}
}
Expand Down Expand Up @@ -74,8 +74,8 @@
var record = this.closest('.record'),
recordList = this.getContainerField().getRecordList(),
index = record.index();
console.log(index);
console.log(recordList.find('.record').length - 1);
// console.log(index);
// console.log(recordList.find('.record').length - 1);
if (
(index === 0 && this.hasClass('orderable-up')) ||
(index === recordList.find('.record').length - 1 && this.hasClass('orderable-down'))
Expand Down
96 changes: 65 additions & 31 deletions scss/ArrayListField.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,34 @@
padding-bottom: 10px;
}
> .middleColumn {
margin-left: 0;
max-width: 83.33333%;
}
div.CompositeField {
margin: 0 !important;
padding: 0 !important;
display: block !important;

> .form__fieldgroup {
margin: 0 !important;
padding: 0 !important;
max-width: none !important;
-webkit-flex: none !important;
flex: none !important;
}
}
//div.field-inner {
// display: block !important;
//
// > div {
// margin-left: 0 !important;
// display: block !important;
// padding-left: 0 !important;
// padding-right: 0 !important;
// max-width: 83.33333% !important;
// -webkit-flex: none !important;
// flex: none !important;
// }
//}
div.field {
border: 0;
-webkit-box-shadow: none;
Expand All @@ -19,13 +45,13 @@
border-radius: 3px;
border: 1px solid #CDCCD0;
background: rgba(#000, .05);
margin: 0 0 10px;

margin: 0 0 10px !important;
.record {
padding: 20px 10px 10px;
padding: 15px 10px 10px !important;
border-bottom: 1px solid #CDCCD0;
position: relative;

&:last-child {
border-bottom: 0;
}
Expand All @@ -34,37 +60,45 @@
}
.controls {
position: absolute;
right: 5px;
top: 10px;

> * {
display: block;
float: left;
margin: 0 5px 0 0;
}

.orderable-handle {
height: 22px;
width: 16px;
cursor: move;
background: center center no-repeat url('../images/orderable-handle.png');
}
.orderable-up, .orderable-down, .delete-record {
padding: 2px;

&:before {
margin: 0;
right: 0;
top: 0;
z-index: 50;

> .form__fieldgroup {
> * {
display: block;
float: left;
margin: 0 5px 0 0;
}
span {
display: none;
}
&:hover {

button {
background: transparent;
opacity: .6;
border-radius: none;
}
.orderable-handle {
height: 22px;
width: 16px;
cursor: move;
background: center center no-repeat url('../images/orderable-handle.png');
}
.orderable-up, .orderable-down, .delete-record {
padding: 2px;

&:before {
margin: 0;
}
span {
display: none;
}
&:hover {
background: transparent;
opacity: .6;
}
}
}
}
&:first-child .controls .orderable-up, &:last-child .controls .orderable-down {
&:first-child .controls > .form__fieldgroup .orderable-up,
&:last-child .controls > .form__fieldgroup .orderable-down {
cursor: default;
opacity: .4 !important;
}
Expand Down
13 changes: 6 additions & 7 deletions src/DBField/AbstractField.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
abstract class AbstractField extends DBField {
protected $isChanged = false;

/**
* @return AbstractList|AbstractField|null
*/
Expand All @@ -24,7 +24,7 @@ function getValue() {
}
return $this->value;
}

/**
* @param AbstractList|AbstractDataObject|AbstractField|null|string $value
* @param null $record
Expand All @@ -40,11 +40,11 @@ public function setValue($value, $record = null, $markAsChanged = true) {
}
parent::setValue($value, $record);
}

public function isChanged() {
return $this->isChanged;
}

public function prepValueForDB($value) {
if (is_a($value, __CLASS__)) {
$value = $value->getValue();
Expand All @@ -54,9 +54,8 @@ public function prepValueForDB($value) {
}
return parent::prepValueForDB($value);
}

public function requireField() {
// keep using deprecated DB::requireField() for 3.1 compatibility
DB::require_field($this->tableName, $this->name, [
'type' => 'text',
'parts' => [
Expand All @@ -67,7 +66,7 @@ public function requireField() {
],
]);
}

public function __toString() {
return $this->prepValueForDB($this->getValue());
}
Expand Down
5 changes: 3 additions & 2 deletions src/Form/ArrayListField.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ArrayListField extends FormField {
protected $recordFieldsUpdateCallback;
protected $recordClassName;
protected $orderable = false;
protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_CUSTOM;

public function __construct($name, $title, $recordClassName) {
$this->recordClassName = $recordClassName;
Expand Down Expand Up @@ -128,7 +129,7 @@ public function Field($properties = []) {
->setUseButtonTag(true)
->addExtraClass('font-icon-plus')
->addExtraClass('add-record'),
]))->FieldHolder()->forTemplate();
]))->addExtraClass('field-inner')->FieldHolder()->forTemplate();
}

/**
Expand Down Expand Up @@ -293,7 +294,7 @@ public function handleSubField($fullFieldName) {
* @param DataObjectInterface $record
*/
public function saveInto(DataObjectInterface $record) {
$record->{$this->name} = $this->Value();
$record->{$this->name} = $this->Value()->__toString();
}

private static $allowed_actions = [
Expand Down

0 comments on commit 0a7c86e

Please sign in to comment.