Skip to content

Commit

Permalink
Fix: add canEdit to connector modal (#812)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampoyigi committed Jul 5, 2021
1 parent e3c0328 commit 63f2976
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
15 changes: 10 additions & 5 deletions app/admin/formwidgets/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class Connector extends BaseFormWidget
*/
public $sortable = FALSE;

/**
* @var bool Items can be edited.
*/
public $editable = TRUE;

public $popupSize;

public function initialize()
Expand All @@ -68,12 +73,12 @@ public function initialize()
'formName',
'form',
'prompt',
'editable',
'sortable',
'nameFrom',
'descriptionFrom',
'partial',
'popupSize',
'canEdit',
]);

$fieldName = $this->formField->getName(FALSE);
Expand Down Expand Up @@ -113,12 +118,12 @@ public function prepareVars()
$this->vars['fieldItems'] = $this->processLoadValue() ?? [];

$this->vars['prompt'] = $this->prompt;
$this->vars['editable'] = $this->editable;
$this->vars['sortable'] = $this->sortable;
$this->vars['nameFrom'] = $this->nameFrom;
$this->vars['partial'] = $this->partial;
$this->vars['descriptionFrom'] = $this->descriptionFrom;
$this->vars['sortableInputName'] = $this->sortableInputName;
$this->vars['canEdit'] = $this->canEdit ?? true;
}

public function onLoadRecord()
Expand Down Expand Up @@ -213,15 +218,15 @@ protected function processSaveValue($value)
$sortedIndexes = (array)post($this->sortableInputName);
$sortedIndexes = array_flip($sortedIndexes);

$value = [];
$results = [];
foreach ($items as $index => $item) {
$value[$index] = [
$results[$index] = [
$item->getKeyName() => $item->getKey(),
$this->sortColumnName => $sortedIndexes[$item->getKey()],
];
}

return $value;
return $results;
}

protected function makeItemFormWidget($model, $context)
Expand Down
3 changes: 2 additions & 1 deletion app/admin/formwidgets/connector/assets/js/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@

Connector.DEFAULTS = {
alias: undefined,
editable: true,
sortableHandle: '.connector-item-handle',
sortableContainer: '.field-connector-items',
}

Connector.prototype.init = function () {
if (this.options.canEdit)
if (this.options.editable)
this.$el.on('click', '[data-control="load-item"]', $.proxy(this.onLoadItem, this))

this.$el.on('click', '[data-control="delete-item"]', $.proxy(this.onDeleteItem, this))
Expand Down
2 changes: 1 addition & 1 deletion app/admin/formwidgets/connector/connector.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class="field-connector"
data-alias="{{ $this->alias }}"
data-sortable-container="#{{ $this->getId('items') }}"
data-sortable-handle=".{{ $this->getId('items') }}-handle"
data-editable="{{ $canEdit }}"
data-editable="{{ $editable ? 'true' : 'false' }}"
>
<div
id="{{ $this->getId('items') }}"
Expand Down

0 comments on commit 63f2976

Please sign in to comment.