Skip to content

Commit 97b3412

Browse files
committed
wip
1 parent 9ceeb6a commit 97b3412

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

resources/views/actions/form/modal.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="modal fade" tabindex="-1" role="dialog" id="{{ $modal_id }}">
1+
<div class="modal" tabindex="-1" role="dialog" id="{{ $modal_id }}">
22
<div class="modal-dialog" role="document">
33
<div class="modal-content">
44
<div class="modal-header">

src/Actions/Action.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ public function handleActionPromise()
365365
};
366366
367367
var actionCatcher = function (request) {
368-
if (typeof request.responseJSON === 'object') {
368+
if (request && typeof request.responseJSON === 'object') {
369369
$.admin.toastr.error(request.responseJSON.message, '', {positionClass:"toast-bottom-center", timeOut: 10000}).css("width","500px")
370370
}
371371
};

src/Actions/Interactor/Form.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public function addElementAttr($content, $selector)
280280
$crawler = new Crawler($content);
281281

282282
$node = $crawler->filter($selector)->getNode(0);
283-
$node->setAttribute('modal', $this->modalId);
283+
$node->setAttribute('modal', $this->getModalId());
284284

285285
return $crawler->children()->html();
286286
}
@@ -368,29 +368,44 @@ protected function resolveView($class)
368368
}
369369

370370
/**
371-
* @param string $modalID
371+
* @return void
372372
*/
373-
public function addModalHtml($modalID)
373+
public function addModalHtml()
374374
{
375375
$data = [
376376
'fields' => $this->fields,
377377
'title' => $this->action->name(),
378-
'modal_id' => $modalID,
378+
'modal_id' => $this->getModalId(),
379379
];
380380

381381
$modal = view('admin::actions.form.modal', $data)->render();
382382

383383
Admin::html($modal);
384384
}
385385

386+
/**
387+
* @return string
388+
*/
389+
protected function getModalId()
390+
{
391+
if (!$this->modalId) {
392+
393+
if ($this->action instanceof RowAction) {
394+
$this->modalId = uniqid('row-action-modal-');
395+
} else {
396+
$this->modalId = strtolower(str_replace('\\', '-', get_class($this->action)));
397+
}
398+
}
399+
400+
return $this->modalId;
401+
}
402+
386403
/**
387404
* @return void
388405
*/
389406
public function addScript()
390407
{
391-
$this->modalId = uniqid('action-modal-');
392-
393-
$this->action->attribute('modal', $this->modalId);
408+
$this->action->attribute('modal', $this->getModalId());
394409

395410
$parameters = json_encode($this->action->parameters());
396411

@@ -430,7 +445,7 @@ protected function buildActionPromise()
430445
call_user_func([$this->action, 'form']);
431446
}
432447

433-
$this->addModalHtml($this->modalId);
448+
$this->addModalHtml();
434449

435450
return <<<SCRIPT
436451
var process = new Promise(function (resolve,reject) {

0 commit comments

Comments
 (0)