Total Complexity | 42 |
Total Lines | 1099 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Complex classes like WPInv_Payment_Form_Elements often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use WPInv_Payment_Form_Elements, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
7 | class WPInv_Payment_Form_Elements { |
||
8 | |||
9 | /** |
||
10 | * @param array payment form elements |
||
11 | */ |
||
12 | protected $elements; |
||
13 | |||
14 | public function __construct() { |
||
25 | } |
||
26 | |||
27 | } |
||
28 | |||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Returns all the elements that can be added to a form. |
||
33 | */ |
||
34 | public function get_elements() { |
||
232 | } |
||
233 | |||
234 | /** |
||
235 | * Returns the restrict markup. |
||
236 | */ |
||
237 | public function get_restrict_markup( $field, $field_type ) { |
||
238 | $restrict = "$field.type=='$field_type'"; |
||
239 | return "v-if=\"$restrict\""; |
||
240 | } |
||
241 | |||
242 | /** |
||
243 | * Renders the title element template. |
||
244 | */ |
||
245 | public function render_heading_template( $field ) { |
||
246 | $restrict = $this->get_restrict_markup( $field, 'heading' ); |
||
247 | echo "<component :is='$field.level' $restrict v-html='$field.text'></component>"; |
||
248 | } |
||
249 | |||
250 | /** |
||
251 | * Renders the edit title element template. |
||
252 | */ |
||
253 | public function edit_heading_template( $field ) { |
||
254 | $restrict = $this->get_restrict_markup( $field, 'heading' ); |
||
255 | $label = __( 'Heading', 'invoicing' ); |
||
256 | $label2 = __( 'Select Heading Level', 'invoicing' ); |
||
257 | $id = $field . '.id + "_edit"'; |
||
258 | $id2 = $field . '.id + "_edit2"'; |
||
259 | |||
260 | echo " |
||
261 | <div $restrict> |
||
262 | <div class='form-group'> |
||
263 | <label :for='$id'>$label</label> |
||
264 | <input class='form-control' :id='$id' v-model='$field.text' type='text' /> |
||
265 | </div> |
||
266 | |||
267 | <div class='form-group'> |
||
268 | <label :for='$id2'>$label2</label> |
||
269 | |||
270 | <select class='form-control custom-select' :id='$id2' v-model='$field.level'> |
||
271 | <option value='h1'>H1</option> |
||
272 | <option value='h2'>H2</option> |
||
273 | <option value='h3'>H3</option> |
||
274 | <option value='h4'>H4</option> |
||
275 | <option value='h5'>H5</option> |
||
276 | <option value='h6'>H6</option> |
||
277 | <option value='h7'>H7</option> |
||
278 | </select> |
||
279 | </div> |
||
280 | </div> |
||
281 | "; |
||
282 | |||
283 | } |
||
284 | |||
285 | /** |
||
286 | * Renders a paragraph element template. |
||
287 | */ |
||
288 | public function render_paragraph_template( $field ) { |
||
289 | $restrict = $this->get_restrict_markup( $field, 'paragraph' ); |
||
290 | $label = "$field.text"; |
||
291 | echo "<p $restrict v-html='$label' style='font-size: 16px;'></p>"; |
||
292 | } |
||
293 | |||
294 | /** |
||
295 | * Renders the edit paragraph element template. |
||
296 | */ |
||
297 | public function edit_paragraph_template( $field ) { |
||
298 | $restrict = $this->get_restrict_markup( $field, 'paragraph' ); |
||
299 | $label = __( 'Enter your text', 'invoicing' ); |
||
300 | $id = $field . '.id + "_edit"'; |
||
301 | echo " |
||
302 | <div $restrict> |
||
303 | <div class='form-group'> |
||
304 | <label :for='$id'>$label</label> |
||
305 | <textarea :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea> |
||
306 | </div> |
||
307 | </div> |
||
308 | "; |
||
309 | |||
310 | } |
||
311 | |||
312 | /** |
||
313 | * Renders the text element template. |
||
314 | */ |
||
315 | public function render_text_template( $field ) { |
||
316 | $restrict = $this->get_restrict_markup( $field, 'text' ); |
||
317 | $label = "$field.label"; |
||
318 | echo " |
||
319 | <div $restrict> |
||
320 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
321 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='text'> |
||
322 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
323 | </div> |
||
324 | "; |
||
325 | } |
||
326 | |||
327 | /** |
||
328 | * Renders the edit text element template. |
||
329 | */ |
||
330 | public function edit_text_template( $field ) { |
||
331 | $restrict = $this->get_restrict_markup( $field, 'text' ); |
||
332 | $label = __( 'Field Label', 'invoicing' ); |
||
333 | $id = $field . '.id + "_edit"'; |
||
334 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
335 | $id2 = $field . '.id + "_edit2"'; |
||
336 | $label3 = __( 'Help text', 'invoicing' ); |
||
337 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
338 | $id3 = $field . '.id + "_edit3"'; |
||
339 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
340 | $id4 = $field . '.id + "_edit4"'; |
||
341 | echo " |
||
342 | <div $restrict> |
||
343 | <div class='form-group'> |
||
344 | <label :for='$id'>$label</label> |
||
345 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
346 | </div> |
||
347 | <div class='form-group'> |
||
348 | <label :for='$id2'>$label2</label> |
||
349 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
350 | </div> |
||
351 | <div class='form-group'> |
||
352 | <label :for='$id3'>$label3</label> |
||
353 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
354 | </div> |
||
355 | <div class='form-group form-check'> |
||
356 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
357 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
358 | </div> |
||
359 | </div> |
||
360 | "; |
||
361 | |||
362 | } |
||
363 | |||
364 | /** |
||
365 | * Renders the textarea element template. |
||
366 | */ |
||
367 | public function render_textarea_template( $field ) { |
||
368 | $restrict = $this->get_restrict_markup( $field, 'textarea' ); |
||
369 | $label = "$field.label"; |
||
370 | echo " |
||
371 | <div $restrict> |
||
372 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
373 | <textarea :placeholder='$field.placeholder' :id='$field.id' class='form-control' rows='3'></textarea> |
||
374 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
375 | </div> |
||
376 | "; |
||
377 | } |
||
378 | |||
379 | /** |
||
380 | * Renders the edit textarea element template. |
||
381 | */ |
||
382 | public function edit_textarea_template( $field ) { |
||
383 | $restrict = $this->get_restrict_markup( $field, 'textarea' ); |
||
384 | $label = __( 'Field Label', 'invoicing' ); |
||
385 | $id = $field . '.id + "_edit"'; |
||
386 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
387 | $id2 = $field . '.id + "_edit2"'; |
||
388 | $label3 = __( 'Help text', 'invoicing' ); |
||
389 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
390 | $id3 = $field . '.id + "_edit3"'; |
||
391 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
392 | $id4 = $field . '.id + "_edit4"'; |
||
393 | echo " |
||
394 | <div $restrict> |
||
395 | <div class='form-group'> |
||
396 | <label :for='$id'>$label</label> |
||
397 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
398 | </div> |
||
399 | <div class='form-group'> |
||
400 | <label :for='$id2'>$label2</label> |
||
401 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
402 | </div> |
||
403 | <div class='form-group'> |
||
404 | <label :for='$id3'>$label3</label> |
||
405 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
406 | </div> |
||
407 | <div class='form-group form-check'> |
||
408 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
409 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
410 | </div> |
||
411 | </div> |
||
412 | "; |
||
413 | |||
414 | } |
||
415 | |||
416 | /** |
||
417 | * Renders the select element template. |
||
418 | */ |
||
419 | public function render_select_template( $field ) { |
||
420 | $restrict = $this->get_restrict_markup( $field, 'select' ); |
||
421 | $label = "$field.label"; |
||
422 | $placeholder = "$field.placeholder"; |
||
423 | $id = $field . '.id'; |
||
424 | echo " |
||
425 | <div $restrict> |
||
426 | <label :for='$id'>{{" . $label . "}}</label> |
||
427 | <select id='$id' class='form-control custom-select' v-model='$field.value'> |
||
428 | <option v-if='$placeholder' value='' disabled>{{" . $placeholder . "}}</option> |
||
429 | <option v-for='option in $field.options' value='option'>{{option}}</option> |
||
430 | </select> |
||
431 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
432 | </div> |
||
433 | "; |
||
434 | } |
||
435 | |||
436 | /** |
||
437 | * Renders the edit select element template. |
||
438 | */ |
||
439 | public function edit_select_template( $field ) { |
||
440 | $restrict = $this->get_restrict_markup( $field, 'select' ); |
||
441 | $label = __( 'Field Label', 'invoicing' ); |
||
442 | $id = $field . '.id + "_edit"'; |
||
443 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
444 | $id2 = $field . '.id + "_edit2"'; |
||
445 | $label3 = __( 'Help text', 'invoicing' ); |
||
446 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
447 | $id3 = $field . '.id + "_edit3"'; |
||
448 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
449 | $id4 = $field . '.id + "_edit4"'; |
||
450 | $label6 = __( 'Available Options', 'invoicing' ); |
||
451 | echo " |
||
452 | <div $restrict> |
||
453 | <div class='form-group'> |
||
454 | <label :for='$id'>$label</label> |
||
455 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
456 | </div> |
||
457 | <div class='form-group'> |
||
458 | <label :for='$id2'>$label2</label> |
||
459 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
460 | </div> |
||
461 | <div class='form-group'> |
||
462 | <label :for='$id3'>$label3</label> |
||
463 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
464 | </div> |
||
465 | <div class='form-group form-check'> |
||
466 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
467 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
468 | </div> |
||
469 | <hr class='featurette-divider mt-4'> |
||
470 | <h5>$label6</h5> |
||
471 | <div class='form-group input-group' v-for='(option, index) in $field.options'> |
||
472 | <input type='text' class='form-control' v-model='$field.options[index]'> |
||
473 | <div class='input-group-append'> |
||
474 | <button class='btn btn-outline-secondary' type='button' @click.prevent='$field.options.splice(index, 1)'><span class='dashicons dashicons-trash'></span></button> |
||
475 | </div> |
||
476 | </div> |
||
477 | <div class='form-group'> |
||
478 | <button class='btn btn-outline-secondary' type='button' @click.prevent='$field.options.push(\"\")'>Add Option</button> |
||
479 | </div> |
||
480 | </div> |
||
481 | "; |
||
482 | |||
483 | } |
||
484 | |||
485 | /** |
||
486 | * Renders the checkbox element template. |
||
487 | */ |
||
488 | public function render_checkbox_template( $field ) { |
||
489 | $restrict = $this->get_restrict_markup( $field, 'checkbox' ); |
||
490 | $label = "$field.label"; |
||
491 | echo " |
||
492 | <div class='form-check' $restrict> |
||
493 | <input :id='$field.id' class='form-check-input' type='checkbox' /> |
||
494 | <label class='form-check-label' :for='$field.id'>{{" . $label . "}}</label> |
||
495 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
496 | </div> |
||
497 | "; |
||
498 | } |
||
499 | |||
500 | /** |
||
501 | * Renders the edit checkbox element template. |
||
502 | */ |
||
503 | public function edit_checkbox_template( $field ) { |
||
525 | </div> |
||
526 | </div> |
||
527 | "; |
||
528 | |||
529 | } |
||
530 | |||
531 | /** |
||
532 | * Renders the radio element template. |
||
533 | */ |
||
534 | public function render_radio_template( $field ) { |
||
535 | $restrict = $this->get_restrict_markup( $field, 'radio' ); |
||
536 | $label = "$field.label"; |
||
537 | $id = $field . '.id'; |
||
538 | echo " |
||
539 | <div $restrict> |
||
540 | <legend class='col-form-label' v-if='$label'>{{" . $label . "}}</legend> |
||
541 | <div class='form-check' v-for='(option, index) in $field.options'> |
||
542 | <input class='form-check-input' type='radio' :id='$id + index'> |
||
543 | <label class='form-check-label' :for='$id + index'>{{option}}</label> |
||
544 | </div> |
||
545 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
546 | </div> |
||
547 | "; |
||
548 | } |
||
549 | |||
550 | /** |
||
551 | * Renders the edit radio element template. |
||
552 | */ |
||
553 | public function edit_radio_template( $field ) { |
||
554 | $restrict = $this->get_restrict_markup( $field, 'radio' ); |
||
555 | $label = __( 'Field Label', 'invoicing' ); |
||
556 | $id = $field . '.id + "_edit"'; |
||
557 | $label2 = __( 'Help text', 'invoicing' ); |
||
558 | $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
559 | $id2 = $field . '.id + "_edit3"'; |
||
560 | $label4 = __( 'Is this field required?', 'invoicing' ); |
||
561 | $id3 = $field . '.id + "_edit4"'; |
||
562 | $label5 = __( 'Available Options', 'invoicing' ); |
||
563 | echo " |
||
564 | <div $restrict> |
||
565 | <div class='form-group'> |
||
566 | <label :for='$id'>$label</label> |
||
567 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
568 | </div> |
||
569 | <div class='form-group'> |
||
570 | <label :for='$id2'>$label2</label> |
||
571 | <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
572 | </div> |
||
573 | <div class='form-group form-check'> |
||
574 | <input :id='$id3' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
575 | <label class='form-check-label' :for='$id3'>$label4</label> |
||
576 | </div> |
||
577 | <hr class='featurette-divider mt-4'> |
||
578 | <h5>$label5</h5> |
||
579 | <div class='form-group input-group' v-for='(option, index) in $field.options'> |
||
580 | <input type='text' class='form-control' v-model='$field.options[index]'> |
||
581 | <div class='input-group-append'> |
||
582 | <button class='btn btn-outline-secondary' type='button' @click.prevent='$field.options.splice(index, 1)'><span class='dashicons dashicons-trash'></span></button> |
||
583 | </div> |
||
584 | </div> |
||
585 | <div class='form-group'> |
||
586 | <button class='btn btn-outline-secondary' type='button' @click.prevent='$field.options.push(\"\")'>Add Option</button> |
||
587 | </div> |
||
588 | </div> |
||
589 | "; |
||
590 | |||
591 | } |
||
592 | |||
593 | /** |
||
594 | * Renders the email element template. |
||
595 | */ |
||
596 | public function render_email_template( $field ) { |
||
597 | $restrict = $this->get_restrict_markup( $field, 'email' ); |
||
598 | $label = "$field.label"; |
||
599 | echo " |
||
600 | <div $restrict> |
||
601 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
602 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='email'> |
||
603 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
604 | </div> |
||
605 | "; |
||
606 | } |
||
607 | |||
608 | /** |
||
609 | * Renders the edit email element template. |
||
610 | */ |
||
611 | public function edit_email_template( $field ) { |
||
612 | $restrict = $this->get_restrict_markup( $field, 'email' ); |
||
613 | $label = __( 'Field Label', 'invoicing' ); |
||
614 | $id = $field . '.id + "_edit"'; |
||
615 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
616 | $id2 = $field . '.id + "_edit2"'; |
||
617 | $label3 = __( 'Help text', 'invoicing' ); |
||
618 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
619 | $id3 = $field . '.id + "_edit3"'; |
||
620 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
621 | $id4 = $field . '.id + "_edit4"'; |
||
622 | echo " |
||
623 | <div $restrict> |
||
624 | <div class='form-group'> |
||
625 | <label :for='$id'>$label</label> |
||
626 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
627 | </div> |
||
628 | <div class='form-group'> |
||
629 | <label :for='$id2'>$label2</label> |
||
630 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
631 | </div> |
||
632 | <div class='form-group'> |
||
633 | <label :for='$id3'>$label3</label> |
||
634 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
635 | </div> |
||
636 | <div class='form-group form-check'> |
||
637 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
638 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
639 | </div> |
||
640 | </div> |
||
641 | "; |
||
642 | |||
643 | } |
||
644 | |||
645 | /** |
||
646 | * Renders the website element template. |
||
647 | */ |
||
648 | public function render_website_template( $field ) { |
||
649 | $restrict = $this->get_restrict_markup( $field, 'website' ); |
||
650 | $label = "$field.label"; |
||
651 | echo " |
||
652 | <div $restrict> |
||
653 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
654 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='url'> |
||
655 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
656 | </div> |
||
657 | "; |
||
658 | } |
||
659 | |||
660 | /** |
||
661 | * Renders the edit website element template. |
||
662 | */ |
||
663 | public function edit_website_template( $field ) { |
||
664 | $restrict = $this->get_restrict_markup( $field, 'website' ); |
||
665 | $label = __( 'Field Label', 'invoicing' ); |
||
666 | $id = $field . '.id + "_edit"'; |
||
667 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
668 | $id2 = $field . '.id + "_edit2"'; |
||
669 | $label3 = __( 'Help text', 'invoicing' ); |
||
670 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
671 | $id3 = $field . '.id + "_edit3"'; |
||
672 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
673 | $id4 = $field . '.id + "_edit4"'; |
||
674 | echo " |
||
675 | <div $restrict> |
||
676 | <div class='form-group'> |
||
677 | <label :for='$id'>$label</label> |
||
678 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
679 | </div> |
||
680 | <div class='form-group'> |
||
681 | <label :for='$id2'>$label2</label> |
||
682 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
683 | </div> |
||
684 | <div class='form-group'> |
||
685 | <label :for='$id3'>$label3</label> |
||
686 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
687 | </div> |
||
688 | <div class='form-group form-check'> |
||
689 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
690 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
691 | </div> |
||
692 | </div> |
||
693 | "; |
||
694 | |||
695 | } |
||
696 | |||
697 | /** |
||
698 | * Renders the date element template. |
||
699 | */ |
||
700 | public function render_date_template( $field ) { |
||
701 | $restrict = $this->get_restrict_markup( $field, 'date' ); |
||
702 | $label = "$field.label"; |
||
703 | echo " |
||
704 | <div $restrict> |
||
705 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
706 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='date'> |
||
707 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
708 | </div> |
||
709 | "; |
||
710 | } |
||
711 | |||
712 | /** |
||
713 | * Renders the edit date element template. |
||
714 | */ |
||
715 | public function edit_date_template( $field ) { |
||
716 | $restrict = $this->get_restrict_markup( $field, 'date' ); |
||
717 | $label = __( 'Field Label', 'invoicing' ); |
||
718 | $id = $field . '.id + "_edit"'; |
||
719 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
720 | $id2 = $field . '.id + "_edit2"'; |
||
721 | $label3 = __( 'Help text', 'invoicing' ); |
||
722 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
723 | $id3 = $field . '.id + "_edit3"'; |
||
724 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
725 | $id4 = $field . '.id + "_edit4"'; |
||
726 | echo " |
||
727 | <div $restrict> |
||
728 | <div class='form-group'> |
||
729 | <label :for='$id'>$label</label> |
||
730 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
731 | </div> |
||
732 | <div class='form-group'> |
||
733 | <label :for='$id2'>$label2</label> |
||
734 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
735 | </div> |
||
736 | <div class='form-group'> |
||
737 | <label :for='$id3'>$label3</label> |
||
738 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
739 | </div> |
||
740 | <div class='form-group form-check'> |
||
741 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
742 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
743 | </div> |
||
744 | </div> |
||
745 | "; |
||
746 | |||
747 | } |
||
748 | |||
749 | /** |
||
750 | * Renders the time element template. |
||
751 | */ |
||
752 | public function render_time_template( $field ) { |
||
760 | </div> |
||
761 | "; |
||
762 | } |
||
763 | |||
764 | /** |
||
765 | * Renders the edit time element template. |
||
766 | */ |
||
767 | public function edit_time_template( $field ) { |
||
768 | $restrict = $this->get_restrict_markup( $field, 'time' ); |
||
769 | $label = __( 'Field Label', 'invoicing' ); |
||
770 | $id = $field . '.id + "_edit"'; |
||
771 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
772 | $id2 = $field . '.id + "_edit2"'; |
||
773 | $label3 = __( 'Help text', 'invoicing' ); |
||
774 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
775 | $id3 = $field . '.id + "_edit3"'; |
||
776 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
777 | $id4 = $field . '.id + "_edit4"'; |
||
778 | echo " |
||
779 | <div $restrict> |
||
780 | <div class='form-group'> |
||
781 | <label :for='$id'>$label</label> |
||
782 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
783 | </div> |
||
784 | <div class='form-group'> |
||
785 | <label :for='$id2'>$label2</label> |
||
786 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
787 | </div> |
||
788 | <div class='form-group'> |
||
789 | <label :for='$id3'>$label3</label> |
||
790 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
791 | </div> |
||
792 | <div class='form-group form-check'> |
||
793 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
794 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
795 | </div> |
||
796 | </div> |
||
797 | "; |
||
798 | |||
799 | } |
||
800 | |||
801 | /** |
||
802 | * Renders the number element template. |
||
803 | */ |
||
804 | public function render_number_template( $field ) { |
||
805 | $restrict = $this->get_restrict_markup( $field, 'number' ); |
||
806 | $label = "$field.label"; |
||
807 | echo " |
||
808 | <div $restrict> |
||
809 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
810 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='number'> |
||
811 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
812 | </div> |
||
813 | "; |
||
814 | } |
||
815 | |||
816 | /** |
||
817 | * Renders the edit number element template. |
||
818 | */ |
||
819 | public function edit_number_template( $field ) { |
||
820 | $restrict = $this->get_restrict_markup( $field, 'number' ); |
||
821 | $label = __( 'Field Label', 'invoicing' ); |
||
822 | $id = $field . '.id + "_edit"'; |
||
823 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
824 | $id2 = $field . '.id + "_edit2"'; |
||
825 | $label3 = __( 'Help text', 'invoicing' ); |
||
826 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
827 | $id3 = $field . '.id + "_edit3"'; |
||
828 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
829 | $id4 = $field . '.id + "_edit4"'; |
||
830 | echo " |
||
831 | <div $restrict> |
||
832 | <div class='form-group'> |
||
833 | <label :for='$id'>$label</label> |
||
834 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
835 | </div> |
||
836 | <div class='form-group'> |
||
837 | <label :for='$id2'>$label2</label> |
||
838 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
839 | </div> |
||
840 | <div class='form-group'> |
||
841 | <label :for='$id3'>$label3</label> |
||
842 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
843 | </div> |
||
844 | <div class='form-group form-check'> |
||
845 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
846 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
847 | </div> |
||
848 | </div> |
||
849 | "; |
||
850 | |||
851 | } |
||
852 | |||
853 | /** |
||
854 | * Renders the pay button element template. |
||
855 | */ |
||
856 | public function render_pay_button_template( $field ) { |
||
857 | $restrict = $this->get_restrict_markup( $field, 'pay_button' ); |
||
858 | $label = "$field.label"; |
||
859 | echo " |
||
860 | <div $restrict> |
||
861 | <button class='form-control btn submit-button' :class='$field.class' type='submit' @click.prevent=''>{{" . $label . "}}</button> |
||
862 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
863 | </div> |
||
864 | "; |
||
865 | } |
||
866 | |||
867 | /** |
||
868 | * Renders the pay button element template. |
||
869 | */ |
||
870 | public function edit_pay_button_template( $field ) { |
||
871 | $restrict = $this->get_restrict_markup( $field, 'pay_button' ); |
||
872 | $label = __( 'Button Text', 'invoicing' ); |
||
873 | $id = $field . '.id + "_edit"'; |
||
874 | $label2 = __( 'Help text', 'invoicing' ); |
||
875 | $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
876 | $id2 = $field . '.id + "_edit2"'; |
||
877 | $label4 = esc_attr__( 'Button Type', 'invoicing' ); |
||
878 | $id3 = $field . '.id + "_edit3"'; |
||
879 | echo " |
||
880 | <div $restrict> |
||
881 | <div class='form-group'> |
||
882 | <label :for='$id'>$label</label> |
||
883 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
884 | </div> |
||
885 | <div class='form-group'> |
||
886 | <label :for='$id2'>$label2</label> |
||
887 | <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
888 | </div> |
||
889 | <div class='form-group'> |
||
890 | <label :for='$id3'>$label4</label> |
||
891 | |||
892 | <select class='form-control custom-select' :id='$id3' v-model='$field.class'> |
||
893 | <option value='btn-primary'>" . __( 'Primary', 'invoicing' ) ."</option> |
||
894 | <option value='btn-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option> |
||
895 | <option value='btn-success'>" . __( 'Success', 'invoicing' ) ."</option> |
||
896 | <option value='btn-danger'>" . __( 'Danger', 'invoicing' ) ."</option> |
||
897 | <option value='btn-warning'>" . __( 'Warning', 'invoicing' ) ."</option> |
||
898 | <option value='btn-info'>" . __( 'Info', 'invoicing' ) ."</option> |
||
899 | <option value='btn-light'>" . __( 'Light', 'invoicing' ) ."</option> |
||
900 | <option value='btn-dark'>" . __( 'Dark', 'invoicing' ) ."</option> |
||
901 | <option value='btn-link'>" . __( 'Link', 'invoicing' ) ."</option> |
||
902 | </select> |
||
903 | </div> |
||
904 | </div> |
||
905 | "; |
||
906 | |||
907 | } |
||
908 | |||
909 | /** |
||
910 | * Renders the alert element template. |
||
911 | */ |
||
912 | public function render_alert_template( $field ) { |
||
913 | $restrict = $this->get_restrict_markup( $field, 'alert' ); |
||
914 | $text = "$field.text"; |
||
915 | echo " |
||
916 | <div $restrict class='alert' :class='$field.class' role='alert'> |
||
917 | <span v-html='$text'></span> |
||
918 | <button v-if='$field.dismissible' type='button' class='close' @click.prevent=''> |
||
919 | <span aria-hidden='true'>×</span> |
||
920 | </button> |
||
921 | </div> |
||
922 | "; |
||
923 | } |
||
924 | |||
925 | /** |
||
926 | * Renders the alert element template. |
||
927 | */ |
||
928 | public function edit_alert_template( $field ) { |
||
929 | $restrict = $this->get_restrict_markup( $field, 'alert' ); |
||
930 | $label = __( 'Alert Text', 'invoicing' ); |
||
931 | $label2 = esc_attr__( 'Enter your alert text here', 'invoicing' ); |
||
932 | $id = $field . '.id + "_edit"'; |
||
933 | $label3 = __( 'Is Dismissible?', 'invoicing' ); |
||
934 | $id2 = $field . '.id + "_edit2"'; |
||
935 | $label4 = esc_attr__( 'Alert Type', 'invoicing' ); |
||
936 | $id3 = $field . '.id + "_edit3"'; |
||
937 | echo " |
||
938 | <div $restrict> |
||
939 | <div class='form-group'> |
||
940 | <label :for='$id'>$label</label> |
||
941 | <textarea placeholder='$label2' :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea> |
||
942 | </div> |
||
943 | <div class='form-group form-check'> |
||
944 | <input :id='$id2' v-model='$field.dismissible' type='checkbox' class='form-check-input' /> |
||
945 | <label class='form-check-label' :for='$id2'>$label3</label> |
||
946 | </div> |
||
947 | <div class='form-group'> |
||
948 | <label :for='$id3'>$label4</label> |
||
949 | |||
950 | <select class='form-control custom-select' :id='$id3' v-model='$field.class'> |
||
951 | <option value='alert-primary'>" . __( 'Primary', 'invoicing' ) ."</option> |
||
952 | <option value='alert-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option> |
||
953 | <option value='alert-success'>" . __( 'Success', 'invoicing' ) ."</option> |
||
954 | <option value='alert-danger'>" . __( 'Danger', 'invoicing' ) ."</option> |
||
955 | <option value='alert-warning'>" . __( 'Warning', 'invoicing' ) ."</option> |
||
956 | <option value='alert-info'>" . __( 'Info', 'invoicing' ) ."</option> |
||
957 | <option value='alert-light'>" . __( 'Light', 'invoicing' ) ."</option> |
||
958 | <option value='alert-dark'>" . __( 'Dark', 'invoicing' ) ."</option> |
||
959 | </select> |
||
960 | </div> |
||
961 | </div> |
||
962 | "; |
||
963 | |||
964 | } |
||
965 | |||
966 | /** |
||
967 | * Renders the discount element template. |
||
968 | */ |
||
969 | public function render_discount_templates( $field ) { |
||
978 | </div> |
||
979 | "; |
||
980 | } |
||
981 | |||
982 | /** |
||
983 | * Renders the discount element template. |
||
984 | */ |
||
985 | public function edit_discount_template( $field ) { |
||
986 | $restrict = $this->get_restrict_markup( $field, 'discount' ); |
||
987 | $label = __( 'Discount Input Placeholder', 'invoicing' ); |
||
988 | $label2 = __( 'Help Text', 'invoicing' ); |
||
989 | $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
990 | $label4 = __( 'Button Text', 'invoicing' ); |
||
991 | $id = $field . '.id + "_edit"'; |
||
992 | $id2 = $field . '.id + "_edit2"'; |
||
993 | $id3 = $field . '.id + "_edit3"'; |
||
994 | echo " |
||
995 | <div $restrict> |
||
996 | <div class='form-group'> |
||
997 | <label :for='$id'>$label</label> |
||
998 | <input :id='$id' v-model='$field.input_label' class='form-control' /> |
||
999 | </div> |
||
1000 | |||
1001 | <div class='form-group'> |
||
1002 | <label :for='$id2'>$label4</label> |
||
1003 | <input :id='$id2' v-model='$field.button_label' class='form-control' /> |
||
1004 | </div> |
||
1005 | |||
1006 | <div class='form-group'> |
||
1007 | <label :for='$id3'>$label2</label> |
||
1008 | <textarea placeholder='$label3' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
1009 | </div> |
||
1010 | |||
1011 | </div> |
||
1012 | "; |
||
1013 | |||
1014 | } |
||
1015 | |||
1016 | /** |
||
1017 | * Renders the items element template. |
||
1018 | */ |
||
1019 | public function render_items_template( $field ) { |
||
1040 | |||
1041 | <pre> |
||
1042 | // TODO: Ask admin to select which items he/she |
||
1043 | // wants to sell via this form |
||
1044 | |||
1045 | // TODO:- Let admin set whether they want customers to select some items, |
||
1046 | // a single item( use case variations), or be tied to all items ( i.e |
||
1047 | // Only display the totals) |
||
1048 | </pre> |
||
1049 | </div> |
||
1050 | "; |
||
1051 | } |
||
1052 | |||
1053 | /** |
||
1054 | * Renders the items element template. |
||
1055 | */ |
||
1056 | public function edit_items_template( $field ) { |
||
1057 | $restrict = $this->get_restrict_markup( $field, 'items' ); |
||
1058 | $label = __( 'Items Type', 'invoicing' ); |
||
1069 | |||
1070 | <pre> |
||
1071 | {{items}} |
||
1072 | </pre> |
||
1073 | |||
1074 | </div> |
||
1075 | "; |
||
1076 | |||
1077 | } |
||
1078 | |||
1079 | public function get_published_items() { |
||
1106 | |||
1107 | } |
||
1110 |