forked from DiscipleTools/disciple-tools-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate-contacts-new.php
More file actions
278 lines (251 loc) · 14.3 KB
/
template-contacts-new.php
File metadata and controls
278 lines (251 loc) · 14.3 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<?php
declare(strict_types=1);
if ( ! current_user_can( 'create_contacts' ) ) {
wp_die( esc_html( "You do not have permission to publish contacts" ), "Permission denied", 403 );
}
get_header();
( function() {
$contact_fields = Disciple_Tools_Contact_Post_Type::instance()->get_custom_fields_settings();
?>
<div id="content" class="template-contacts-new">
<div id="inner-content" class="grid-x grid-margin-x">
<div class="large-2 medium-12 small-12 cell"></div>
<div class="large-8 medium-12 small-12 cell">
<form class="js-create-contact bordered-box" style="margin-bottom:200px">
<h3 class="section-header"><?php esc_html_e( "Create New Contact", "disciple_tools" ); ?><button class="help-button float-right" data-section="new-contact-help-text">
<img class="help-icon" src="<?php echo esc_html( get_template_directory_uri() . '/dt-assets/images/help.svg' ) ?>"/>
</button></h3>
<label for="name-field">
<img src="<?php echo esc_url( get_template_directory_uri() ) . '/dt-assets/images/name.svg' ?>">
<?php esc_html_e( "Name of Contact", "disciple_tools" ); ?>
<button class="help-button" type="button" data-section="contact-name-help-text">
<img class="help-icon" src="<?php echo esc_html( get_template_directory_uri() . '/dt-assets/images/help.svg' ) ?>"/>
</button>
<input id="name-field" name="title" type="text" placeholder="<?php echo esc_html_x( "Name", 'input field placeholder', 'disciple_tools' ); ?>" required dir="auto" aria-describedby="name-help-text">
</label>
<p class="help-text" id="name-help-text"><?php esc_html_e( "This is required", "disciple_tools" ); ?></p>
<label for="tel-input">
<img src="<?php echo esc_url( get_template_directory_uri() ) . '/dt-assets/images/phone.svg' ?>">
<?php esc_html_e( "Phone number", "disciple_tools" ); ?>
<button class="help-button" type="button" data-section="phone-help-text">
<img class="help-icon" src="<?php echo esc_html( get_template_directory_uri() . '/dt-assets/images/help.svg' ) ?>"/>
</button>
<input id="tel-input" name="phone" type="tel" placeholder="<?php esc_html_e( "Phone number", 'disciple_tools' ); ?>">
</label>
<label for="email-input">
<img src="<?php echo esc_url( get_template_directory_uri() ) . '/dt-assets/images/email.svg' ?>">
<?php esc_html_e( "Email", "disciple_tools" ); ?>
<button class="help-button" type="button" data-section="email-help-text">
<img class="help-icon" src="<?php echo esc_html( get_template_directory_uri() . '/dt-assets/images/help.svg' ) ?>"/>
</button>
<input id="email-input" name="email" type="text" placeholder="<?php esc_html_e( "Email", "disciple_tools" ); ?>">
</label>
<?php if ( DT_Mapbox_API::get_key() ) :
DT_Mapbox_API::load_mapbox_header_scripts();
DT_Mapbox_API::load_mapbox_search_widget();
DT_Mapbox_API::mapbox_search_widget_css();
?>
<!-- Locations -->
<label for="location-input">
<img src="<?php echo esc_url( get_template_directory_uri() ) . '/dt-assets/images/location.svg' ?>">
<?php echo esc_html( $contact_fields["location_grid"]["name"] ) ?>
<button class="help-button" type="button" data-section="location-help-text">
<img class="help-icon" src="<?php echo esc_html( get_template_directory_uri() . '/dt-assets/images/help.svg' ) ?>"/>
</button>
</label>
<div class="grid-x">
<div id="mapbox-wrapper" class="cell">
<div id="mapbox-autocomplete" class="mapbox-autocomplete input-group" data-autosubmit="false">
<input id="mapbox-search" type="text" name="mapbox_search" placeholder="Search Location" />
<div class="input-group-button">
<button class="button hollow" id="mapbox-spinner-button" style="display:none;"><img src="<?php echo esc_url( get_stylesheet_directory_uri() ) ?>/spinner.svg" alt="spinner" style="width: 18px;" /></button>
</div>
<div id="mapbox-autocomplete-list" class="mapbox-autocomplete-items"></div>
</div>
</div>
</div>
<script>
jQuery(document).ready(function() {
write_input_widget()
})
</script>
<?php else : ?>
<!-- Locations -->
<label for="location-input">
<img src="<?php echo esc_url( get_template_directory_uri() ) . '/dt-assets/images/location.svg' ?>">
<?php echo esc_html( $contact_fields["location_grid"]["name"] ) ?>
<button class="help-button" type="button" data-section="location-help-text">
<img class="help-icon" src="<?php echo esc_html( get_template_directory_uri() . '/dt-assets/images/help.svg' ) ?>"/>
</button>
<div class="location_grid">
<var id="location_grid-result-container" class="result-container"></var>
<div id="location_grid_t" name="form-location_grid" class="scrollable-typeahead typeahead-margin-when-active">
<div class="typeahead__container">
<div class="typeahead__field">
<span class="typeahead__query">
<input id="location-input" class="js-typeahead-location_grid input-height"
name="location_grid[query]"
placeholder="<?php echo esc_html( sprintf( _x( "Search %s", "Search 'something'", 'disciple_tools' ), $contact_fields["location_grid"]["name"] ) )?>"
autocomplete="off">
</span>
</div>
</div>
</div>
</div>
</label>
<?php endif; ?>
<label for="source-input">
<img src="<?php echo esc_url( get_template_directory_uri() ) . '/dt-assets/images/source.svg' ?>">
<?php echo esc_html( $contact_fields["sources"]["name"] ) ?>
<button class="help-button" type="button" data-section="source-help-text">
<img class="help-icon" src="<?php echo esc_html( get_template_directory_uri() . '/dt-assets/images/help.svg' ) ?>"/>
</button>
<select for="source-input" name="sources" aria-describedby="source-help-text">
<?php
$contacts_settings = apply_filters( "dt_get_post_type_settings", [], "contacts" );
$sources = $contacts_settings["fields"]["sources"]["default"];
foreach ( $sources as $source_key => $source ): ?>
<?php if ( !isset( $source["deleted"] ) || $source["delete"] !== true ) : ?>
<option value="<?php echo esc_attr( $source_key, 'disciple_tools' ); ?>">
<?php echo esc_html( $source['label'] )?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</label>
<label for="comment-input">
<?php esc_html_e( "Initial Comment", "disciple_tools" ); ?>
<button class="help-button" type="button" data-section="initial-comment-help-text">
<img class="help-icon" src="<?php echo esc_html( get_template_directory_uri() . '/dt-assets/images/help.svg' ) ?>"/>
</button>
<textarea id="comment-input" name="initial_comment" dir="auto" placeholder="<?php esc_html_e( "Initial Comment", "disciple_tools" ); ?>"></textarea>
</label>
<div style="text-align: center">
<a href="<?php echo esc_html( get_site_url() . "/contacts/" )?>" class="button small clear"><?php echo esc_html__( 'Cancel', 'disciple_tools' )?></a>
<button class="button loader js-create-contact-button dt-green" type="submit" disabled title="<?php esc_html_e( 'Save and continue editing', 'disciple_tools' )?>"><?php esc_html_e( "Save and continue editing", "disciple_tools" ); ?></button>
</div>
</form>
</div>
</div> <!-- inner content -->
<div class="large-2 medium-12 small-12 cell"></div>
</div>
<script>jQuery(function($) {
$('input:enabled:visible:first').focus();
$(".js-create-contact-button").removeAttr("disabled");
let selectedLocations = []
$(".js-create-contact").on("submit", function(event) {
event.preventDefault();
$(".js-create-contact-button")
.attr("disabled", true)
.addClass("loading");
let source = $(".js-create-contact select[name=sources]").val()
let data = {
title: $(".js-create-contact input[name=title]").val(),
contact_phone: [{value:$(".js-create-contact input[name=phone]").val()}],
contact_email: [{value:$(".js-create-contact input[name=email]").val()}],
sources: {values:[{value:source || "personal"}]},
initial_comment: $(".js-create-contact textarea[name=initial_comment]").val()
}
if ( typeof dtMapbox === 'undefined' ) {
data['location_grid'] = { values:selectedLocations.map(i=>{return {value:i}}) }
} else {
if ( typeof window.selected_location_grid_meta !== 'undefined' && typeof window.selected_location_grid_meta.location_grid_meta !== 'undefined' ) {
data['location_grid_meta'] = window.selected_location_grid_meta.location_grid_meta
}
}
API.create_post( 'contacts', data ).then(function(data) {
window.location = data.permalink;
}).catch(function(error) {
$(".js-create-contact-button").removeClass("loading").addClass("alert");
$(".js-create-contact").append(
$("<div>").html(error.responseText)
);
console.error(error);
});
return false;
});
/**
* Locations
*/
if ( typeof dtMapbox === 'undefined' ) {
typeaheadTotals = {}
$.typeahead({
input: '.js-typeahead-location_grid',
minLength: 0,
accent: true,
searchOnFocus: true,
maxItem: 20,
dropdownFilter: [{
key: 'group',
value: 'focus',
template: _.escape(window.wpApiShare.translations.regions_of_focus),
all: _.escape(window.wpApiShare.translations.all_locations),
}],
source: {
focus: {
display: "name",
ajax: {
url: wpApiShare.root + 'dt/v1/mapping_module/search_location_grid_by_name',
data: {
s: "{{query}}",
filter: function () {
return _.get(window.Typeahead['.js-typeahead-location_grid'].filters.dropdown, 'value', 'all')
}
},
beforeSend: function (xhr) {
xhr.setRequestHeader('X-WP-Nonce', wpApiShare.nonce);
},
callback: {
done: function (data) {
if (typeof typeaheadTotals !== "undefined") {
typeaheadTotals.field = data.total
}
return data.location_grid
}
}
}
}
},
display: "name",
templateValue: "{{name}}",
dynamic: true,
multiselect: {
matchOn: ["ID"],
data: [],
callback: {
onCancel: function (node, item) {
_.pull(selectedLocations, item.ID)
}
}
},
callback: {
onClick: function(node, a, item, event){
selectedLocations.push(item.ID)
this.addMultiselectItemLayout(item)
event.preventDefault()
this.hideLayout();
this.resetInput();
},
onReady(){
this.filters.dropdown = {key: "group", value: "focus", template: _.escape(window.wpApiShare.translations.regions_of_focus)}
this.container
.removeClass("filter")
.find("." + this.options.selector.filterButton)
.html(_.escape(window.wpApiShare.translations.regions_of_focus));
},
onResult: function (node, query, result, resultCount) {
resultCount = typeaheadTotals.location_grid
let text = TYPEAHEADS.typeaheadHelpText(resultCount, query, result)
$('#location_grid-result-container').html(text);
},
onHideLayout: function () {
$('#location_grid-result-container').html("");
}
}
});
}
});
</script>
<?php
} )();
get_footer();