/
item-text.php
352 lines (317 loc) · 17.9 KB
/
item-text.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<?php
/**
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
* @copyright Aimeos (aimeos.org), 2017-2024
*/
/** admin/jqadm/product/item/text/config/suggest
* List of suggested configuration keys in product text panel
*
* Item references can store arbitrary key value pairs. This setting gives
* editors a hint which config keys are available and are used in the templates.
*
* @param string List of suggested config keys
* @since 2020.01
*/
/** admin/jqadm/api/translate
* Configuration for realtime online translation service
*
* Contains the required settings for configuring the online translation service.
* Currently, only DeepL is supported and a paid DeepL API account is required to
* use the service. The necessary settings for DeepL are:
*
* [
* 'url' => 'https://api.deepl.com/v2',
* 'key' => '<your-DeepL-API-key>',
* ]
*
* @param array Associative list of key/value pairs
* @since 2019.10
*/
/** admin/jqadm/api/openai
* Configuration for ChatGPT API to generate texts
*
* Contains the required settings for configuring the ChatGPT API.
* The necessary settings for ChatGPT are:
*
* [
* 'key' => '<your-OpenAI-API-key>',
* ]
*
* @param array Associative list of key/value pairs
* @since 2022.10
*/
$enc = $this->encoder();
?>
<div id="text" class="item-text tab-pane fade" role="tablist" aria-labelledby="text">
<div id="item-text-group"
data-openaiprompt="<?= $enc->attr( $this->translate( 'admin', 'Please insert the description of the text that should be generated here' ) ) ?>"
data-openai="<?= $enc->attr( $this->config( 'admin/jqadm/api/openai' ) ) ?>"
data-translate="<?= $enc->attr( $this->config( 'admin/jqadm/api/translate', [] ) ) ?>"
data-data="<?= $enc->attr( $this->get( 'textData', [] ) ) ?>"
data-siteid="<?= $this->site()->siteid() ?>"
data-domain="product" >
<div class="group-list" role="tablist" aria-multiselectable="true">
<div is="vue:draggable" item-key="text.id" group="text" :list="items" handle=".act-move">
<template #item="{element, index}">
<div class="group-item card box" v-bind:class="{loading: element['loading'], mismatch: !can('match', index)}">
<div v-bind:id="'item-text-group-item-' + index" class="card-header header">
<div class="card-tools-start">
<div class="btn btn-card-header act-show icon" v-bind:class="element['_show'] ? 'show' : 'collapsed'" v-on:click="toggle('_show', index)"
v-bind:data-bs-target="'#item-text-group-data-' + index" data-bs-toggle="collapse"
v-bind:aria-controls="'item-text-group-data-' + index" aria-expanded="false"
title="<?= $enc->attr( $this->translate( 'admin', 'Show/hide this entry' ) ) ?>" tabindex="<?= $this->get( 'tabindex' ) ?>">
</div>
</div>
<div class="item-label header-label" v-bind:class="{disabled: !active(index)}" v-on:click="toggle('_show', index)">{{ label(index) }}</div>
<div class="card-tools-end">
<a class="btn btn-card-header act-generate icon" href="#" v-on:click.prevent="generate(index)"
title="<?= $enc->attr( $this->translate( 'admin', 'Generate text' ) ) ?>">
</a>
<div class="dropdown">
<a v-bind:id="'translate-menu-' + index" class="btn btn-card-header act-translate icon dropdown-toggle" href="#"
tabindex="<?= $this->get( 'tabindex' ) ?>" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"
title="<?= $enc->attr( $this->translate( 'admin', 'Translate text' ) ) ?>">
</a>
<div class="dropdown-menu dropdown-menu-end" v-bind:aria-labelledby="'translate-menu-' + index">
<?php foreach( ['bg', 'cs', 'da', 'de', 'el', 'en', 'es', 'et', 'fi', 'fr', 'hu', 'id', 'it', 'ja', 'lt', 'lv', 'nl', 'no', 'pl', 'pt', 'pt_BR', 'ro', 'ru', 'sk', 'sl', 'sv', 'tr', 'uk', 'zh'] as $lang ) : ?>
<a class="dropdown-item" href="#" v-on:click="translate(index, `<?= $lang ?>`)"><?= $enc->html( $this->translate( 'language', $lang ) ) ?></a>
<?php endforeach ?>
</div>
</div>
<div v-if="can('move', index)"
class="btn btn-card-header act-move icon" tabindex="<?= $this->get( 'tabindex' ) ?>"
title="<?= $enc->attr( $this->translate( 'admin', 'Move this entry up/down' ) ) ?>">
</div>
<div v-if="can('delete', index)"
class="btn btn-card-header act-delete icon" tabindex="<?= $this->get( 'tabindex' ) ?>"
title="<?= $enc->attr( $this->translate( 'admin', 'Delete this entry' ) ) ?>"
v-on:click.stop="remove(index)">
</div>
</div>
</div>
<div v-bind:id="'item-text-group-data-' + index" v-bind:class="element['_show'] ? 'show' : 'collapsed'"
v-bind:aria-labelledby="'item-text-group-item-' + index" role="tabpanel" class="card-block collapse row">
<input type="hidden" v-model="element['text.id']"
v-bind:name="`<?= $enc->js( $this->formparam( array( 'text', '_idx_', 'text.id' ) ) ) ?>`.replace('_idx_', index)">
<div class="col-xl-6">
<div class="form-group row mandatory">
<div class="col-sm-12">
<textarea is="vue:ckeditor" v-if="element['_show']" class="form-control item-content" required="required"
tabindex="<?= $enc->attr( $this->get( 'tabindex' ) ) ?>"
v-bind:editor="CKEditor"
v-bind:config="Aimeos.ckeditor"
v-bind:disabled="!can('change', index)"
v-bind:model-value="element['text.content']"
@blur="(...args) => update(element, ...args)"
></textarea>
<textarea v-show="!element['_show']" class="form-control item-content" readonly
v-bind:name="`<?= $enc->js( $this->formparam( array( 'text', '_idx_', 'text.content' ) ) ) ?>`.replace('_idx_', index)"
>{{ element['text.content'] }}</textarea>
</div>
</div>
</div>
<div class="col-xl-6">
<div class="form-group row mandatory">
<label class="col-sm-4 form-control-label"><?= $enc->html( $this->translate( 'admin', 'Status' ) ) ?></label>
<div class="col-sm-8">
<select class="form-select item-status" required="required" tabindex="<?= $this->get( 'tabindex' ) ?>"
v-bind:name="`<?= $enc->js( $this->formparam( array( 'text', '_idx_', 'text.status' ) ) ) ?>`.replace('_idx_', index)"
v-bind:readonly="!can('change', index)"
v-model="element['text.status']" >
<option value=""><?= $enc->html( $this->translate( 'admin', 'Please select' ) ) ?></option>
<option value="1" v-bind:selected="element['text.status'] == 1" >
<?= $enc->html( $this->translate( 'mshop/code', 'status:1' ) ) ?>
</option>
<option value="0" v-bind:selected="element['text.status'] == 0" >
<?= $enc->html( $this->translate( 'mshop/code', 'status:0' ) ) ?>
</option>
<option value="-1" v-bind:selected="element['text.status'] == -1" >
<?= $enc->html( $this->translate( 'mshop/code', 'status:-1' ) ) ?>
</option>
<option value="-2" v-bind:selected="element['text.status'] == -2" >
<?= $enc->html( $this->translate( 'mshop/code', 'status:-2' ) ) ?>
</option>
</select>
</div>
</div>
<?php if( ( $languages = $this->get( 'pageLangItems', map() ) )->count() !== 1 ) : ?>
<div class="form-group row mandatory">
<label class="col-sm-4 form-control-label help"><?= $enc->html( $this->translate( 'admin', 'Language' ) ) ?></label>
<div class="col-sm-8">
<select is="vue:select-component" required class="form-select item-languageid" tabindex="<?= $enc->attr( $this->get( 'tabindex' ) ) ?>"
v-bind:items="<?= $enc->attr( $languages->col( 'locale.language.label', 'locale.language.id' )->toArray() ) ?>"
v-bind:name="`<?= $enc->js( $this->formparam( ['text', '_idx_', 'text.languageid'] ) ) ?>`.replace('_idx_', index)"
v-bind:text="`<?= $enc->js( $this->translate( 'admin', 'Please select' ) ) ?>`"
v-bind:all="`<?= $enc->js( $this->translate( 'admin', 'All' ) ) ?>`"
v-bind:readonly="!can('change', index)"
v-model="element['text.languageid']" >
</select>
</div>
<div class="col-sm-12 form-text text-muted help-text">
<?= $enc->html( $this->translate( 'admin', 'Language of the entered text' ) ) ?>
</div>
</div>
<?php else : ?>
<input class="text-langid" type="hidden"
v-bind:name="`<?= $enc->js( $this->formparam( array( 'text', '_idx_', 'text.languageid' ) ) ) ?>`.replace('_idx_', index)"
value="<?= $enc->attr( $languages->getCode()->first() ) ?>">
<?php endif ?>
<?php if( ( $textTypes = $this->get( 'textTypes', map() ) )->count() !== 1 ) : ?>
<div class="form-group row mandatory">
<label class="col-sm-4 form-control-label help"><?= $enc->html( $this->translate( 'admin', 'Type' ) ) ?></label>
<div class="col-sm-8">
<select is="vue:select-component" required class="form-select item-type" tabindex="<?= $enc->attr( $this->get( 'tabindex' ) ) ?>"
v-bind:items="<?= $enc->attr( $textTypes->col( 'text.type.label', 'text.type.code' )->toArray() ) ?>"
v-bind:name="`<?= $enc->js( $this->formparam( ['text', '_idx_', 'text.type'] ) ) ?>`.replace('_idx_', index)"
v-bind:text="`<?= $enc->js( $this->translate( 'admin', 'Please select' ) ) ?>`"
v-bind:readonly="!can('change', index)"
v-model="element['text.type']" >
</select>
</div>
<div class="col-sm-12 form-text text-muted help-text">
<?= $enc->html( $this->translate( 'admin', 'Types for additional texts like per one lb/kg or per month' ) ) ?>
</div>
</div>
<?php else : ?>
<input class="item-type" type="hidden"
v-bind:name="`<?= $enc->js( $this->formparam( array( 'text', '_idx_', 'text.type' ) ) ) ?>`.replace('_idx_', index)"
value="<?= $enc->attr( $textTypes->getCode()->first() ) ?>">
<?php endif ?>
<div class="form-group row optional">
<label class="col-sm-4 form-control-label help"><?= $enc->html( $this->translate( 'admin', 'Label' ) ) ?></label>
<div class="col-sm-8">
<input class="form-control item-label" type="text" tabindex="<?= $this->get( 'tabindex' ) ?>"
v-bind:name="`<?= $enc->js( $this->formparam( array( 'text', '_idx_', 'text.label' ) ) ) ?>`.replace('_idx_', index)"
placeholder="<?= $enc->attr( $this->translate( 'admin', 'Label' ) ) ?>"
v-bind:readonly="!can('change', index)"
v-model="element['text.label']">
</div>
<div class="col-sm-12 form-text text-muted help-text">
<?= $enc->html( $this->translate( 'admin', 'Description of the text content if it\'s in a foreign language' ) ) ?>
</div>
</div>
</div>
<div class="col-12 secondary item-meta text-muted">
<small>
<?= $enc->html( $this->translate( 'admin', 'Site' ) ) ?>:
<span class="meta-value">{{ element['text.siteid'] }}</span>
</small>
<small>
<?= $enc->html( $this->translate( 'admin', 'Editor' ) ) ?>:
<span class="meta-value">{{ element['text.editor'] }}</span>
</small>
<small>
<?= $enc->html( $this->translate( 'admin', 'Created' ) ) ?>:
<span class="meta-value">{{ element['text.ctime'] }}</span>
</small>
<small>
<?= $enc->html( $this->translate( 'admin', 'Modified' ) ) ?>:
<span class="meta-value">{{ element['text.mtime'] }}</span>
</small>
</div>
<div v-on:click="toggle('_ext', index)" class="col-xl-12 advanced" v-bind:class="{'collapsed': !element['_ext']}">
<div class="card-tools-start">
<div class="btn act-show icon" tabindex="<?= $this->get( 'tabindex' ) ?>"
title="<?= $enc->attr( $this->translate( 'admin', 'Show/hide advanced data' ) ) ?>">
</div>
</div>
<span class="header-label"><?= $enc->html( $this->translate( 'admin', 'Advanced' ) ) ?></span>
</div>
<div v-show="element['_ext']" class="col-xl-6 secondary">
<?php if( ( $listTypes = $this->get( 'textListTypes', map() ) )->count() !== 1 ) : ?>
<div class="form-group row mandatory">
<label class="col-sm-4 form-control-label help"><?= $enc->html( $this->translate( 'admin', 'List type' ) ) ?></label>
<div class="col-sm-8">
<select is="vue:select-component" required class="form-select listitem-type" tabindex="<?= $enc->attr( $this->get( 'tabindex' ) ) ?>"
v-bind:items="<?= $enc->attr( $listTypes->col( 'product.lists.type.label', 'product.lists.type.code' )->toArray() ) ?>"
v-bind:name="`<?= $enc->js( $this->formparam( ['text', '_idx_', 'product.lists.type'] ) ) ?>`.replace('_idx_', index)"
v-bind:text="`<?= $enc->js( $this->translate( 'admin', 'Please select' ) ) ?>`"
v-bind:readonly="!can('change', index)"
v-model="element['product.lists.type']" >
</select>
</div>
<div class="col-sm-12 form-text text-muted help-text">
<?= $enc->html( $this->translate( 'admin', 'Second level type for grouping items' ) ) ?>
</div>
</div>
<?php else : ?>
<input class="listitem-type" type="hidden"
v-bind:name="`<?= $enc->js( $this->formparam( array( 'text', '_idx_', 'product.lists.type' ) ) ) ?>`.replace('_idx_', index)"
value="<?= $enc->attr( $listTypes->getCode()->first() ) ?>">
<?php endif ?>
<div class="form-group row optional">
<label class="col-sm-4 form-control-label help"><?= $enc->html( $this->translate( 'admin', 'Start date' ) ) ?></label>
<div class="col-sm-8">
<input is="vue:flat-pickr" class="form-control listitem-datestart select" type="datetime-local" tabindex="<?= $this->get( 'tabindex' ) ?>"
v-bind:name="`<?= $enc->js( $this->formparam( array( 'text', '_idx_', 'product.lists.datestart' ) ) ) ?>`.replace('_idx_', index)"
placeholder="<?= $enc->attr( $this->translate( 'admin', 'YYYY-MM-DD hh:mm:ss (optional)' ) ) ?>"
v-bind:disabled="!can('change', index)"
v-bind:config="Aimeos.flatpickr.datetime"
v-model="element['product.lists.datestart']">
</div>
<div class="col-sm-12 form-text text-muted help-text">
<?= $enc->html( $this->translate( 'admin', 'The item is only shown on the web site after that date and time' ) ) ?>
</div>
</div>
<div class="form-group row optional">
<label class="col-sm-4 form-control-label help"><?= $enc->html( $this->translate( 'admin', 'End date' ) ) ?></label>
<div class="col-sm-8">
<input is="vue:flat-pickr" class="form-control listitem-dateend select" type="datetime-local" tabindex="<?= $this->get( 'tabindex' ) ?>"
v-bind:name="`<?= $enc->js( $this->formparam( array( 'text', '_idx_', 'product.lists.dateend' ) ) ) ?>`.replace('_idx_', index)"
placeholder="<?= $enc->attr( $this->translate( 'admin', 'YYYY-MM-DD hh:mm:ss (optional)' ) ) ?>"
v-bind:disabled="!can('change', index)"
v-bind:config="Aimeos.flatpickr.datetime"
v-model="element['product.lists.dateend']">
</div>
<div class="col-sm-12 form-text text-muted help-text">
<?= $enc->html( $this->translate( 'admin', 'The item is only shown on the web site until that date and time' ) ) ?>
</div>
</div>
</div>
<div v-show="element['_ext']" class="col-xl-6 secondary">
<config-table v-bind:tabindex="`<?= $enc->js( $this->get( 'tabindex' ) ) ?>`"
v-bind:keys="<?= $enc->attr( $this->config( 'admin/jqadm/product/item/text/config/suggest', [] ) ) ?>"
v-bind:name="`<?= $enc->js( $this->formparam( ['text', '_idx_', 'config', '_pos_', '_key_'] ) ) ?>`.replace('_idx_', index)"
v-bind:index="index" v-bind:readonly="!can('change', index)"
v-bind:items="element['config']" v-on:update:items="element['config'] = $event"
v-bind:i18n="{
value: `<?= $enc->js( $this->translate( 'admin', 'Value' ) ) ?>`,
option: `<?= $enc->js( $this->translate( 'admin', 'Option' ) ) ?>`,
help: `<?= $enc->js( $this->translate( 'admin', 'Item specific configuration options, will be available as key/value pairs in the templates' ) ) ?>`,
insert: `<?= $enc->js( $this->translate( 'admin', 'Insert new entry (Ctrl+I)' ) ) ?>`,
delete: `<?= $enc->js( $this->translate( 'admin', 'Delete this entry' ) ) ?>`,
}">
</config-table>
</div>
<div v-show="element['_ext']" class="col-12 secondary item-meta text-muted">
<small>
<?= $enc->html( $this->translate( 'admin', 'Site' ) ) ?>:
<span class="meta-value">{{ element['product.lists.siteid'] }}</span>
</small>
<small>
<?= $enc->html( $this->translate( 'admin', 'Editor' ) ) ?>:
<span class="meta-value">{{ element['product.lists.editor'] }}</span>
</small>
<small>
<?= $enc->html( $this->translate( 'admin', 'Created' ) ) ?>:
<span class="meta-value">{{ element['product.lists.ctime'] }}</span>
</small>
<small>
<?= $enc->html( $this->translate( 'admin', 'Modified' ) ) ?>:
<span class="meta-value">{{ element['product.lists.mtime'] }}</span>
</small>
</div>
<?= $this->get( 'textBody' ) ?>
</div>
</div>
</template>
</div>
<div slot="footer" class="card-tools-more">
<div class="btn btn-primary btn-card-more act-add icon" tabindex="<?= $this->get( 'tabindex' ) ?>"
title="<?= $enc->attr( $this->translate( 'admin', 'Insert new entry (Ctrl+I)' ) ) ?>"
v-on:click="add()" >
</div>
</div>
</div>
</div>
</div>