CRM-15789 - Add icons to submit buttons
authorColeman Watts <coleman@civicrm.org>
Tue, 6 Jan 2015 18:31:44 +0000 (13:31 -0500)
committerColeman Watts <coleman@civicrm.org>
Thu, 8 Jan 2015 19:14:48 +0000 (14:14 -0500)
CRM/Core/Form.php
CRM/Core/Smarty/plugins/function.crmAttributes.php
CRM/Core/Smarty/plugins/function.crmGetAttribute.php [new file with mode: 0644]
css/civicrm.css
js/crm.ajax.js
templates/CRM/common/formButtons.tpl

index 336dc5e776c1f47eadb2bb7f4bf4b8ce82248188..a155cc4447052467d2b42ddb0c5ef66eda14a819 100644 (file)
@@ -496,8 +496,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    *
    */
   public function addButtons($params) {
-    $prevnext = array();
-    $spacing = array();
+    $prevnext = $spacing = array();
     foreach ($params as $button) {
       $js = CRM_Utils_Array::value('js', $button);
       $isDefault = CRM_Utils_Array::value('isDefault', $button, FALSE);
@@ -512,8 +511,11 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
         $attrs = array_merge($js, $attrs);
       }
 
+      $defaultIcon = 'check';
+
       if ($button['type'] === 'cancel') {
         $attrs['class'] .= ' cancel';
+        $defaultIcon = 'close';
       }
 
       if ($button['type'] === 'reset') {
@@ -521,6 +523,9 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
       }
       else {
         if (!empty($button['subName'])) {
+          if ($button['subName'] == 'new') {
+            $defaultIcon = 'plus';
+          }
           $buttonName = $this->getButtonName($button['type'], $button['subName']);
         }
         else {
@@ -530,6 +535,10 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
         if (in_array($button['type'], array('next', 'upload', 'done')) && $button['name'] === ts('Save')) {
           $attrs = array_merge($attrs, (array('accesskey' => 'S')));
         }
+        $icon = CRM_Utils_Array::value('icon', $button, $defaultIcon);
+        if ($icon) {
+          $attrs['crm-icon'] = $icon;
+        }
         $prevnext[] = $this->createElement('submit', $buttonName, $button['name'], $attrs);
       }
       if (!empty($button['isDefault'])) {
index e2652f0b1ac9a42cd2af564d006b4114513e2098..39ddadb70b31f2bf02b68576879728b1aff7577d 100644 (file)
  */
 
 /**
- * Add a stylesheet <LINK> to a specific part of the page
+ * Formats an array of attributes as html
  *
  * @param array $params
  *   ['a'] array of attributes.
  * @param CRM_Core_Smarty $smarty
  *
+ * @return string
  * @throws Exception
  */
 function smarty_function_crmAttributes($params, &$smarty) {
diff --git a/CRM/Core/Smarty/plugins/function.crmGetAttribute.php b/CRM/Core/Smarty/plugins/function.crmGetAttribute.php
new file mode 100644 (file)
index 0000000..9fd1b74
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.6                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
+ +--------------------------------------------------------------------+
+ | 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        |
+ +--------------------------------------------------------------------+
+*/
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC
+ * $Id$
+ *
+ */
+
+/**
+ * Fetch an attribute from html
+ *
+ * @param array $params
+ * @param CRM_Core_Smarty $smarty
+ *
+ * @return string
+ */
+function smarty_function_crmGetAttribute($params, &$smarty) {
+  if (preg_match('#\W' . $params['attr'] . '="([^"]+)#', $params['html'], $matches)) {
+    return $matches[1];
+  }
+  return '';
+}
index d36696adbb3c08dbf9eb0be9dd09872f03732d14..e07ffa0c27c7686004ecaa735ef861f46cb771b9 100644 (file)
@@ -2332,8 +2332,7 @@ div.grippie {
   margin-left: .5em;
 }
 
-.crm-container .crm-button,
-#crm-container .crm-button {
+.crm-container .crm-button {
   border: medium none;
   cursor: pointer;
   display: block;
@@ -2341,12 +2340,9 @@ div.grippie {
   overflow: hidden;
   text-shadow: 0 1px 0 black;
   margin: 0px 12px 0 0;
-  padding: 0px 4px;
-  cursor: pointer;
 }
 
-.crm-container .crm-button input,
-#crm-container .crm-button input {
+.crm-container .crm-button input {
   background: none;
   _background: #6C6C6C;
   /* IE6 only */
@@ -2360,13 +2356,10 @@ div.grippie {
 }
 
 .crm-container .crm-button-type-cancel,
-.crm-container .crm-button-type-back,
-#crm-container .crm-button-type-cancel,
-#crm-container .crm-button-type-back {
+.crm-container .crm-button-type-back {
   margin-left: 20px;
 }
-.crm-container .crm-button-type-cancel input,
-#crm-container .crm-button-type-cancel input {
+.crm-container .crm-button-type-cancel input {
   color: #E6E6DC!important;
 }
 
@@ -2379,9 +2372,9 @@ div.grippie {
 .crm-container input.crm-form-submit,
 .crm-container .crm-button,
 .crm-container .ui-dialog-buttonset .ui-button,
-#crm-container input[type=button],
-#crm-container input.crm-form-submit-inline,
-#crm-container .crm-button {
+.crm-container input[type=button],
+.crm-container input.crm-form-submit-inline,
+.crm-container .crm-button {
   text-shadow: 0 1px 0 black;
   background: #70716B url(../i/crm-button-bg.gif) repeat-x top left;
   color: #FFF;
@@ -2395,30 +2388,25 @@ div.grippie {
 }
 
 .crm-container input.crm-form-submit[disabled],
-.crm-container .crm-button[disabled],
-#crm-container input[type=button][disabled],
-#crm-container input.crm-form-submit-inline[disabled],
-#crm-container .crm-button[disabled] {
+.crm-container input[type=button][disabled],
+.crm-container input.crm-form-submit-inline[disabled],
+.crm-container .crm-button[disabled] {
     color: #999;
 }
 
-.crm-container .crm-button,
-#crm-container .crm-button {
+.crm-container .crm-button {
   padding: 1px;
 }
 
 .crm-container input.crm-form-submit,
-#crm-container input[type=button],
-#crm-container input.crm-form-submit-inline {
+.crm-container input[type=button],
+.crm-container input.crm-form-submit-inline {
   padding: 2px 6px;
 }
 
 .crm-container .crm-button input[type=button],
 .crm-container .crm-button input.crm-form-submit,
-.crm-container .crm-button input.crm-form-submit-inline,
-#crm-container .crm-button input[type=button],
-#crm-container .crm-button input.crm-form-submit,
-#crm-container .crm-button input.crm-form-submit-inline {
+.crm-container .crm-button input.crm-form-submit-inline {
   padding: 2px 4px;
   margin: 0px;
   background: none;
@@ -2620,6 +2608,23 @@ div.grippie {
   margin-top: 3px;
 }
 
+.crm-container input.crm-button.crm-icon-button {
+  position: relative;
+}
+
+.crm-container .crm-button.crm-icon-button input {
+  padding-left: 18px;
+}
+
+.crm-container .crm-button-icon {
+  background-image: url("../i/icons/jquery-ui-FFFFFF.png");
+  height: 16px;
+  width: 16px;
+  display: block;
+  position: absolute;
+  pointer-events: none;
+}
+
 .crm-container .dark-icon {
   background-image: url("../packages/jquery/jquery-ui/images/ui-icons_222222_256x240.png")
 }
index fc7610cceff39938f2eea044bf0a0b1513c34ed4..5b02ef01372172942c66195502f11ac9c7e63cc8 100644 (file)
             if ($icon.length) {
               button.icons = {primary: $icon.attr('class')};
             } else {
-              var action = $el.hasClass('cancel') ? 'close' : (identifier.substr(identifier.length-4) === '_new' ? 'plus' : 'check');
+              var action = $el.attr('crm-icon') || ($el.hasClass('cancel') ? 'close' : 'check');
               button.icons = {primary: 'ui-icon-' + action};
             }
             buttons.push(button);
index c6d849f2d25d3e31ed5420ccb043ae68a66f91ed..01459abfa3acf2c0a65107c0eb753aa86a49fe7e 100644 (file)
           {assign var='html' value=$form.buttons.$key.html}
         {/if}
         {capture assign=validate}{$key|crmBtnValidate}{/capture}
-        <span class="crm-button crm-button-type-{$key|crmBtnType} crm-button{$key}"{if $buttonStyle} style="{$buttonStyle}"{/if}>{$html|crmAddClass:$validate}</span>
+        {capture assign=icon}{crmGetAttribute html=$html attr='crm-icon'}{/capture}
+        <span class="crm-button crm-button-type-{$key|crmBtnType} crm-button{$key}{if $icon} crm-icon-button{/if}"{if $buttonStyle} style="{$buttonStyle}"{/if}>
+          {if $icon}<span class="crm-button-icon ui-icon-{$icon}"> </span>{/if}
+          {$html|crmAddClass:$validate}
+        </span>
     {/if}
   {/foreach}
 {/crmRegion}