Skip to content

Commit

Permalink
Merge pull request #1019 from bolt/feature/limit-collections
Browse files Browse the repository at this point in the history
Feature/limit collection
  • Loading branch information
bobdenotter committed Feb 5, 2020
2 parents e02106b + 1ce76da commit ca618dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 8 additions & 1 deletion assets/js/app/editor/Components/Collection.vue
Expand Up @@ -16,6 +16,7 @@
<button
class="btn btn-secondary"
type="button"
:disabled="!allowMore"
@click="addCollectionItem"
>
<i class="fas fa-fw fa-plus"></i>
Expand All @@ -31,7 +32,7 @@ var uniqid = require('locutus/php/misc/uniqid');
export default {
name: 'EditorCollection',
props: ['templates', 'existingFields', 'labels'],
props: ['templates', 'existingFields', 'labels', 'limit'],
data() {
let elements = [];
this.existingFields.forEach(function(field) {
Expand All @@ -49,6 +50,7 @@ export default {
return {
elements: elements,
counter: elements.length,
templateSelectName: 'templateSelect' + this.id,
templateSelectOptions: templateSelectOptions,
selector: {
Expand All @@ -64,6 +66,9 @@ export default {
initialSelectValue() {
return this.templateSelectOptions[0].key;
},
allowMore: function() {
return this.counter < this.limit;
},
},
mounted() {
let vueThis = this;
Expand All @@ -79,6 +84,7 @@ export default {
.closest(vueThis.selector.collectionContainer);
vueThis.getCollectionItemFromPressedButton(this).remove();
vueThis.setAllButtonsStates(collectionContainer);
vueThis.counter--;
});
window.$(document).on('click', vueThis.selector.moveUp, function(e) {
Expand Down Expand Up @@ -167,6 +173,7 @@ export default {
);
let res = Vue.compile(html);
this.elements.push(res);
this.counter++;
},
getSelectedTemplate() {
let selectValue = this.$refs.templateSelect.selected;
Expand Down
8 changes: 5 additions & 3 deletions templates/_partials/fields/collection.html.twig
Expand Up @@ -5,6 +5,7 @@
{% set labels = {
'add_collection_item': 'collection.add_item'|trans({'%name%': field.definition.label}),
} %}
{% set limit = field.definition.get('limit')|default(200) %}

{# get the html for all collection field already in the database #}
{% set existing_fields = []|json_encode %}
Expand All @@ -19,9 +20,10 @@
{% endif %}

<editor-collection
:existing-fields='{{ existing_fields }}'
:templates='{{ templated_fields }}'
:labels='{{ labels | json_encode }}'
:existing-fields='{{ existing_fields }}'
:templates='{{ templated_fields }}'
:labels='{{ labels | json_encode }}'
:limit='{{ limit | json_encode }}'
></editor-collection>

{% endblock %}

0 comments on commit ca618dd

Please sign in to comment.