Subversion Repositories wpShopGermany4

Rev

Rev 7824 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7824 daniel 1
<?php
2
 
3
	namespace wpsg;
4
 
5
	$arTemplates = array_values($this->callMod('wpsg_mod_downloadplus', 'getTemplate'));
6
 
7
	$arFontVue = [];
8
	foreach ($this->view['wpsg_mod_downloadplus']['arFonts'] as $font_code => $font_label) {
9
 
10
	    $arFontVue[] = ['code' => $font_code, 'label' => $font_label];
11
 
12
    }
13
 
14
?>
15
 
16
<div id="wpsg_dp_templates_app">
17
 
18
	<div class="head">
19
 
20
        <a href="#" @click.prevent="addTemplate" title="<?php echo __('Neues Template anlegen', 'wpsg'); ?>">
21
            <span class="wpsg-glyphicon glyphicon glyphicon-plus"></span>
22
        </a>
23
 
24
		<div v-if="arTemplates.length > 0">
25
 
26
			<select v-model="template">
27
				<option :value="null"><?php echo __('Bitte auswählen', 'wpsg'); ?></option>
28
				<option v-for="(template, index) in arTemplates" :value="template">
29
                    {{template.name}} ({{template.arField.length}} <?php echo __('Felder', 'wpsg'); ?><template v-if="template.defaulttemplate">, <?php echo __('Standard', 'wpsg'); ?></template>)
30
                </option>
31
			</select>
32
 
33
		</div>
34
		<div v-else>
35
 
36
			<?php echo __('Keine Templates vorhanden', 'wpsg'); ?>
37
 
38
		</div>
39
 
40
        <a v-if="template" href="#" @click.prevent="removeTemplate" title="<?php echo __('Template löschen', 'wpsg'); ?>">
41
            <span class="wpsg-glyphicon glyphicon glyphicon-trash"></span>
42
        </a>
43
 
44
	</div>
45
 
46
	<div v-if="template" class="template">
47
 
48
		<div class="form-group form-group-sm has-feedback">
7841 daniel 49
			<label class="col-sm-6 control-label label-copy" for="wpsg_mod_downloadplus_filename">
50
                <a href="#" title="<?php echo __('Template kopieren', 'wpsg'); ?>" @click="copyTemplate()"><span class="wpsg-glyphicon glyphicon glyphicon-copy"></span></a>
51
                <span><?php echo __('Name des Templates', 'wpsg'); ?></span>
52
            </label>
7824 daniel 53
			<div class="col-sm-6">
54
				<div class="wpsg_field_wrap wpsg_field_wrap_template_name">
55
					<input type="text" v-model="template.name" />
56
                    <div>
57
                        <label class="control-label"><?php echo __('Standard: ', 'wpsg'); ?></label>
58
                        <input type="checkbox" :checked="template.defaulttemplate" @click="setDefaultTemplate" />
59
                    </div>
60
				</div>
61
			</div>
62
			<div class="clearfix wpsg_clear"></div>
63
		</div>
64
 
65
		<table class="table table-body-striped wpsg_mod_downloadplus_fieldtable">
66
            <thead>
67
                <tr>
68
                    <th class="col_bezeichnung">
69
                        <a href="#" @click.prevent="addField" title="<?php echo __('Neues Feld', 'wpsg'); ?>">
70
                            <span class="wpsg-glyphicon glyphicon glyphicon-plus"></span>
71
                        </a>
72
                    </th>
73
                    <th class="col_x"><?php echo __('X', 'wpsg'); ?></th>
74
                    <th class="col_y"><?php echo __('Y', 'wpsg'); ?></th>
75
                    <th class="col_align"><?php echo __('Zentriert', 'wpsg'); ?></th>
76
                    <th class="col_bg"><?php echo __('Hintergrund', 'wpsg'); ?></th>
77
                    <th class="col_color"><?php echo __('Farbe', 'wpsg'); ?></th>
78
                    <th class="col_alpha"><?php echo __('Deckkraft', 'wpsg'); ?></th>
79
                    <th class="col_angle"><?php echo __('Winkel', 'wpsg'); ?></th>
80
                    <th class="col_groesse"><?php echo __('Größe', 'wpsg'); ?></th>
81
                    <th class="col_action"></th>
82
                </tr>
83
            </thead>
84
			<tbody v-for="(field, field_index) in template.arField">
85
                <tr>
86
                    <td>#{{field_index + 1}}</td>
87
                    <td>
88
                        <input type="text" style="width:50px;" v-model="field.x" />
89
                    </td>
90
                    <td>
91
                        <input type="text" style="width:50px;" v-model="field.y" />
92
                    </td>
93
                    <td class="col_align">
94
                        <input class="wpsg_hideBarcode" type="checkbox" v-model="field.align" />
95
                    </td>
96
                    <td class="col_bg">
97
                        <input class="wpsg_hideBarcode" type="checkbox" v-model="field.bg" />
98
                    </td>
99
                    <td class="col_color">
100
                        <input class="wpsg_hideBarcode" type="text" style="width:75px;" v-model="field.color" />
101
                    </td>
102
                    <td class="col_alpha">
103
                        <input class="wpsg_hideBarcode" type="text" style="width:50px;" v-model="field.alpha" />
104
                    </td>
105
                    <td>
106
                        <input class="wpsg_hideBarcode" type="text" style="width:50px;" v-model="field.angle" />
107
                    </td>
108
                    <td>
109
                        <select v-model="field.fontsize" style="width:100%;">
110
                            <option v-for="size in [4,5,6,7,8,9,10,11,12,13,14,16,18,20,22,24,26,28,30,32,34]" :value="size">{{size}}</option>
111
                        </select>
112
                    </td>
113
                    <td>
114
                        <input type="checkbox" title="<?php echo __('Hier können Sie die Zeile deaktivieren/aktivieren.', 'wpsg'); ?>" value="1" v-model="field.aktiv" />
115
                    </td>
116
                </tr>
117
                <tr>
118
                    <td>
119
                        <a href="#" @click.prevent="addField(field_index)" title="<?php echo __('Neues Feld davor einfügen', 'wpsg'); ?>">
120
                            <span class="wpsg-glyphicon glyphicon glyphicon-plus"></span>
121
                        </a>
122
                    </td>
123
                    <td class="col_freitext_label"><?php echo __('Freitext', 'wpsg'); ?>:</td>
124
                    <td colspan="5" class="col_freitext">
125
                        <input type="text" style="width:100%;" v-model="field.text" />
126
                    </td>
127
                    <td colspan="2">
128
                        <select class="fontselect" v-model="field.font" style="width:100%;">
129
                            <option v-for="(font, index_font) in arFont" :value="font.code">{{font.label}}</option>
130
                        </select>
131
                    </td>
132
                    <td>
133
                        <a href="#" @click.prevent="removeField(field_index)" title="<?php echo __('Feld löschen', 'wpsg'); ?>">
134
                            <span class="wpsg-glyphicon glyphicon glyphicon-trash"></span>
135
                        </a>
136
                    </td>
137
                </tr>
138
            </tbody>
139
		</table>
140
 
141
        <div class="file_wrap">
142
 
143
            <div class="uploadstate">
144
                <template v-if="uploadstate.run">
145
                    <img src="<?php echo WPSG_URL; ?>views/gfx/ajax-loader.gif" alt="<?php echo __('Bitte warten ...', 'wpsg'); ?>" />
146
                    <span><?php echo __('Bitte warten', 'wpsg'); ?> ... <template v-if="uploadstate.proz">{{uploadstate.proz}} %</template></span>
147
                </template>
148
                <input v-else type="file" v-on:change="upload" />
149
            </div>
150
 
151
            <div v-if="template.file" class="file">
152
                <span>{{template.file}}</span>
153
                <a href="#" @click.prevent="removeFile" title="<?php echo __('Datei löschen', 'wpsg'); ?>">
154
                    <span class="wpsg-glyphicon glyphicon glyphicon-trash"></span>
155
                </a>
156
            </div>
157
 
158
        </div>
159
 
160
	</div>
161
 
162
    <textarea style="display:none;" name="template">{{arTemplates}}</textarea>
163
 
164
	<br />
165
 
166
</div>
167
 
168
<style>
169
 
170
	#wpsg_dp_templates_app .head { width:100%; display:flex; align-items:center; justify-content:space-between; border-bottom:1px solid #DDDDDD; margin-bottom:1rem; padding-bottom:1rem; }
171
	#wpsg_dp_templates_app .head select { width:300px; }
172
    #wpsg_dp_templates_app .head div { flex-grow:1;  }
173
    #wpsg_dp_templates_app .wpsg_field_wrap_template_name { display:flex; justify-content:space-between; align-items:center; padding-right:10px !important; }
174
    #wpsg_dp_templates_app .wpsg_field_wrap_template_name > div { gap:1rem; display:flex; justify-content:flex-start; align-items:center; }
175
    #wpsg_dp_templates_app .template td.col_bg,
176
    #wpsg_dp_templates_app .template td.col_align { width:50px; text-align:center; }
177
    #wpsg_dp_templates_app .template tr td { vertical-align:middle; }
178
    #wpsg_dp_templates_app .template tr td:last-child { text-align:right; }
179
    #wpsg_dp_templates_app .template tr td:last-child .wpsg-glyphicon { margin-right:0; }
180
    #wpsg_dp_templates_app .uploadstate { display:flex; justify-content:flex-start; align-items:center; }
181
    #wpsg_dp_templates_app .uploadstate > img { margin-right:1rem; }
182
    #wpsg_dp_templates_app .file_wrap { display:flex; justify-content:space-between; align-items:center; }
183
    #wpsg_dp_templates_app .file_wrap .file { display:flex; gap:1rem; justify-content:flex-end; align-items:center; }
184
    #wpsg_dp_templates_app .file_wrap .file .wpsg-glyphicon { margin-right:8px; }
7841 daniel 185
    #wpsg_dp_templates_app .label-copy { display:flex; justify-content:space-between; }
186
    #wpsg_dp_templates_app .label-copy .glyphicon  { font-size:14px; }
7824 daniel 187
 
188
</style>
189
 
190
<script src="<?php echo WPSG_URL_CONTENT.'plugins/'.WPSG_FOLDERNAME.'/views/js/vue3.js'; ?>"></script>
191
<script>
192
 
193
	const Counter = {
194
        data() {
195
            return {
196
            	arFont: <?php echo json_encode($arFontVue); ?>,
197
                arTemplates: <?php echo json_encode($arTemplates); ?>,
198
	            template: null,
199
                uploadstate: {
200
	                run: false,
201
                    proz: null
202
                }
203
            }
204
        },
205
		methods: {
206
 
207
        	addTemplate: function() {
208
 
209
        		let new_template = {
210
			        id: 0,
211
					name: '<?php echo __('Template', 'wpsg'); ?>' + (this.arTemplates.length + 1),
212
			        arField: [
213
				        {
214
				        	id: 0, x: 0, y:0, align:false, bg:false, color:'000000', alpha:1, angle:0, fontsize:22, aktiv:true,
215
                            text: '', font: '', defaulttemplate: false, file: null, file_data: null
216
				        }
217
			        ],
218
                    file: null,
219
                    file_delete: false,
220
                    file_data: false
221
		        };
222
 
223
        		this.arTemplates.push(new_template);
224
        		this.template = new_template;
225
 
226
	        },
227
 
7841 daniel 228
            copyTemplate: function() {
229
 
230
        		if (!confirm('<?php echo __('Sind Sie sich sicher, dass sie das Template kopieren möchten?', 'wpsg'); ?>')) return false;
231
 
232
                let new_template = JSON.parse(JSON.stringify(this.template));
233
 
234
                new_template.name += ' (Kopie)';
235
 
236
                this.arTemplates.push(new_template);
237
                this.template = new_template;
238
 
239
            },
240
 
7824 daniel 241
            removeTemplate: function() {
242
 
243
        		if (!confirm('<?php echo __('Sind Sie sich sicher? Das ganze Template und alle Felder werden gelöscht.', 'wpsg'); ?>')) return;
244
 
245
        		for (let i = 0; i < this.arTemplates.length; i ++) {
246
 
247
        			if (this.arTemplates[i] === this.template) {
248
 
249
        				this.arTemplates.splice(i, 1);
250
 
251
                    }
252
 
253
                }
254
 
255
        		if (this.arTemplates.length > 0) this.template = this.arTemplates[0];
256
        		else this.template = null;
257
 
258
            },
259
 
260
	        addField: function(field_index) {
261
 
262
        		if (field_index === undefined) field_index = this.template.arField.length;
263
 
264
        		this.template.arField.splice(field_index, 0,  {
265
                    id: 0, x: 0, y:0, align:false, bg:false, color:'000000', alpha:1, angle:0, fontsize:22, aktiv:true,
266
                    text: '', font: ''
267
                })
268
 
269
            },
270
 
271
            removeField: function(field_index) {
272
 
273
        		if (!confirm('<?php echo __('Sind Sie sich sicher, dass sie das Feld löschen möchten?', 'wpsg'); ?>')) return;
274
 
275
        		this.template.arField.splice(field_index, 1);
276
 
277
            },
278
 
279
            setDefaultTemplate: function() {
280
 
281
        		for (let i = 0; i < this.arTemplates.length; i ++) {
282
 
283
        			this.arTemplates[i].defaulttemplate = false;
284
 
285
                }
286
 
287
        		this.template.defaulttemplate = true;
288
 
289
            },
290
 
291
            removeFile: function() {
292
 
293
        		if (!confirm('<?php echo __('Sind Sie sich sicher?', 'wpsg'); ?>')) return;
294
 
295
        		this.template.file_data = null;
296
        		this.template.file = null;
297
        		this.template.file_delete = true;
298
 
299
            },
300
 
301
            upload: function(e) {
302
 
303
        		const files = e.target.files || e.dataTransfer.files;
304
                if (!files.length) return;
305
 
306
                if (files[0].type !== 'application/pdf') {
307
 
308
                	alert('<?php echo __('Ungültier Dateityp', 'wpsg'); ?>');
309
                	return;
310
 
311
                }
312
 
313
                this.uploadstate.run = true;
314
                this.uploadstate.proz = null;
315
 
316
                const reader = new FileReader();
317
 
318
				reader.addEventListener("load", () => {
319
 
320
					this.template.file = files[0].name
321
                    this.template.file_data = reader.result;
322
					this.template.file_delete = false;
323
 
324
					this.uploadstate.run = false;
325
 
326
					e.target.value = '';
327
 
328
				}, false);
329
 
330
				reader.addEventListener('progress', (event) => {
331
 
332
                    if (event.lengthComputable) this.uploadstate.proz = Math.round((event.loaded / event.total) * 100);
333
 
334
                });
335
 
336
				reader.readAsDataURL(files[0]);
337
 
338
            }
339
 
340
		},
341
        mounted() {
342
 
343
        	for (let i = 0; i < this.arTemplates.length; i ++) {
344
 
345
        		if (this.arTemplates[i].defaulttemplate === true) this.template = this.arTemplates[i];
346
 
347
            }
348
 
349
        },
350
        watch: {
351
        	'template.file': function(newValue, oldValue) {
352
 
353
        		console.log(newValue);
354
 
355
	        }
356
        }
357
	}
358
 
359
	Vue.createApp(Counter).mount('#wpsg_dp_templates_app');
360
 
361
</script>