Improve optiongroups admin UI workflow
authorMatthew Wire <devel@mrwire.co.uk>
Sat, 14 Jul 2018 15:52:48 +0000 (16:52 +0100)
committerMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Mon, 23 Jul 2018 16:28:31 +0000 (17:28 +0100)
CRM/Admin/Form/OptionGroup.php
templates/CRM/Admin/Form/OptionGroup.tpl
templates/CRM/Admin/Page/OptionGroup.tpl
templates/CRM/Admin/Page/Options.tpl

index c1216fcd83c2294b8d88f289009b8114161ac15b..0b76228f1c1c9a8bbd47f389fa027de8f11bbcee 100644 (file)
@@ -78,7 +78,7 @@ class CRM_Admin_Form_OptionGroup extends CRM_Admin_Form {
       CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionGroup', 'description')
     );
 
-    $this->addSelect('data_type', array('options' => CRM_Utils_Type::dataTypes()), TRUE);
+    $this->addSelect('data_type', array('options' => CRM_Utils_Type::dataTypes()), empty($this->_values['is_reserved']));
 
     $element = $this->add('checkbox', 'is_active', ts('Enabled?'));
     if ($this->_action & CRM_Core_Action::UPDATE) {
@@ -96,8 +96,12 @@ class CRM_Admin_Form_OptionGroup extends CRM_Admin_Form {
           $element->freeze();
         }
       }
+
+      $this->add('checkbox', 'is_reserved', ts('Reserved?'));
+      $this->freeze('is_reserved');
+
       if (!empty($this->_values['is_reserved'])) {
-        $this->freeze(array('name', 'is_active'));
+        $this->freeze(array('name', 'is_active', 'data_type'));
       }
     }
 
@@ -118,12 +122,13 @@ class CRM_Admin_Form_OptionGroup extends CRM_Admin_Form {
       // store the submitted values in an array
       $params = $this->exportValues();
 
-      // If we are adding option group via UI it should not be marked reserved.
-      if (!isset($params['is_reserved'])) {
-        $params['is_reserved'] = 0;
+      if ($this->_action & CRM_Core_Action::ADD) {
+        // If we are adding option group via UI it should not be marked reserved.
+        if (!isset($params['is_reserved'])) {
+          $params['is_reserved'] = 0;
+        }
       }
-
-      if ($this->_action & CRM_Core_Action::UPDATE) {
+      elseif ($this->_action & CRM_Core_Action::UPDATE) {
         $params['id'] = $this->_id;
       }
 
index a5f60ea67d9f0f71e805680828dddb5e81eddb55..0712447471b2523c7ed471f33e417457918d73d4 100644 (file)
               <td class="label">{$form.is_active.label}</td>
               <td>{$form.is_active.html}</td>
           </tr>
+        <tr class="crm-admin-optiongroup-form-block-is_reserved">
+          <td class="label">{$form.is_reserved.label}</td>
+          <td>{$form.is_reserved.html}</td>
+        </tr>
       </table>
      {/if}
      <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
index e8c60e31d833edb9972bbee03a8686e5592b04a4..9b57c75c2483cbc2a1d3c0a92973af890855daec 100644 (file)
           <td class="crm-admin-optionGroup-name">{$row.name}</td>
           <td class="crm-admin-optionGroup-is_reserved">{if $row.is_reserved eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if}</td>
           <td class="crm-admin-optionGroup-is_active" id="row_{$row.id}_status">{if $row.is_active eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if}</td>
-          <td><a href="{crmURL p="civicrm/admin/options" q="gid=`$row.id`&reset=1"}" title="{ts}View and Edit Options{/ts}">{ts}Options{/ts}</a></td>
+          <td>
+            <a href="{crmURL p="civicrm/admin/options" q="id=`$row.id`&action=update&reset=1"}" class="action-item crm-hover-button" title="{ts}OptionGroup settings{/ts}">{ts}Settings{/ts}</a>
+            <a href="{crmURL p="civicrm/admin/options" q="gid=`$row.id`&reset=1"}" class="action-item crm-hover-button" title="{ts}View and Edit Options{/ts}">{ts}Edit Options{/ts}</a>
+          </td>
         </tr>
         {/foreach}
     </table>
index 8a5936b6312beb782fbed3f5f507a37921d56eae..bea754d8f42f5ad3bb5b00ca6d0ee33533bfaa75 100644 (file)
       {if $isLocked ne 1}
         {crmButton p="civicrm/admin/options/$gName" q='action=add&reset=1' class="new-option" icon="plus-circle"}{ts 1=$gLabel}Add %1{/ts}{/crmButton}
       {/if}
-      {crmButton p="civicrm/admin" q="reset=1" class="cancel" icon="times"}{ts}Done{/ts}{/crmButton}
+      {crmButton p="civicrm/admin/options" q="action=browse&reset=1" class="next no-popup" icon="check"}{ts}Done{/ts}{/crmButton}
     </div>
 </div>
 {/if}