Passed
Pull Request — master (#284)
by Brian
06:18
created

WPInv_Payment_Form_Elements::edit_items_template()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 81
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 26
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 81
rs 9.504

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
if ( ! defined( 'ABSPATH' ) ) {
4
    exit; // Exit if accessed directly
5
}
6
7
class WPInv_Payment_Form_Elements {
8
9
    /**
10
     * @param array payment form elements
11
     */
12
    protected $elements;
13
14
    public function __construct() {
15
16
        foreach( $this->get_elements() as $element ) {
17
            $element = $element['type'];
18
19
            if ( method_exists( $this, "render_{$element}_template" ) ) {
20
                add_action( 'wpinv_payment_form_render_element_template', array( $this, "render_{$element}_template" ), 10, 2 );
21
            }
22
23
            if ( method_exists( $this, "edit_{$element}_template" ) ) {
24
                add_action( 'wpinv_payment_form_edit_element_template', array( $this, "edit_{$element}_template" ), 10, 2 );
25
            }
26
27
            if ( method_exists( $this, "frontend_render_{$element}_template" ) ) {
28
                add_action( "wpinv_frontend_render_payment_form_$element", array( $this, "frontend_render_{$element}_template" ), 10, 3 );
29
            }
30
31
        }
32
        
33
    }
34
35
    /**
36
     * Returns all the elements that can be added to a form.
37
     */
38
    public function get_elements() {
39
40
        if ( ! empty( $this->elements ) ) {
41
            return $this->elements;
42
        }
43
44
        $this->elements = array(
45
46
            array(
47
                'type'     => 'heading',
48
                'name'     => __( 'Heading', 'invoicing' ),
49
                'defaults' => array(
50
                    'level' => 'h2',
51
                    'text'  => __( 'Heading', 'invoicing' ),
52
                )
53
            ),
54
55
            array(
56
                'type' => 'paragraph',
57
                'name' => __( 'Paragraph', 'invoicing' ),
58
                'defaults'  => array(
59
                    'text'  => __( 'Paragraph text', 'invoicing' ),
60
                )
61
            ),
62
63
            array( 
64
                'type' => 'alert',
65
                'name' => __( 'Alert', 'invoicing' ),
66
                'defaults'  => array(
67
                    'value'        => '',
68
                    'class'        => 'alert-warning',
69
                    'text'         => __( 'Alert', 'invoicing' ),
70
                    'dismissible'  => false,
71
                )
72
            ),
73
74
            /*array( 
75
                'type' => 'separator',
76
                'name' => __( 'Separator', 'invoicing' ),
77
                'defaults'  => array(
78
                    'value'        => '',
79
                    'dismissible'  => false,
80
                )
81
            ),*/
82
83
            array(
84
                'type' => 'text',
85
                'name' => __( 'Text Input', 'invoicing' ),
86
                'defaults'  => array(
87
                    'placeholder'  => __( 'Enter some text', 'invoicing' ),
88
                    'value'        => '',
89
                    'label'        => __( 'Field Label', 'invoicing' ),
90
                    'description'  => '',
91
                    'required'     => false,
92
                )
93
            ),
94
95
            array(
96
                'type' => 'textarea',
97
                'name' => __( 'Textarea', 'invoicing' ),
98
                'defaults'         => array(
99
                    'placeholder'  => __( 'Enter your text hear', 'invoicing' ),
100
                    'value'        => '',
101
                    'label'        => __( 'Textarea Label', 'invoicing' ),
102
                    'description'  => '',
103
                    'required'     => false,
104
                )
105
            ),
106
107
            array(
108
                'type' => 'select',
109
                'name' => __( 'Dropdown', 'invoicing' ),
110
                'defaults'         => array(
111
                    'placeholder'  => __( 'Select a value', 'invoicing' ),
112
                    'value'        => '',
113
                    'label'        => __( 'Dropdown Label', 'invoicing' ),
114
                    'description'  => '',
115
                    'required'     => false,
116
                    'options'      => array(
117
                        esc_attr__( 'Option One', 'invoicing' ),
118
                        esc_attr__( 'Option Two', 'invoicing' ),
119
                        esc_attr__( 'Option Three', 'invoicing' )
120
                    ),
121
                )
122
            ),
123
124
            array(
125
                'type' => 'checkbox',
126
                'name' => __( 'Checkbox', 'invoicing' ),
127
                'defaults'         => array(
128
                    'value'        => '',
129
                    'label'        => __( 'Checkbox Label', 'invoicing' ),
130
                    'description'  => '',
131
                    'required'     => false,
132
                )
133
            ),
134
135
            array( 
136
                'type' => 'radio',
137
                'name' => __( 'Multiple Choice', 'invoicing' ),
138
                'defaults'     => array(
139
                    'label'    => __( 'Select one choice', 'invoicing' ),
140
                    'options'  => array(
141
                        esc_attr__( 'Choice One', 'invoicing' ),
142
                        esc_attr__( 'Choice Two', 'invoicing' ),
143
                        esc_attr__( 'Choice Three', 'invoicing' )
144
                    ),
145
                )
146
            ),
147
148
            array( 
149
                'type' => 'date',
150
                'name' => __( 'Date', 'invoicing' ),
151
                'defaults' => array(
152
                    'placeholder'  => '',
153
                    'value'        => '',
154
                    'label'        => __( 'Date', 'invoicing' ),
155
                    'description'  => '',
156
                    'required'     => false,
157
                )
158
            ),
159
160
            array( 
161
                'type' => 'time',
162
                'name' => __( 'Time', 'invoicing' ),
163
                'defaults' => array(
164
                    'placeholder'  => '',
165
                    'value'        => '',
166
                    'label'        => __( 'Time', 'invoicing' ),
167
                    'description'  => '',
168
                    'required'     => false,
169
                )
170
            ),
171
172
            array( 
173
                'type' => 'number',
174
                'name' => __( 'Number', 'invoicing' ),
175
                'defaults' => array(
176
                    'placeholder'  => '',
177
                    'value'        => '',
178
                    'label'        => __( 'Number', 'invoicing' ),
179
                    'description'  => '',
180
                    'required'     => false,
181
                )
182
            ),
183
184
            array( 
185
                'type' => 'website',
186
                'name' => __( 'Website', 'invoicing' ),
187
                'defaults' => array(
188
                    'placeholder'  => 'http://example.com',
189
                    'value'        => '',
190
                    'label'        => __( 'Website', 'invoicing' ),
191
                    'description'  => '',
192
                    'required'     => false,
193
                )
194
            ),
195
196
            array( 
197
                'type' => 'email',
198
                'name' => __( 'Email', 'invoicing' ),
199
                'defaults'  => array(
200
                    'placeholder'  => '[email protected]',
201
                    'value'        => '',
202
                    'label'        => __( 'Email Address', 'invoicing' ),
203
                    'description'  => '',
204
                    'required'     => false,
205
                )
206
            ),
207
208
            array( 
209
                'type' => 'billing_email',
210
                'name' => __( 'Billing Email', 'invoicing' ),
211
                'defaults'  => array(
212
                    'placeholder'  => '[email protected]',
213
                    'value'        => '',
214
                    'label'        => __( 'Billing Email', 'invoicing' ),
215
                    'description'  => '',
216
                    'premade'      => true,
217
                )
218
            ),
219
220
            array( 
221
                'type' => 'discount',
222
                'name' => __( 'Discount Input', 'invoicing' ),
223
                'defaults'  => array(
224
                    'value'        => '',
225
                    'input_label'  => __( 'Coupon Code', 'invoicing' ),
226
                    'button_label' => __( 'Apply Coupon', 'invoicing' ),
227
                    'description'  => __( 'Have a discount code? Enter it above.', 'invoicing' ),
228
                )
229
            ),
230
231
            array( 
232
                'type' => 'items',
233
                'name' => __( 'Items', 'invoicing' ),
234
                'defaults'  => array(
235
                    'value'        => '',
236
                    'items_type'   => 'total',
237
                    'description'  => '',
238
                    'premade'      => true,
239
                )
240
            ),
241
242
            array( 
243
                'type'       => 'pay_button',
244
                'name'       => __( 'Payment Button', 'invoicing' ),
245
                'defaults'   => array(
246
                    'value'        => '',
247
                    'class'        => 'btn-primary',
248
                    'label'        => __( 'Pay Now »', 'invoicing' ),
249
                    'description'  => __( 'By continuing with our payment, you are agreeing to our privacy policy and terms of service.', 'invoicing' ),
250
                    'premade'      => true,
251
                )
252
            )
253
        );
254
255
        $this->elements = apply_filters( 'wpinv_filter_core_payment_form_elements', $this->elements );
256
        return $this->elements;
257
    }
258
259
    /**
260
     * Returns the restrict markup.
261
     */
262
    public function get_restrict_markup( $field, $field_type ) {
263
        $restrict = "$field.type=='$field_type'";
264
        return "v-if=\"$restrict\"";
265
    }
266
267
    /**
268
     * Renders the title element template.
269
     */
270
    public function render_heading_template( $field ) {
271
        $restrict = $this->get_restrict_markup( $field, 'heading' );
272
        echo "<component :is='$field.level' $restrict v-html='$field.text'></component>";
273
    }
274
275
    /**
276
     * Renders the title element on the frontend.
277
     */
278
    public function frontend_render_heading_template( $field ) {
279
        $tag = $field['level'];
280
        echo "<$tag>{$field['text']}</$tag>";
281
    }
282
283
    /**
284
     * Renders the edit title element template.
285
     */
286
    public function edit_heading_template( $field ) {
287
        $restrict = $this->get_restrict_markup( $field, 'heading' );
288
        $label    = __( 'Heading', 'invoicing' );
289
        $label2   = __( 'Select Heading Level', 'invoicing' );
290
        $id       = $field . '.id + "_edit"';
291
        $id2      = $field . '.id + "_edit2"';
292
293
        echo "
294
            <div $restrict>
295
                <div class='form-group'>
296
                    <label :for='$id'>$label</label>
297
                    <input class='form-control' :id='$id' v-model='$field.text' type='text' />
298
                </div>
299
300
                <div class='form-group'>
301
                    <label :for='$id2'>$label2</label>
302
303
                    <select class='form-control custom-select' :id='$id2' v-model='$field.level'>
304
                        <option value='h1'>H1</option>
305
                        <option value='h2'>H2</option>
306
                        <option value='h3'>H3</option>
307
                        <option value='h4'>H4</option>
308
                        <option value='h5'>H5</option>
309
                        <option value='h6'>H6</option>
310
                        <option value='h7'>H7</option>
311
                    </select>
312
                </div>
313
            </div>
314
        ";
315
316
    }
317
318
    /**
319
     * Renders a paragraph element template.
320
     */
321
    public function render_paragraph_template( $field ) {
322
        $restrict = $this->get_restrict_markup( $field, 'paragraph' );
323
        $label    = "$field.text";
324
        echo "<p $restrict v-html='$label' style='font-size: 16px;'></p>";
325
    }
326
327
    /**
328
     * Renders the paragraph element on the frontend.
329
     */
330
    public function frontend_render_paragraph_template( $field ) {
331
        echo "<p>{$field['text']}</p>";
332
    }
333
334
    /**
335
     * Renders the edit paragraph element template.
336
     */
337
    public function edit_paragraph_template( $field ) {
338
        $restrict = $this->get_restrict_markup( $field, 'paragraph' );
339
        $label    = __( 'Enter your text', 'invoicing' );
340
        $id       = $field . '.id + "_edit"';
341
        echo "
342
            <div $restrict>
343
                <div class='form-group'>
344
                    <label :for='$id'>$label</label>
345
                    <textarea :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea>
346
                </div>
347
            </div>
348
        ";
349
350
    }
351
352
    /**
353
     * Renders the text element template.
354
     */
355
    public function render_text_template( $field ) {
356
        $restrict = $this->get_restrict_markup( $field, 'text' );
357
        $label    = "$field.label";
358
        echo "
359
            <div $restrict>
360
                <label :for='$field.id'>{{" . $label . "}}</label>
361
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='text'>
362
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
363
            </div>    
364
        ";
365
    }
366
367
    /**
368
     * Renders the text element on the frontend.
369
     */
370
    public function frontend_render_text_template( $field ) {
371
        
372
        echo "<div class='form-group'>";
373
374
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

374
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
375
            array(
376
                'name'       => esc_attr( $field['id'] ),
377
                'id'         => esc_attr( $field['id'] ),
378
                'placeholder'=> esc_attr( $field['placeholder'] ),
379
                'required'   => (bool) $field['required'],
380
                'label'      => wp_kses_post( $field['label'] ),
381
                'no_wrap'    => true,
382
            )
383
        );
384
385
        if ( ! empty( $field['description'] ) ) {
386
            $description = wp_kses_post( $field['description'] );
387
            echo "<small class='form-text text-muted'>$description</small>";
388
        }
389
390
        echo '</div>';
391
392
    }
393
394
    /**
395
     * Renders the edit text element template.
396
     */
397
    public function edit_text_template( $field ) {
398
        $restrict = $this->get_restrict_markup( $field, 'text' );
399
        $label    = __( 'Field Label', 'invoicing' );
400
        $id       = $field . '.id + "_edit"';
401
        $label2   = __( 'Placeholder text', 'invoicing' );
402
        $id2      = $field . '.id + "_edit2"';
403
        $label3   = __( 'Help text', 'invoicing' );
404
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
405
        $id3      = $field . '.id + "_edit3"';
406
        $label5   = __( 'Is this field required?', 'invoicing' );
407
        $id4      = $field . '.id + "_edit4"';
408
        echo "
409
            <div $restrict>
410
                <div class='form-group'>
411
                    <label :for='$id'>$label</label>
412
                    <input :id='$id' v-model='$field.label' class='form-control' />
413
                </div>
414
                <div class='form-group'>
415
                    <label :for='$id2'>$label2</label>
416
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
417
                </div>
418
                <div class='form-group'>
419
                    <label :for='$id3'>$label3</label>
420
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
421
                </div>
422
                <div class='form-group form-check'>
423
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
424
                    <label class='form-check-label' :for='$id4'>$label5</label>
425
                </div>
426
            </div>
427
        ";
428
429
    }
430
431
    /**
432
     * Renders the textarea element template.
433
     */
434
    public function render_textarea_template( $field ) {
435
        $restrict = $this->get_restrict_markup( $field, 'textarea' );
436
        $label    = "$field.label";
437
        echo "
438
            <div $restrict>
439
                <label :for='$field.id'>{{" . $label . "}}</label>
440
                <textarea  :placeholder='$field.placeholder' :id='$field.id' class='form-control' rows='3'></textarea>
441
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
442
            </div>    
443
        ";
444
    }
445
446
    /**
447
     * Renders the textarea element on the frontend.
448
     */
449
    public function frontend_render_textarea_template( $field ) {
450
        
451
        echo "<div class='form-group'>";
452
453
        echo aui()->textarea(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

453
        echo /** @scrutinizer ignore-call */ aui()->textarea(
Loading history...
454
            array(
455
                'name'       => esc_attr( $field['id'] ),
456
                'id'         => esc_attr( $field['id'] ),
457
                'placeholder'=> esc_attr( $field['placeholder'] ),
458
                'required'   => (bool) $field['required'],
459
                'label'      => wp_kses_post( $field['label'] ),
460
                'no_wrap'    => true,
461
                'rows'       => 3,
462
            )
463
        );
464
465
        if ( ! empty( $field['description'] ) ) {
466
            $description = wp_kses_post( $field['description'] );
467
            echo "<small class='form-text text-muted'>$description</small>";
468
        }
469
470
        echo '</div>';
471
472
    }
473
474
    /**
475
     * Renders the edit textarea element template.
476
     */
477
    public function edit_textarea_template( $field ) {
478
        $restrict = $this->get_restrict_markup( $field, 'textarea' );
479
        $label    = __( 'Field Label', 'invoicing' );
480
        $id       = $field . '.id + "_edit"';
481
        $label2   = __( 'Placeholder text', 'invoicing' );
482
        $id2      = $field . '.id + "_edit2"';
483
        $label3   = __( 'Help text', 'invoicing' );
484
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
485
        $id3      = $field . '.id + "_edit3"';
486
        $label5   = __( 'Is this field required?', 'invoicing' );
487
        $id4      = $field . '.id + "_edit4"';
488
        echo "
489
            <div $restrict>
490
                <div class='form-group'>
491
                    <label :for='$id'>$label</label>
492
                    <input :id='$id' v-model='$field.label' class='form-control' />
493
                </div>
494
                <div class='form-group'>
495
                    <label :for='$id2'>$label2</label>
496
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
497
                </div>
498
                <div class='form-group'>
499
                    <label :for='$id3'>$label3</label>
500
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
501
                </div>
502
                <div class='form-group form-check'>
503
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
504
                    <label class='form-check-label' :for='$id4'>$label5</label>
505
                </div>
506
            </div>
507
        ";
508
509
    }
510
511
    /**
512
     * Renders the select element template.
513
     */
514
    public function render_select_template( $field ) {
515
        $restrict    = $this->get_restrict_markup( $field, 'select' );
516
        $label       = "$field.label";
517
        $placeholder = "$field.placeholder";
518
        $id          = $field . '.id';
519
        echo "
520
            <div $restrict>
521
                <label :for='$id'>{{" . $label . "}}</label>
522
                <select id='$id' class='form-control custom-select'  v-model='$field.value'>
523
                    <option v-if='$placeholder' value='' disabled>{{" . $placeholder . "}}</option>
524
                    <option v-for='option in $field.options' value='option'>{{option}}</option>
525
                </select>
526
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
527
            </div>
528
        ";
529
    }
530
531
    /**
532
     * Renders the select element on the frontend.
533
     */
534
    public function frontend_render_select_template( $field ) {
535
        
536
        echo "<div class='form-group'>";
537
538
        echo aui()->select(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

538
        echo /** @scrutinizer ignore-call */ aui()->select(
Loading history...
539
            array(
540
                'name'       => esc_attr( $field['id'] ),
541
                'id'         => esc_attr( $field['id'] ),
542
                'placeholder'=> esc_attr( $field['placeholder'] ),
543
                'required'   => (bool) $field['required'],
544
                'label'      => wp_kses_post( $field['label'] ),
545
                'no_wrap'    => true,
546
                'options'    => $field['options'],
547
            )
548
        );
549
550
        if ( ! empty( $field['description'] ) ) {
551
            $description = wp_kses_post( $field['description'] );
552
            echo "<small class='form-text text-muted'>$description</small>";
553
        }
554
555
        echo '</div>';
556
557
    }
558
559
    /**
560
     * Renders the edit select element template.
561
     */
562
    public function edit_select_template( $field ) {
563
        $restrict = $this->get_restrict_markup( $field, 'select' );
564
        $label    = __( 'Field Label', 'invoicing' );
565
        $id       = $field . '.id + "_edit"';
566
        $label2   = __( 'Placeholder text', 'invoicing' );
567
        $id2      = $field . '.id + "_edit2"';
568
        $label3   = __( 'Help text', 'invoicing' );
569
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
570
        $id3      = $field . '.id + "_edit3"';
571
        $label5   = __( 'Is this field required?', 'invoicing' );
572
        $id4      = $field . '.id + "_edit4"';
573
        $label6   = __( 'Available Options', 'invoicing' );
574
        echo "
575
            <div $restrict>
576
                <div class='form-group'>
577
                    <label :for='$id'>$label</label>
578
                    <input :id='$id' v-model='$field.label' class='form-control' />
579
                </div>
580
                <div class='form-group'>
581
                    <label :for='$id2'>$label2</label>
582
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
583
                </div>
584
                <div class='form-group'>
585
                    <label :for='$id3'>$label3</label>
586
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
587
                </div>
588
                <div class='form-group form-check'>
589
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
590
                    <label class='form-check-label' :for='$id4'>$label5</label>
591
                </div>
592
                <hr class='featurette-divider mt-4'>
593
                <h5>$label6</h5>
594
                <div class='form-group input-group' v-for='(option, index) in $field.options'>
595
                    <input type='text' class='form-control' v-model='$field.options[index]'>
596
                    <div class='input-group-append'>
597
                        <button class='btn btn-outline-secondary' type='button' @click.prevent='$field.options.splice(index, 1)'><span class='dashicons dashicons-trash'></span></button>
598
                    </div>
599
                </div>
600
                <div class='form-group'>
601
                    <button class='btn btn-outline-secondary' type='button' @click.prevent='$field.options.push(\"\")'>Add Option</button>
602
                </div>
603
            </div>
604
        ";
605
606
    }
607
608
    /**
609
     * Renders the checkbox element template.
610
     */
611
    public function render_checkbox_template( $field ) {
612
        $restrict = $this->get_restrict_markup( $field, 'checkbox' );
613
        $label    = "$field.label";
614
        echo "
615
            <div class='form-check' $restrict>
616
                <input  :id='$field.id' class='form-check-input' type='checkbox' />
617
                <label class='form-check-label' :for='$field.id'>{{" . $label . "}}</label>
618
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
619
            </div>    
620
        ";
621
    }
622
623
    /**
624
     * Renders the checkbox element on the frontend.
625
     */
626
    public function frontend_render_checkbox_template( $field ) {
627
        
628
        echo "<div class='form-group'>";
629
630
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

630
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
631
            array(
632
                'name'       => esc_attr( $field['id'] ),
633
                'id'         => esc_attr( $field['id'] ),
634
                'required'   => (bool) $field['required'],
635
                'label'      => wp_kses_post( $field['label'] ),
636
                'no_wrap'    => true,
637
                'type'       => 'checkbox',
638
            )
639
        );
640
641
        if ( ! empty( $field['description'] ) ) {
642
            $description = wp_kses_post( $field['description'] );
643
            echo "<small class='form-text text-muted'>$description</small>";
644
        }
645
646
        echo '</div>';
647
648
    }
649
650
    /**
651
     * Renders the edit checkbox element template.
652
     */
653
    public function edit_checkbox_template( $field ) {
654
        $restrict = $this->get_restrict_markup( $field, 'checkbox' );
655
        $label    = __( 'Field Label', 'invoicing' );
656
        $id       = $field . '.id + "_edit"';
657
        $label2   = __( 'Help text', 'invoicing' );
658
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
659
        $id2      = $field . '.id + "_edit2"';
660
        $label4   = __( 'Is this field required?', 'invoicing' );
661
        $id3      = $field . '.id + "_edit3"';
662
        echo "
663
            <div $restrict>
664
                <div class='form-group'>
665
                    <label :for='$id'>$label</label>
666
                    <input :id='$id' v-model='$field.label' class='form-control' />
667
                </div>
668
                <div class='form-group'>
669
                    <label :for='$id2'>$label2</label>
670
                    <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea>
671
                </div>
672
                <div class='form-group form-check'>
673
                    <input :id='$id3' v-model='$field.required' type='checkbox' class='form-check-input' />
674
                    <label class='form-check-label' :for='$id3'>$label4</label>
675
                </div>
676
            </div>
677
        ";
678
679
    }
680
681
    /**
682
     * Renders the radio element template.
683
     */
684
    public function render_radio_template( $field ) {
685
        $restrict    = $this->get_restrict_markup( $field, 'radio' );
686
        $label       = "$field.label";
687
        $id          = $field . '.id';
688
        echo "
689
            <div $restrict>
690
                <legend class='col-form-label' v-if='$label'>{{" . $label . "}}</legend>
691
                <div class='form-check' v-for='(option, index) in $field.options'>
692
                    <input class='form-check-input' type='radio' :id='$id + index'>
693
                    <label class='form-check-label' :for='$id + index'>{{option}}</label>
694
                </div>
695
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
696
            </div>
697
        ";
698
    }
699
700
    /**
701
     * Renders the radio element on the frontend.
702
     */
703
    public function frontend_render_radio_template( $field ) {
704
        
705
        echo "<div class='form-group'>";
706
707
        if ( ! empty( $field['label'] ) ) {
708
            $label = wp_kses_post( $field['label'] );
709
            echo "<legend class='col-form-label'>$label</legend>";
710
        }
711
712
        foreach( $field['options'] as $index => $option ) {
713
            $id    = $field['id'] . $index;
714
            $value = esc_attr( $option );
715
            $label = wp_kses_post( $option );
716
717
            echo "
718
                <div class='form-check'>
719
                    <input class='form-check-input' type='radio' id='$id' value='$value'>
720
                    <label class='form-check-label' for='$id'>$label</label>
721
                </div>
722
            ";
723
        }
724
725
        if ( ! empty( $field['description'] ) ) {
726
            $description = wp_kses_post( $field['description'] );
727
            echo "<small class='form-text text-muted'>$description</small>";
728
        }
729
730
        echo '</div>';
731
732
    }
733
734
    /**
735
     * Renders the edit radio element template.
736
     */
737
    public function edit_radio_template( $field ) {
738
        $restrict = $this->get_restrict_markup( $field, 'radio' );
739
        $label    = __( 'Field Label', 'invoicing' );
740
        $id       = $field . '.id + "_edit"';
741
        $label2   = __( 'Help text', 'invoicing' );
742
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
743
        $id2      = $field . '.id + "_edit3"';
744
        $label4   = __( 'Is this field required?', 'invoicing' );
745
        $id3      = $field . '.id + "_edit4"';
746
        $label5   = __( 'Available Options', 'invoicing' );
747
        echo "
748
            <div $restrict>
749
                <div class='form-group'>
750
                    <label :for='$id'>$label</label>
751
                    <input :id='$id' v-model='$field.label' class='form-control' />
752
                </div>
753
                <div class='form-group'>
754
                    <label :for='$id2'>$label2</label>
755
                    <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea>
756
                </div>
757
                <div class='form-group form-check'>
758
                    <input :id='$id3' v-model='$field.required' type='checkbox' class='form-check-input' />
759
                    <label class='form-check-label' :for='$id3'>$label4</label>
760
                </div>
761
                <hr class='featurette-divider mt-4'>
762
                <h5>$label5</h5>
763
                <div class='form-group input-group' v-for='(option, index) in $field.options'>
764
                    <input type='text' class='form-control' v-model='$field.options[index]'>
765
                    <div class='input-group-append'>
766
                        <button class='btn btn-outline-secondary' type='button' @click.prevent='$field.options.splice(index, 1)'><span class='dashicons dashicons-trash'></span></button>
767
                    </div>
768
                </div>
769
                <div class='form-group'>
770
                    <button class='btn btn-outline-secondary' type='button' @click.prevent='$field.options.push(\"\")'>Add Option</button>
771
                </div>
772
            </div>
773
        ";
774
775
    }
776
777
    /**
778
     * Renders the email element template.
779
     */
780
    public function render_email_template( $field ) {
781
        $restrict = $this->get_restrict_markup( $field, 'email' );
782
        $label    = "$field.label";
783
        echo "
784
            <div $restrict>
785
                <label :for='$field.id'>{{" . $label . "}}</label>
786
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='email'>
787
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
788
            </div>    
789
        ";
790
    }
791
792
    /**
793
     * Renders the billing_email element template.
794
     */
795
    public function render_billing_email_template( $field ) {
796
        $restrict = $this->get_restrict_markup( $field, 'billing_email' );
797
        $label    = "$field.label";
798
        echo "
799
            <div $restrict>
800
                <label :for='$field.id'>{{" . $label . "}}</label>
801
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='email'>
802
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
803
            </div>    
804
        ";
805
    }
806
807
    /**
808
     * Renders the email element on the frontend.
809
     */
810
    public function frontend_render_email_template( $field ) {
811
        
812
        echo "<div class='form-group'>";
813
814
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

814
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
815
            array(
816
                'name'       => esc_attr( $field['id'] ),
817
                'id'         => esc_attr( $field['id'] ),
818
                'required'   => (bool) $field['required'],
819
                'label'      => wp_kses_post( $field['label'] ),
820
                'no_wrap'    => true,
821
                'placeholder' => esc_attr( $field['placeholder'] ),
822
                'type'       => 'email',
823
            )
824
        );
825
826
        if ( ! empty( $field['description'] ) ) {
827
            $description = wp_kses_post( $field['description'] );
828
            echo "<small class='form-text text-muted'>$description</small>";
829
        }
830
831
        echo '</div>';
832
833
    }
834
835
    /**
836
     * Renders the billing email element on the frontend.
837
     */
838
    public function frontend_render_billing_email_template( $field ) {
839
        
840
        echo "<div class='form-group'>";
841
842
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

842
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
843
            array(
844
                'name'       => 'billing_email',
845
                'id'         => esc_attr( $field['id'] ),
846
                'required'   => true,
847
                'label'      => wp_kses_post( $field['label'] ),
848
                'no_wrap'    => true,
849
                'placeholder' => esc_attr( $field['placeholder'] ),
850
                'type'       => 'email',
851
            )
852
        );
853
854
        if ( ! empty( $field['description'] ) ) {
855
            $description = wp_kses_post( $field['description'] );
856
            echo "<small class='form-text text-muted'>$description</small>";
857
        }
858
859
        echo '</div>';
860
861
    }
862
863
    /**
864
     * Renders the edit email element template.
865
     */
866
    public function edit_email_template( $field ) {
867
        $restrict = $this->get_restrict_markup( $field, 'email' );
868
        $label    = __( 'Field Label', 'invoicing' );
869
        $id       = $field . '.id + "_edit"';
870
        $label2   = __( 'Placeholder text', 'invoicing' );
871
        $id2      = $field . '.id + "_edit2"';
872
        $label3   = __( 'Help text', 'invoicing' );
873
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
874
        $id3      = $field . '.id + "_edit3"';
875
        $label5   = __( 'Is this field required?', 'invoicing' );
876
        $id4      = $field . '.id + "_edit4"';
877
        echo "
878
            <div $restrict>
879
                <div class='form-group'>
880
                    <label :for='$id'>$label</label>
881
                    <input :id='$id' v-model='$field.label' class='form-control' />
882
                </div>
883
                <div class='form-group'>
884
                    <label :for='$id2'>$label2</label>
885
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
886
                </div>
887
                <div class='form-group'>
888
                    <label :for='$id3'>$label3</label>
889
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
890
                </div>
891
                <div class='form-group form-check'>
892
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
893
                    <label class='form-check-label' :for='$id4'>$label5</label>
894
                </div>
895
            </div>
896
        ";
897
898
    }
899
900
    /**
901
     * Renders the edit billing_email element template.
902
     */
903
    public function edit_billing_email_template( $field ) {
904
        $restrict = $this->get_restrict_markup( $field, 'billing_email' );
905
        $label    = __( 'Field Label', 'invoicing' );
906
        $id       = $field . '.id + "_edit"';
907
        $label2   = __( 'Placeholder text', 'invoicing' );
908
        $id2      = $field . '.id + "_edit2"';
909
        $label3   = __( 'Help text', 'invoicing' );
910
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
911
        $id3      = $field . '.id + "_edit3"';
912
        $label5   = __( 'Is this field required?', 'invoicing' );
0 ignored issues
show
Unused Code introduced by
The assignment to $label5 is dead and can be removed.
Loading history...
913
        $id4      = $field . '.id + "_edit4"';
0 ignored issues
show
Unused Code introduced by
The assignment to $id4 is dead and can be removed.
Loading history...
914
        echo "
915
            <div $restrict>
916
                <div class='form-group'>
917
                    <label :for='$id'>$label</label>
918
                    <input :id='$id' v-model='$field.label' class='form-control' />
919
                </div>
920
                <div class='form-group'>
921
                    <label :for='$id2'>$label2</label>
922
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
923
                </div>
924
                <div class='form-group'>
925
                    <label :for='$id3'>$label3</label>
926
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
927
                </div>
928
            </div>
929
        ";
930
931
    }
932
933
    /**
934
     * Renders the website element template.
935
     */
936
    public function render_website_template( $field ) {
937
        $restrict = $this->get_restrict_markup( $field, 'website' );
938
        $label    = "$field.label";
939
        echo "
940
            <div $restrict>
941
                <label :for='$field.id'>{{" . $label . "}}</label>
942
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='url'>
943
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
944
            </div>    
945
        ";
946
    }
947
948
    /**
949
     * Renders the website element on the frontend.
950
     */
951
    public function frontend_render_website_template( $field ) {
952
        
953
        echo "<div class='form-group'>";
954
955
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

955
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
956
            array(
957
                'name'       => esc_attr( $field['id'] ),
958
                'id'         => esc_attr( $field['id'] ),
959
                'required'   => (bool) $field['required'],
960
                'label'      => wp_kses_post( $field['label'] ),
961
                'no_wrap'    => true,
962
                'placeholder' => esc_attr( $field['placeholder'] ),
963
                'type'       => 'url',
964
            )
965
        );
966
967
        if ( ! empty( $field['description'] ) ) {
968
            $description = wp_kses_post( $field['description'] );
969
            echo "<small class='form-text text-muted'>$description</small>";
970
        }
971
972
        echo '</div>';
973
974
    }
975
976
    /**
977
     * Renders the edit website element template.
978
     */
979
    public function edit_website_template( $field ) {
980
        $restrict = $this->get_restrict_markup( $field, 'website' );
981
        $label    = __( 'Field Label', 'invoicing' );
982
        $id       = $field . '.id + "_edit"';
983
        $label2   = __( 'Placeholder text', 'invoicing' );
984
        $id2      = $field . '.id + "_edit2"';
985
        $label3   = __( 'Help text', 'invoicing' );
986
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
987
        $id3      = $field . '.id + "_edit3"';
988
        $label5   = __( 'Is this field required?', 'invoicing' );
989
        $id4      = $field . '.id + "_edit4"';
990
        echo "
991
            <div $restrict>
992
                <div class='form-group'>
993
                    <label :for='$id'>$label</label>
994
                    <input :id='$id' v-model='$field.label' class='form-control' />
995
                </div>
996
                <div class='form-group'>
997
                    <label :for='$id2'>$label2</label>
998
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
999
                </div>
1000
                <div class='form-group'>
1001
                    <label :for='$id3'>$label3</label>
1002
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1003
                </div>
1004
                <div class='form-group form-check'>
1005
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1006
                    <label class='form-check-label' :for='$id4'>$label5</label>
1007
                </div>
1008
            </div>
1009
        ";
1010
1011
    }
1012
1013
    /**
1014
     * Renders the date element template.
1015
     */
1016
    public function render_date_template( $field ) {
1017
        $restrict = $this->get_restrict_markup( $field, 'date' );
1018
        $label    = "$field.label";
1019
        echo "
1020
            <div $restrict>
1021
                <label :for='$field.id'>{{" . $label . "}}</label>
1022
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='date'>
1023
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1024
            </div>    
1025
        ";
1026
    }
1027
1028
    /**
1029
     * Renders the date element on the frontend.
1030
     */
1031
    public function frontend_render_date_template( $field ) {
1032
        
1033
        echo "<div class='form-group'>";
1034
1035
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1035
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1036
            array(
1037
                'name'       => esc_attr( $field['id'] ),
1038
                'id'         => esc_attr( $field['id'] ),
1039
                'required'   => (bool) $field['required'],
1040
                'label'      => wp_kses_post( $field['label'] ),
1041
                'placeholder' => esc_attr( $field['placeholder'] ),
1042
                'no_wrap'    => true,
1043
                'type'       => 'date',
1044
            )
1045
        );
1046
1047
        if ( ! empty( $field['description'] ) ) {
1048
            $description = wp_kses_post( $field['description'] );
1049
            echo "<small class='form-text text-muted'>$description</small>";
1050
        }
1051
1052
        echo '</div>';
1053
1054
    }
1055
1056
    /**
1057
     * Renders the edit date element template.
1058
     */
1059
    public function edit_date_template( $field ) {
1060
        $restrict = $this->get_restrict_markup( $field, 'date' );
1061
        $label    = __( 'Field Label', 'invoicing' );
1062
        $id       = $field . '.id + "_edit"';
1063
        $label2   = __( 'Placeholder text', 'invoicing' );
1064
        $id2      = $field . '.id + "_edit2"';
1065
        $label3   = __( 'Help text', 'invoicing' );
1066
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1067
        $id3      = $field . '.id + "_edit3"';
1068
        $label5   = __( 'Is this field required?', 'invoicing' );
1069
        $id4      = $field . '.id + "_edit4"';
1070
        echo "
1071
            <div $restrict>
1072
                <div class='form-group'>
1073
                    <label :for='$id'>$label</label>
1074
                    <input :id='$id' v-model='$field.label' class='form-control' />
1075
                </div>
1076
                <div class='form-group'>
1077
                    <label :for='$id2'>$label2</label>
1078
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
1079
                </div>
1080
                <div class='form-group'>
1081
                    <label :for='$id3'>$label3</label>
1082
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1083
                </div>
1084
                <div class='form-group form-check'>
1085
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1086
                    <label class='form-check-label' :for='$id4'>$label5</label>
1087
                </div>
1088
            </div>
1089
        ";
1090
1091
    }
1092
1093
    /**
1094
     * Renders the time element template.
1095
     */
1096
    public function render_time_template( $field ) {
1097
        $restrict = $this->get_restrict_markup( $field, 'time' );
1098
        $label    = "$field.label";
1099
        echo "
1100
            <div $restrict>
1101
                <label :for='$field.id'>{{" . $label . "}}</label>
1102
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='time'>
1103
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1104
            </div>    
1105
        ";
1106
    }
1107
1108
    /**
1109
     * Renders the time element on the frontend.
1110
     */
1111
    public function frontend_render_time_template( $field ) {
1112
        
1113
        echo "<div class='form-group'>";
1114
1115
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1115
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1116
            array(
1117
                'name'       => esc_attr( $field['id'] ),
1118
                'id'         => esc_attr( $field['id'] ),
1119
                'required'   => (bool) $field['required'],
1120
                'label'      => wp_kses_post( $field['label'] ),
1121
                'no_wrap'    => true,
1122
                'placeholder' => esc_attr( $field['placeholder'] ),
1123
                'type'       => 'time',
1124
            )
1125
        );
1126
1127
        if ( ! empty( $field['description'] ) ) {
1128
            $description = wp_kses_post( $field['description'] );
1129
            echo "<small class='form-text text-muted'>$description</small>";
1130
        }
1131
1132
        echo '</div>';
1133
1134
    }
1135
1136
    /**
1137
     * Renders the edit time element template.
1138
     */
1139
    public function edit_time_template( $field ) {
1140
        $restrict = $this->get_restrict_markup( $field, 'time' );
1141
        $label    = __( 'Field Label', 'invoicing' );
1142
        $id       = $field . '.id + "_edit"';
1143
        $label2   = __( 'Placeholder text', 'invoicing' );
1144
        $id2      = $field . '.id + "_edit2"';
1145
        $label3   = __( 'Help text', 'invoicing' );
1146
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1147
        $id3      = $field . '.id + "_edit3"';
1148
        $label5   = __( 'Is this field required?', 'invoicing' );
1149
        $id4      = $field . '.id + "_edit4"';
1150
        echo "
1151
            <div $restrict>
1152
                <div class='form-group'>
1153
                    <label :for='$id'>$label</label>
1154
                    <input :id='$id' v-model='$field.label' class='form-control' />
1155
                </div>
1156
                <div class='form-group'>
1157
                    <label :for='$id2'>$label2</label>
1158
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
1159
                </div>
1160
                <div class='form-group'>
1161
                    <label :for='$id3'>$label3</label>
1162
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1163
                </div>
1164
                <div class='form-group form-check'>
1165
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1166
                    <label class='form-check-label' :for='$id4'>$label5</label>
1167
                </div>
1168
            </div>
1169
        ";
1170
1171
    }
1172
1173
    /**
1174
     * Renders the number element template.
1175
     */
1176
    public function render_number_template( $field ) {
1177
        $restrict = $this->get_restrict_markup( $field, 'number' );
1178
        $label    = "$field.label";
1179
        echo "
1180
            <div $restrict>
1181
                <label :for='$field.id'>{{" . $label . "}}</label>
1182
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='number'>
1183
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1184
            </div>    
1185
        ";
1186
    }
1187
1188
    /**
1189
     * Renders the number element on the frontend.
1190
     */
1191
    public function frontend_render_number_template( $field ) {
1192
        
1193
        echo "<div class='form-group'>";
1194
1195
        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1195
        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1196
            array(
1197
                'name'       => esc_attr( $field['id'] ),
1198
                'id'         => esc_attr( $field['id'] ),
1199
                'required'   => (bool) $field['required'],
1200
                'label'      => wp_kses_post( $field['label'] ),
1201
                'placeholder' => esc_attr( $field['placeholder'] ),
1202
                'no_wrap'    => true,
1203
                'type'       => 'number',
1204
            )
1205
        );
1206
1207
        if ( ! empty( $field['description'] ) ) {
1208
            $description = wp_kses_post( $field['description'] );
1209
            echo "<small class='form-text text-muted'>$description</small>";
1210
        }
1211
1212
        echo '</div>';
1213
1214
    }
1215
1216
    /**
1217
     * Renders the edit number element template.
1218
     */
1219
    public function edit_number_template( $field ) {
1220
        $restrict = $this->get_restrict_markup( $field, 'number' );
1221
        $label    = __( 'Field Label', 'invoicing' );
1222
        $id       = $field . '.id + "_edit"';
1223
        $label2   = __( 'Placeholder text', 'invoicing' );
1224
        $id2      = $field . '.id + "_edit2"';
1225
        $label3   = __( 'Help text', 'invoicing' );
1226
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1227
        $id3      = $field . '.id + "_edit3"';
1228
        $label5   = __( 'Is this field required?', 'invoicing' );
1229
        $id4      = $field . '.id + "_edit4"';
1230
        echo "
1231
            <div $restrict>
1232
                <div class='form-group'>
1233
                    <label :for='$id'>$label</label>
1234
                    <input :id='$id' v-model='$field.label' class='form-control' />
1235
                </div>
1236
                <div class='form-group'>
1237
                    <label :for='$id2'>$label2</label>
1238
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
1239
                </div>
1240
                <div class='form-group'>
1241
                    <label :for='$id3'>$label3</label>
1242
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1243
                </div>
1244
                <div class='form-group form-check'>
1245
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1246
                    <label class='form-check-label' :for='$id4'>$label5</label>
1247
                </div>
1248
            </div>
1249
        ";
1250
1251
    }
1252
1253
    /**
1254
     * Renders the separator element template.
1255
     */
1256
    public function render_separator_template( $field ) {
1257
        $restrict = $this->get_restrict_markup( $field, 'separator' );
1258
        echo "<hr class='featurette-divider mt-0 mb-2' $restrict>";
1259
    }
1260
1261
    /**
1262
     * Renders the separator element on the frontend.
1263
     */
1264
    public function frontend_render_separator_template( $field ) {
1265
        echo '<hr class="featurette-divider mt-0 mb-2" />';
1266
    }
1267
1268
    /**
1269
     * Renders the pay button element template.
1270
     */
1271
    public function render_pay_button_template( $field ) {
1272
        $restrict = $this->get_restrict_markup( $field, 'pay_button' );
1273
        $label    = "$field.label";
1274
        echo "
1275
            <div $restrict>
1276
                <button class='form-control btn submit-button' :class='$field.class' type='submit' @click.prevent=''>{{" . $label . "}}</button>
1277
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1278
            </div>    
1279
        ";
1280
    }
1281
1282
    /**
1283
     * Renders the pay_button element on the frontend.
1284
     */
1285
    public function frontend_render_pay_button_template( $field ) {
1286
        
1287
        echo "<div class='form-group'>";
1288
1289
        $class = 'btn btn-block submit-button ' . sanitize_html_class( $field['class'] );
1290
        echo aui()->button(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1290
        echo /** @scrutinizer ignore-call */ aui()->button(
Loading history...
1291
            array(
1292
                'name'       => esc_attr( $field['id'] ),
1293
                'id'         => esc_attr( $field['id'] ),
1294
                'content'    => wp_kses_post( $field['label'] ),
1295
                'no_wrap'    => true,
1296
                'type'       => 'button',
1297
                'class'      => $class,
1298
            )
1299
        );
1300
1301
        if ( ! empty( $field['description'] ) ) {
1302
            $description = wp_kses_post( $field['description'] );
1303
            echo "<small class='form-text text-muted'>$description</small>";
1304
        }
1305
1306
        echo '</div>';
1307
1308
    }
1309
1310
    /**
1311
     * Renders the pay button element template.
1312
     */
1313
    public function edit_pay_button_template( $field ) {
1314
        $restrict = $this->get_restrict_markup( $field, 'pay_button' );
1315
        $label    = __( 'Button Text', 'invoicing' );
1316
        $id       = $field . '.id + "_edit"';
1317
        $label2   = __( 'Help text', 'invoicing' );
1318
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1319
        $id2      = $field . '.id + "_edit2"';
1320
        $label4   = esc_attr__( 'Button Type', 'invoicing' );
1321
        $id3      = $field . '.id + "_edit3"';
1322
        echo "
1323
            <div $restrict>
1324
                <div class='form-group'>
1325
                    <label :for='$id'>$label</label>
1326
                    <input :id='$id' v-model='$field.label' class='form-control' />
1327
                </div>
1328
                <div class='form-group'>
1329
                    <label :for='$id2'>$label2</label>
1330
                    <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea>
1331
                </div>
1332
                <div class='form-group'>
1333
                    <label :for='$id3'>$label4</label>
1334
1335
                    <select class='form-control custom-select' :id='$id3' v-model='$field.class'>
1336
                        <option value='btn-primary'>"   . __( 'Primary', 'invoicing' ) ."</option>
1337
                        <option value='btn-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option>
1338
                        <option value='btn-success'>"   . __( 'Success', 'invoicing' ) ."</option>
1339
                        <option value='btn-danger'>"    . __( 'Danger', 'invoicing' ) ."</option>
1340
                        <option value='btn-warning'>"   . __( 'Warning', 'invoicing' ) ."</option>
1341
                        <option value='btn-info'>"      . __( 'Info', 'invoicing' ) ."</option>
1342
                        <option value='btn-light'>"     . __( 'Light', 'invoicing' ) ."</option>
1343
                        <option value='btn-dark'>"      . __( 'Dark', 'invoicing' ) ."</option>
1344
                        <option value='btn-link'>"      . __( 'Link', 'invoicing' ) ."</option>
1345
                    </select>
1346
                </div>
1347
            </div>
1348
        ";
1349
1350
    }
1351
1352
    /**
1353
     * Renders the alert element template.
1354
     */
1355
    public function render_alert_template( $field ) {
1356
        $restrict = $this->get_restrict_markup( $field, 'alert' );
1357
        $text     = "$field.text";
1358
        echo "
1359
            <div $restrict class='alert' :class='$field.class' role='alert'>
1360
                <span v-html='$text'></span>
1361
                <button v-if='$field.dismissible' type='button' class='close' @click.prevent=''>
1362
                    <span aria-hidden='true'>&times;</span>
1363
                </button>
1364
            </div>    
1365
        ";
1366
    }
1367
1368
    /**
1369
     * Renders the alert element on the frontend.
1370
     */
1371
    public function frontend_render_alert_template( $field ) {
1372
        
1373
        echo "<div class='form-group'>";
1374
1375
        echo aui()->alert(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1375
        echo /** @scrutinizer ignore-call */ aui()->alert(
Loading history...
1376
            array(
1377
                'content'     => wp_kses_post( $field['text'] ),
1378
                'dismissible' => $field['dismissible'],
1379
                'type'        => str_replace( 'alert-', '', $field['class'] ),
1380
            )
1381
        );
1382
1383
        echo '</div>';
1384
1385
    }
1386
1387
    /**
1388
     * Renders the alert element template.
1389
     */
1390
    public function edit_alert_template( $field ) {
1391
        $restrict = $this->get_restrict_markup( $field, 'alert' );
1392
        $label    = __( 'Alert Text', 'invoicing' );
1393
        $label2   = esc_attr__( 'Enter your alert text here', 'invoicing' );
1394
        $id       = $field . '.id + "_edit"';
1395
        $label3   = __( 'Is Dismissible?', 'invoicing' );
1396
        $id2      = $field . '.id + "_edit2"';
1397
        $label4   = esc_attr__( 'Alert Type', 'invoicing' );
1398
        $id3      = $field . '.id + "_edit3"';
1399
        echo "
1400
            <div $restrict>
1401
                <div class='form-group'>
1402
                    <label :for='$id'>$label</label>
1403
                    <textarea placeholder='$label2' :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea>
1404
                </div>
1405
                <div class='form-group form-check'>
1406
                    <input :id='$id2' v-model='$field.dismissible' type='checkbox' class='form-check-input' />
1407
                    <label class='form-check-label' :for='$id2'>$label3</label>
1408
                </div>
1409
                <div class='form-group'>
1410
                    <label :for='$id3'>$label4</label>
1411
1412
                    <select class='form-control custom-select' :id='$id3' v-model='$field.class'>
1413
                        <option value='alert-primary'>"   . __( 'Primary', 'invoicing' ) ."</option>
1414
                        <option value='alert-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option>
1415
                        <option value='alert-success'>"   . __( 'Success', 'invoicing' ) ."</option>
1416
                        <option value='alert-danger'>"    . __( 'Danger', 'invoicing' ) ."</option>
1417
                        <option value='alert-warning'>"   . __( 'Warning', 'invoicing' ) ."</option>
1418
                        <option value='alert-info'>"      . __( 'Info', 'invoicing' ) ."</option>
1419
                        <option value='alert-light'>"     . __( 'Light', 'invoicing' ) ."</option>
1420
                        <option value='alert-dark'>"      . __( 'Dark', 'invoicing' ) ."</option>
1421
                    </select>
1422
                </div>
1423
            </div>
1424
        ";
1425
1426
    }
1427
1428
    /**
1429
     * Renders the discount element template.
1430
     */
1431
    public function render_discount_template( $field ) {
1432
        $restrict  = $this->get_restrict_markup( $field, 'discount' );
1433
        ?>
1434
1435
            <div <?php echo $restrict; ?> class="discount_field  border rounded p-3">
1436
                <div class="discount_field_inner d-flex flex-column flex-md-row">
1437
                    <input  :placeholder="<?php echo $field ?>.input_label" class="form-control mr-2 mb-2" style="flex: 1;" type="text">
1438
                    <button class="btn btn-secondary submit-button mb-2" type="submit" @click.prevent="">{{<?php echo $field; ?>.button_label}}</button>
1439
                </div>
1440
                <small v-if='<?php echo $field ?>.description' class='form-text text-muted' v-html='<?php echo $field ?>.description'></small>
1441
            </div>
1442
1443
        <?php
1444
    }
1445
1446
    /**
1447
     * Renders the discount element on the frontend.
1448
     */
1449
    public function frontend_render_discount_template( $field ) {
1450
        
1451
        $placeholder = esc_attr( $field['input_label'] );
1452
        $label       = sanitize_text_field( $field['button_label'] );
1453
        $description = '';
1454
1455
        if ( ! empty( $field['description'] ) ) {
1456
            $description = "<small class='form-text text-muted'>{$field['description']}</small>";
1457
        }
1458
?>
1459
1460
    <div class="form-group">
1461
        <div class="discount_field  border rounded p-3">
1462
            <div class="discount_field_inner d-flex flex-column flex-md-row">
1463
                <input  placeholder="<?php echo $placeholder; ?>" class="form-control mr-2 mb-2" style="flex: 1;" type="text">
1464
                <button class="btn btn-secondary submit-button mb-2 wpinv-payment-form-coupon-button" type="submit"><?php echo $label; ?></button>
1465
            </div>
1466
            <?php echo $description ?>
1467
        </div>
1468
    </div>
1469
1470
<?php
1471
    }
1472
1473
    /**
1474
     * Renders the discount element template.
1475
     */
1476
    public function edit_discount_template( $field ) {
1477
        $restrict = $this->get_restrict_markup( $field, 'discount' );
1478
        $label    = __( 'Discount Input Placeholder', 'invoicing' );
1479
        $label2   = __( 'Help Text', 'invoicing' );
1480
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1481
        $label4   = __( 'Button Text', 'invoicing' );
1482
        $id       = $field . '.id + "_edit"';
1483
        $id2      = $field . '.id + "_edit2"';
1484
        $id3      = $field . '.id + "_edit3"';
1485
        echo "
1486
            <div $restrict>
1487
                <div class='form-group'>
1488
                    <label :for='$id'>$label</label>
1489
                    <input :id='$id' v-model='$field.input_label' class='form-control' />
1490
                </div>
1491
1492
                <div class='form-group'>
1493
                    <label :for='$id2'>$label4</label>
1494
                    <input :id='$id2' v-model='$field.button_label' class='form-control' />
1495
                </div>
1496
1497
                <div class='form-group'>
1498
                    <label :for='$id3'>$label2</label>
1499
                    <textarea placeholder='$label3' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1500
                </div>
1501
1502
            </div>
1503
        ";
1504
1505
    }
1506
1507
    /**
1508
     * Renders the items element template.
1509
     */
1510
    public function render_items_template( $field ) {
1511
        $restrict  = $this->get_restrict_markup( $field, 'items' );
1512
        echo "
1513
            <div $restrict class='item_totals'>
1514
1515
                <div v-if='$field.items_type == \"total\"' class='border'>
1516
1517
                    <div v-for='(item, index) in form_items'>
1518
                        <div class='row pl-2 pr-2 pt-2'>
1519
                            <div class='col-8'>{{item.title}}</div>
1520
                            <div class='col-4'>{{formatPrice(item.price)}}</div>
1521
                        </div>
1522
                        <small v-if='item.description' class='form-text text-muted pl-2 pr-2 m-0' v-html='item.description'></small>
1523
                    </div>
1524
1525
                    <div class='mt-4 border-top'>
1526
                        <div class='row p-2'>
1527
                            <div class='col-8'><strong class='mr-5'>Total</strong></div>
1528
                            <div class='col-4'><strong>{{totalPrice}}</strong></div>
1529
                        </div>
1530
                    </div>
1531
                </div>
1532
1533
                <div v-if='$field.items_type == \"checkbox\"'>
1534
1535
                    <div class='form-check' v-for='(item, index) in form_items'>
1536
                        <input class='form-check-input' type='checkbox' :id='$field.id + index'>
1537
                        <label class='form-check-label' :for='$field.id + index'>{{item.title}} &nbsp;<strong>{{formatPrice(item.price)}}</strong></label>
1538
                        <small v-if='item.description' class='form-text text-muted' v-html='item.description'></small>
1539
                    </div>
1540
1541
                </div>
1542
1543
                <div v-if='$field.items_type == \"radio\"'>
1544
1545
                    <div class='form-check' v-for='(item, index) in form_items'>
1546
                        <input class='form-check-input' type='radio' :name='$field.id' :id='$field.id + index'>
1547
                        <label class='form-check-label' :for='$field.id + index'>{{item.title}} &nbsp;<strong>{{formatPrice(item.price)}}</strong></label>
1548
                        <small v-if='item.description' class='form-text text-muted' v-html='item.description'></small>
1549
                    </div>
1550
1551
                </div>
1552
1553
                <div v-if='$field.items_type == \"select\"'>
1554
1555
                    <select class='form-control custom-select'>
1556
                        <option value='' disabled selected='selected'>"        . __( 'Select an option', 'invoicing' ) ."</option>
1557
                        <option v-for='(item, index) in form_items' :value='index'>{{item.title}} &nbsp;{{formatPrice(item.price)}}</option>
1558
                    </select>
1559
                </div>
1560
1561
                <div v-if='$field.items_type == \"multi_select\"'>
1562
1563
                    <select class='form-control custom-select' multiple>
1564
                        <option v-for='(item, index) in form_items' :value='index'>{{item.title}} &nbsp;{{formatPrice(item.price)}}</option>
1565
                    </select>
1566
1567
                </div>
1568
                
1569
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1570
            </div>
1571
        ";
1572
    }
1573
1574
    /**
1575
     * Renders the items element on the frontend.
1576
     */
1577
    public function frontend_render_items_template( $field, $items ) {
1578
        
1579
        echo "<div class='form-group item_totals'>";
1580
        
1581
        $id = esc_attr( $field['id'] );
1582
        if ( 'total' == $field[ 'items_type' ] ) {
1583
            $total = 0;
1584
1585
            ?>
1586
            <div class="border item_totals_type_total">
1587
1588
                <?php
1589
                    foreach( $items as $item ) {
1590
                        $total = $total + floatval( $item['price'] );
1591
                ?>
1592
                    <div  class="item_totals_item">
1593
                        <div class='row pl-2 pr-2 pt-2'>
1594
                            <div class='col-8'><?php echo esc_html( $item['title'] ) ?></div>
1595
                            <div class='col-4'><?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?></div>
1596
                        </div>
1597
                        <?php if ( ! empty( $item['description'] )) { ?>
1598
                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
1599
                        <?php } ?>
1600
                    </div>
1601
                <?php } ?>
1602
1603
                <div class='mt-4 border-top item_totals_total'>
1604
                    <div class='row p-2'>
1605
                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
1606
                        <div class='col-4'><strong><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
1607
                    </div>
1608
                </div>
1609
1610
            </div>
1611
        <?php } ?>
1612
1613
        <?php if ( 'radio' == $field[ 'items_type' ] ) { ?>
1614
            <div class="item_totals_type_radio">
1615
1616
                <?php foreach( $items as $index => $item ) { ?>
1617
                    <div  class="form-check">
1618
                        <input class='form-check-input' type='radio' name='<?php echo $id; ?>' id='<?php echo $id . $index; ?>'>
1619
                        <label class='form-check-label' for=<?php echo $id . $index; ?>'><?php echo sanitize_text_field( $item['title'] ); ?>&nbsp;<strong><?php echo wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) ); ?></strong></label>
1620
                    </div>
1621
                    <?php if ( ! empty( $item['description'] )) { ?>
1622
                        <small class='form-text text-muted pl-4 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
1623
                    <?php } ?>
1624
                <?php } ?>
1625
1626
            </div>
1627
        <?php } ?>
1628
1629
        <?php if ( 'checkbox' == $field[ 'items_type' ] ) { ?>
1630
1631
            <div class="item_totals_type_checkbox">
1632
1633
                <?php
1634
                    foreach ( $items as $index => $item ) {
1635
                        $title = sanitize_text_field(  $item['title'] );
1636
                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
1637
                        echo aui()->input(
0 ignored issues
show
Bug introduced by
The function aui was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1637
                        echo /** @scrutinizer ignore-call */ aui()->input(
Loading history...
1638
                            array(
1639
                                'name'       => $id,
1640
                                'id'         => $id . "_$index",
1641
                                'label'      => "$title &nbsp; ($price)",
1642
                                'no_wrap'    => true,
1643
                                'type'       => 'checkbox',
1644
                            )
1645
                        );
1646
1647
                        if ( ! empty( $item['description'] ) ) {
1648
                            echo "<small class='form-text text-muted'>{$item['description']}</small>";
1649
                        }
1650
                    }
1651
                ?>
1652
1653
            </div>
1654
        <?php } ?>
1655
1656
        <?php if ( 'select' == $field[ 'items_type' ] ) { ?>
1657
1658
            <div class="item_totals_type_select">
1659
1660
                <?php
1661
1662
                    $options = array();
1663
1664
                    foreach ( $items as $index => $item ) {
1665
                        $title = sanitize_text_field(  $item['title'] );
1666
                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
1667
                        $options[ $item['id'] ] = "$title &nbsp; ($price)";
1668
                    }
1669
1670
                    echo aui()->select(
1671
                        array(
1672
                                'name'        => $id,
1673
                                'id'          => $id,
1674
                                'placeholder' => __( 'Select an item', 'invoicing' ),
1675
                                'no_wrap'     => true,
1676
                                'options'     => $options,
1677
                        )
1678
                    );
1679
                ?>
1680
1681
            </div>
1682
        <?php } ?>
1683
1684
        <?php if ( 'multi_select' == $field[ 'items_type' ] ) { ?>
1685
1686
            <div class="item_totals_type_multi_select">
1687
1688
                <?php
1689
1690
                    $options = array();
1691
1692
                    foreach ( $items as $index => $item ) {
1693
                        $title = sanitize_text_field(  $item['title'] );
1694
                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
1695
                        $options[ $item['id'] ] = "$title &nbsp; ($price)";
1696
                    }
1697
1698
                    echo aui()->select(
1699
                        array(
1700
                                'name'        => $id,
1701
                                'id'          => $id,
1702
                                'placeholder' => __( 'Select one or more items', 'invoicing' ),
1703
                                'no_wrap'     => true,
1704
                                'options'     => $options,
1705
                                'multiple'    => true,
1706
                        )
1707
                    );
1708
                ?>
1709
1710
            </div>
1711
        <?php } ?>
1712
1713
        </div>
1714
        <?php
1715
    }
1716
1717
    /**
1718
     * Renders the items element template.
1719
     */
1720
    public function edit_items_template( $field ) {
1721
        $restrict = $this->get_restrict_markup( $field, 'items' );
1722
        $label    = __( 'Let customers...', 'invoicing' );
1723
        $label2   = __( 'Available Items', 'invoicing' );
1724
        $label3   = esc_attr__( 'Add some help text for this element', 'invoicing' );
1725
        $id       = $field . '.id + "_edit"';
1726
        $id2      = $field . '.id + "_edit2"';
1727
        $id3      = $field . '.id + "_edit3"';
1728
        $id4      = $field . '.id + "_edit4"';
0 ignored issues
show
Unused Code introduced by
The assignment to $id4 is dead and can be removed.
Loading history...
1729
        echo "<div $restrict>
1730
                
1731
                <label>$label2</label>
1732
1733
                <draggable v-model='form_items' group='selectable_form_items'>
1734
                    <div class='wpinv-available-items-editor' v-for='(item, index) in form_items' :class='\"item_\" + item.id' :key='item.id'>
1735
1736
                        <div class='wpinv-available-items-editor-header' @click.prevent='togglePanel(item.id)'>
1737
                            <span class='label'>{{item.title}}</span>
1738
                            <span class='price'>({{formatPrice(item.price)}})</span>
1739
                            <span class='toggle-icon'>
1740
                                <span class='dashicons dashicons-arrow-down'></span>
1741
                                <span class='dashicons dashicons-arrow-up' style='display:none'></span>
1742
                            </span>
1743
                        </div>
1744
1745
                        <div class='wpinv-available-items-editor-body'>
1746
                            <div class='p-2'>
1747
1748
                                <div class='form-group'>
1749
                                    <label :for='$id + item.id'>Item Name</label>
1750
                                    <input :id='$id + item.id' v-model='item.title' class='form-control' />
1751
                                </div>
1752
1753
                                <div class='form-group'>
1754
                                    <label :for='$id + item.id + \"price\"'>Item Price</label>
1755
                                    <input :id='$id + item.id + \"price\"' v-model='item.price' class='form-control' />
1756
                                </div>
1757
1758
                                <div class='form-group'>
1759
                                    <label :for='$id + item.id + \"description\"'>Item Description</label>
1760
                                    <textarea :id='$id + item.id + \"description\"' v-model='item.description' class='form-control'></textarea>
1761
                                </div>
1762
1763
                            </div>
1764
                        </div>
1765
1766
                    </div>
1767
                </draggable>
1768
1769
                <small v-if='! form_items.length' class='form-text text-muted'> You have not set up any items. Please select an item below or create a new item.</small>
1770
1771
                <div class='form-group mt-2'>
1772
1773
                    <select class='form-control custom-select' v-model='selected_item'>
1774
                        <option value=''>"        . __( 'Add an item to the form', 'invoicing' ) ."</option>
1775
                        <option v-for='(item, index) in all_items' :value='index'>{{item.title}}</option>
1776
                    </select>
1777
1778
                </div>
1779
1780
                <div class='form-group'>
1781
                    <input type='button' value='Add item' class='button button-primary'  @click.prevent='addSelectedItem' :disabled='selected_item == \"\"'>
1782
                    <small>Or <a href='' @click.prevent='addNewItem'>create a new item</a>.</small>
1783
                </div>
1784
1785
                <div class='form-group mt-5'>
1786
                    <label :for='$id2'>$label</label>
1787
1788
                    <select class='form-control custom-select' :id='$id2' v-model='$field.items_type'>
1789
                        <option value='total'>"        . __( 'Buy all items on the list', 'invoicing' ) ."</option>
1790
                        <option value='radio'>"        . __( 'Select a single item from the list', 'invoicing' ) ."</option>
1791
                        <option value='checkbox'>"     . __( 'Select one or more items on the list', 'invoicing' ) ."</option>
1792
                        <option value='select'>"       . __( 'Select a single item from a dropdown', 'invoicing' ) ."</option>
1793
                        <option value='multi_select'>" . __( 'Select a one or more items from a dropdown', 'invoicing' ) ."</option>
1794
                    </select>
1795
1796
                </div>
1797
1798
                <div class='form-group'>
1799
                    <label :for='$id3'>Help Text</label>
1800
                    <textarea placeholder='$label3' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1801
                </div>
1802
1803
            </div>
1804
        ";
1805
1806
    }
1807
1808
    /**
1809
     * Returns an array of all published items.
1810
     */
1811
    public function get_published_items() {
1812
    
1813
        $item_args = array(
1814
            'post_type'      => 'wpi_item',
1815
            'orderby'        => 'title',
1816
            'order'          => 'ASC',
1817
            'posts_per_page' => -1,
1818
            'post_status'    => array( 'publish' ),
1819
        );
1820
    
1821
        $items      = get_posts( apply_filters( 'wpinv_item_dropdown_query_args', $item_args ) );
1822
1823
        if ( empty( $items ) ) {
1824
            return array();
1825
        }
1826
1827
        $options    = array();
1828
        foreach ( $items as $item ) {
1829
            $title       = esc_html( $item->post_title );
1830
            $title      .= wpinv_get_item_suffix( $item->ID, false );
1831
            $id          = absint( $item->ID );
1832
            $price       = wpinv_sanitize_amount( get_post_meta( $id, '_wpinv_price', true ) );
1833
            $recurring   = (bool) get_post_meta( $id, '_wpinv_is_recurring', true );
1834
            $description = $item->post_excerpt;
1835
            $options[] = compact( 'title', 'id', 'price', 'recurring', 'description' );
1836
1837
        }
1838
        return $options;
1839
1840
    }
1841
1842
    /**
1843
     * Returns an array of items for the currently being edited form.
1844
     */
1845
    public function get_form_items( $id = false ) {
1846
        
1847
        if ( empty( $id ) ) {
1848
            return wpinv_get_data( 'sample-payment-form-items' );
1849
        }
1850
        
1851
        $form_elements = get_post_meta( $id, 'wpinv_form_items', true );
1852
1853
        if ( is_array( $form_elements ) ) {
1854
            return $form_elements;
1855
        }
1856
1857
        return wpinv_get_data( 'sample-payment-form-items' );
1858
1859
    }
1860
1861
    /**
1862
     * Returns an array of elements for the currently being edited form.
1863
     */
1864
    public function get_form_elements( $id = false ) {
1865
1866
        if ( empty( $id ) ) {
1867
            return wpinv_get_data( 'sample-payment-form' );
1868
        }
1869
        
1870
        $form_elements = get_post_meta( $id, 'wpinv_form_elements', true );
1871
1872
        if ( is_array( $form_elements ) ) {
1873
            return $form_elements;
1874
        }
1875
1876
        return wpinv_get_data( 'sample-payment-form' );
1877
    }
1878
1879
}
1880