Skip to content

Commit

Permalink
Merge pull request #15560 from craftcms/feature/cms-1336-add-inline-e…
Browse files Browse the repository at this point in the history
…diting-support-for-post-date-expiry-date-etc

Feature/cms 1336 add inline editing support for post date expiry date etc
  • Loading branch information
brandonkelly authored Aug 24, 2024
2 parents 41ff132 + 8f6e5ff commit 48a50dc
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
### Content Management
- Element conditions can now have a “Not Related To” rule. ([#15496](https://github.com/craftcms/cms/pull/15496))
- Asset chips and cards no longer include the “Replace file” action. ([#15498](https://github.com/craftcms/cms/issues/15498))
- Category slugs are now inline-editable from the Categories index page. ([#15560](https://github.com/craftcms/cms/pull/15560))
- Entry post dates, expiry dates, slugs, and authors are now inline-editable from the Entries index page. ([#15560](https://github.com/craftcms/cms/pull/15560))

### Accessibility
- Improved the accessibility of Tags fields.
Expand Down
16 changes: 16 additions & 0 deletions src/elements/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,22 @@ public function getGroup(): CategoryGroup
// Indexes, etc.
// -------------------------------------------------------------------------

/**
* @inheritdoc
*/
protected function inlineAttributeInputHtml(string $attribute): string
{
switch ($attribute) {
case 'slug':
return Cp::textHtml([
'name' => 'slug',
'value' => $this->slug,
]);
default:
return parent::inlineAttributeInputHtml($attribute);
}
}

/**
* @inheritdoc
* @since 3.3.0
Expand Down
47 changes: 47 additions & 0 deletions src/elements/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -1934,6 +1934,53 @@ protected function attributeHtml(string $attribute): string
}
}

/**
* @inheritdoc
*/
protected function inlineAttributeInputHtml(string $attribute): string
{
switch ($attribute) {
case 'postDate':
return Cp::dateTimeFieldHtml([
'name' => 'postDate',
'value' => $this->postDate,
]);
case 'expiryDate':
return Cp::dateTimeFieldHtml([
'name' => 'expiryDate',
'value' => $this->expiryDate,
]);
case 'slug':
return Cp::textHtml([
'name' => 'slug',
'value' => $this->slug,
]);
case 'authors':
$authors = $this->getAuthors();
$section = $this->getSection();
return Cp::elementSelectHtml([
'status' => $this->getAttributeStatus('authorIds'),
'label' => Craft::t('app', '{max, plural, =1{Author} other {Authors}}', [
'max' => $section->maxAuthors,
]),
'id' => 'authorIds',
'name' => 'authorIds',
'elementType' => User::class,
'selectionLabel' => Craft::t('app', 'Choose'),
'criteria' => [
'can' => "viewEntries:$section->uid",
],
'single' => false,
'elements' => $authors ?: null,
'disabled' => false,
'errors' => $this->getErrors('authorIds'),
'limit' => $section->maxAuthors,
]);
default:
return parent::inlineAttributeInputHtml($attribute);
}
}

/**
* @inheritdoc
*/
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js.map

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions src/web/assets/cp/src/js/TableElementIndexView.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ Craft.TableElementIndexView = Craft.BaseElementIndexView.extend({

this.addListener(this.$saveBtn, 'activate', () => {
this.$saveBtn.addClass('loading');
this.closeDateTimeFields();

this.saveChanges()
.then((data) => {
if (data.errors) {
Expand Down Expand Up @@ -191,6 +193,8 @@ Craft.TableElementIndexView = Craft.BaseElementIndexView.extend({
) {
this.$cancelBtn.addClass('loading');
this.elementIndex.inlineEditing = false;
this.closeDateTimeFields();

this.elementIndex.updateElements(true, false).then(() => {
this.elementIndex.$elements.removeClass('inline-editing');
});
Expand Down Expand Up @@ -229,6 +233,14 @@ Craft.TableElementIndexView = Craft.BaseElementIndexView.extend({
}
},

closeDateTimeFields: function () {
// ensure opened date/time pickers don't linger after activating the Cancel btn
this.elementIndex.$elements.find('.timewrapper input').timepicker('remove');
this.elementIndex.$elements
.find('.datewrapper input')
.datepicker('destroy');
},

serializeInputs: function () {
const data = Garnish.getPostData(this.$elementContainer);
const serialized = [];
Expand Down

0 comments on commit 48a50dc

Please sign in to comment.