Skip to content

Commit

Permalink
feat(admin): Add custom dialog titles for Selectize input
Browse files Browse the repository at this point in the history
Add options `dialog_title_create` and `dialog_title_update` to customize the dialog to create or update an option. Defaults to the property's label.
  • Loading branch information
mcaskill committed Mar 11, 2024
1 parent 26018e9 commit ffc3382
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 3 deletions.
12 changes: 12 additions & 0 deletions packages/admin/assets/dist/scripts/charcoal.admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10890,6 +10890,8 @@ Charcoal.Admin.Property_Input_SelectPicker.prototype.create_select = function ()
this.allow_update = opts.data.allow_update || this.allow_update;
this.allow_create = opts.data.allow_create || this.allow_create;
this.title = opts.data.title || this.title;
this.dialog_title_update = opts.data.dialog_title_update || this.dialog_title_update;
this.dialog_title_create = opts.data.dialog_title_create || this.dialog_title_create;
this.translations = opts.data.translations || this.translations;
this.pattern = opts.data.pattern || this.pattern;
this.multiple = opts.data.multiple || this.multiple;
Expand Down Expand Up @@ -11043,6 +11045,16 @@ Charcoal.Admin.Property_Input_SelectPicker.prototype.create_select = function ()
var selectize_property_ident = this.selectize_property_ident;
var selectize_obj_type = this.selectize_obj_type;

if (id) {
if (this.dialog_title_update) {
title = this.dialog_title_update;
}
} else {
if (this.dialog_title_create) {
title = this.dialog_title_create;
}
}

// Get the form ident
if (form_ident && typeof form_ident === 'object') {
if (!id && form_ident.create) {
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/assets/dist/scripts/charcoal.admin.min.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
this.allow_update = opts.data.allow_update || this.allow_update;
this.allow_create = opts.data.allow_create || this.allow_create;
this.title = opts.data.title || this.title;
this.dialog_title_update = opts.data.dialog_title_update || this.dialog_title_update;
this.dialog_title_create = opts.data.dialog_title_create || this.dialog_title_create;
this.translations = opts.data.translations || this.translations;
this.pattern = opts.data.pattern || this.pattern;
this.multiple = opts.data.multiple || this.multiple;
Expand Down Expand Up @@ -235,6 +237,16 @@
var selectize_property_ident = this.selectize_property_ident;
var selectize_obj_type = this.selectize_obj_type;

if (id) {
if (this.dialog_title_update) {
title = this.dialog_title_update;
}
} else {
if (this.dialog_title_create) {
title = this.dialog_title_create;
}
}

// Get the form ident
if (form_ident && typeof form_ident === 'object') {
if (!id && form_ident.create) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@ class SelectizeInput extends SelectInput
*/
private $formData;

/**
* Label for the create item dialog.
*
* @var \Charcoal\Translator\Translation|string|null
*/
private $dialogTitleCreate;

/**
* Label for the update item dialog.
*
* @var \Charcoal\Translator\Translation|string|null
*/
private $dialogTitleUpdate;

/**
* Check used to parse multi Choice map against the obj properties.
*
Expand Down Expand Up @@ -433,6 +447,52 @@ public function formIdentAsJson()
return json_encode($this->formIdent());
}

/**
* Set the title for the create item dialog.
*
* @param string|string[] $title The dialog title.
* @return self
*/
public function setDialogTitleCreate($title)
{
$this->dialogTitleCreate = $this->translator()->translation($title);

return $this;
}

/**
* Retrieve the title for the create item dialog.
*
* @return \Charcoal\Translator\Translation|string|null
*/
public function getDialogTitleCreate()
{
return $this->dialogTitleCreate;
}

/**
* Set the title for the update item dialog.
*
* @param string|string[] $title The dialog title.
* @return self
*/
public function setDialogTitleUpdate($title)
{
$this->dialogTitleUpdate = $this->translator()->translation($title);

return $this;
}

/**
* Retrieve the title for the update item dialog.
*
* @return \Charcoal\Translator\Translation|string|null
*/
public function getDialogTitleUpdate()
{
return $this->dialogTitleUpdate;
}

/**
* Set the selectize picker's options.
*
Expand Down Expand Up @@ -1044,6 +1104,9 @@ public function controlDataForJs()
'allow_update' => $this->allowUpdate(),
'allow_create' => $this->allowCreate(),

'dialog_title_create' => (string)$this->getDialogTitleCreate(),
'dialog_title_update' => (string)$this->getDialogTitleUpdate(),

'form_data' => $this->getFormData(),
'form_ident' => $this->formIdent(),
'form_widget' => $this->formWidget(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

namespace Charcoal\Property\Structure;

// From 'charcoal-core'
use Charcoal\Model\AbstractModel;

/**
*
* An abstract model designed for structure properties.
*/
class StructureModel extends AbstractModel
{
Expand Down

0 comments on commit ffc3382

Please sign in to comment.