Skip to content

Commit

Permalink
Merge pull request #3 from DiscipleTools/master
Browse files Browse the repository at this point in the history
Getting the updated changes
  • Loading branch information
mikeallbutt committed Jun 3, 2019
2 parents 310dc94 + c0d0401 commit 2b8d210
Show file tree
Hide file tree
Showing 55 changed files with 7,853 additions and 6,885 deletions.
30 changes: 30 additions & 0 deletions archive-template.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);

( function () {
$post_type = dt_get_url_path();
if ( !current_user_can( 'access_' . $post_type ) ) {
wp_safe_redirect( '/settings' );
}

get_header();
?>

<div id="content">
<div id="inner-content" class="grid-x grid-margin-x">
<aside class="large-3 cell padding-bottom show-for-large">
<div class="bordered-box js-pane-filters">
<?php /* Javascript may move .js-filters-modal-content to this location. */ ?>
</div>
</aside>
<main id="main" class="large-9 cell padding-bottom" role="main">
<div class="bordered-box">
<div id="table-content">
</div>
</main>
</div>
</div>

<?php
get_footer();
} )();
33 changes: 23 additions & 10 deletions dt-assets/functions/enqueue-scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,18 @@ function dt_site_scripts() {
dt_theme_enqueue_script( 'typeahead-jquery', 'dt-core/dependencies/typeahead/dist/jquery.typeahead.min.js', array( 'jquery' ), true );
dt_theme_enqueue_style( 'typeahead-jquery-css', 'dt-core/dependencies/typeahead/dist/jquery.typeahead.min.css', array() );

if ( is_singular( "contacts" ) || is_singular( "groups" ) ) {
$post_types = apply_filters( 'dt_registered_post_types', [ 'contacts', 'groups' ] );
if ( is_singular( $post_types ) ) {
$post_type = get_post_type();
if ( is_singular( "contacts" )){
$post = Disciple_Tools_Contacts::get_contact( get_the_ID(), true, true );
} else {
} elseif ( is_singular( "groups" ) ){
$post = Disciple_Tools_Groups::get_group( get_the_ID(), true, true );
} else {
$post = DT_Posts::get_post( get_post_type(), get_the_ID() );
}
if ( !is_wp_error( $post )){
$post_settings = apply_filters( "dt_get_post_type_settings", [], $post_type );
dt_theme_enqueue_script( 'jquery-mentions', 'dt-core/dependencies/jquery-mentions-input/jquery.mentionsInput.min.js', array( 'jquery' ), true );
dt_theme_enqueue_script( 'jquery-mentions-elastic', 'dt-core/dependencies/jquery-mentions-input/lib/jquery.elastic.min.js', array( 'jquery' ), true );
dt_theme_enqueue_style( 'jquery-mentions-css', 'dt-core/dependencies/jquery-mentions-input/jquery.mentionsInput.css', array() );
Expand All @@ -160,24 +164,27 @@ function dt_site_scripts() {
],
'current_user_id' => get_current_user_id(),
'additional_sections' => apply_filters( 'dt_comments_additional_sections', [], $post_type ),
'comments' => Disciple_Tools_Posts::get_post_comments( $post_type, $post["ID"], true ),
'activity' => $post_type === 'contacts' ? Disciple_Tools_Contacts::get_activity( $post["ID"] ) : Disciple_Tools_Groups::get_activity( $post["ID"] )
'comments' => DT_Posts::get_post_comments( $post_type, $post["ID"] ),
'activity' => DT_Posts::get_post_activity( $post_type, $post["ID"] )
]
);
dt_theme_enqueue_script( 'details', 'dt-assets/js/details.js', array(
'jquery',
'lodash'
'lodash',
'shared-functions',
) );
wp_localize_script( 'details', 'detailsSettings', [
'post_type' => $post_type,
'post_id' => get_the_ID()
'post_id' => get_the_ID(),
'post_settings' => $post_settings,
'current_user_id' => get_current_user_id(),
'post_fields' => $post
]);


$translations = [
"not-set" => [
"source" => __( 'No source set', 'disciple_tools' ),
"locations" => __( 'No location set', 'disciple_tools' ),
"geonames" => __( 'No location set', 'disciple_tools' ),
"leaders" => __( 'No leaders set', 'disciple_tools' ),
"people_groups" => __( 'No people group set', 'disciple_tools' ),
Expand Down Expand Up @@ -220,9 +227,7 @@ function dt_site_scripts() {
'custom_data' => apply_filters( 'dt_contacts_js_data', [] ), // nest associated array
)
);

}
if ( is_singular( "groups" ) ) {
} elseif ( is_singular( "groups" ) ) {
dt_theme_enqueue_script( 'group-details', 'dt-assets/js/group-details.js', array(
'jquery',
'lodash',
Expand Down Expand Up @@ -323,6 +328,14 @@ function dt_site_scripts() {
'translations' => apply_filters( 'dt_list_js_translations', $translations ),
'custom_data' => apply_filters( 'dt_list_js_data', [] ), // nest associated array
) );
} elseif ( in_array( $url_path, $post_types ) ){
$post_type = $url_path;
$post_settings = apply_filters( "dt_get_post_type_settings", [], $post_type );
dt_theme_enqueue_script( 'modular-list-js', 'dt-assets/js/modular-list.js', array( 'jquery', 'lodash', 'shared-functions', 'typeahead-jquery', 'site-js' ), true );
wp_localize_script( 'modular-list-js', 'listSettings', array(
'post_type' => $post_type,
'post_type_settings' => $post_settings,
) );
}

add_action( 'wp_footer', function() {
Expand Down
22 changes: 12 additions & 10 deletions dt-assets/js/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ jQuery(document).ready(function($) {
let commentPostedEvent = document.createEvent('Event');
commentPostedEvent.initEvent('comment_posted', true, true);

let postId = $("#post-id").text()
let postType = $("#post-type").text()
let postId = window.detailsSettings.post_id
let postType = window.detailsSettings.post_type
let rest_api = window.API

let comments = []
let activity = [] // not guaranteed to be in any particular order
Expand All @@ -17,11 +18,12 @@ jQuery(document).ready(function($) {
commentButton.toggleClass('loading')
commentInput.attr("disabled", true)
commentButton.attr("disabled", true)
API.post_comment(postType, postId, _.escape(comment_plain_text)).then(data => {
rest_api.post_comment(postType, postId, _.escape(comment_plain_text)).then(data => {
let updated_comment = data.comment || data
commentInput.val("").trigger( "change" )
commentButton.toggleClass('loading')
data.comment.date = moment(data.comment.comment_date_gmt + "Z")
comments.push(data.comment)
updated_comment.date = moment(updated_comment.comment_date_gmt + "Z")
comments.push(updated_comment)
display_activity_comment()
// fire comment posted event
$('#content')[0].dispatchEvent(commentPostedEvent);
Expand Down Expand Up @@ -136,7 +138,7 @@ jQuery(document).ready(function($) {
$('#confirm-comment-delete').on("click", function () {
let id = $(this).data("id")
$(this).toggleClass('loading')
API.delete_comment( postType, postId, id ).then(response=>{
rest_api.delete_comment( postType, postId, id ).then(response=>{
$(this).toggleClass('loading')
if (response){
$('#delete-comment-modal').foundation('close')
Expand Down Expand Up @@ -171,9 +173,9 @@ jQuery(document).ready(function($) {
$(this).toggleClass('loading')
let id = $(this).data("id")
let updated_comment = $('#comment-to-edit').val()
API.update_comment( postType, postId, id, updated_comment).then((response)=>{
rest_api.update_comment( postType, postId, id, updated_comment).then((response)=>{
$(this).toggleClass('loading')
if (response === 1 || response === 0){
if (response === 1 || response === 0 || response.comment_ID){
$('#edit-comment-modal').foundation('close')
} else {
$('.edit-comment.callout').show()
Expand Down Expand Up @@ -333,8 +335,8 @@ jQuery(document).ready(function($) {
getActivityPromise.abort()
getCommentsPromise.abort()
}
getCommentsPromise = API.get_comments(postType, postId)
getActivityPromise = API.get_activity(postType, postId)
getCommentsPromise = rest_api.get_comments(postType, postId)
getActivityPromise = rest_api.get_activity(postType, postId)
getAllPromise = $.when(
getCommentsPromise,
getActivityPromise
Expand Down
56 changes: 23 additions & 33 deletions dt-assets/js/contact-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function save_quick_action(contactId, fieldKey){
let numberIndicator = jQuery("." + fieldKey + " span")
let newNumber = parseInt(numberIndicator.first().text() || "0" ) + 1
data[fieldKey] = newNumber
API.save_field_api("contact", contactId, data)
API.update_post('contacts', contactId, data)
.then(data=>{
console.log("updated " + fieldKey + " to: " + newNumber)
if (fieldKey.indexOf("quick_button")>-1){
Expand Down Expand Up @@ -111,7 +111,7 @@ jQuery(document).ready(function($) {
}
return `<span>${_.escape(item.name)}</span>`
},
source: TYPEAHEADS.typeaheadSource('groups', 'dt/v1/groups/compact/'),
source: TYPEAHEADS.typeaheadSource('groups', 'dt-posts/v2/groups/compact/'),
display: "name",
templateValue: "{{name}}",
dynamic: true,
Expand All @@ -123,7 +123,7 @@ jQuery(document).ready(function($) {
})
}, callback: {
onCancel: function (node, item) {
API.save_field_api('contact', contactId, {groups: {values:[{value:item.ID, delete:true}]}})
API.update_post('contacts', contactId, {groups: {values:[{value:item.ID, delete:true}]}})
}
},
href: function(item){
Expand All @@ -138,7 +138,7 @@ jQuery(document).ready(function($) {
event.preventDefault();
$('#create-group-modal').foundation('open');
} else {
API.save_field_api('contact', contactId, {groups: {values:[{value:item.ID}]}})
API.update_post('contacts', contactId, {groups: {values:[{value:item.ID}]}})
this.addMultiselectItemLayout(item)
event.preventDefault()
this.hideLayout();
Expand Down Expand Up @@ -170,7 +170,7 @@ jQuery(document).ready(function($) {
$(".js-create-group").on("submit", function(e) {
e.preventDefault();
let title = $("#create-group-modal .js-create-group input[name=title]").val()
API.create_group({title,created_from_contact_id:contactId})
API.create_post('groups', {title, members: {values: [{value: contactId}]}})
.then((newGroup)=>{
$(".reveal-after-group-create").show()
$("#new-group-link").html(`<a href="${_.escape( newGroup.permalink )}">${_.escape(title)}</a>`)
Expand Down Expand Up @@ -198,7 +198,7 @@ jQuery(document).ready(function($) {
data: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
dataType: "json",
url: contactsDetailsWpApiSettings.root + 'dt/v1/contact/' + contactId + "/accept",
url: contactsDetailsWpApiSettings.root + 'dt-posts/v2/contacts/' + contactId + "/accept",
beforeSend: function(xhr) {
xhr.setRequestHeader('X-WP-Nonce', contactsDetailsWpApiSettings.nonce);
}
Expand Down Expand Up @@ -453,7 +453,7 @@ jQuery(document).ready(function($) {
emptyTemplate: 'No users found "{{query}}"',
callback: {
onClick: function(node, a, item){
API.save_field_api('contact', contactId, {assigned_to: 'user-' + item.ID}).then(function (response) {
API.update_post('contacts', contactId, {assigned_to: 'user-' + item.ID}).then(function (response) {
_.set(contact, "assigned_to", response.assigned_to)
setStatus(response)
assigned_to_input.val(contact.assigned_to.display)
Expand Down Expand Up @@ -482,16 +482,6 @@ jQuery(document).ready(function($) {
assigned_to_input.focus()
})

/**
* Share
*/
let shareTypeahead = null
$('.open-share').on("click", function(){
$('#share-contact-modal').foundation('open');
if (!shareTypeahead) {
shareTypeahead = TYPEAHEADS.share("contact", contactId)
}
})


/**
Expand Down Expand Up @@ -520,7 +510,7 @@ jQuery(document).ready(function($) {
})
}, callback: {
onCancel: function (node, item) {
API.save_field_api('contact', contactId, {[field_id]: {values:[{value:item.ID, delete:true}]}}).then(()=>{
API.update_post('contacts', contactId, {[field_id]: {values:[{value:item.ID, delete:true}]}}).then(()=>{
if(field_id === "subassigned"){
$(`.${field_id}-list .${item.ID}`).remove()
let listItems = $(`.${field_id}-list li`)
Expand All @@ -536,7 +526,7 @@ jQuery(document).ready(function($) {
},
callback: {
onClick: function(node, a, item, event){
API.save_field_api('contact', contactId, {[field_id]: {values:[{"value":item.ID}]}}).then((addedItem)=>{
API.update_post('contacts', contactId, {[field_id]: {values:[{"value":item.ID}]}}).then((addedItem)=>{
if (field_id === "baptized_by"){
openBaptismModal(addedItem)
}
Expand Down Expand Up @@ -581,7 +571,7 @@ jQuery(document).ready(function($) {
tags: {
display: ["name"],
ajax: {
url: contactsDetailsWpApiSettings.root + 'dt/v1/contact/multi-select-options',
url: contactsDetailsWpApiSettings.root + 'dt-posts/v2/contacts/multi-select-values',
data: {
s: "{{query}}",
field: "tags"
Expand Down Expand Up @@ -610,13 +600,13 @@ jQuery(document).ready(function($) {
})
}, callback: {
onCancel: function (node, item) {
API.save_field_api('contact', contactId, {'tags': {values:[{value:item.name, delete:true}]}})
API.update_post('contacts', contactId, {'tags': {values:[{value:item.name, delete:true}]}})
}
}
},
callback: {
onClick: function(node, a, item, event){
API.save_field_api('contact', contactId, {tags: {values:[{value:item.name}]}})
API.update_post('contacts', contactId, {tags: {values:[{value:item.name}]}})
this.addMultiselectItemLayout(item)
event.preventDefault()
this.hideLayout();
Expand All @@ -641,7 +631,7 @@ jQuery(document).ready(function($) {
$("#create-tag-return").on("click", function () {
let tag = $("#new-tag").val()
Typeahead['.js-typeahead-tags'].addMultiselectItemLayout({name:tag})
API.save_field_api('contact', contactId, {tags: {values:[{value:tag}]}})
API.update_post('contacts', contactId, {tags: {values:[{value:tag}]}})

})

Expand Down Expand Up @@ -737,13 +727,13 @@ jQuery(document).ready(function($) {
*/
$('#update-needed.dt-switch').change(function () {
let updateNeeded = $(this).is(':checked')
API.save_field_api( "contact", contactId, {"requires_update":updateNeeded}).then(resp=>{
API.update_post('contacts', contactId, {"requires_update":updateNeeded}).then(resp=>{
contact = resp
})
})
$('#content')[0].addEventListener('comment_posted', function (e) {
if ( _.get(contact, "requires_update") === true ){
API.get_post("contact", contactId ).then(resp=>{
API.get_post("contacts", contactId ).then(resp=>{
contact = resp
contactUpdated(_.get(resp, "requires_update") === true )
}).catch(err => { console.error(err) })
Expand All @@ -755,7 +745,7 @@ jQuery(document).ready(function($) {
*/
$('.make-active').on('click', function () {
let data = {overall_status:"active"}
API.save_field_api('contact', contactId, data).then((contact)=>{
API.update_post('contacts', contactId, data).then((contact)=>{
setStatus(contact)
}).catch(err => { console.error(err) })
})
Expand Down Expand Up @@ -802,7 +792,7 @@ jQuery(document).ready(function($) {
$(this).toggleClass('loading')
let data = {overall_status:field}
data[`reason_${field}`] = select.val()
API.save_field_api('contact', contactId, data).then(contactData=>{
API.update_post('contacts', contactId, data).then(contactData=>{
$(this).toggleClass('loading')
$(`#${field}-contact-modal`).foundation('close')
setStatus(contactData)
Expand Down Expand Up @@ -1013,7 +1003,7 @@ jQuery(document).ready(function($) {
editFieldsUpdate[`contact_${channelType}`].values.push({value:val})
}
})
API.save_field_api( "contact", contactId, editFieldsUpdate).then((updatedContact)=>{
API.update_post('contacts', contactId, editFieldsUpdate).then((updatedContact)=>{
contact = updatedContact
$(this).toggleClass("loading")
resetDetailsFields(contact)
Expand Down Expand Up @@ -1162,7 +1152,7 @@ jQuery(document).ready(function($) {
let numberIndicator = $(`span.${fieldKey}`)
let newNumber = parseInt(numberIndicator.first().text() || "0" ) + 1
data[fieldKey] = newNumber
API.save_field_api("contact", contactId, data)
API.update_post('contacts', contactId, data)
.then(data=>{
console.log(data);
console.log("updated " + fieldKey + " to: " + newNumber)
Expand Down Expand Up @@ -1320,7 +1310,7 @@ jQuery(document).ready(function($) {
modalBaptismDatePicker.datepicker({
dateFormat: 'yy-mm-dd',
onSelect: function (date) {
API.save_field_api('contact', contactId, { baptism_date: date }).catch(handleAjaxError)
API.update_post('contacts', contactId, { baptism_date: date }).catch(handleAjaxError)
},
changeMonth: true,
changeYear: true
Expand Down Expand Up @@ -1352,15 +1342,15 @@ jQuery(document).ready(function($) {
})
}, callback: {
onCancel: function (node, item) {
API.save_field_api('contact', contactId, {"baptized_by": {values:[{value:item.ID, delete:true}]}})
API.update_post('contacts', contactId, {"baptized_by": {values:[{value:item.ID, delete:true}]}})
.catch(err => { console.error(err) })
}
},
href: _.escape( window.wpApiShare.site_url ) + "/contacts/{{ID}}"
},
callback: {
onClick: function (node, a, item) {
API.save_field_api('contact', contactId, {"baptized_by": {values:[{"value":item.ID}]}})
API.update_post('contacts', contactId, {"baptized_by": {values:[{"value":item.ID}]}})
.catch(err => { console.error(err) })
console.log(item);
this.addMultiselectItemLayout(item)
Expand Down Expand Up @@ -1390,7 +1380,7 @@ jQuery(document).ready(function($) {
})
$('#modal-baptism_generation').change(function () {
console.log($(this).val());
API.save_field_api( "contact", contactId, {
API.update_post('contacts', contactId, {
baptism_generation: $(this).val(),
fixed_baptism_generation: true
})
Expand Down
Loading

0 comments on commit 2b8d210

Please sign in to comment.