Improve navigation menu item edit form
authorColeman Watts <coleman@civicrm.org>
Mon, 1 Feb 2016 23:57:31 +0000 (16:57 -0700)
committerColeman Watts <coleman@civicrm.org>
Mon, 1 Feb 2016 23:57:31 +0000 (16:57 -0700)
CRM/Admin/Form/Navigation.php
templates/CRM/Admin/Form/Navigation.tpl

index 846ab4636029471a14d44aad115527eb402f4053..5f631f62e12a40dfe4b11e8594e40e2c71f6dee5 100644 (file)
@@ -47,6 +47,8 @@ class CRM_Admin_Form_Navigation extends CRM_Admin_Form {
   public function buildQuickForm() {
     parent::buildQuickForm();
 
+    $this->setPageTitle(ts('Menu Item'));
+
     if ($this->_action & CRM_Core_Action::DELETE) {
       return;
     }
@@ -65,27 +67,22 @@ class CRM_Admin_Form_Navigation extends CRM_Admin_Form {
     );
 
     $this->add('text', 'url', ts('Url'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Navigation', 'url'));
-    $permissions = CRM_Core_Permission::basicPermissions(TRUE);
-    $include = &$this->addElement('advmultiselect', 'permission',
-      ts('Permission') . ' ', $permissions,
-      array(
-        'size' => 5,
-        'style' => 'width:auto',
-        'class' => 'advmultiselect',
-      )
+    $permissions = array();
+    foreach (CRM_Core_Permission::basicPermissions(TRUE, TRUE) as $id => $vals) {
+      $permissions[] = array('id' => $id, 'label' => $vals[0], 'description' => (array) CRM_Utils_Array::value(1, $vals));
+    }
+    $this->add('text', 'permission', ts('Permission'),
+      array('placeholder' => ts('Unrestricted'), 'class' => 'huge', 'data-select-params' => json_encode(array('data' => $permissions)))
     );
 
-    $include->setButtonAttributes('add', array('value' => ts('Add >>')));
-    $include->setButtonAttributes('remove', array('value' => ts('<< Remove')));
-
-    $operators = array('AND' => 'AND', 'OR' => 'OR');
-    $this->add('select', 'permission_operator', ts('Operator'), $operators);
+    $operators = array('AND' => ts('AND'), 'OR' => ts('OR'));
+    $this->add('select', 'permission_operator', NULL, $operators);
 
     //make separator location configurable
-    $separator = array(0 => 'None', 1 => 'After Menu Element', 2 => 'Before Menu Element');
-    $this->add('select', 'has_separator', ts('Separator?'), $separator);
+    $separator = array(ts('None'), ts('After menu element'), ts('Before menu element'));
+    $this->add('select', 'has_separator', ts('Separator'), $separator);
 
-    $active = $this->add('advcheckbox', 'is_active', ts('Enabled?'));
+    $active = $this->add('advcheckbox', 'is_active', ts('Enabled'));
 
     if (CRM_Utils_Array::value('name', $this->_defaults) == 'Home') {
       $active->freeze();
@@ -101,7 +98,7 @@ class CRM_Admin_Form_Navigation extends CRM_Admin_Form {
       $homeMenuId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Home', 'id', 'name');
       unset($parentMenu[$homeMenuId]);
 
-      $parent = $this->add('select', 'parent_id', ts('Parent'), array('' => ts('- select -')) + $parentMenu);
+      $this->add('select', 'parent_id', ts('Parent'), array('' => ts('Top level')) + $parentMenu, FALSE, array('class' => 'crm-select2'));
     }
   }
 
@@ -111,12 +108,6 @@ class CRM_Admin_Form_Navigation extends CRM_Admin_Form {
   public function setDefaultValues() {
     $defaults = $this->_defaults;
     if (isset($this->_id)) {
-      if (!empty($this->_defaults['permission'])) {
-        foreach (explode(',', $this->_defaults['permission']) as $value) {
-          $components[$value] = $value;
-        }
-        $defaults['permission'] = $components;
-      }
       //Take parent id in object variable to calculate the menu
       //weight if menu parent id changed
       $this->_currentParentID = CRM_Utils_Array::value('parent_id', $this->_defaults);
index 95770d3ee42733fa21974749820043b1b0539626..f3cb505ef6e0cf77962b14ce0544c67d024023d6 100644 (file)
 {* this template is used for adding/editing CiviCRM Menu *}
 <div class="crm-block crm-form-block crm-navigation-form-block">
 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
-<fieldset><legend>{if $action eq 1}{ts}New Menu{/ts}{elseif $action eq 2}{ts}Edit Menu{/ts}{else}{ts}Delete Menu{/ts}{/if}</legend>
 <table class="form-layout-compressed">
     <tr class="crm-navigation-form-block-label">
         <td class="label">{$form.label.label}</td><td>{$form.label.html}</td>
     </tr>
     <tr class="crm-navigation-form-block-url">
-        <td class="label">{$form.url.label}</td><td>{$form.url.html} {help id="id-menu_url" file="CRM/Admin/Form/Navigation.hlp"}</td>
+        <td class="label">{$form.url.label} {help id="id-menu_url" file="CRM/Admin/Form/Navigation.hlp"}</td>
+        <td>{$form.url.html} </td>
     </tr>
-    { if $form.parent_id.html }
+    {if $form.parent_id.html}
     <tr class="crm-navigation-form-block-parent_id">
-        <td class="label">{$form.parent_id.label}</td><td>{$form.parent_id.html} {help id="id-parent" file="CRM/Admin/Form/Navigation.hlp"}</td>
+        <td class="label">{$form.parent_id.label} {help id="id-parent" file="CRM/Admin/Form/Navigation.hlp"}</td>
+        <td>{$form.parent_id.html}</td>
     </tr>
     {/if}
     <tr class="crm-navigation-form-block-has_separator">
-        <td class="label">{$form.has_separator.label}</td><td>{$form.has_separator.html} {help id="id-has_separator" file="CRM/Admin/Form/Navigation.hlp"}</td>
+        <td class="label">{$form.has_separator.label} {help id="id-has_separator" file="CRM/Admin/Form/Navigation.hlp"}</td>
+        <td>{$form.has_separator.html} </td>
     </tr>
     <tr class="crm-navigation-form-block-permission">
-        <td class="label">{$form.permission.label}{help id="id-menu_permission" file="CRM/Admin/Form/Navigation.hlp"}</td><td>{$form.permission.html}</td>
-    </tr>
-    <tr class="crm-navigation-form-block-permission_operator">
-        <td class="label">&nbsp;</td><td>{$form.permission_operator.html}&nbsp;{$form.permission_operator.label} {help id="id-permission_operator" file="CRM/Admin/Form/Navigation.hlp"}</td>
+        <td class="label">{$form.permission.label}{help id="id-menu_permission" file="CRM/Admin/Form/Navigation.hlp"}</td>
+        <td>{$form.permission.html} <span class="permission_operator_wrapper">{$form.permission_operator.html}  {help id="id-permission_operator" file="CRM/Admin/Form/Navigation.hlp"}</span></td>
     </tr>
     <tr class="crm-navigation-form-block-is_active">
         <td class="label">{$form.is_active.label}</td><td>{$form.is_active.html}</td>
     </tr>
 </table>
-</fieldset>
 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
 </div>
+{literal}
+<script type="text/javascript">
+    CRM.$(function($) {
+        var $form = $('form.{/literal}{$form.formClass}{literal}');
+        $('input[name=permission]', $form)
+          .on('change', function() {
+              $('span.permission_operator_wrapper').toggle(CRM._.includes($(this).val(), ','));
+          })
+          .change()
+          .crmSelect2({
+            formatResult: CRM.utils.formatSelect2Result,
+            formatSelection: function(row) {return row.label},
+            multiple: true
+          });
+    });
+</script>
+{/literal}