Completed
Push — master ( 260ce8...60cf75 )
by Brian
21s queued 16s
created

WPInv_Payment_Form_Elements::checkout_error()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 11
rs 10
c 0
b 0
f 0
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
28
        }
29
        
30
    }
31
32
    /**
33
     * Returns all the elements that can be added to a form.
34
     */
35
    public function get_elements() {
36
37
        if ( ! empty( $this->elements ) ) {
38
            return $this->elements;
39
        }
40
41
        $this->elements = wpinv_get_data( 'payment-form-elements' );
42
43
        $this->elements = apply_filters( 'wpinv_filter_core_payment_form_elements', $this->elements );
44
        return $this->elements;
45
    }
46
47
    /**
48
     * Returns the restrict markup.
49
     */
50
    public function get_restrict_markup( $field, $field_type ) {
51
        $restrict = "$field.type=='$field_type'";
52
        return "v-if=\"$restrict\"";
53
    }
54
55
    /**
56
     * Renders the gateway select element template.
57
     */
58
    public function render_gateway_select_template( $field ) {
59
        $restrict = $this->get_restrict_markup( $field, 'gateway_select' );
60
        $text     = __( 'The gateway select box will appear hear', 'invoicing' );
61
        echo "
62
            <div $restrict class='alert alert-info' role='alert'>
63
                <span>$text</span>
64
            </div>
65
        ";
66
    }
67
68
    /**
69
     * Renders the edit gateway select element template.
70
     */
71
    public function edit_gateway_select_template( $field ) {
72
        $restrict = $this->get_restrict_markup( $field, 'gateway_select' );
73
        $label    = __( 'The gateway select text', 'invoicing' );
74
        $id       = $field . '.id + "_edit"';
75
        echo "
76
            <div $restrict>
77
                <div class='form-group'>
78
                    <label :for='$id'>$label</label>
79
                    <textarea :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea>
80
                </div>
81
            </div>
82
        ";
83
84
    }
85
86
    /**
87
     * Renders the ip address element template.
88
     */
89
    public function render_ip_address_template( $field ) {
90
        $restrict   = $this->get_restrict_markup( $field, 'ip_address' );
91
        $ip_address = sanitize_text_field( wpinv_get_ip() );
92
        $url        = esc_url( getpaid_ip_location_url( $ip_address ) );
93
94
        echo "
95
            <div $restrict class='getpaid-ip-info'>
96
                <span>{{{$field}.text}}</span>
97
                <a target='_blank' href='$url'>$ip_address&nbsp;&nbsp;<i class='fa fa-external-link-square' aria-hidden='true'></i></a>
98
            </div>
99
        ";
100
    }
101
102
    /**
103
     * Renders the edit ip address element template.
104
     */
105
    public function edit_ip_address_template( $field ) {
106
        $restrict = $this->get_restrict_markup( $field, 'ip_address' );
107
        $label    = __( 'The IP Address text', 'invoicing' );
108
        $id       = $field . '.id + "_edit"';
109
        echo "
110
            <div $restrict>
111
                <div class='form-group'>
112
                    <label :for='$id'>$label</label>
113
                    <textarea :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea>
114
                </div>
115
            </div>
116
        ";
117
118
    }
119
120
    /**
121
     * Renders the total payable element template.
122
     */
123
    public function render_total_payable_template( $field ) {
124
        $restrict = $this->get_restrict_markup( $field, 'total_payable' );
125
        $text     = __( 'The total payable amount will appear here', 'invoicing' );
126
        echo "
127
            <div $restrict class='alert alert-info' role='alert'>
128
                <span>$text</span>
129
            </div>
130
        ";
131
    }
132
133
    /**
134
     * Renders the edit total payable element template.
135
     */
136
    public function edit_total_payable_template( $field ) {
137
        $restrict = $this->get_restrict_markup( $field, 'total_payable' );
138
        $label    = __( 'The total payable text', 'invoicing' );
139
        $id       = $field . '.id + "_edit"';
140
        echo "
141
            <div $restrict>
142
                <div class='form-group'>
143
                    <label :for='$id'>$label</label>
144
                    <textarea :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea>
145
                </div>
146
            </div>
147
        ";
148
149
    }
150
151
    /**
152
     * Renders the title element template.
153
     */
154
    public function render_heading_template( $field ) {
155
        $restrict = $this->get_restrict_markup( $field, 'heading' );
156
        echo "<component :is='$field.level' $restrict v-html='$field.text'></component>";
157
    }
158
159
    /**
160
     * Renders the edit title element template.
161
     */
162
    public function edit_heading_template( $field ) {
163
        $restrict = $this->get_restrict_markup( $field, 'heading' );
164
        $label    = __( 'Heading', 'invoicing' );
165
        $label2   = __( 'Select Heading Level', 'invoicing' );
166
        $id       = $field . '.id + "_edit"';
167
        $id2      = $field . '.id + "_edit2"';
168
169
        echo "
170
            <div $restrict>
171
                <div class='form-group'>
172
                    <label :for='$id'>$label</label>
173
                    <input class='form-control' :id='$id' v-model='$field.text' type='text' />
174
                </div>
175
176
                <div class='form-group'>
177
                    <label :for='$id2'>$label2</label>
178
179
                    <select class='form-control custom-select' :id='$id2' v-model='$field.level'>
180
                        <option value='h1'>H1</option>
181
                        <option value='h2'>H2</option>
182
                        <option value='h3'>H3</option>
183
                        <option value='h4'>H4</option>
184
                        <option value='h5'>H5</option>
185
                        <option value='h6'>H6</option>
186
                        <option value='h7'>H7</option>
187
                    </select>
188
                </div>
189
            </div>
190
        ";
191
192
    }
193
194
    /**
195
     * Renders a paragraph element template.
196
     */
197
    public function render_paragraph_template( $field ) {
198
        $restrict = $this->get_restrict_markup( $field, 'paragraph' );
199
        $label    = "$field.text";
200
        echo "<p $restrict v-html='$label' style='font-size: 16px;'></p>";
201
    }
202
203
    /**
204
     * Renders the edit paragraph element template.
205
     */
206
    public function edit_paragraph_template( $field ) {
207
        $restrict = $this->get_restrict_markup( $field, 'paragraph' );
208
        $label    = __( 'Enter your text', 'invoicing' );
209
        $id       = $field . '.id + "_edit"';
210
        echo "
211
            <div $restrict>
212
                <div class='form-group'>
213
                    <label :for='$id'>$label</label>
214
                    <textarea :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea>
215
                </div>
216
            </div>
217
        ";
218
219
    }
220
221
    /**
222
     * Renders the text element template.
223
     */
224
    public function render_text_template( $field ) {
225
        $restrict = $this->get_restrict_markup( $field, 'text' );
226
        $label    = "$field.label";
227
        echo "
228
            <div $restrict class='wpinv-payment-form-field-preview'>
229
                <div class='wpinv-payment-form-field-preview-overlay'></div>
230
                <label :for='$field.id'>{{" . $label . "}}</label>
231
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='text'>
232
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
233
            </div>    
234
        ";
235
    }
236
237
    /**
238
     * Renders the edit price select element template.
239
     */
240
    public function edit_price_select_template( $field ) {
241
        $restrict = $this->get_restrict_markup( $field, 'price_select' );
242
        
243
        $label3   = __( 'Help text', 'invoicing' );
0 ignored issues
show
Unused Code introduced by
The assignment to $label3 is dead and can be removed.
Loading history...
244
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
0 ignored issues
show
Unused Code introduced by
The assignment to $label4 is dead and can be removed.
Loading history...
245
        $id3      = $field . '.id + "_edit3"';
0 ignored issues
show
Unused Code introduced by
The assignment to $id3 is dead and can be removed.
Loading history...
246
        $label6   = __( 'Options', 'invoicing' );
0 ignored issues
show
Unused Code introduced by
The assignment to $label6 is dead and can be removed.
Loading history...
247
        $id6      = $field . '.id + "_edit5"';
0 ignored issues
show
Unused Code introduced by
The assignment to $id6 is dead and can be removed.
Loading history...
248
        ?>
249
            <div <?php echo $restrict; ?>>
250
                <small class='form-text text-muted mb-2'><?php _e( 'This amount will be added to the total amount for this form', 'invoicing' ); ?></small>
251
                <div class='form-group'>
252
                    <label class="d-block">
253
                        <span><?php _e( 'Field Label', 'invoicing' ); ?></span>
254
                        <input v-model='<?php echo $field; ?>.label' class='form-control' />
255
                    </label>
256
                </div>
257
258
                <div class='form-group' v-if="<?php echo $field; ?>.select_type=='select'">
259
                    <label class="d-block">
260
                        <span><?php _e( 'Placeholder text', 'invoicing' ); ?></span>
261
                        <input v-model='<?php echo $field; ?>.placeholder' class='form-control' />
262
                    </label>
263
                </div>
264
265
                <div class='form-group'>
266
                    <label class="d-block">
267
                        <span><?php _e( 'Select Type', 'invoicing' ); ?></span>
268
                        <select class='form-control custom-select' v-model='<?php echo $field; ?>.select_type'>
269
                            <option value='select'><?php _e( 'Dropdown', 'invoicing' ) ?></option>
270
                            <option value='checkboxes'><?php _e( 'Checkboxes', 'invoicing' ) ?></option>
271
                            <option value='radios'><?php _e( 'Radio Buttons', 'invoicing' ) ?></option>
272
                            <option value='buttons'><?php _e( 'Buttons', 'invoicing' ) ?></option>
273
                            <option value='circles'><?php _e( 'Circles', 'invoicing' ) ?></option>
274
                        </select>
275
                    </label>
276
                </div>
277
278
                <div class='form-group'>
279
                    <label class="d-block">
280
                        <span><?php _e( 'Options', 'invoicing' ); ?></span>
281
                        <textarea placeholder='Basic|10,Pro|99,Business|199' v-model='<?php echo $field; ?>.options' class='form-control' rows='3'></textarea>
282
                        <small class='form-text text-muted mb-2'><?php _e( 'Use commas to separate options and pipes to separate a label and its price. Do not include a currency symbol in the price.', 'invoicing' ); ?></small>
283
                    </label>
284
                </div>
285
286
                <div class='form-group'>
287
                    <label class="d-block">
288
                        <span><?php _e( 'Help Text', 'invoicing' ); ?></span>
289
                        <textarea placeholder='<?php esc_attr_e( 'Add some help text for this field', 'invoicing' ); ?>' v-model='<?php echo $field; ?>.description' class='form-control' rows='3'></textarea>
290
                    </label>
291
                </div>
292
            </div>
293
        <?php
294
295
    }
296
297
    /**
298
     * Renders the price select element template.
299
     */
300
    public function render_price_select_template( $field ) {
301
        $restrict = $this->get_restrict_markup( $field, 'price_select' );
302
        ?>
303
            <div <?php echo $restrict; ?> class='wpinv-payment-form-field-preview'>
304
                <div class='wpinv-payment-form-field-preview-overlay'></div>
305
306
                <label>{{<?php echo $field; ?>.label}}</label>
307
308
                <!-- Buttons -->
309
                <div v-if='<?php echo esc_attr( $field ); ?>.select_type=="buttons"' class="getpaid-price-buttons">
310
                    <span v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index">
311
                        <input type="radio" :id="<?php echo esc_attr( $field ); ?>.id + index" :checked="index==0" />
312
                        <label :for="<?php echo esc_attr( $field ); ?>.id + index" class="rounded">{{option | optionize}}</label>
313
                    </span>
314
                </div>
315
316
                <!-- Circles -->
317
                <div v-if='<?php echo esc_attr( $field ); ?>.select_type=="circles"' class="getpaid-price-buttons getpaid-price-circles">
318
                    <span v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index">
319
                        <input type="radio" :id="<?php echo esc_attr( $field ); ?>.id + index" :checked="index==0" />
320
                        <label :for="<?php echo esc_attr( $field ); ?>.id + index"><span>{{option | optionize}}</span></label>
321
                    </span>
322
                </div>
323
324
                <!-- Radios -->
325
                <div v-if='<?php echo esc_attr( $field ); ?>.select_type=="radios"'>
326
                    <div v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index">
327
                        <label>
328
                            <input type="radio" :checked="index==0" />
329
                            <span>{{option | optionize}}</span>
330
                        </label>
331
                    </div>
332
                </div>
333
334
                <!-- Checkboxes -->
335
                <div v-if='<?php echo esc_attr( $field ); ?>.select_type=="checkboxes"'>
336
                    <div v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index">
337
                        <label>
338
                            <input type="checkbox" :checked="index==0" />
339
                            <span>{{option | optionize}}</span>
340
                        </label>
341
                    </div>
342
                </div>
343
344
                <!-- Select -->
345
                <select v-if='<?php echo esc_attr( $field ); ?>.select_type=="select"' class='form-control custom-select'>
346
                    <option v-if="<?php echo esc_attr( $field ); ?>.placeholder" selected="selected">
347
                        {{<?php echo esc_attr( $field ); ?>.placeholder}}
348
                    </option>
349
                    <option v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index">
350
                        {{option | optionize}}
351
                    </option>
352
                </select>
353
                <small v-if='<?php echo esc_attr( $field ); ?>.description' class='form-text text-muted' v-html='<?php echo esc_attr( $field ); ?>.description'></small>
354
            </div>
355
356
        <?php
357
    }
358
359
    /**
360
     * Renders the edit price input element template.
361
     */
362
    public function edit_price_input_template( $field ) {
363
        $restrict = $this->get_restrict_markup( $field, 'price_input' );
364
        $label    = __( 'Field Label', 'invoicing' );
365
        $id       = $field . '.id + "_edit"';
366
        $label2   = __( 'Placeholder text', 'invoicing' );
367
        $id2      = $field . '.id + "_edit2"';
368
        $label3   = __( 'Help text', 'invoicing' );
369
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
370
        $id3      = $field . '.id + "_edit3"';
371
        $label5   = __( 'The amount that users add to this field will be added to the total amount', 'invoicing' );
372
        $label6   = __( 'Default Amount', 'invoicing' );
373
        $id6      = $field . '.id + "_edit5"';
374
        echo "
375
            <div $restrict>
376
                <small class='form-text text-muted mb-2'>$label5</small>
377
                <div class='form-group'>
378
                    <label :for='$id'>$label</label>
379
                    <input :id='$id' v-model='$field.label' class='form-control' />
380
                </div>
381
                <div class='form-group'>
382
                    <label :for='$id6'>$label6</label>
383
                    <input :id='$id6' v-model='$field.value' class='form-control' />
384
                </div>
385
                <div class='form-group'>
386
                    <label :for='$id2'>$label2</label>
387
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
388
                </div>
389
                <div class='form-group'>
390
                    <label :for='$id3'>$label3</label>
391
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
392
                </div>
393
            </div>
394
        ";
395
    }
396
397
    /**
398
     * Renders the edit text element template.
399
     */
400
    public function edit_text_template( $field ) {
401
        $restrict = $this->get_restrict_markup( $field, 'text' );
402
        $label    = __( 'Field Label', 'invoicing' );
403
        $id       = $field . '.id + "_edit"';
404
        $label2   = __( 'Placeholder text', 'invoicing' );
405
        $id2      = $field . '.id + "_edit2"';
406
        $label3   = __( 'Help text', 'invoicing' );
407
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
408
        $id3      = $field . '.id + "_edit3"';
409
        $label5   = __( 'Is this field required?', 'invoicing' );
410
        $id4      = $field . '.id + "_edit4"';
411
        echo "
412
            <div $restrict>
413
                <div class='form-group'>
414
                    <label :for='$id'>$label</label>
415
                    <input :id='$id' v-model='$field.label' class='form-control' />
416
                </div>
417
                <div class='form-group'>
418
                    <label :for='$id2'>$label2</label>
419
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
420
                </div>
421
                <div class='form-group'>
422
                    <label :for='$id3'>$label3</label>
423
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
424
                </div>
425
                <div class='form-group form-check'>
426
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
427
                    <label class='form-check-label' :for='$id4'>$label5</label>
428
                </div>
429
            </div>
430
        ";
431
432
    }
433
434
    /**
435
     * Renders the textarea element template.
436
     */
437
    public function render_textarea_template( $field ) {
438
        $restrict = $this->get_restrict_markup( $field, 'textarea' );
439
        $label    = "$field.label";
440
        echo "
441
            <div $restrict class='wpinv-payment-form-field-preview'>
442
                <div class='wpinv-payment-form-field-preview-overlay'></div>
443
                <label :for='$field.id'>{{" . $label . "}}</label>
444
                <textarea  :placeholder='$field.placeholder' :id='$field.id' class='form-control' rows='3'></textarea>
445
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
446
            </div>    
447
        ";
448
    }
449
450
    /**
451
     * Renders the edit textarea element template.
452
     */
453
    public function edit_textarea_template( $field ) {
454
        $restrict = $this->get_restrict_markup( $field, 'textarea' );
455
        $label    = __( 'Field Label', 'invoicing' );
456
        $id       = $field . '.id + "_edit"';
457
        $label2   = __( 'Placeholder text', 'invoicing' );
458
        $id2      = $field . '.id + "_edit2"';
459
        $label3   = __( 'Help text', 'invoicing' );
460
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
461
        $id3      = $field . '.id + "_edit3"';
462
        $label5   = __( 'Is this field required?', 'invoicing' );
463
        $id4      = $field . '.id + "_edit4"';
464
        echo "
465
            <div $restrict>
466
                <div class='form-group'>
467
                    <label :for='$id'>$label</label>
468
                    <input :id='$id' v-model='$field.label' class='form-control' />
469
                </div>
470
                <div class='form-group'>
471
                    <label :for='$id2'>$label2</label>
472
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
473
                </div>
474
                <div class='form-group'>
475
                    <label :for='$id3'>$label3</label>
476
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
477
                </div>
478
                <div class='form-group form-check'>
479
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
480
                    <label class='form-check-label' :for='$id4'>$label5</label>
481
                </div>
482
            </div>
483
        ";
484
485
    }
486
487
    /**
488
     * Renders the select element template.
489
     */
490
    public function render_select_template( $field ) {
491
        $restrict    = $this->get_restrict_markup( $field, 'select' );
492
        $label       = "$field.label";
493
        $placeholder = "$field.placeholder";
494
        $id          = $field . '.id';
495
        echo "
496
            <div $restrict class='wpinv-payment-form-field-preview'>
497
                <div class='wpinv-payment-form-field-preview-overlay'></div>
498
                <label :for='$id'>{{" . $label . "}}</label>
499
                <select id='$id' class='form-control custom-select'  v-model='$field.value'>
500
                    <option v-if='$placeholder' value='' disabled>{{" . $placeholder . "}}</option>
501
                    <option v-for='option in $field.options' value='option'>{{option}}</option>
502
                </select>
503
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
504
            </div>
505
        ";
506
    }
507
508
    /**
509
     * Renders the edit select element template.
510
     */
511
    public function edit_select_template( $field ) {
512
        $restrict = $this->get_restrict_markup( $field, 'select' );
513
        $label    = __( 'Field Label', 'invoicing' );
514
        $id       = $field . '.id + "_edit"';
515
        $label2   = __( 'Placeholder text', 'invoicing' );
516
        $id2      = $field . '.id + "_edit2"';
517
        $label3   = __( 'Help text', 'invoicing' );
518
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
519
        $id3      = $field . '.id + "_edit3"';
520
        $label5   = __( 'Is this field required?', 'invoicing' );
521
        $id4      = $field . '.id + "_edit4"';
522
        $label6   = __( 'Available Options', 'invoicing' );
523
        echo "
524
            <div $restrict>
525
                <div class='form-group'>
526
                    <label :for='$id'>$label</label>
527
                    <input :id='$id' v-model='$field.label' class='form-control' />
528
                </div>
529
                <div class='form-group'>
530
                    <label :for='$id2'>$label2</label>
531
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
532
                </div>
533
                <div class='form-group'>
534
                    <label :for='$id3'>$label3</label>
535
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
536
                </div>
537
                <div class='form-group form-check'>
538
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
539
                    <label class='form-check-label' :for='$id4'>$label5</label>
540
                </div>
541
                <hr class='featurette-divider mt-4'>
542
                <h5>$label6</h5>
543
                <div class='form-group input-group' v-for='(option, index) in $field.options'>
544
                    <input type='text' class='form-control' v-model='$field.options[index]'>
545
                    <div class='input-group-append'>
546
                        <button class='button button-secondary border' type='button' @click.prevent='$field.options.splice(index, 1)'><span class='dashicons dashicons-trash'></span></button>
547
                    </div>
548
                </div>
549
                <div class='form-group'>
550
                    <button class='button button-secondary' type='button' @click.prevent='$field.options.push(\"\")'>Add Option</button>
551
                </div>
552
            </div>
553
        ";
554
555
    }
556
557
    /**
558
     * Renders the checkbox element template.
559
     */
560
    public function render_checkbox_template( $field ) {
561
        $restrict = $this->get_restrict_markup( $field, 'checkbox' );
562
        echo "
563
            <div class='form-check' $restrict>
564
                <div class='wpinv-payment-form-field-preview-overlay'></div>
565
                <input  :id='$field.id' class='form-check-input' type='checkbox' />
566
                <label class='form-check-label' :for='$field.id' v-html='$field.label'></label>
567
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
568
            </div>    
569
        ";
570
    }
571
572
    /**
573
     * Renders the edit checkbox element template.
574
     */
575
    public function edit_checkbox_template( $field ) {
576
        $restrict = $this->get_restrict_markup( $field, 'checkbox' );
577
        $label    = __( 'Field Label', 'invoicing' );
578
        $id       = $field . '.id + "_edit"';
579
        $label2   = __( 'Help text', 'invoicing' );
580
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
581
        $id2      = $field . '.id + "_edit2"';
582
        $label4   = __( 'Is this field required?', 'invoicing' );
583
        $id3      = $field . '.id + "_edit3"';
584
        echo "
585
            <div $restrict>
586
                <div class='form-group'>
587
                    <label :for='$id'>$label</label>
588
                    <input :id='$id' v-model='$field.label' class='form-control' />
589
                </div>
590
                <div class='form-group'>
591
                    <label :for='$id2'>$label2</label>
592
                    <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea>
593
                </div>
594
                <div class='form-group form-check'>
595
                    <input :id='$id3' v-model='$field.required' type='checkbox' class='form-check-input' />
596
                    <label class='form-check-label' :for='$id3'>$label4</label>
597
                </div>
598
            </div>
599
        ";
600
601
    }
602
603
    /**
604
     * Renders the radio element template.
605
     */
606
    public function render_radio_template( $field ) {
607
        $restrict    = $this->get_restrict_markup( $field, 'radio' );
608
        $label       = "$field.label";
609
        $id          = $field . '.id';
610
        echo "
611
            <div $restrict class='wpinv-payment-form-field-preview'>
612
                <div class='wpinv-payment-form-field-preview-overlay'></div>
613
                <legend class='col-form-label' v-if='$label'>{{" . $label . "}}</legend>
614
                <div class='form-check' v-for='(option, index) in $field.options'>
615
                    <input class='form-check-input' type='radio' :id='$id + index'>
616
                    <label class='form-check-label' :for='$id + index'>{{option}}</label>
617
                </div>
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 edit radio element template.
625
     */
626
    public function edit_radio_template( $field ) {
627
        $restrict = $this->get_restrict_markup( $field, 'radio' );
628
        $label    = __( 'Field Label', 'invoicing' );
629
        $id       = $field . '.id + "_edit"';
630
        $label2   = __( 'Help text', 'invoicing' );
631
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
632
        $id2      = $field . '.id + "_edit3"';
633
        $label4   = __( 'Is this field required?', 'invoicing' );
634
        $id3      = $field . '.id + "_edit4"';
635
        $label5   = __( 'Available Options', 'invoicing' );
636
        echo "
637
            <div $restrict>
638
                <div class='form-group'>
639
                    <label :for='$id'>$label</label>
640
                    <input :id='$id' v-model='$field.label' class='form-control' />
641
                </div>
642
                <div class='form-group'>
643
                    <label :for='$id2'>$label2</label>
644
                    <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea>
645
                </div>
646
                <div class='form-group form-check'>
647
                    <input :id='$id3' v-model='$field.required' type='checkbox' class='form-check-input' />
648
                    <label class='form-check-label' :for='$id3'>$label4</label>
649
                </div>
650
                <hr class='featurette-divider mt-4'>
651
                <h5>$label5</h5>
652
                <div class='form-group input-group' v-for='(option, index) in $field.options'>
653
                    <input type='text' class='form-control' v-model='$field.options[index]'>
654
                    <div class='input-group-append'>
655
                        <button class='button button-secondary border' type='button' @click.prevent='$field.options.splice(index, 1)'><span class='dashicons dashicons-trash'></span></button>
656
                    </div>
657
                </div>
658
                <div class='form-group'>
659
                    <button class='button button-secondary' type='button' @click.prevent='$field.options.push(\"\")'>Add Option</button>
660
                </div>
661
            </div>
662
        ";
663
664
    }
665
666
    /**
667
     * Renders the address element template.
668
     */
669
    public function render_address_template( $field ) {
670
        $restrict    = $this->get_restrict_markup( $field, 'address' );
671
672
        echo "
673
            <div class='wpinv-address-wrapper' $restrict>
674
                <draggable v-model='$field.fields' group='address_fields_preview'>
675
                    <div class='form-group address-field-preview wpinv-payment-form-field-preview' v-for='(field, index) in $field.fields' :key='field.name' v-show='field.visible'>
676
                        <div class='wpinv-payment-form-field-preview-overlay'></div>
677
                        <label :for='field.name'>{{field.label}}<span class='text-danger' v-if='field.required'> *</span></label>
678
                        <input v-if='field.name !== \"wpinv_country\" && field.name !== \"wpinv_state\"' class='form-control' type='text' :id='field.name' :placeholder='field.placeholder'>
679
                        <select v-else class='form-control' :id='field.name'>
680
                            <option v-if='field.placeholder'>{{field.placeholder}}</option>
681
                        </select>
682
                        <small v-if='field.description' class='form-text text-muted' v-html='field.description'></small>
683
                    </div>
684
                </draggable>
685
            </div>
686
        ";
687
    }
688
689
    /**
690
     * Renders the edit address element template.
691
     */
692
    public function edit_address_template( $field ) {
693
        $restrict  = $this->get_restrict_markup( $field, 'address' );
694
        $label     = __( 'Field Label', 'invoicing' );
695
        $label2    = __( 'Placeholder', 'invoicing' );
696
        $label3    = __( 'Description', 'invoicing' );
697
        $label4    = __( 'Is required', 'invoicing' );
698
        $label5    = __( 'Is visible', 'invoicing' );
699
        $id        = $field . '.id + "_edit_label"';
700
        $id2       = $field . '.id + "_edit_placeholder"';
701
        $id3       = $field . '.id + "_edit_description"';
702
        $id4       = $field . '.id + "_edit_required"';
703
        $id5       = $field . '.id + "_edit_visible"';
0 ignored issues
show
Unused Code introduced by
The assignment to $id5 is dead and can be removed.
Loading history...
704
        $id5       = $field . '.id + "_edit_visible"';
705
        $id_main   = $field . '.id';
706
707
        echo "
708
            <div $restrict :id='$id_main'>
709
                <draggable v-model='$field.fields' group='address_fields'>
710
                    <div class='wpinv-form-address-field-editor' v-for='(field, index) in $field.fields' :class=\"[field.name, { 'visible' : field.visible }]\" :key='field.name'>
711
712
                        <div class='wpinv-form-address-field-editor-header' @click.prevent='toggleAddressPanel($id_main, field.name)'>
713
                            <span class='label'>{{field.label}}</span>
714
                            <span class='toggle-visibility-icon' @click.stop='field.visible = !field.visible;'>
715
                                <span class='dashicons dashicons-hidden'></span>
716
                                <span class='dashicons dashicons-visibility'></span>
717
                            </span>
718
                            <span class='toggle-icon'>
719
                                <span class='dashicons dashicons-arrow-down'></span>
720
                                <span class='dashicons dashicons-arrow-up' style='display:none'></span>
721
                            </span>
722
                        </div>
723
724
                        <div class='wpinv-form-address-field-editor-editor-body'>
725
                            <div class='p-2'>
726
727
                                <div class='form-group'>
728
                                    <label :for='$id + index'>$label</label>
729
                                    <input :id='$id + index' v-model='field.label' class='form-control' />
730
                                </div>
731
732
                                <div class='form-group'>
733
                                    <label :for='$id2 + index'>$label2</label>
734
                                    <input :id='$id2 + index' v-model='field.placeholder' class='form-control' />
735
                                </div>
736
737
                                <div class='form-group'>
738
                                    <label :for='$id3 + index'>$label3</label>
739
                                    <textarea :id='$id3 + index' v-model='field.description' class='form-control'></textarea>
740
                                </div>
741
742
                                <div class='form-group form-check'>
743
                                    <input :id='$id4 + index' v-model='field.required' type='checkbox' class='form-check-input' />
744
                                    <label class='form-check-label' :for='$id4 + index'>$label4</label>
745
                                </div>
746
747
                                <div class='form-group form-check'>
748
                                    <input :id='$id5 + index' v-model='field.visible' type='checkbox' class='form-check-input' />
749
                                    <label class='form-check-label' :for='$id5 + index'>$label5</label>
750
                                </div>
751
752
                            </div>
753
                        </div>
754
755
                    </div>
756
                </draggable>
757
758
            </div>
759
        ";
760
761
    }
762
763
    /**
764
     * Renders the email element template.
765
     */
766
    public function render_email_template( $field ) {
767
        $restrict = $this->get_restrict_markup( $field, 'email' );
768
        $label    = "$field.label";
769
        echo "
770
            <div $restrict class='wpinv-payment-form-field-preview'>
771
                <div class='wpinv-payment-form-field-preview-overlay'></div>
772
                <label :for='$field.id'>{{" . $label . "}}</label>
773
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='email'>
774
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
775
            </div>    
776
        ";
777
    }
778
779
    /**
780
     * Renders the billing_email element template.
781
     */
782
    public function render_billing_email_template( $field ) {
783
        $restrict = $this->get_restrict_markup( $field, 'billing_email' );
784
        $label    = "$field.label";
785
        echo "
786
            <div $restrict>
787
                <label :for='$field.id'>{{" . $label . "}}</label>
788
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='email'>
789
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
790
            </div>    
791
        ";
792
    }
793
794
    /**
795
     * Renders the edit email element template.
796
     */
797
    public function edit_email_template( $field ) {
798
        $restrict = $this->get_restrict_markup( $field, 'email' );
799
        $label    = __( 'Field Label', 'invoicing' );
800
        $id       = $field . '.id + "_edit"';
801
        $label2   = __( 'Placeholder text', 'invoicing' );
802
        $id2      = $field . '.id + "_edit2"';
803
        $label3   = __( 'Help text', 'invoicing' );
804
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
805
        $id3      = $field . '.id + "_edit3"';
806
        $label5   = __( 'Is this field required?', 'invoicing' );
807
        $id4      = $field . '.id + "_edit4"';
808
        echo "
809
            <div $restrict>
810
                <div class='form-group'>
811
                    <label :for='$id'>$label</label>
812
                    <input :id='$id' v-model='$field.label' class='form-control' />
813
                </div>
814
                <div class='form-group'>
815
                    <label :for='$id2'>$label2</label>
816
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
817
                </div>
818
                <div class='form-group'>
819
                    <label :for='$id3'>$label3</label>
820
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
821
                </div>
822
                <div class='form-group form-check'>
823
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
824
                    <label class='form-check-label' :for='$id4'>$label5</label>
825
                </div>
826
            </div>
827
        ";
828
829
    }
830
831
    /**
832
     * Renders the edit billing_email element template.
833
     */
834
    public function edit_billing_email_template( $field ) {
835
        $restrict = $this->get_restrict_markup( $field, 'billing_email' );
836
        $label    = __( 'Field Label', 'invoicing' );
837
        $id       = $field . '.id + "_edit"';
838
        $label2   = __( 'Placeholder text', 'invoicing' );
839
        $id2      = $field . '.id + "_edit2"';
840
        $label3   = __( 'Help text', 'invoicing' );
841
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
842
        $id3      = $field . '.id + "_edit3"';
843
        $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...
844
        $id4      = $field . '.id + "_edit4"';
0 ignored issues
show
Unused Code introduced by
The assignment to $id4 is dead and can be removed.
Loading history...
845
        echo "
846
            <div $restrict>
847
                <div class='form-group'>
848
                    <label :for='$id'>$label</label>
849
                    <input :id='$id' v-model='$field.label' class='form-control' />
850
                </div>
851
                <div class='form-group'>
852
                    <label :for='$id2'>$label2</label>
853
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
854
                </div>
855
                <div class='form-group'>
856
                    <label :for='$id3'>$label3</label>
857
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
858
                </div>
859
            </div>
860
        ";
861
862
    }
863
864
    /**
865
     * Renders the website element template.
866
     */
867
    public function render_website_template( $field ) {
868
        $restrict = $this->get_restrict_markup( $field, 'website' );
869
        $label    = "$field.label";
870
        echo "
871
            <div $restrict class='wpinv-payment-form-field-preview'>
872
                <div class='wpinv-payment-form-field-preview-overlay'></div>
873
                <label :for='$field.id'>{{" . $label . "}}</label>
874
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='url'>
875
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
876
            </div>    
877
        ";
878
    }
879
880
    /**
881
     * Renders the edit website element template.
882
     */
883
    public function edit_website_template( $field ) {
884
        $restrict = $this->get_restrict_markup( $field, 'website' );
885
        $label    = __( 'Field Label', 'invoicing' );
886
        $id       = $field . '.id + "_edit"';
887
        $label2   = __( 'Placeholder text', 'invoicing' );
888
        $id2      = $field . '.id + "_edit2"';
889
        $label3   = __( 'Help text', 'invoicing' );
890
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
891
        $id3      = $field . '.id + "_edit3"';
892
        $label5   = __( 'Is this field required?', 'invoicing' );
893
        $id4      = $field . '.id + "_edit4"';
894
        echo "
895
            <div $restrict>
896
                <div class='form-group'>
897
                    <label :for='$id'>$label</label>
898
                    <input :id='$id' v-model='$field.label' class='form-control' />
899
                </div>
900
                <div class='form-group'>
901
                    <label :for='$id2'>$label2</label>
902
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
903
                </div>
904
                <div class='form-group'>
905
                    <label :for='$id3'>$label3</label>
906
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
907
                </div>
908
                <div class='form-group form-check'>
909
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
910
                    <label class='form-check-label' :for='$id4'>$label5</label>
911
                </div>
912
            </div>
913
        ";
914
915
    }
916
917
    /**
918
     * Renders the date element template.
919
     */
920
    public function render_date_template( $field ) {
921
        $restrict = $this->get_restrict_markup( $field, 'date' );
922
        $label    = "$field.label";
923
        echo "
924
            <div $restrict class='wpinv-payment-form-field-preview'>
925
                <div class='wpinv-payment-form-field-preview-overlay'></div>
926
                <label :for='$field.id'>{{" . $label . "}}</label>
927
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='date'>
928
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
929
            </div>    
930
        ";
931
    }
932
933
    /**
934
     * Renders the edit date element template.
935
     */
936
    public function edit_date_template( $field ) {
937
        $restrict = $this->get_restrict_markup( $field, 'date' );
938
        $label    = __( 'Field Label', 'invoicing' );
939
        $id       = $field . '.id + "_edit"';
940
        $label3   = __( 'Help text', 'invoicing' );
941
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
942
        $id3      = $field . '.id + "_edit3"';
943
        $label5   = __( 'Is this field required?', 'invoicing' );
944
        $id4      = $field . '.id + "_edit4"';
945
        echo "
946
            <div $restrict>
947
                <div class='form-group'>
948
                    <label :for='$id'>$label</label>
949
                    <input :id='$id' v-model='$field.label' class='form-control' />
950
                </div>
951
                <div class='form-group'>
952
                    <label :for='$id3'>$label3</label>
953
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
954
                </div>
955
                <div class='form-group form-check'>
956
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
957
                    <label class='form-check-label' :for='$id4'>$label5</label>
958
                </div>
959
            </div>
960
        ";
961
962
    }
963
964
    /**
965
     * Renders the time element template.
966
     */
967
    public function render_time_template( $field ) {
968
        $restrict = $this->get_restrict_markup( $field, 'time' );
969
        $label    = "$field.label";
970
        echo "
971
            <div $restrict class='wpinv-payment-form-field-preview'>
972
                <div class='wpinv-payment-form-field-preview-overlay'></div>
973
                <label :for='$field.id'>{{" . $label . "}}</label>
974
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='time'>
975
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
976
            </div>    
977
        ";
978
    }
979
980
    /**
981
     * Renders the edit time element template.
982
     */
983
    public function edit_time_template( $field ) {
984
        $restrict = $this->get_restrict_markup( $field, 'time' );
985
        $label    = __( 'Field Label', 'invoicing' );
986
        $id       = $field . '.id + "_edit"';
987
        $label3   = __( 'Help text', 'invoicing' );
988
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
989
        $id3      = $field . '.id + "_edit3"';
990
        $label5   = __( 'Is this field required?', 'invoicing' );
991
        $id4      = $field . '.id + "_edit4"';
992
        echo "
993
            <div $restrict>
994
                <div class='form-group'>
995
                    <label :for='$id'>$label</label>
996
                    <input :id='$id' v-model='$field.label' class='form-control' />
997
                </div>
998
                <div class='form-group'>
999
                    <label :for='$id3'>$label3</label>
1000
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1001
                </div>
1002
                <div class='form-group form-check'>
1003
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1004
                    <label class='form-check-label' :for='$id4'>$label5</label>
1005
                </div>
1006
            </div>
1007
        ";
1008
1009
    }
1010
1011
    /**
1012
     * Renders the number element template.
1013
     */
1014
    public function render_number_template( $field ) {
1015
        $restrict = $this->get_restrict_markup( $field, 'number' );
1016
        $label    = "$field.label";
1017
        echo "
1018
            <div $restrict class='wpinv-payment-form-field-preview'>
1019
                <div class='wpinv-payment-form-field-preview-overlay'></div>
1020
                <label :for='$field.id'>{{" . $label . "}}</label>
1021
                <input  :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='number'>
1022
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1023
            </div>    
1024
        ";
1025
    }
1026
1027
    /**
1028
     * Renders the edit number element template.
1029
     */
1030
    public function edit_number_template( $field ) {
1031
        $restrict = $this->get_restrict_markup( $field, 'number' );
1032
        $label    = __( 'Field Label', 'invoicing' );
1033
        $id       = $field . '.id + "_edit"';
1034
        $label2   = __( 'Placeholder text', 'invoicing' );
1035
        $id2      = $field . '.id + "_edit2"';
1036
        $label3   = __( 'Help text', 'invoicing' );
1037
        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1038
        $id3      = $field . '.id + "_edit3"';
1039
        $label5   = __( 'Is this field required?', 'invoicing' );
1040
        $id4      = $field . '.id + "_edit4"';
1041
        echo "
1042
            <div $restrict>
1043
                <div class='form-group'>
1044
                    <label :for='$id'>$label</label>
1045
                    <input :id='$id' v-model='$field.label' class='form-control' />
1046
                </div>
1047
                <div class='form-group'>
1048
                    <label :for='$id2'>$label2</label>
1049
                    <input :id='$id2' v-model='$field.placeholder' class='form-control' />
1050
                </div>
1051
                <div class='form-group'>
1052
                    <label :for='$id3'>$label3</label>
1053
                    <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1054
                </div>
1055
                <div class='form-group form-check'>
1056
                    <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' />
1057
                    <label class='form-check-label' :for='$id4'>$label5</label>
1058
                </div>
1059
            </div>
1060
        ";
1061
1062
    }
1063
1064
    /**
1065
     * Renders the separator element template.
1066
     */
1067
    public function render_separator_template( $field ) {
1068
        $restrict = $this->get_restrict_markup( $field, 'separator' );
1069
        echo "<hr class='featurette-divider' $restrict>";
1070
    }
1071
1072
    /**
1073
     * Renders the pay button element template.
1074
     */
1075
    public function render_pay_button_template( $field ) {
1076
        $restrict = $this->get_restrict_markup( $field, 'pay_button' );
1077
        $label    = "$field.label";
1078
        echo "
1079
            <div $restrict>
1080
                <button class='form-control btn submit-button' :class='$field.class' type='submit' @click.prevent=''>{{" . $label . "}}</button>
1081
                <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small>
1082
            </div>    
1083
        ";
1084
    }
1085
1086
    /**
1087
     * Renders the pay button element template.
1088
     */
1089
    public function edit_pay_button_template( $field ) {
1090
        $restrict = $this->get_restrict_markup( $field, 'pay_button' );
1091
        $label    = __( 'Button Text', 'invoicing' );
1092
        $id       = $field . '.id + "_edit"';
1093
        $label2   = __( 'Help text', 'invoicing' );
1094
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1095
        $id2      = $field . '.id + "_edit2"';
1096
        $label4   = esc_attr__( 'Button Type', 'invoicing' );
1097
        $id3      = $field . '.id + "_edit3"';
1098
1099
        echo "
1100
            <div $restrict>
1101
                <div class='form-group'>
1102
                    <label :for='$id'>$label</label>
1103
                    <input :id='$id' v-model='$field.label' class='form-control' />
1104
                </div>
1105
                <div class='form-group'>
1106
                    <label :for='$id2'>$label2</label>
1107
                    <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea>
1108
                </div>
1109
                <div class='form-group'>
1110
                    <label :for='$id3'>$label4</label>
1111
1112
                    <select class='form-control custom-select' :id='$id3' v-model='$field.class'>
1113
                        <option value='btn-primary'>"   . __( 'Primary', 'invoicing' ) ."</option>
1114
                        <option value='btn-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option>
1115
                        <option value='btn-success'>"   . __( 'Success', 'invoicing' ) ."</option>
1116
                        <option value='btn-danger'>"    . __( 'Danger', 'invoicing' ) ."</option>
1117
                        <option value='btn-warning'>"   . __( 'Warning', 'invoicing' ) ."</option>
1118
                        <option value='btn-info'>"      . __( 'Info', 'invoicing' ) ."</option>
1119
                        <option value='btn-light'>"     . __( 'Light', 'invoicing' ) ."</option>
1120
                        <option value='btn-dark'>"      . __( 'Dark', 'invoicing' ) ."</option>
1121
                        <option value='btn-link'>"      . __( 'Link', 'invoicing' ) ."</option>
1122
                    </select>
1123
                </div>
1124
            </div>
1125
        ";
1126
1127
    }
1128
1129
    /**
1130
     * Renders the alert element template.
1131
     */
1132
    public function render_alert_template( $field ) {
1133
        $restrict = $this->get_restrict_markup( $field, 'alert' );
1134
        $text     = "$field.text";
1135
        echo "
1136
            <div $restrict class='alert' :class='$field.class' role='alert'>
1137
                <span v-html='$text'></span>
1138
                <button v-if='$field.dismissible' type='button' class='close' @click.prevent=''>
1139
                    <span aria-hidden='true'>&times;</span>
1140
                </button>
1141
            </div>    
1142
        ";
1143
    }
1144
1145
    /**
1146
     * Renders the alert element template.
1147
     */
1148
    public function edit_alert_template( $field ) {
1149
        $restrict = $this->get_restrict_markup( $field, 'alert' );
1150
        $label    = __( 'Alert Text', 'invoicing' );
1151
        $label2   = esc_attr__( 'Enter your alert text here', 'invoicing' );
1152
        $id       = $field . '.id + "_edit"';
1153
        $label3   = __( 'Is Dismissible?', 'invoicing' );
1154
        $id2      = $field . '.id + "_edit2"';
1155
        $label4   = esc_attr__( 'Alert Type', 'invoicing' );
1156
        $id3      = $field . '.id + "_edit3"';
1157
        echo "
1158
            <div $restrict>
1159
                <div class='form-group'>
1160
                    <label :for='$id'>$label</label>
1161
                    <textarea placeholder='$label2' :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea>
1162
                </div>
1163
                <div class='form-group form-check'>
1164
                    <input :id='$id2' v-model='$field.dismissible' type='checkbox' class='form-check-input' />
1165
                    <label class='form-check-label' :for='$id2'>$label3</label>
1166
                </div>
1167
                <div class='form-group'>
1168
                    <label :for='$id3'>$label4</label>
1169
1170
                    <select class='form-control custom-select' :id='$id3' v-model='$field.class'>
1171
                        <option value='alert-primary'>"   . __( 'Primary', 'invoicing' ) ."</option>
1172
                        <option value='alert-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option>
1173
                        <option value='alert-success'>"   . __( 'Success', 'invoicing' ) ."</option>
1174
                        <option value='alert-danger'>"    . __( 'Danger', 'invoicing' ) ."</option>
1175
                        <option value='alert-warning'>"   . __( 'Warning', 'invoicing' ) ."</option>
1176
                        <option value='alert-info'>"      . __( 'Info', 'invoicing' ) ."</option>
1177
                        <option value='alert-light'>"     . __( 'Light', 'invoicing' ) ."</option>
1178
                        <option value='alert-dark'>"      . __( 'Dark', 'invoicing' ) ."</option>
1179
                    </select>
1180
                </div>
1181
            </div>
1182
        ";
1183
1184
    }
1185
1186
    /**
1187
     * Renders the discount element template.
1188
     */
1189
    public function render_discount_template( $field ) {
1190
        $restrict  = $this->get_restrict_markup( $field, 'discount' );
1191
        ?>
1192
1193
            <div <?php echo $restrict; ?> class="discount_field border rounded p-3 wpinv-payment-form-field-preview">
1194
                <div class='wpinv-payment-form-field-preview-overlay'></div>
1195
                <div class="discount_field_inner d-flex flex-column flex-md-row">
1196
                    <input  :placeholder="<?php echo $field ?>.input_label" class="form-control mr-2 mb-2" style="flex: 1;" type="text">
1197
                    <button class="btn btn-secondary submit-button mb-2" type="submit" @click.prevent="">{{<?php echo $field; ?>.button_label}}</button>
1198
                </div>
1199
                <small v-if='<?php echo $field ?>.description' class='form-text text-muted' v-html='<?php echo $field ?>.description'></small>
1200
            </div>
1201
1202
        <?php
1203
    }
1204
1205
    /**
1206
     * Renders the discount element template.
1207
     */
1208
    public function edit_discount_template( $field ) {
1209
        $restrict = $this->get_restrict_markup( $field, 'discount' );
1210
        $label    = __( 'Discount Input Placeholder', 'invoicing' );
1211
        $label2   = __( 'Help Text', 'invoicing' );
1212
        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1213
        $label4   = __( 'Button Text', 'invoicing' );
1214
        $id       = $field . '.id + "_edit"';
1215
        $id2      = $field . '.id + "_edit2"';
1216
        $id3      = $field . '.id + "_edit3"';
1217
        echo "
1218
            <div $restrict>
1219
                <div class='form-group'>
1220
                    <label :for='$id'>$label</label>
1221
                    <input :id='$id' v-model='$field.input_label' class='form-control' />
1222
                </div>
1223
1224
                <div class='form-group'>
1225
                    <label :for='$id2'>$label4</label>
1226
                    <input :id='$id2' v-model='$field.button_label' class='form-control' />
1227
                </div>
1228
1229
                <div class='form-group'>
1230
                    <label :for='$id3'>$label2</label>
1231
                    <textarea placeholder='$label3' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea>
1232
                </div>
1233
1234
            </div>
1235
        ";
1236
1237
    }
1238
1239
    /**
1240
     * Renders the items element template.
1241
     */
1242
    public function render_items_template( $field ) {
1243
        $restrict  = $this->get_restrict_markup( $field, 'items' );
1244
        ?>
1245
1246
        <div <?php echo $restrict; ?> class='item_totals'>
1247
            <div v-if='!is_default'>
1248
                <div v-if='! canCheckoutSeveralSubscriptions(<?php echo $field; ?>)' class='alert alert-info' role='alert'><?php _e( 'Item totals will appear here. Click to set items.', 'invoicing' ) ?></div>
1249
                <div v-if='canCheckoutSeveralSubscriptions(<?php echo $field; ?>)' class='alert alert-danger' role='alert'><?php _e( 'Your form allows customers to buy several recurring items. This is not supported and might lead to unexpected behaviour.', 'invoicing' ); ?></div>
1250
            </div>
1251
            <div v-if='is_default'>
1252
                <div class='alert alert-info' role='alert'><?php _e( 'Item totals will appear here.', 'invoicing' ) ?></div>
1253
            </div>
1254
        </div>
1255
1256
        <?php
1257
    }
1258
1259
    /**
1260
     * Renders the items element template.
1261
     */
1262
    public function edit_items_template( $field ) {
1263
        global $wpinv_euvat, $post;
1264
1265
        $restrict = $this->get_restrict_markup( $field, 'items' );
1266
        $id2      = $field . '.id + "_edit2"';
1267
        $id3      = $field . '.id + "_edit3"';
1268
1269
        // Item types.
1270
        $item_types = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post );
1271
1272
        ?>
1273
        <div <?php echo $restrict; ?>>
1274
            <div v-if="!is_default">
1275
                <label class='form-group'>
1276
                    <input v-model='<?php echo $field; ?>.hide_cart' type='checkbox' />
1277
                    <span class='form-check-label'><?php _e( 'Hide cart details', 'invoicing' ); ?></span>
1278
                </label>
1279
1280
                <div class="mb-1"><?php _e( 'Form Items', 'invoicing' ); ?></div>
1281
                <draggable v-model='form_items' group='selectable_form_items'>
1282
                    <div class='wpinv-available-items-editor' v-for='(item, index) in form_items' :class="'item_' + item.id" :key="item.id">
1283
1284
                        <div class='wpinv-available-items-editor-header' @click.prevent='togglePanel(item.id)'>
1285
                            <span class='label'>{{item.title}}</span>
1286
                            <span class='price'>({{formatPrice(item.price)}})</span>
1287
                            <span class='toggle-icon'>
1288
                                <span class='dashicons dashicons-arrow-down'></span>
1289
                                <span class='dashicons dashicons-arrow-up' style='display:none'></span>
1290
                            </span>
1291
                        </div>
1292
1293
                        <div class='wpinv-available-items-editor-body'>
1294
                            <div class='p-3'>
1295
1296
                                <div class="form-group" v-if="! item.new">
1297
                                    <span class='form-text'>
1298
                                        <a target="_blank" :href="'<?php echo esc_url( admin_url( '/post.php?action=edit&post' ) ) ?>=' + item.id">
1299
                                            <?php _e( 'Edit the item name, price and other details', 'invoicing' ); ?>
1300
                                        </a>
1301
                                    </span>
1302
                                </div>
1303
1304
                                <div class='form-group' v-if="item.new">
1305
                                    <label class='mb-0 w-100'>
1306
                                        <span><?php _e( 'Item Name', 'invoicing' ); ?></span>
1307
                                        <input v-model='item.title' type='text' class='w-100'/>
1308
                                    </label>
1309
                                </div>
1310
1311
                                <div class='form-group'  v-if="item.new">
1312
                                    <label class='mb-0 w-100'>
1313
                                        <span v-if='!item.custom_price'><?php _e( 'Item Price', 'invoicing' ); ?></span>
1314
                                        <span v-if='item.custom_price'><?php _e( 'Recommended Price', 'invoicing' ); ?></span>
1315
                                        <input v-model='item.price' type='text' class='w-100'/>
1316
                                    </label>
1317
                                </div>
1318
1319
                                <div class='form-group' v-if='item.new'>
1320
                                    <label :for="'edit_item_type' + item.id" class='mb-0 w-100'>
1321
                                        <span><?php _e( 'Item Type', 'invoicing' ); ?></span>
1322
                                        <select class='w-100' v-model='item.type'>
1323
                                            <?php
1324
                                                foreach ( $item_types as $type => $_label ) {
1325
                                                    $type  = esc_attr( $type );
1326
                                                    $_label = esc_html( $_label );
1327
                                                    echo "<option value='$type'>$_label</type>";
1328
                                                }
1329
                                            ?>
1330
                                        </select>
1331
                                    </label>
1332
                                </div>
1333
1334
                                <div v-if='item.new'>
1335
                                    <?php if ( $wpinv_euvat->allow_vat_rules() ) : ?>
1336
                                        <div class='form-group'>
1337
                                            <label class='w-100 mb-0'><?php _e( 'VAT Rule', 'invoicing' ) ; ?>
1338
                                                <select class='w-100' v-model='item.rule'>
1339
                                                    <?php
1340
                                                        foreach ( $wpinv_euvat->get_rules() as $type => $_label ) {
1341
                                                            $type  = esc_attr( $type );
1342
                                                            $_label = esc_html( $_label );
1343
                                                            echo "<option value='$type'>$_label</type>";
1344
                                                        }
1345
                                                    ?>
1346
                                                </select>
1347
                                            </label>
1348
                                        </div>
1349
                                    <?php endif;?>
1350
1351
                                    <?php if ( $wpinv_euvat->allow_vat_classes() ) : ?>
1352
                                        <div class='form-group'>
1353
                                            <label class='w-100 mb-0'><?php _e( 'VAT class', 'invoicing' ) ; ?>
1354
                                                <select class='w-100' v-model='item.class'>
1355
                                                    <?php
1356
                                                        foreach ( $wpinv_euvat->get_all_classes() as $type => $_label ) {
1357
                                                            $type  = esc_attr( $type );
1358
                                                            $_label = esc_html( $_label );
1359
                                                            echo "<option value='$type'>$_label</type>"; 
1360
                                                        }
1361
                                                    ?>
1362
                                                </select>
1363
                                            </label>
1364
                                        </div>
1365
                                    <?php endif;?>
1366
                                                        
1367
                                </div>
1368
1369
                                <label v-if='item.new' class='form-group'>
1370
                                    <input v-model='item.custom_price' type='checkbox' />
1371
                                    <span class='form-check-label'><?php _e( 'Allow users to pay what they want', 'invoicing' ); ?></span>
1372
                                </label>
1373
1374
                                <div class='form-group' v-if='item.new && item.custom_price'>
1375
                                    <label class='mb-0 w-100'>
1376
                                        <span><?php _e( 'Minimum Price', 'invoicing' ); ?></span>
1377
                                        <input placeholder='0.00' v-model='item.minimum_price' class='w-100' />
1378
                                        <small class='form-text text-muted'><?php _e( 'Enter the minimum price that a user can pay', 'invoicing' ); ?></small>
1379
                                    </label>
1380
                                </div>
1381
1382
                                <label class='form-group'>
1383
                                    <input v-model='item.allow_quantities' type='checkbox' />
1384
                                    <span><?php _e( 'Allow users to buy several quantities', 'invoicing' ); ?></span>
1385
                                </label>
1386
1387
                                <label class='form-group'>
1388
                                    <input v-model='item.required' type='checkbox' />
1389
                                    <span><?php _e( 'This item is required', 'invoicing' ); ?></span>
1390
                                </label>
1391
1392
                                <div class='form-group'>
1393
                                    <label class="mb-0 w-100">
1394
                                        <span><?php _e( 'Item Description', 'invoicing' ); ?></span>
1395
                                        <textarea v-model='item.description' class='w-100'></textarea>
1396
                                    </label>
1397
                                </div>
1398
1399
                                    <button type='button' class='button button-link button-link-delete' @click.prevent='removeItem(item)'><?php _e( 'Delete Item', 'invoicing' ); ?></button>
1400
1401
                                </div>
1402
                            </div>
1403
1404
                        </div>
1405
                </draggable>
1406
1407
                <small v-if='! form_items.length' class='form-text text-danger'><?php _e( 'You have not set up any items. Please select an item below or create a new item.', 'invoicing' ); ?></small>
1408
1409
                <div class='form-group mt-2'>
1410
1411
                    <select class='w-100' style="padding: 6px 24px 6px 8px; border-color: #e0e0e0;" v-model='selected_item' @change='addSelectedItem'>
1412
                        <option value=''><?php _e( 'Select an item to add...', 'invoicing' ) ?></option>
1413
                        <option v-for='(item, index) in all_items' :value='index'>{{item.title}}</option>
1414
                    </select>
1415
1416
                </div>
1417
1418
                <div class='form-group'>
1419
                    <button @click.prevent='addNewItem' class="button button-link"><?php _e( 'Or create a new item.', 'invoicing' ) ?></button>
1420
                </div>
1421
1422
                <div class='form-group mt-5'>
1423
                    <label :for='<?php echo $id2; ?>'><?php _e( 'Let customers...', 'invoicing' ) ?></label>
1424
1425
                    <select class='w-100' style="padding: 6px 24px 6px 8px; border-color: #e0e0e0;" :id='<?php echo $id2; ?>' v-model='<?php echo $field; ?>.items_type'>
1426
                        <option value='total' :disabled='canCheckoutSeveralSubscriptions(<?php echo $field; ?>)'><?php _e( 'Buy all items on the list', 'invoicing' ); ?></option>
1427
                        <option value='radio'><?php _e( 'Select a single item from the list', 'invoicing' ); ?></option>
1428
                        <option value='checkbox' :disabled='canCheckoutSeveralSubscriptions(<?php echo $field; ?>)'><?php _e( 'Select one or more items on the list', 'invoicing' ) ;?></option>
1429
                        <option value='select'><?php _e( 'Select a single item from a dropdown', 'invoicing' ); ?></option>
1430
                    </select>
1431
1432
                </div>
1433
            </div>
1434
            <div class='form-group'>
1435
                <label :for='<?php echo $id3; ?>'><?php _e( 'Help Text', 'invoicing' ); ?></label>
1436
                <textarea placeholder='<?php esc_attr_e( 'Add some help text for this element', 'invoicing' ); ?>' :id='<?php echo $id3; ?>' v-model='<?php echo $field; ?>.description' class='form-control' rows='3'></textarea>
1437
            </div>
1438
1439
        </div>
1440
1441
        <?php
1442
1443
    }
1444
1445
    /**
1446
     * Returns an array of all published items.
1447
     */
1448
    public function get_published_items() {
1449
1450
        $item_args = array(
1451
            'post_type'      => 'wpi_item',
1452
            'orderby'        => 'title',
1453
            'order'          => 'ASC',
1454
            'posts_per_page' => -1,
1455
            'post_status'    => array( 'publish' ),
1456
            'meta_query'     => array(
1457
                array(
1458
                    'key'       => '_wpinv_type',
1459
                    'compare'   => '!=',
1460
                    'value'     => 'package'
1461
                )
1462
            )
1463
        );
1464
1465
        $items = get_posts( apply_filters( 'getpaid_payment_form_item_dropdown_query_args', $item_args ) );
1466
1467
        if ( empty( $items ) ) {
1468
            return array();
1469
        }
1470
1471
        $options    = array();
1472
        foreach ( $items as $item ) {
1473
            $item      = new GetPaid_Form_Item( $item );
1474
            $options[] = $item->prepare_data_for_use();
1475
        }
1476
        return $options;
1477
1478
    }
1479
1480
    /**
1481
     * Returns an array of items for the currently being edited form.
1482
     */
1483
    public function get_form_items( $id = false ) {
1484
        $form = new GetPaid_Payment_Form( $id );
1485
1486
        // Is this a default form?
1487
        if ( $form->is_default() ) {
1488
            return array();
1489
        }
1490
1491
        return $form->get_items( 'view', 'arrays' );
1492
    }
1493
1494
    /**
1495
     * Converts form items for use.
1496
     */
1497
    public function convert_checkout_items( $items, $invoice ) {
1498
1499
        $converted = array();
1500
        foreach ( $items as $item ) {
1501
1502
            $item_id = $item['id'];
1503
            $_item   = new WPInv_Item( $item_id );
1504
1505
            if( ! $_item ) {
1506
                continue;
1507
            }
1508
1509
            $converted[] = array(
1510
                'title'            => esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $_item ),
1511
                'id'               => $item['id'],
1512
                'price'            => $item['subtotal'],
1513
                'custom_price'     => $_item->get_is_dynamic_pricing(),
1514
                'recurring'        => $_item->is_recurring(),
1515
                'description'      => apply_filters( 'wpinv_checkout_cart_line_item_summary', '', $item, $_item, $invoice ),
1516
                'minimum_price'    => $_item->get_minimum_price(),
1517
                'allow_quantities' => false,
1518
                'quantity'         => $item['quantity'],
1519
                'required'         => true,
1520
            );
1521
        }
1522
        return $converted;
1523
1524
    }
1525
1526
    /**
1527
     * Converts an array of id => quantity for use.
1528
     */
1529
    public function convert_normal_items( $items ) {
1530
1531
        $converted = array();
1532
        foreach ( $items as $item_id => $quantity ) {
1533
1534
            $item   = new WPInv_Item( $item_id );
1535
1536
            if( ! $item ) {
1537
                continue;
1538
            }
1539
1540
            $converted[] = array(
1541
                'title'            => esc_html( $item->get_name() ) . wpinv_get_item_suffix( $item ),
1542
                'id'               => $item_id,
1543
                'price'            => $item->get_price(),
1544
                'custom_price'     => $item->get_is_dynamic_pricing(),
1545
                'recurring'        => $item->is_recurring(),
1546
                'description'      => $item->get_summary(),
1547
                'minimum_price'    => $item->get_minimum_price(),
1548
                'allow_quantities' => ! empty( $quantity ),
1549
                'quantity'         => empty( $quantity ) ? 1 : $quantity,
1550
                'required'         => true,
1551
            );
1552
1553
        }
1554
1555
        return $converted;
1556
1557
    }
1558
1559
    /**
1560
     * Returns an array of elements for the currently being edited form.
1561
     */
1562
    public function get_form_elements( $id = false ) {
1563
1564
        if ( empty( $id ) ) {
1565
            return wpinv_get_data( 'sample-payment-form' );
1566
        }
1567
        
1568
        $form_elements = get_post_meta( $id, 'wpinv_form_elements', true );
1569
1570
        if ( is_array( $form_elements ) ) {
1571
            return $form_elements;
1572
        }
1573
1574
        return wpinv_get_data( 'sample-payment-form' );
1575
    }
1576
1577
}
1578