From d24c529a3c58ef14a209b42b6a37bbb0a9d4e001 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 20 Jan 2015 21:08:16 -0500 Subject: [PATCH] WordReplacement form improvement - auto-check new items and warn unsaved changes --- CRM/Admin/Form/WordReplacements.php | 15 +--- templates/CRM/Admin/Form/WordReplacements.tpl | 68 +++++++++++-------- 2 files changed, 44 insertions(+), 39 deletions(-) diff --git a/CRM/Admin/Form/WordReplacements.php b/CRM/Admin/Form/WordReplacements.php index 009060b42e..d33f3e846a 100644 --- a/CRM/Admin/Form/WordReplacements.php +++ b/CRM/Admin/Form/WordReplacements.php @@ -23,7 +23,7 @@ | GNU Affero General Public License or the licensing of CiviCRM, | | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ - */ +*/ /** * @@ -39,6 +39,8 @@ class CRM_Admin_Form_WordReplacements extends CRM_Core_Form { protected $_defaults = NULL; + public $unsavedChangesWarn = TRUE; + public function preProcess() { // This controller was originally written to CRUD $config->locale_custom_strings, // but that's no longer the canonical store. Re-sync from canonical store to ensure @@ -48,16 +50,6 @@ class CRM_Admin_Form_WordReplacements extends CRM_Core_Form { $this->_soInstance = CRM_Utils_Array::value('instance', $_GET); $this->assign('soInstance', $this->_soInstance); - $breadCrumbUrl = CRM_Utils_System::url('civicrm/admin/options/wordreplacements', - "reset=1" - ); - $breadCrumb = array( - array( - 'title' => ts('Word Replacements'), - 'url' => $breadCrumbUrl, - ), - ); - CRM_Utils_System::appendBreadCrumb($breadCrumb); } /** @@ -281,5 +273,4 @@ class CRM_Admin_Form_WordReplacements extends CRM_Core_Form { )); } } - } diff --git a/templates/CRM/Admin/Form/WordReplacements.tpl b/templates/CRM/Admin/Form/WordReplacements.tpl index 214f3a5c78..85f841715e 100644 --- a/templates/CRM/Admin/Form/WordReplacements.tpl +++ b/templates/CRM/Admin/Form/WordReplacements.tpl @@ -26,7 +26,8 @@ {* template for a single row *} {if $soInstance} - + {$form.enabled.$soInstance.html} {$form.old.$soInstance.html} {$form.new.$soInstance.html} @@ -45,17 +46,20 @@ @@ -71,36 +75,35 @@ CRM.$(function($) { {/literal} {if $stringOverrideInstances} - {foreach from=$stringOverrideInstances key="index" item="instance"} - buildStringOverrideRow( {$instance} ); - {/foreach} + {* Rebuild necessary rows in case of form error *} + {foreach from=$stringOverrideInstances key="index" item="instance"} + buildStringOverrideRow( {$instance} ); + {/foreach} {/if} {literal} function buildStringOverrideRow( curInstance ) { - var rowId = 'string_override_row_'; + var newRowNum; if (curInstance) { - if (curInstance <= 10) return; - currentInstance = curInstance; - previousInstance = currentInstance - 1; + // Don't fetch if already present + if ($('tr.string-override-row[data-row=' + curInstance + ']').length) { + return; + } + newRowNum = curInstance; } else { - var previousInstance = $('[id^="'+ rowId +'"]:last').attr('id').slice(rowId.length); - var currentInstance = parseInt(previousInstance) + 1; + newRowNum = 1 + $('tr.string-override-row:last').data('row'); } var dataUrl = {/literal}"{crmURL q='snippet=4' h=0}"{literal}; - dataUrl += "&instance="+currentInstance; - - var prevInstRowId = '#string_override_row_' + previousInstance; + dataUrl += "&instance="+newRowNum; $.ajax({ url: dataUrl, async: false, success: function(html) { - $(prevInstRowId).after(html); - $('#old_'+currentInstance).TextAreaResizer(); - $('#new_'+currentInstance).TextAreaResizer(); + $('.string-override-table tbody').append(html); + $('tr.string-override-row:last').trigger('crmLoad'); } }); } @@ -109,6 +112,17 @@ buildStringOverrideRow(false); e.preventDefault(); }); + + // Auto-check new items + $('.string-override-table').on('keyup', 'textarea', function() { + if (!$(this).data('crm-initial-value')) { + var otherValue = $(this).closest('tr').find('textarea').not(this).val(); + if ($(this).val() && otherValue) { + $(this).closest('tr').find('input[type=checkbox]').first().prop('checked', true); + } + } + }); + }); {/literal} -- 2.25.1
- - - - - - - - - {section name="numStrings" start=1 step=1 loop=$numStrings+1} - {include file="CRM/Admin/Form/WordReplacements.tpl" soInstance=$smarty.section.numStrings.index} - {/section} +
{ts}Enabled{/ts}{ts}Original{/ts}{ts}Replacement{/ts}{ts}Exact Match{/ts}
+ + + + + + + + + + {section name="numStrings" start=1 step=1 loop=$numStrings+1} + {include file="CRM/Admin/Form/WordReplacements.tpl" soInstance=$smarty.section.numStrings.index} + {/section} +
{ts}Enabled{/ts}{ts}Original{/ts}{ts}Replacement{/ts}{ts}Exact Match{/ts}
    {ts}Add row{/ts}