From 4a143c04038bf9a78a79c8e3f0e1e9d0b022f287 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 7 Feb 2014 09:10:50 -0800 Subject: [PATCH] CRM-13929 - Centralize and simplify radio clear widget --- CRM/Core/Form/Renderer.php | 27 +++++++++++++---- css/civicrm.css | 12 ++++---- js/Common.js | 24 +++++---------- templates/CRM/Activity/Form/Search.tpl | 4 --- templates/CRM/Activity/Form/Search/Common.tpl | 9 ------ .../CRM/Admin/Form/ScheduleReminders.tpl | 5 ---- templates/CRM/Badge/Form/Layout.js | 29 ++++++++----------- templates/CRM/Badge/Form/Layout.tpl | 10 +++---- .../CRM/Campaign/Form/Petition/Block.tpl | 9 +----- .../Contact/Form/Edit/Address/CustomField.tpl | 8 +---- .../CRM/Contact/Form/Edit/Demographics.tpl | 1 - .../CRM/Contact/Form/Inline/Demographics.tpl | 4 +-- .../Contact/Form/Search/Criteria/Basic.tpl | 6 ++-- .../Form/Search/Criteria/ChangeLog.tpl | 4 --- .../Form/Search/Criteria/Demographics.tpl | 3 +- .../Form/AdditionalInfo/Honoree.tpl | 3 +- .../Form/ContributionPage/Amount.tpl | 2 +- .../CRM/Contribute/Form/Search/Common.tpl | 21 -------------- templates/CRM/Contribute/Form/SoftCredit.tpl | 1 - .../CRM/Contribute/Form/Task/PDFLetter.tpl | 2 +- templates/CRM/Custom/Form/CustomField.tpl | 7 +---- templates/CRM/Custom/Form/Preview.tpl | 8 +---- templates/CRM/Custom/Form/Search.tpl | 9 +----- .../Cart/Form/Checkout/ConferenceEvents.tpl | 1 - .../CRM/Event/Cart/Form/Checkout/Payment.tpl | 1 - templates/CRM/Event/Form/ManageEvent/Fee.tpl | 2 +- templates/CRM/Event/Form/Search/Common.tpl | 6 ---- templates/CRM/Form/attachment.tpl | 4 +-- templates/CRM/Mailing/Form/Search.tpl | 19 +++--------- templates/CRM/Mailing/Form/Search/Common.tpl | 12 -------- templates/CRM/Member/Form/MembershipBlock.tpl | 2 +- templates/CRM/Member/Form/Search/Common.tpl | 16 ---------- templates/CRM/Pledge/Form/Search/Common.tpl | 2 +- templates/CRM/Profile/Form/Dynamic.tpl | 8 +---- templates/CRM/Profile/Form/Search.tpl | 7 +---- templates/CRM/UF/Form/Block.tpl | 9 +----- templates/CRM/UF/Form/Preview.tpl | 7 +---- templates/CRM/common/jcalendar.tpl | 2 +- .../templates/CRM/Profile/Form/15/Edit.tpl | 8 +---- .../CRM/Profile/Form/Survey/Edit.tpl | 8 +---- 40 files changed, 80 insertions(+), 242 deletions(-) diff --git a/CRM/Core/Form/Renderer.php b/CRM/Core/Form/Renderer.php index 0f86236723..ad22dd4d66 100644 --- a/CRM/Core/Form/Renderer.php +++ b/CRM/Core/Form/Renderer.php @@ -117,16 +117,23 @@ class CRM_Core_Form_Renderer extends HTML_QuickForm_Renderer_ArraySmarty { } } - if ($element->getType() == 'select' && $element->getAttribute('data-option-group-url')) { - $this->addOptionsEditLink($el, $element); - } - + // Display-only (frozen) elements if (!empty($el['frozen'])) { if ($element->getAttribute('data-api-params') && $element->getAttribute('data-entity-value')) { $this->renderFrozenEntityRef($el, $element); } $el['html'] = '
' . $el['html'] . '
'; } + // Active form elements + else { + if ($element->getType() == 'select' && $element->getAttribute('data-option-group-url')) { + $this->addOptionsEditLink($el, $element); + } + + if ($element->getType() == 'group' && strpos($el['html'], 'crm-form-radio')) { + $this->appendUnselectButton($el, $element); + } + } return $el; } @@ -217,6 +224,16 @@ class CRM_Core_Form_Renderer extends HTML_QuickForm_Renderer_ArraySmarty { $el['html'] .= ' '; } } + + /** + * @param array $el + * @param HTML_QuickForm_element $field + */ + function appendUnselectButton(&$el, $field) { + // Initially hide if not needed + // Note: visibility:hidden prevents layout jumping around unlike display:none + $display = $field->getValue() ? '' : ' style="visibility:hidden;"'; + $el['html'] .= ' '; + } } -// end CRM_Core_Form_Renderer diff --git a/css/civicrm.css b/css/civicrm.css index 6594ffdd25..c1c77a7279 100644 --- a/css/civicrm.css +++ b/css/civicrm.css @@ -796,8 +796,7 @@ div.crm-container fieldset label{ */ /* Inline form field 'post-help' and radio-button unselect */ -.crm-container .description, -.crm-container .crm-clear-link { +.crm-container .description { font-size: 0.9em; font-weight: normal; white-space: normal; @@ -2212,10 +2211,6 @@ div.grippie { margin-left: 8px; } -.crm-container .crm-clear-link { - margin-left: .5em; -} - #crm-container .crm-button { border: medium none; cursor: pointer; @@ -2551,7 +2546,9 @@ div.grippie { .crm-container .play-icon { background-position: -3px -161px; } - +.crm-container .close-icon { + background-position: -82px -130px; +} .crm-container .swap-icon { background-position: -82px -81px; } @@ -2625,6 +2622,7 @@ div.grippie { /* Icon hover-buttons */ .crm-container .crm-hover-button { display: inline-block; + border: 1px solid transparent; } .crm-container .crm-hover-button:hover, .crm-container .crm-hover-button:active { diff --git a/js/Common.js b/js/Common.js index 27c9d767c5..38ccd44369 100644 --- a/js/Common.js +++ b/js/Common.js @@ -171,22 +171,6 @@ function showHideByValue(trigger_field_id, trigger_value, target_element_id, tar } } -/** - * reset all the radio buttons with a given name - * - * @param string fieldName - * @param object form - * @return null - */ -function unselectRadio(fieldName, form) { - for (i = 0; i < document.forms[form].elements.length; i++) { - if (document.forms[form].elements[i].name == fieldName) { - document.forms[form].elements[i].checked = false; - } - } - return; -} - /** * Function to change button text and disable one it is clicked * @@ -967,6 +951,14 @@ CRM.validate = CRM.validate || { }); }); return false; + }) + // Handle clear button for form elements + .on('click', 'a.crm-clear-link', function() { + $(this).css({visibility: 'hidden'}).siblings('.crm-form-radio:checked').prop('checked', false).change(); + return false; + }) + .on('change', 'input.crm-form-radio:checked', function() { + $(this).siblings('.crm-clear-link').css({visibility: ''}); }); $().crmtooltip(); }); diff --git a/templates/CRM/Activity/Form/Search.tpl b/templates/CRM/Activity/Form/Search.tpl index 6932aada41..a2a53d55f7 100644 --- a/templates/CRM/Activity/Form/Search.tpl +++ b/templates/CRM/Activity/Form/Search.tpl @@ -104,9 +104,5 @@ } }).change(); - cj(".crm-clear-link").click(function () { - cj('.description .contact-name-option').hide(); - }); - {/literal} diff --git a/templates/CRM/Activity/Form/Search/Common.tpl b/templates/CRM/Activity/Form/Search/Common.tpl index 15d3e60550..5050dd49c5 100644 --- a/templates/CRM/Activity/Form/Search/Common.tpl +++ b/templates/CRM/Activity/Form/Search/Common.tpl @@ -26,12 +26,6 @@ {$form.activity_role.html} - - ( - {ts}clear{/ts} - ) @@ -103,9 +97,6 @@ {$form.activity_test.label} {help id="is-test" file="CRM/Contact/Form/Search/Advanced"}   {$form.activity_test.html} - - ({ts}clear{/ts}) - {if $buildSurveyResult } diff --git a/templates/CRM/Admin/Form/ScheduleReminders.tpl b/templates/CRM/Admin/Form/ScheduleReminders.tpl index 4f066f0ae5..d8ac88aa56 100644 --- a/templates/CRM/Admin/Form/ScheduleReminders.tpl +++ b/templates/CRM/Admin/Form/ScheduleReminders.tpl @@ -197,11 +197,6 @@ } }); - cj('#absolute_date_display').parent( ).children('.crm-clear-link').children('a').click( function() { - cj('#relativeDate').show(); - cj('#relativeDateRepeat').show(); - }); - cj(function() { if (cj('#absolute_date_display').val()) { cj('#relativeDate').hide(); diff --git a/templates/CRM/Badge/Form/Layout.js b/templates/CRM/Badge/Form/Layout.js index 183331393f..3398ba757d 100644 --- a/templates/CRM/Badge/Form/Layout.js +++ b/templates/CRM/Badge/Form/Layout.js @@ -1,24 +1,19 @@ // http://civicrm.org/licensing cj(function ($) { function openKCFinder(field) { + var field = $(this); window.KCFinder = { callBack: function(url) { - field.val(url); + field.val(url).change(); // calculate the image default width, height // and assign to respective fields var ajaxUrl = CRM.url('civicrm/ajax/rest', 'className=CRM_Badge_Page_AJAX&fnName=getImageProp&json=1&img=' + url); - $.ajax({ - url: ajaxUrl, - async: false, - global: false, - dataType: "json", - success: function ( response ) { + $.getJSON(ajaxUrl).done(function ( response ) { var widthId = 'width_' + field.attr('id'); var heightId = 'height_' + field.attr('id'); $('#' + widthId).val(response.width.toFixed(0)); $('#' + heightId).val(response.height.toFixed(0)); - } - }); + }); window.KCFinder = null; } }; @@ -29,15 +24,15 @@ cj(function ($) { ); } - $('input[id^="image_"]').click(function(){ - openKCFinder($(this)); - }); + $('input[id^="image_"]') + .click(openKCFinder) + .change(function() { + $(this).siblings('.clear-image').css({visibility: $(this).val() ? '' : 'hidden'}); + }) + .change(); - $('.clear-image').click(function(){ - var imgName = $(this).attr('imgname'); - $('#' + imgName).val(''); - $('#width_' + imgName).val(''); - $('#height_' + imgName).val(''); + $('.clear-image').click(function() { + $(this).closest('tr').find('input[type=text]').val('').change(); return false; }); }); diff --git a/templates/CRM/Badge/Form/Layout.tpl b/templates/CRM/Badge/Form/Layout.tpl index cd3269b247..50a6eba02b 100644 --- a/templates/CRM/Badge/Form/Layout.tpl +++ b/templates/CRM/Badge/Form/Layout.tpl @@ -52,9 +52,8 @@ @@ -78,10 +75,7 @@ {include file="CRM/common/jcalendar.tpl" blockId=$blockId blockSection='address' elementName=$element_name} {/if} - {if $element.html_type eq 'Radio'} - ({ts}clear{/ts}) - - {elseif $element.data_type eq 'File'} + {if $element.data_type eq 'File'} {if $element.element_value.data}
 {ts}Attached File{/ts}:   diff --git a/templates/CRM/Contact/Form/Edit/Demographics.tpl b/templates/CRM/Contact/Form/Edit/Demographics.tpl index e28f62698e..e8ff3c878a 100644 --- a/templates/CRM/Contact/Form/Edit/Demographics.tpl +++ b/templates/CRM/Contact/Form/Edit/Demographics.tpl @@ -33,7 +33,6 @@ {$form.gender_id.html} - ({ts}clear{/ts})
diff --git a/templates/CRM/Contact/Form/Inline/Demographics.tpl b/templates/CRM/Contact/Form/Inline/Demographics.tpl index f15074e9b7..88799399b1 100644 --- a/templates/CRM/Contact/Form/Inline/Demographics.tpl +++ b/templates/CRM/Contact/Form/Inline/Demographics.tpl @@ -32,9 +32,7 @@
{$form.gender_id.label}
-
{$form.gender_id.html} - ({ts}clear{/ts}) -
+
{$form.gender_id.html}
{$form.birth_date.label}
diff --git a/templates/CRM/Contact/Form/Search/Criteria/Basic.tpl b/templates/CRM/Contact/Form/Search/Criteria/Basic.tpl index 40b25281a0..e05611ea44 100644 --- a/templates/CRM/Contact/Form/Search/Criteria/Basic.tpl +++ b/templates/CRM/Contact/Form/Search/Criteria/Basic.tpl @@ -66,11 +66,11 @@ {/if} {if $form.group}
@@ -40,17 +34,11 @@ {$form.mailing_click_status.label}
{$form.mailing_click_status.html} - - ({ts}clear{/ts}) - diff --git a/templates/CRM/Member/Form/MembershipBlock.tpl b/templates/CRM/Member/Form/MembershipBlock.tpl index 88e0e7c1cc..947b601ab8 100644 --- a/templates/CRM/Member/Form/MembershipBlock.tpl +++ b/templates/CRM/Member/Form/MembershipBlock.tpl @@ -91,7 +91,7 @@ {strip}
{$form.image_1.html} - - ({ts}clear{/ts}) -
+ +
{ts}Click above and select a file by double clicking on it.{/ts}
@@ -73,9 +72,8 @@ - {/if}
{$form.image_2.html} - - ({ts}clear{/ts}) -
+ +
{ts}Click above and select a file by double clicking on it.{/ts}
diff --git a/templates/CRM/Campaign/Form/Petition/Block.tpl b/templates/CRM/Campaign/Form/Petition/Block.tpl index 3937e75849..ccc528f8d0 100644 --- a/templates/CRM/Campaign/Form/Petition/Block.tpl +++ b/templates/CRM/Campaign/Form/Petition/Block.tpl @@ -111,16 +111,9 @@ {include file="CRM/common/jcalendar.tpl" elementName=$n} {else} {$form.$n.html} - {if $n eq 'gender' && $form.$fieldName.frozen neq true} - ({ts}clear{/ts}) - {/if} {/if} {*CRM-4564*} - {if $field.html_type eq 'Radio' && $form.$fieldName.frozen neq true && $field.is_required neq 1} - - ({ts}clear{/ts}) - - {elseif $field.html_type eq 'Autocomplete-Select'} + {if $field.html_type eq 'Autocomplete-Select'} {if $field.data_type eq 'ContactReference'} {include file="CRM/Custom/Form/ContactReference.tpl" element_name = $n} {else} diff --git a/templates/CRM/Contact/Form/Edit/Address/CustomField.tpl b/templates/CRM/Contact/Form/Edit/Address/CustomField.tpl index 07f2c19083..4ce81755cf 100644 --- a/templates/CRM/Contact/Form/Edit/Address/CustomField.tpl +++ b/templates/CRM/Contact/Form/Edit/Address/CustomField.tpl @@ -54,9 +54,6 @@ {/if} {/if} {/foreach} - {if $element.html_type eq 'Radio'} - ({ts}clear{/ts})
-
+
{$form.group.html}
- + {$form.group_type.html} {literal} {/literal} diff --git a/templates/CRM/Mailing/Form/Search/Common.tpl b/templates/CRM/Mailing/Form/Search/Common.tpl index 00db5d5d58..cb24ac6180 100644 --- a/templates/CRM/Mailing/Form/Search/Common.tpl +++ b/templates/CRM/Mailing/Form/Search/Common.tpl @@ -19,9 +19,6 @@ {$form.mailing_delivery_status.label}
{$form.mailing_delivery_status.html} - - ({ts}clear{/ts}) -
{$form.mailing_bounce_types.label} {$form.mailing_bounce_types.html} @@ -30,9 +27,6 @@ {$form.mailing_open_status.label}
{$form.mailing_open_status.html} - - ({ts}clear{/ts}) -
{$form.mailing_reply_status.label}
{$form.mailing_reply_status.html} - - ({ts}clear{/ts}) -
{ts}Default{/ts}
- (unselect){if $is_recur}
{/if} + {if $is_recur}{/if} {assign var="index" value="1"} {foreach name=outer key=key item=item from=$form.membership_type} {if $index < 10} diff --git a/templates/CRM/Member/Form/Search/Common.tpl b/templates/CRM/Member/Form/Search/Common.tpl index 5ecac84a33..5d41ae1d89 100644 --- a/templates/CRM/Member/Form/Search/Common.tpl +++ b/templates/CRM/Member/Form/Search/Common.tpl @@ -50,10 +50,6 @@
{$form.member_source.html}

{$form.member_test.label} {help id="is-test" file="CRM/Contact/Form/Search/Advanced"}  {$form.member_test.html} - - ( - {ts}clear{/ts}) -

diff --git a/templates/CRM/Pledge/Form/Search/Common.tpl b/templates/CRM/Pledge/Form/Search/Common.tpl index 07e78649e7..9d3a8329a9 100644 --- a/templates/CRM/Pledge/Form/Search/Common.tpl +++ b/templates/CRM/Pledge/Form/Search/Common.tpl @@ -78,7 +78,7 @@ diff --git a/templates/CRM/Profile/Form/Dynamic.tpl b/templates/CRM/Profile/Form/Dynamic.tpl index 8ed3c3b7b7..75b97da33d 100644 --- a/templates/CRM/Profile/Form/Dynamic.tpl +++ b/templates/CRM/Profile/Form/Dynamic.tpl @@ -159,9 +159,6 @@ function checkResponse(responseText, statusText, xhr, $form) { {/foreach}
{ts}Include these membership types{/ts}{ts}Auto-renew{/ts}
{ts}Auto-renew{/ts}
@@ -61,24 +57,12 @@ {$form.member_is_primary.label} {help id="id-member_is_primary" file="CRM/Member/Form/Search.hlp"} {$form.member_is_primary.html} - - ( - {ts}clear{/ts}) -

{$form.member_pay_later.label} {$form.member_pay_later.html} - - ( - {ts}clear{/ts}) -

{$form.member_auto_renew.label} {$form.member_auto_renew.html} - - ( - {ts}clear{/ts}) -


- {$form.pledge_test.label} {help id="is-test" file="CRM/Contact/Form/Search/Advanced"}   {$form.pledge_test.html} ({ts}clear{/ts}) + {$form.pledge_test.label} {help id="is-test" file="CRM/Contact/Form/Search/Advanced"}   {$form.pledge_test.html}
- {if $field.html_type eq 'Radio' and $form.formName eq 'Edit' and $field.is_view neq 1 } -  ({ts}clear{/ts}) - {/if} {/strip}
@@ -205,10 +202,7 @@ function checkResponse(responseText, statusText, xhr, $form) { {else} {$form.$n.html} {/if} - {if (($n eq 'gender') or ($field.html_type eq 'Radio' and $form.formName eq 'Edit' and $field.is_required neq 1)) and - ($field.is_view neq 1)} -  ({ts}clear{/ts}) - {elseif $field.html_type eq 'Autocomplete-Select'} + {if $field.html_type eq 'Autocomplete-Select'} {if $field.data_type eq 'ContactReference'} {include file="CRM/Custom/Form/ContactReference.tpl" element_name = $n} {else} diff --git a/templates/CRM/Profile/Form/Search.tpl b/templates/CRM/Profile/Form/Search.tpl index 6143ca7917..f9605b3430 100644 --- a/templates/CRM/Profile/Form/Search.tpl +++ b/templates/CRM/Profile/Form/Search.tpl @@ -87,9 +87,6 @@ {/foreach} - {if $field.html_type eq 'Radio' and $form.formName eq 'Search'} - ({ts}clear{/ts}) - {/if} {/strip} @@ -122,9 +119,7 @@ {else} {$form.$n.html} {/if} - {if ($n eq 'gender') or ($field.html_type eq 'Radio' and $form.formName eq 'Search')} - ({ts}clear{/ts}) - {elseif $field.html_type eq 'Autocomplete-Select'} + {if $field.html_type eq 'Autocomplete-Select'} {if $field.data_type eq 'ContactReference'} {include file="CRM/Custom/Form/ContactReference.tpl" element_name = $n} {else} diff --git a/templates/CRM/UF/Form/Block.tpl b/templates/CRM/UF/Form/Block.tpl index a789951303..3c93b82d97 100644 --- a/templates/CRM/UF/Form/Block.tpl +++ b/templates/CRM/UF/Form/Block.tpl @@ -131,17 +131,10 @@ {/if} {else} {if $prefix}{$form.$prefix.$n.html}{else}{$form.$n.html}{/if} - {if $n eq 'gender' && $form.$fieldName.frozen neq true} - ({ts}clear{/ts}) - {/if} {/if} {*CRM-4564*} - {if $field.html_type eq 'Radio' && $form.$fieldName.frozen neq true && $field.is_required neq 1} - - ({ts}clear{/ts}) - - {elseif $field.html_type eq 'Autocomplete-Select'} + {if $field.html_type eq 'Autocomplete-Select'} {if $field.data_type eq 'ContactReference'} {include file="CRM/Custom/Form/ContactReference.tpl" element_name = $n} {else} diff --git a/templates/CRM/UF/Form/Preview.tpl b/templates/CRM/UF/Form/Preview.tpl index aa94a78ecc..9d47362840 100644 --- a/templates/CRM/UF/Form/Preview.tpl +++ b/templates/CRM/UF/Form/Preview.tpl @@ -97,9 +97,6 @@ {/if} {/foreach} - {if $field.html_type eq 'Radio' and $form.formName eq 'Preview'} - ({ts}clear{/ts}) - {/if} {/strip} @@ -132,9 +129,7 @@ {/if} {$form.$n.html} {if $field.is_view eq 0} - {if ( $field.html_type eq 'Radio' or $n eq 'gender') and $form.formName eq 'Preview'} - ({ts}clear{/ts}) - {elseif $field.html_type eq 'Autocomplete-Select'} + {if $field.html_type eq 'Autocomplete-Select'} {if $field.data_type eq 'ContactReference'} {include file="CRM/Custom/Form/ContactReference.tpl" element_name = $n} {else} diff --git a/templates/CRM/common/jcalendar.tpl b/templates/CRM/common/jcalendar.tpl index 98b67ed168..3e21f188c3 100644 --- a/templates/CRM/common/jcalendar.tpl +++ b/templates/CRM/common/jcalendar.tpl @@ -64,7 +64,7 @@ {/if} {if $action neq 1028} - ({ts}clear{/ts}) + {/if}