CRM-14015 CRM-14023 - Extend new enable/disable to acl page (and add acl api)
authorColeman Watts <coleman@civicrm.org>
Fri, 20 Dec 2013 23:41:41 +0000 (15:41 -0800)
committerColeman Watts <coleman@civicrm.org>
Mon, 6 Jan 2014 19:10:40 +0000 (11:10 -0800)
CRM/ACL/BAO/ACL.php
CRM/ACL/Page/ACL.php
api/v3/Acl.php [new file with mode: 0644]
api/v3/utils.php
js/crm.livePage.js
js/jquery/jquery.crmeditable.js
templates/CRM/ACL/Page/ACL.tpl
templates/CRM/common/enableDisableApi.tpl

index ea17556c6b1f5e29adb5e934a7d2b082a8f9a669..6c19cc3d8f648c5a738533f207d027ef0b666e57 100644 (file)
@@ -648,6 +648,7 @@ SELECT $acl.*
     $dao = new CRM_ACL_DAO_ACL();
     $dao->copyValues($params);
     $dao->save();
+    return $dao;
   }
 
   static function retrieve(&$params, &$defaults) {
index aa1974966089b62851dfbd40c3169410dad2429c..9ac0c75ac795df9af38f689f02b3103fd9c389c7 100644 (file)
@@ -75,14 +75,12 @@ class CRM_ACL_Page_ACL extends CRM_Core_Page_Basic {
         ),
         CRM_Core_Action::DISABLE => array(
           'name' => ts('Disable'),
-          'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_ACL_BAO_ACL' . '\',\'' . 'enable-disable' . '\' );"',
-          'ref' => 'disable-action',
+          'ref' => 'crm-enable-disable',
           'title' => ts('Disable ACL'),
         ),
         CRM_Core_Action::ENABLE => array(
           'name' => ts('Enable'),
-          'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_ACL_BAO_ACL' . '\',\'' . 'disable-enable' . '\' );"',
-          'ref' => 'enable-action',
+          'ref' => 'crm-enable-disable',
           'title' => ts('Enable ACL'),
         ),
         CRM_Core_Action::DELETE => array(
diff --git a/api/v3/Acl.php b/api/v3/Acl.php
new file mode 100644 (file)
index 0000000..93ac3c0
--- /dev/null
@@ -0,0 +1,77 @@
+<?php
+
+/*
+ +--------------------------------------------------------------------+
+ | 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        |
+ +--------------------------------------------------------------------+
+*/
+
+/**
+ * File for the CiviCRM APIv3 acl functions
+ *
+ * @package CiviCRM_APIv3
+ * @subpackage API_acl
+ *
+ */
+
+/**
+ * Save an acl
+ *
+ * Allowed @params array keys are:
+ * {@getfields acl_create}
+ * @example aclCreate.php
+ *
+ * @return array of newly created acl property values.
+ * @access public
+ */
+function civicrm_api3_acl_create($params) {
+  return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
+
+/**
+ * Get an acl
+ *
+ * Allowed @params array keys are:
+ * {@getfields acl_get}
+ * @example aclCreate.php
+ *
+ * @return array of retrieved acl property values.
+ * @access public
+ */
+function civicrm_api3_acl_get($params) {
+  return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
+
+/**
+ * Delete an acl
+ *
+ * Allowed @params array keys are:
+ * {@getfields acl_delete}
+ * @example aclCreate.php
+ *
+ * @return array of deleted values.
+ * @access public
+ */
+function civicrm_api3_acl_delete($params) {
+  return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
index 59ba512613afc10d225161669b8c59d1a273b746..b788c167b1d00c1544d43c50bf59150d7b99fcc6 100644 (file)
@@ -288,12 +288,12 @@ function _civicrm_api3_get_DAO($name) {
   //hack to deal with incorrectly named BAO/DAO - see CRM-10859 -
   // several of these have been removed but am not confident mailing_recipients is
   // tests so have not tackled.
-  // correct approach for im is unclear
   if($name == 'mailing_recipients' || $name == 'MailingRecipients'){
     return 'CRM_Mailing_BAO_Recipients';
   }
-  if(strtolower($name) == 'im'){
-    return 'CRM_Core_BAO_IM';
+  // correct approach for im & acl is unclear
+  if (strtolower($name) == 'im' || strtolower($name) == 'acl') {
+    $name = strtoupper($name);
   }
   return CRM_Core_DAO_AllCoreTables::getFullName(_civicrm_api_get_camel_name($name, 3));
 }
index 7f49d58136bdbdf2aa1deb2ed37660291d6d4550..722ebabc158f0c4e460473ae2da4ac81a8ae9981 100644 (file)
@@ -7,7 +7,7 @@ cj(function($) {
     // Open action links in a popup
     .on('click', 'a.button, a.action-item:not(".crm-enable-disable")', function() {
       CRM.loadForm($(this).attr('href'), {
-        openInline: 'a'
+        openInline: 'a:not(".crm-enable-disable")'
       }).on('crmFormSuccess', function(e, data) {
         // Refresh page when form completes
         $('#crm-main-content-wrapper').crmSnippet('refresh');
index 287e136ceefa52f8878fd98475e61ec3ad30163b..e0c620dd929acf988317b6a76fb7b3164e297d24 100644 (file)
@@ -1,27 +1,4 @@
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-
-*
+/**
 * Copyright (C) 2012 Xavier Dutoit
 * Licensed to CiviCRM under the Academic Free License version 3.0.
 *
@@ -39,7 +16,6 @@
 *   to make it easier to customize the form (eg. hide a button...) it triggers a 'load' event on the form. you can then catch the load on your code (using the $('#id_of_the_form').on(function(){//do something
 */
 
-
 (function($) {
 
     $.fn.crmEditable = function (options) {
       }
       // param in : a dom object that contains the field name as a class crmf-xxx
       var getFieldName = function (field) {
-        if ($(field).data('field')) {
-           return $(field).data('field');
-        }
-        var fieldName=field.className.match(/crmf-(\S*)/)[1];
+        var fieldName = $(field).data('field') || field.className.match(/crmf-(\S*)/)[1];
         if (!fieldName) {
           console && console.log && console.log("Couldn't get the crm-editable field name to modify. You need to set crmf-{field_name} or data-{field_name}");
-          return false;
         }
         return fieldName;
       }
index 5505ad8f29cc257f7be6c11e4de74e3b888782f8..bb74767aec74be186da73d6083126a9ee905630c 100644 (file)
 </div>
 
 {if $rows}
-<div class="">
 <div id="ltype">
     {strip}
   {* handle enable/disable actions*}
-   {include file="CRM/common/enableDisable.tpl"}
+   {include file="CRM/common/enableDisableApi.tpl"}
     {include file="CRM/common/jsortable.tpl"}
         <table id="options" class="display">
         <thead>
         </thead>
         <tbody>
         {foreach from=$rows item=row key=aclID}
-      <tr id="row_{$aclID}"class="{cycle values="odd-row,even-row"} {$row.class} crm-acl {if NOT $row.is_active} disabled{/if}">
+        <tr id="acl-{$aclID}" class="{cycle values="odd-row,even-row"} {$row.class} crm-acl crm-entity {if NOT $row.is_active} disabled{/if}">
           <td class="crm-acl-entity">{$row.entity}</td>
           <td class="crm-acl-operation" >{$row.operation}</td>
           <td class="crm-acl-object_name">{$row.object_name}</td>
           <td class="crm-acl-object" >{$row.object}</td>
-          <td class="crm-acl-name">{$row.name}</td>
+          <td class="crm-acl-name crm-editable" data-field="name">{$row.name}</td>
           <td class="crm-acl-is_active" id="row_{$aclID}_status">{if $row.is_active eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if}</td>
           <td>{$row.action|replace:'xx':$aclID}</td>
         </tr>
@@ -79,6 +78,7 @@
         </div>
         {/if}
 </div>
+{include file="CRM/common/crmeditable.tpl"}
 {elseif $action ne 1 and $action ne 2 and $action ne 8}
     <div class="messages status no-popup">
         <img src="{$config->resourceBase}i/Inform.gif" alt="{ts}status{/ts}"/>
index 4f98b8b82b3854f4c9cd7c521f25868df5ffa618..36ef55d950e005970974ebb2aa5cc3202b22a9e5 100644 (file)
 {literal}
 <script type="text/javascript">
   cj(function($) {
-    var $row, entity, id, enabled, snippet;
+    var $row, $table, entity, id, enabled;
 
     function refresh() {
-      snippet.crmSnippet('refresh');
+      if (false && $.fn.DataTable.fnIsDataTable($table[0])) { // fixme why doesn't this work?
+        $table.dataTable().fnDraw();
+      } else {
+        // Refresh an existing ajax container or create a new one
+        $row.closest('.crm-ajax-container, #crm-main-content-wrapper').crmSnippet().crmSnippet('refresh');
+      }
       CRM.alert('', enabled ? {/literal}'{ts escape="js"}Record Disabled{/ts}' : '{ts escape="js"}Record Enabled{/ts}'{literal}, 'success');
     }
 
     function save() {
-      snippet = $row.closest('.crm-ajax-container');
-      if (snippet.length && snippet.crmSnippet('option', 'block')) {
-        snippet.block();
-      }
+      $table = $row.closest('table');
+      $table.block();
       CRM.api(entity, 'create', {id: id, is_active: enabled ? 0 : 1}, {success: refresh});
     }