Browse Source

Add resource types setting

develop^2
Sam Black 1 year ago
parent
commit
79ee12f316
Signed by: samwwwblack GPG Key ID: 0FF0223994EA47D8
  1. 51
      admin/class-bespokomatic-ebs-admin.php
  2. 7
      includes/booked/Pages/Admin/ManageResourceTypesPage.php
  3. 1
      includes/booked/Web/scripts/admin/resource-types.js
  4. 16
      includes/booked/tpl/Admin/Resources/manage_resource_types.tpl
  5. 21
      includes/class-bespokomatic-ebs.php

51
admin/class-bespokomatic-ebs-admin.php

@ -372,6 +372,55 @@ class Bespokomatic_Ebs_Admin {
return new reflectionClass( 'ManageResourceGroupsActions' );
}
/**
* Admin resource types
*/
public function admin_resources_types() {
$this->define_root_dir();
require_once BESPOKOMATIC_EBS_BOOKED_PATH . 'Pages/Admin/ManageResourceTypesPage.php';
require_once BESPOKOMATIC_EBS_BOOKED_PATH . 'Presenters/Admin/ManageResourceTypesPresenter.php';
// TODO: This should use WordPress role settings, for now assume admin
//$page = new RoleRestrictedPageDecorator(new ManageResourceTypesPage(), array(RoleLevel::APPLICATION_ADMIN, RoleLevel::SCHEDULE_ADMIN, RoleLevel::RESOURCE_ADMIN));
$page = new ManageResourceTypesPage();
return $page;
}
/**
* Admin resources types page POST
*
* @since 0.1
*/
public function post_admin_resources_types() {
$page = $this->admin_resources_types();
$page->PageLoad();
}
/**
* Admin resources types AJAX
*
* @since 0.1
*/
public function ajax_admin_resources_types() {
// booked's ActionPage understands `action=`, so remove WordPress's one
unset( $_GET['action'] );
$page = $this->admin_resources_types();
$page->PageLoad();
wp_die();
}
/**
* Admin resource types POST endpoints
*
* @since 0.1
*/
public function admin_resource_types_post_endpoints() {
$this->define_root_dir();
require_once BESPOKOMATIC_EBS_BOOKED_PATH . 'Presenters/Admin/ManageResourceTypesPresenter.php';
return new reflectionClass( 'ManageResourceTypesActions' );
}
/**
* Admin resource statuses
*/
@ -398,7 +447,7 @@ class Bespokomatic_Ebs_Admin {
}
/**
* Admin resources status AJAX POST
* Admin resources status AJAX
*
* @since 0.1
*/

7
includes/booked/Pages/Admin/ManageResourceTypesPage.php

@ -84,6 +84,13 @@ class ManageResourceTypesPage extends ActionPage implements IManageResourceTypes
->GetUserSession(),
new ResourceRepository(),
new AttributeService(new AttributeRepository()));
if ( $this->smarty->GetWordPressEmbed() ) {
$this->Set('WP_ADMIN_POST_PREFIX', BESPOKOMATIC_EBS_AJAX_PREFIX . '_resources_types');
$this->Set('WP_ADMIN_AJAX_PREFIX', BESPOKOMATIC_EBS_AJAX_PREFIX . '_resources_types');
$this->Set('WP_ADMIN_AJAX_PAGE_REQUESTS', admin_url('admin-ajax.php') . '?action=' . BESPOKOMATIC_EBS_AJAX_PREFIX . '_resources_types');
$this->smarty->SetBookedScript('admin/manage_resource_types.php');
}
}
public function ProcessPageLoad()

1
includes/booked/Web/scripts/admin/resource-types.js

@ -58,6 +58,7 @@ function ResourceTypeManagement(opts) {
$(".save").click(function () {
$(this).closest('form').submit();
$(this).closest('form').trigger('reset');
});
$(".cancel").click(function () {

16
includes/booked/tpl/Admin/Resources/manage_resource_types.tpl

@ -20,11 +20,16 @@ along with Booked Scheduler. If not, see <http://www.gnu.org/licenses/>.
<div id="page-manage-resource-types" class="admin-page">
{include file='Admin/Resources/manage_resource_menu.tpl' ResourcePageTitleKey='ManageResourceTypes'}
{if ! $WP_EMBED}
{include file='Admin/Resources/manage_resource_menu.tpl' ResourcePageTitleKey='ManageResourceStatus'}
{else}
<div class="clear"></div>
{/if}
<div id="globalError" class="error" style="display:none"></div>
<form id="addForm" ajaxAction="{ManageResourceTypesActions::Add}" class="form-inline" role="form" method="post">
<input type="hidden" name="action" value="{$WP_ADMIN_POST_PREFIX}_{ManageResourceTypesActions::Add}"/>
<div class="panel panel-default" id="add-resource-type-panel">
<div class="panel-heading">{translate key="AddResourceType"} {showhide_icon}</div>
<div class="panel-body add-contents">
@ -93,6 +98,7 @@ along with Booked Scheduler. If not, see <http://www.gnu.org/licenses/>.
aria-hidden="true">
<div class="modal-dialog">
<form id="editForm" method="post" ajaxAction="{ManageResourceTypesActions::Update}">
<input type="hidden" name="action" value="{$WP_ADMIN_POST_PREFIX}_{ManageResourceTypesActions::Update}"/>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
@ -127,6 +133,7 @@ along with Booked Scheduler. If not, see <http://www.gnu.org/licenses/>.
aria-hidden="true">
<div class="modal-dialog">
<form id="deleteForm" method="post" ajaxAction="{ManageResourceTypesActions::Delete}">
<input type="hidden" name="action" value="{$WP_ADMIN_POST_PREFIX}_{ManageResourceTypesActions::Delete}"/>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
@ -195,10 +202,11 @@ along with Booked Scheduler. If not, see <http://www.gnu.org/licenses/>.
$.fn.editable.defaults.emptyclass = '';
$.fn.editable.defaults.params = function(params) {
params.CSRF_TOKEN = $('#csrf_token').val();
params.action = '{$WP_ADMIN_POST_PREFIX}_{ManageResourceTypesActions::ChangeAttribute}';
return params;
};
var updateUrl = '{$smarty.server.SCRIPT_NAME}?action=';
var updateUrl = '{$WP_ADMIN_POST|default:$smarty.server.SCRIPT_NAME}?action=';
$('.inlineAttribute').editable({
url: updateUrl + '{ManageResourceTypesActions::ChangeAttribute}',
@ -212,8 +220,8 @@ along with Booked Scheduler. If not, see <http://www.gnu.org/licenses/>.
setUpEditables();
var opts = {
submitUrl: '{$smarty.server.SCRIPT_NAME}',
saveRedirect: '{$smarty.server.SCRIPT_NAME}'
submitUrl: '{$WP_ADMIN_POST|default:$smarty.server.SCRIPT_NAME}',
saveRedirect: '{$WP_ADMIN_POST|default:$smarty.server.SCRIPT_NAME}'
};
var resourceTypes = new ResourceTypeManagement(opts);

21
includes/class-bespokomatic-ebs.php

@ -218,13 +218,6 @@ class Bespokomatic_Ebs {
// Admin manage resource AJAX functions
$this->loader->add_action( 'wp_ajax_' . BESPOKOMATIC_EBS_AJAX_PREFIX . '_resources_manage', $plugin_admin, 'ajax_admin_resources_manage' );
// Admin resource status post functions
foreach ( $plugin_admin->admin_resource_statuses_post_endpoints()->getConstants() as $key => $value ) {
$this->loader->add_action( 'admin_post_' . BESPOKOMATIC_EBS_AJAX_PREFIX . '_resources_statuses_' . $value, $plugin_admin, 'post_admin_resources_statuses' );
}
// Admin manage resource AJAX functions
$this->loader->add_action( 'wp_ajax_' . BESPOKOMATIC_EBS_AJAX_PREFIX . '_resources_statuses', $plugin_admin, 'ajax_admin_resources_statuses' );
// Admin resource group post functions
foreach ( $plugin_admin->admin_resource_groups_post_endpoints()->getConstants() as $key => $value ) {
$this->loader->add_action( 'admin_post_' . BESPOKOMATIC_EBS_AJAX_PREFIX . '_resources_groups_' . $value, $plugin_admin, 'post_admin_resources_groups' );
@ -232,6 +225,20 @@ class Bespokomatic_Ebs {
// Admin manage group AJAX functions
$this->loader->add_action( 'wp_ajax_' . BESPOKOMATIC_EBS_AJAX_PREFIX . '_resources_groups', $plugin_admin, 'ajax_admin_resources_groups' );
// Admin resource status post functions
foreach ( $plugin_admin->admin_resource_types_post_endpoints()->getConstants() as $key => $value ) {
$this->loader->add_action( 'admin_post_' . BESPOKOMATIC_EBS_AJAX_PREFIX . '_resources_types_' . $value, $plugin_admin, 'post_admin_resources_types' );
}
// Admin manage status AJAX functions
$this->loader->add_action( 'wp_ajax_' . BESPOKOMATIC_EBS_AJAX_PREFIX . '_resources_types', $plugin_admin, 'ajax_admin_resources_types' );
// Admin resource status post functions
foreach ( $plugin_admin->admin_resource_statuses_post_endpoints()->getConstants() as $key => $value ) {
$this->loader->add_action( 'admin_post_' . BESPOKOMATIC_EBS_AJAX_PREFIX . '_resources_statuses_' . $value, $plugin_admin, 'post_admin_resources_statuses' );
}
// Admin manage status AJAX functions
$this->loader->add_action( 'wp_ajax_' . BESPOKOMATIC_EBS_AJAX_PREFIX . '_resources_statuses', $plugin_admin, 'ajax_admin_resources_statuses' );
}
/**

Loading…
Cancel
Save