This repository has been archived by the owner on Jan 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
/
class-gf-field-repeater-end.php
116 lines (94 loc) · 4.72 KB
/
class-gf-field-repeater-end.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
class GF_Field_Repeater_End extends GF_Field {
public $type = 'repeater-end';
public static function init_admin() {
$admin_page = rgget('page');
if ($admin_page == 'gf_edit_forms' && !empty($_GET['id'])) {
add_action('gform_field_standard_settings' , array('GF_Field_Repeater_End', 'gform_standard_settings'), 10, 2);
add_action('gform_field_appearance_settings' , array('GF_Field_Repeater_End', 'gform_appearance_settings'), 10, 2);
add_action('gform_editor_js', array('GF_Field_Repeater_End', 'gform_editor'));
add_filter('gform_tooltips', array('GF_Field_Repeater_End', 'gform_tooltips'));
}
}
public function get_form_editor_field_title() {
return 'Repeater End';
}
public function get_form_editor_field_settings() {
return apply_filters('gform_editor_repeater_end_field_settings',
array(
'css_class_setting'
)
);
}
public function add_button($field_groups) {
return $field_groups;
}
public static function gform_standard_settings($position, $form_id) {
if ($position == 1600) {
echo "<li class=\"repeater_end_settings field_setting\">
<label for=\"field_repeater_end_add\">Add HTML ";
gform_tooltip('form_field_repeater_end_add');
echo " </label>
<input type=\"text\" id=\"field_repeater_end_add\" class=\"fieldwidth-3\" size=\"35\" onchange=\"SetFieldProperty('add', this.value);\">
</li>";
echo "<li class=\"repeater_end_settings field_setting\">
<label for=\"field_repeater_end_remove\">Remove HTML ";
gform_tooltip('form_field_repeater_end_remove');
echo " </label>
<input type=\"text\" id=\"field_repeater_end_remove\" class=\"fieldwidth-3\" size=\"35\" onchange=\"SetFieldProperty('remove', this.value);\">
</li>";
}
}
public static function gform_appearance_settings($position, $form_id) {
if ($position == 400) {
echo "<li class=\"repeater_end_settings field_setting\">
<input type=\"checkbox\" id=\"field_repeater_end_hideButtons\" onchange=\"SetFieldProperty('hideButtons', this.checked);\">
<label for=\"field_repeater_end_hideButtons\" class=\"inline\">Hide Add & Remove buttons ";
gform_tooltip('form_field_repeater_end_hideButtons');
echo " </label>
</li>";
}
}
public static function gform_editor() {
echo "<script type=\"text/javascript\">
fieldSettings['repeater-end'] += ', .repeater_end_settings';
jQuery(document).bind('gform_load_field_settings', function(event, field, form){
jQuery('#field_repeater_end_add').val(field['add']);
jQuery('#field_repeater_end_remove').val(field['remove']);
jQuery('#field_repeater_end_hideButtons').prop('checked', field['hideButtons']);
});
</script>";
}
public static function gform_tooltips($tooltips) {
$tooltips['form_field_repeater_end_add'] = __( "The HTML to replace the default add button. This HTML will be placed inside of a span tag with the class 'gf_repeater_add'.", 'gravityformsrepeater' );
$tooltips['form_field_repeater_end_remove'] = __( "The HTML to replace the default remove button. This HTML will be placed inside of a span tag with the class 'gf_repeater_remove'.", 'gravityformsrepeater' );
$tooltips['form_field_repeater_end_hideButtons'] = __( "If enabled, no add and remove buttons will be displayed. This is useful if you plan on using custom javascript to trigger the repeater.", 'gravityformsrepeater' );
return $tooltips;
}
public function get_field_content($value, $force_frontend_label, $form) {
if (is_admin()) {
$admin_buttons = $this->get_admin_buttons();
$field_content = "{$admin_buttons}
<div class=\"gf-pagebreak-end gf-pagebreak-container gf-repeater-end\">
<div class=\"gf-pagebreak-text-before\">end repeater</div>
<div class=\"gf-pagebreak-text-main\"><span>REPEATER</span></div>
<div class=\"gf-pagebreak-text-after\">end of repeater</div>
</div>";
} else {
$add_html = $this->add;
$remove_html = $this->remove;
$hideButtons = $this->hideButtons;
$tabindex = GFCommon::get_tabindex();
if (empty($add_html)) { $add_html = "<img class=\"gf_repeater_add_default\" alt=\"+\" src=\"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\">"; }
if (empty($remove_html)) { $remove_html = "<img class=\"gf_repeater_remove_default\" alt=\"-\" src=\"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\">"; }
$field_content = "<div class=\"ginput_container ginput_container_repeater-end\">\n";
if (!$hideButtons) {
$field_content .= "<span class=\"gf_repeater_remove\" {$tabindex}>{$remove_html}</span>";
$field_content .= "<span class=\"gf_repeater_add\" {$tabindex}>{$add_html}</span>";
}
$field_content .= "</div>";
}
return $field_content;
}
}
GF_Fields::register(new GF_Field_Repeater_End());