forked from DiscipleTools/disciple-tools-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate-groups-new.php
83 lines (71 loc) · 3.94 KB
/
template-groups-new.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
<?php
declare(strict_types=1);
if ( ! current_user_can( 'create_groups' ) ) {
wp_die( esc_html( "You do not have permission to publish groups" ), "Permission denied", 403 );
}
get_header();
$group_fields = Disciple_Tools_Groups_Post_Type::instance()->get_custom_fields_settings();
?>
<div id="content" class="template-groups-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-group bordered-box">
<h3 class="section-header"><?php esc_html_e( "Create New Group", "disciple_tools" ); ?><button class="help-button float-right" data-section="new-group-help-text">
<img class="help-icon" src="<?php echo esc_html( get_template_directory_uri() . '/dt-assets/images/help.svg' ) ?>"/>
</button></h3>
<label for="title">
<img src="<?php echo esc_url( get_template_directory_uri() ) . '/dt-assets/images/name.svg' ?>">
<?php esc_html_e( "Name of Group", "disciple_tools" ); ?>
<button class="help-button" data-section="group-name-help-text">
<img class="help-icon" src="<?php echo esc_html( get_template_directory_uri() . '/dt-assets/images/help.svg' ) ?>"/>
</button>
</label>
<input name="title" type="text" placeholder="<?php echo esc_html_x( "Name", 'input field placeholder', 'disciple_tools' ); ?>" required aria-describedby="name-help-text">
<p class="help-text" id="name-help-text"><?php esc_html_e( "This is required", "disciple_tools" ); ?></p>
<div class="section-subheader">
<?php echo esc_html( $group_fields["group_type"]["name"] ) ?>
<button class="help-button" data-section="group-type-help-text">
<img class="help-icon" src="<?php echo esc_html( get_template_directory_uri() . '/dt-assets/images/help.svg' ) ?>"/>
</button>
</div>
<select class="select-field" id="group_type" name="group_name">
<?php
foreach ($group_fields["group_type"]["default"] as $key => $option){ ?>
<option value="<?php echo esc_html( $key ) ?>"><?php echo esc_html( $option["label"] ?? "" ); ?></option>
<?php } ?>
</select>
<div style="text-align: center">
<a href="<?php echo esc_html( get_site_url() . "/groups/" )?>" class="button small clear"><?php echo esc_html__( 'Cancel', 'disciple_tools' )?></a>
<button class="button loader js-create-group-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 class="large-2 medium-12 small-12 cell"></div>
</div>
</div>
<script>jQuery(function($) {
$('input:enabled:visible:first').focus();
$(".js-create-group-button").removeAttr("disabled");
$(".js-create-group").on("submit", function() {
$(".js-create-group-button")
.attr("disabled", true)
.addClass("loading");
API.create_post( 'groups', {
title: $(".js-create-group input[name=title]").val(),
group_type: $(`.js-create-group #group_type`).val()
})
.then(function(data) {
window.location = data.permalink;
}).catch(function(error) {
$(".js-create-group-button").removeClass("loading").addClass("alert");
$(".js-create-group").append(
$("<div>").html(error.responseText)
);
console.error(error);
});
return false;
});
});</script>
<?php
get_footer();