Skip to content

Commit

Permalink
Check for maxLimit on grouped block type init. Bump to 1.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
mmikkel committed Dec 13, 2021
1 parent 5dc09a6 commit 9d709c2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased
## 1.3.3 - 2021-12-13
### Fixed
- Fixes an issue where MatrixMate could make Craft create a provisional draft even if there were no changes to the entry edit form
- Fixes an issue where MatrixMate could make the "Are you sure you want to close the editor?" confirm dialog appear in entry editor slideouts, even if there were no field changes
- Fixes an issue where grouped types with a `maxLimit` setting would not have the proper styling on pageload if the max limit was reached

## 1.3.2 - 2021-12-13
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vaersaagod/matrixmate",
"description": "Welding Matrix into shape, mate!",
"type": "craft-plugin",
"version": "1.3.2",
"version": "1.3.3",
"keywords": [
"craft",
"cms",
Expand Down
52 changes: 41 additions & 11 deletions src/assetbundles/matrixmate/dist/js/MatrixMate.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
if (Craft.EntryTypeSwitcher) {
Garnish.on(Craft.EntryTypeSwitcher, 'beforeTypeChange', $.proxy(function (e) {
this.settings.context = 'entryType:' + e.target.$typeSelect.val();
setTimeout(function () {
if (window.draftEditor) {
window.draftEditor.checkForm();
}
}, 0);
}, this));
}

Expand Down Expand Up @@ -83,6 +88,8 @@
}
}

console.log(e.target);

}, this);

updateEditorContext();
Expand Down Expand Up @@ -150,27 +157,43 @@
Garnish.on(Craft.MatrixInput, 'afterInit', $.proxy(this.onMatrixInputInit, this));
Garnish.on(Craft.MatrixInput, 'blockAdded', $.proxy(this.onMatrixInputBlockAdded, this));

this.overrideDraftEditorInitialSerializedValue();
this.maybeOverrideInitialSerializedForm(Craft.cp.$primaryForm || null);

},

overrideDraftEditorInitialSerializedValue: function () {
if (!window.draftEditor) {
maybeOverrideInitialSerializedForm: function ($form) {
if (!$form.length) {
return;
}
setTimeout(function () {
try {
Craft.cp.$primaryForm.data('initialSerializedValue', window.draftEditor.serializeForm(true));
} catch (error) {
console.error(error);
}
}, 0);
if (window.draftEditor && Craft.cp.$primaryForm && Craft.cp.$primaryForm.attr('id') === $form.attr('id')) {
setTimeout(function () {
try {
Craft.cp.$primaryForm.data('initialSerializedValue', window.draftEditor.serializeForm(true));
} catch (error) {
console.error(error);
}
}, 0);
return;
}
if ($form.data('elementEditor') && $form.data('elementEditor').slideout && !$form.data('matrixMateInitialized')) {
$form.data('matrixMateInitialized', true);
setTimeout(function () {
try {
$form.data('elementEditor').initialData = $form.data('elementEditor').slideout.$container.serialize();
} catch (error) {
console.error(error);
}
}, 0);
}
},

// Initialises a Matrix field, including block type groups and tabs
initField: function ($field) {

var $form = $field.closest('form');

if ($field.hasClass('matrixmate-inited')) {
this.maybeOverrideInitialSerializedForm($form);
return;
}

Expand All @@ -193,7 +216,7 @@
this.initBlock($(block), $field);
}, this));

this.overrideDraftEditorInitialSerializedValue();
this.maybeOverrideInitialSerializedForm($form);
},

// Initialises a Matrix block, including the settings menu and tabs
Expand Down Expand Up @@ -328,8 +351,15 @@
continue;
}

// Check if the type should be disabled
var typeConfig = this._getTypeConfig(type, $field) || {};
var disable = typeConfig && typeConfig.maxLimit && this._countBlockByType(type, $field) >= typeConfig.maxLimit;

var $li = $('<li/>');
var $a = $('<a/>').attr('data-type', type).text($origTypeBtn.text());
if (disable) {
$a.addClass('disabled');
}

$li.append($a).appendTo($mainUl);
$li.clone().appendTo($collapsedUl);
Expand Down

0 comments on commit 9d709c2

Please sign in to comment.