Subversion Repositories wpShopGermany4

Rev

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