From 12798ddc55bc0ff31b23ac155b43f8f4874aa5b2 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 20 Dec 2013 11:33:51 -0800 Subject: [PATCH] CRM-14015 - POC for CustomField page Total rewrite of enableDisable using CRM.api, crmEditable and crmSnippet --- CRM/Admin/Page/AJAX.php | 20 ++---- CRM/Custom/Page/Field.php | 6 +- js/crm.livePage.js | 2 +- templates/CRM/Custom/Page/Field.tpl | 2 +- templates/CRM/common/enableDisableApi.tpl | 82 +++++++++++++++++++++++ 5 files changed, 93 insertions(+), 19 deletions(-) create mode 100644 templates/CRM/common/enableDisableApi.tpl diff --git a/CRM/Admin/Page/AJAX.php b/CRM/Admin/Page/AJAX.php index 4a2523dafa..6c3be55a8c 100644 --- a/CRM/Admin/Page/AJAX.php +++ b/CRM/Admin/Page/AJAX.php @@ -83,15 +83,13 @@ class CRM_Admin_Page_AJAX { * enabling/ disabling various objects */ static function getStatusMsg() { - $recordID = CRM_Utils_Type::escape($_POST['recordID'], 'Integer'); - $recordBAO = CRM_Utils_Type::escape($_POST['recordBAO'], 'String'); - $op = CRM_Utils_Type::escape($_POST['op'], 'String'); - $show = NULL; + require_once('api/v3/utils.php'); + $recordID = CRM_Utils_Type::escape($_GET['id'], 'Integer'); + $entity = CRM_Utils_Type::escape($_GET['entity'], 'String'); + $show = $status = NULL; - if ($op == 'disable-enable') { - $status = ts('Are you sure you want to enable this record?'); - } - else { + if ($recordID && $entity) { + $recordBAO = _civicrm_api3_get_BAO($entity); switch ($recordBAO) { case 'CRM_Core_BAO_UFGroup': require_once (str_replace('_', DIRECTORY_SEPARATOR, $recordBAO) . '.php'); @@ -273,11 +271,7 @@ class CRM_Admin_Page_AJAX { break; } } - $statusMessage['status'] = $status; - $statusMessage['show'] = $show; - - echo json_encode($statusMessage); - CRM_Utils_System::civiExit(); + CRM_Core_Page_AJAX::returnJsonResponse($status); } static function getTagList() { diff --git a/CRM/Custom/Page/Field.php b/CRM/Custom/Page/Field.php index 2ca0f5901e..d0a53d861c 100644 --- a/CRM/Custom/Page/Field.php +++ b/CRM/Custom/Page/Field.php @@ -90,14 +90,12 @@ class CRM_Custom_Page_Field extends CRM_Core_Page { ), CRM_Core_Action::DISABLE => array( 'name' => ts('Disable'), - 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Core_BAO_CustomField' . '\',\'' . 'enable-disable' . '\',0,\'CustomField\' );"', - 'ref' => 'disable-action', + 'ref' => 'crm-enable-disable', 'title' => ts('Disable Custom Field'), ), CRM_Core_Action::ENABLE => array( 'name' => ts('Enable'), - 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Core_BAO_CustomField' . '\',\'' . 'disable-enable' . '\',0,\'CustomField\' );"', - 'ref' => 'enable-action', + 'ref' => 'crm-enable-disable', 'title' => ts('Enable Custom Field'), ), CRM_Core_Action::EXPORT => array( diff --git a/js/crm.livePage.js b/js/crm.livePage.js index 0d313b3af6..7f49d58136 100644 --- a/js/crm.livePage.js +++ b/js/crm.livePage.js @@ -5,7 +5,7 @@ cj(function($) { // Widgetize the content area .crmSnippet() // Open action links in a popup - .on('click', 'a.button, a.action-item:not(".enable-action, .disable-action")', function() { + .on('click', 'a.button, a.action-item:not(".crm-enable-disable")', function() { CRM.loadForm($(this).attr('href'), { openInline: 'a' }).on('crmFormSuccess', function(e, data) { diff --git a/templates/CRM/Custom/Page/Field.tpl b/templates/CRM/Custom/Page/Field.tpl index 1cdfb37c6a..afd27956ba 100644 --- a/templates/CRM/Custom/Page/Field.tpl +++ b/templates/CRM/Custom/Page/Field.tpl @@ -35,7 +35,7 @@
{strip} {* handle enable/disable actions*} - {include file="CRM/common/enableDisable.tpl"} + {include file="CRM/common/enableDisableApi.tpl"} {include file="CRM/common/jsortable.tpl"} diff --git a/templates/CRM/common/enableDisableApi.tpl b/templates/CRM/common/enableDisableApi.tpl new file mode 100644 index 0000000000..4f98b8b82b --- /dev/null +++ b/templates/CRM/common/enableDisableApi.tpl @@ -0,0 +1,82 @@ +{* + +--------------------------------------------------------------------+ + | CiviCRM version 4.4 | + +--------------------------------------------------------------------+ + | Copyright CiviCRM LLC (c) 2004-2013 | + +--------------------------------------------------------------------+ + | This file is a part of CiviCRM. | + | | + | CiviCRM is free software; you can copy, modify, and distribute it | + | under the terms of the GNU Affero General Public License | + | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | + | | + | CiviCRM is distributed in the hope that it will be useful, but | + | WITHOUT ANY WARRANTY; without even the implied warranty of | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | + | See the GNU Affero General Public License for more details. | + | | + | You should have received a copy of the GNU Affero General Public | + | License and the CiviCRM Licensing Exception along | + | with this program; if not, contact CiviCRM LLC | + | at info[AT]civicrm[DOT]org. If you have questions about the | + | GNU Affero General Public License or the licensing of CiviCRM, | + | see the CiviCRM license FAQ at http://civicrm.org/licensing | + +--------------------------------------------------------------------+ +*} +{* handle common enable/disable actions *} +{literal} + +{/literal} -- 2.25.1