Skip to content

Commit 7303826

Browse files
committed
Added buttons to component and removed them from template
1 parent 1b6fdb9 commit 7303826

File tree

4 files changed

+54
-146
lines changed

4 files changed

+54
-146
lines changed

assets/js/app/editor/Components/Collection.vue

+49-126
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</button>
1515
</div>
1616
</div>
17-
17+
<!-- {{ log(elements) }}-->
1818
<div
1919
v-for="element in elements"
2020
:key="element.hash"
@@ -32,12 +32,43 @@
3232
{{ element.label }}
3333
</div>
3434
<!-- Navigation buttons -->
35-
<div :is="compile(element.buttons)"></div>
35+
<div class="btn-group ml-auto mr-2" role="group" aria-label="Collection buttons">
36+
<button class="action-move-up-collection-item btn btn-light btn-sm" style="white-space: nowrap">
37+
<i class="fas fa-fw fa-chevron-up"></i>
38+
{{ labels.collection_up }}
39+
</button>
40+
<button
41+
class="action-move-down-collection-item btn btn-light btn-sm"
42+
style="white-space: nowrap"
43+
>
44+
<i class="fas fa-fw fa-chevron-down"></i>
45+
{{ labels.collection_down }}
46+
</button>
47+
<button
48+
class="action-remove-collection-item btn btn-light-danger btn-sm"
49+
style="white-space: nowrap"
50+
data-confirmation="{{ labels.collection_delete_confirm }}"
51+
>
52+
<i class="fas fa-fw fa-trash"></i>
53+
{{ labels.collection_delete }}
54+
</button>
55+
</div>
3656
</div>
3757
</div>
3858
<div class="card details">
3959
<!-- The actual field -->
40-
<div :is="currentComponent" class="card-body"></div>
60+
<editor-textarea
61+
:name="element.name"
62+
:rows="element.rows"
63+
:required="element.required"
64+
:readonly="element.readonly"
65+
:data-errormessage="element.errormessage"
66+
:placeholder="element.placeholder"
67+
:style="{ height: element.styleHeight }"
68+
:maxlength="element.maxlength"
69+
:title="element.label"
70+
>
71+
</editor-textarea>
4172
</div>
4273
</div>
4374

@@ -62,7 +93,7 @@
6293
:key="field.type"
6394
class="dropdown-item"
6495
:data-field="field.type"
65-
@click="addCollectionItem(field.slug)"
96+
@click="addCollectionItem($event)"
6697
>
6798
<i :class="[field.icon, 'fas fa-fw']" />
6899
{{ field.label }}
@@ -74,7 +105,7 @@
74105
type="button"
75106
class="btn btn-secondary btn-small"
76107
:data-field="fields[0].slug"
77-
@click="addCollectionItem(fields.slug)"
108+
@click="addCollectionItem(fields.type)"
78109
>
79110
<i :class="[fields[0].icon, 'fas fa-fw']" />
80111
{{ labels.add_collection_item }}
@@ -85,53 +116,16 @@
85116
</template>
86117

87118
<script>
88-
import { compile } from 'vue';
119+
import {compile} from 'vue';
89120
/*
90121
Editor Components for rendering
91122
*/
92-
import Text from './Text';
93-
import Slug from './Slug';
94-
import Date from './Date';
95-
import Select from './Select';
96-
import Number from './Number';
97-
import Html from './Html';
98-
import Markdown from './Markdown';
99-
import Textarea from './Textarea';
100-
import Embed from './Embed';
101-
import Image from './Image';
102-
import Imagelist from './Imagelist';
103-
import Email from './Email';
104-
import Password from './Password';
105-
import ThemeSelect from './ThemeSelect';
106-
import Language from './Language';
107-
import File from './File';
108-
import Filelist from './Filelist';
109-
import Checkbox from './Checkbox';
110-
111123
import $ from 'jquery';
124+
import EditorTextarea from './Textarea';
112125
113126
export default {
114127
name: 'EditorCollection',
115-
components: {
116-
Text,
117-
Slug,
118-
Date,
119-
Select,
120-
Number,
121-
Html,
122-
Markdown,
123-
Textarea,
124-
Embed,
125-
Image,
126-
Imagelist,
127-
Email,
128-
Password,
129-
ThemeSelect,
130-
Language,
131-
File,
132-
Filelist,
133-
Checkbox,
134-
},
128+
components: { EditorTextarea },
135129
props: {
136130
name: {
137131
type: String,
@@ -149,6 +143,7 @@ export default {
149143
required: true,
150144
},
151145
limit: {
146+
type: Number,
152147
required: true,
153148
},
154149
variant: {
@@ -157,6 +152,7 @@ export default {
157152
},
158153
},
159154
data() {
155+
console.log(this.existingFields);
160156
let fieldSelectOptions = [];
161157
return {
162158
currentComponent: '',
@@ -313,94 +309,21 @@ export default {
313309
getCollectionItemFromPressedButton(button) {
314310
return window.$(button).closest('.collection-item').last();
315311
},
316-
addCollectionItem(fieldName) {
317-
console.log(this.fields);
312+
addCollectionItem(event) {
318313
this.counter++;
319-
320-
// Create switch case for every field type
321-
switch (fieldName) {
322-
case 'text':
323-
var component = Text;
324-
break;
325-
case 'slug':
326-
this.elements.push(Slug);
327-
this.currentComponent = Slug;
328-
break;
329-
case 'date':
330-
this.elements.push(Date);
331-
this.currentComponent = Date;
332-
break;
333-
case 'select':
334-
this.elements.push(Select);
335-
this.currentComponent = Select;
336-
break;
337-
case 'number':
338-
this.elements.push(Number);
339-
this.currentComponent = Number;
340-
break;
341-
case 'html':
342-
this.elements.push(Html);
343-
this.currentComponent = Html;
344-
break;
345-
case 'markdown':
346-
this.elements.push(Markdown);
347-
this.currentComponent = Markdown;
348-
break;
349-
case 'textarea':
350-
this.elements.push(Textarea);
351-
this.currentComponent = Textarea;
352-
break;
353-
case 'embed':
354-
this.elements.push(Embed);
355-
this.currentComponent = Embed;
356-
break;
357-
case 'image':
358-
this.elements.push(Image);
359-
this.currentComponent = Image;
360-
break;
361-
case 'imagelist':
362-
this.elements.push(Imagelist);
363-
this.currentComponent = Imagelist;
364-
break;
365-
case 'email':
366-
this.elements.push(Email);
367-
this.currentComponent = Email;
368-
break;
369-
case 'password':
370-
this.elements.push(Password);
371-
this.currentComponent = Password;
372-
break;
373-
case 'themeSelect':
374-
this.elements.push(ThemeSelect);
375-
this.currentComponent = ThemeSelect;
376-
break;
377-
case 'language':
378-
this.elements.push(Language);
379-
this.currentComponent = Language;
380-
break;
381-
case 'file':
382-
this.elements.push(File);
383-
this.currentComponent = File;
384-
break;
385-
case 'filelist':
386-
this.elements.push(Filelist);
387-
this.currentComponent = Filelist;
388-
break;
389-
case 'checkbox':
390-
this.elements.push(Checkbox);
391-
this.currentComponent = Checkbox;
392-
break;
393-
}
394-
this.currentComponent(component);
395-
this.elements.push(component);
396-
return this.currentComponent;
314+
let field = this.getSelectedField(event);
315+
this.elements.push(field);
397316
},
398317
getSelectedField(event) {
399318
const target = $(event.target).attr('data-field')
400319
? $(event.target)
401320
: $(event.target).closest('[data-field]');
402321
let selectValue = target.attr('data-field');
403-
return this.fields.find((field) => field.label === selectValue);
322+
let objValues = Object.values(this.fields);
323+
324+
console.log(objValues.find((field) => field.type === selectValue));
325+
326+
return objValues.find((field) => field.type === selectValue);
404327
},
405328
},
406329
};

templates/_macro/_macro.html.twig

+1-4
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,13 @@
7878
</div>
7979
{% endset %}
8080

81-
{# Set the buttons #}
82-
{% set buttons %}{% include '@bolt/_partials/fields/_collection_buttons.html.twig' with { in_compound: true, 'hash': hash } %}{% endset %}
83-
8481
{# Set the icon #}
8582
{% set icon = item_field.definition.icon %}
8683
{% if icon is empty%}{% set icon = 'fa-plus' %}{% endif %}
8784

8885
{# set the label manually as set in _base.html.twig, to pass to Collection.vue for templates #}
8986
{% set label = item_field.definition.label|default(item_field.name|default('unnamed')|ucwords) %}
90-
{% set fieldsHtml = fieldsHtml|merge([{'content': new_field, 'hash': hash, 'label': label, 'buttons': buttons, 'icon': icon}]) %}
87+
{% set fieldsHtml = fieldsHtml|merge([{'content': new_field, 'hash': hash, 'label': label, 'icon': icon}]) %}
9188
{% endfor %}
9289
{{ fieldsHtml|json_encode }}
9390
{% endapply %}{% endmacro %}

templates/_partials/fields/_collection_buttons.html.twig

-16
This file was deleted.

templates/_partials/fields/collection.html.twig

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
'collapse_all': 'collection.collapse_all'|trans,
99
'field_label': label,
1010
'select': 'collection.select'|trans,
11+
'collection_up': 'collection.move_item_up'|trans,
12+
'collection_down': 'collection.move_item_down'|trans,
13+
'collection_delete': 'collection.remove_item'|trans,
14+
'collection_delete_confirm': 'collection.confirm_delete'|trans
1115
} %}
1216
{% set limit = field.definition.get('limit')|default(200) %}
1317

0 commit comments

Comments
 (0)