X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=js%2Fcrm.searchForm.js;h=bf993611cb94ab036f6bdfff74e8c03cc193d2bb;hb=79d7553f54ee92645478d09cf794a539ebb15856;hp=dc3a9cb637299b9e441aa37716a6797a950a4a53;hpb=9862ec3d8c667456d5d14dbe3391bae1820c14b3;p=civicrm-core.git diff --git a/js/crm.searchForm.js b/js/crm.searchForm.js index dc3a9cb637..bf993611cb 100644 --- a/js/crm.searchForm.js +++ b/js/crm.searchForm.js @@ -23,6 +23,19 @@ return $('input.select-row:checked', form).length; } + function clearSelections(e) { + if (selected) { + var $form = $(this).closest('form'); + $('input.select-row, input.select-rows', $form).prop('checked', false).closest('tr').removeClass('crm-row-selected'); + if (usesAjax()) { + phoneHome(false, $(this)); + } else { + selected = 0; + displayCount(); + } + } + } + function usesAjax() { return $(form).hasClass('crm-ajax-selection-form'); } @@ -31,7 +44,7 @@ function phoneHome(single, $el, event) { var url = CRM.url('civicrm/ajax/markSelection'); var params = {qfKey: 'civicrm search ' + $('input[name=qfKey]', form).val()}; - if (!$el.is(':checked')) { + if (!$el.is(':checked') || $el.is('input[name=radio_ts][value=ts_all]')) { params.action = 'unselect'; params.state = 'unchecked'; } @@ -45,8 +58,8 @@ $("input.select-row, input.select-rows", form).prop('checked', false).closest('tr').removeClass('crm-row-selected'); } // Master checkbox - else { - params.name = $('input.select-row').map(function() {return $(this).attr('id')}).get().join('-'); + else if ($el.hasClass('select-rows')) { + params.name = $('input.select-row').map(function() {return $(this).attr('id');}).get().join('-'); } } $.getJSON(url, params, function(data) { @@ -70,71 +83,81 @@ $('#crm-main-content-wrapper').crmSnippet({url: location}).crmSnippet('refresh'); } - // Handle user interactions with search results - $('#crm-container') - // When initially loading and reloading (paging) the results - .on('crmLoad', function(e) { - if ($(e.target).is('#crm-container') || $(e.target).is('#crm-main-content-wrapper')) { + /** + * When initially loading and reloading (paging) the results + */ + function initForm() { + clearTaskMenu(); + if (usesAjax()) { + selected = parseInt($('label[for*=ts_sel] span', form).text(), 10); + } else { + selected = countCheckboxes(); + displayCount(); + } + enableTaskMenu(); + } + + $(function() { + initForm(); + // Handle user interactions with search results + $('#crm-container') + // When toggling between "all records" and "selected records only" + .on('change', '[name=radio_ts]', function() { clearTaskMenu(); - if (usesAjax()) { - selected = parseInt($('label[for*=ts_sel] span', form).text(), 10); - } else { - selected = countCheckboxes(); - displayCount(); - } enableTaskMenu(); - } - }) - // When toggling between "all records" and "selected records only" - .on('change', '[name=radio_ts]', function() { - clearTaskMenu(); - enableTaskMenu(); - }) - // When making a selection - .on('click', 'input.select-row, input.select-rows, a.crm-selection-reset', function(event) { - var $el = $(this), - $form = $el.closest('form'), - single = $el.is('input.select-row'); - clearTaskMenu(); - $('input[name=radio_ts][value=ts_sel]', $form).prop('checked', true); - if (!usesAjax()) { - if (single) { - selected = countCheckboxes(); - } else { - selected = $el.is(':checked') ? $('input.select-row', $form).length : 0; - } - displayCount(); - enableTaskMenu(); - } else { - phoneHome(single, $el, event); - } - }) - // When selecting a task - .on('change', 'select#task', function() { - var $form = $(this).closest('form'), - $go = $('input.crm-search-go-button', $form); - if (1) { - $go.click(); - } - // The following code can load the task in a popup, however not all tasks function correctly with this - // So it's disabled pending a per-task opt-in mechanism - else { - var data = $form.serialize() + '&' + $go.attr('name') + '=' + $go.attr('value'); - var url = $form.attr('action'); - url += (url.indexOf('?') < 0 ? '?' : '&') + 'snippet=json'; + }) + .on('click', 'input[name=radio_ts][value=ts_all]', clearSelections) + // When making a selection + .on('click', 'input.select-row, input.select-rows, a.crm-selection-reset', function(event) { + var $el = $(this), + $form = $el.closest('form'), + single = $el.is('input.select-row'); clearTaskMenu(); - $.post(url, data, function(data) { - CRM.loadForm(data.userContext).on('crmFormSuccess', refresh); + $('input[name=radio_ts][value=ts_sel]', $form).prop('checked', true); + if (!usesAjax()) { + if (single) { + selected = countCheckboxes(); + } else { + selected = $el.is(':checked') ? $('input.select-row', $form).length : 0; + } + displayCount(); enableTaskMenu(); - }, 'json'); - } - }); + } else { + phoneHome(single, $el, event); + } + }) + // When selecting a task + .on('change', 'select#task', function() { + var $form = $(this).closest('form'), + $go = $('input.crm-search-go-button', $form); + if (1) { + $go.click(); + } + // The following code can load the task in a popup, however not all tasks function correctly with this + // So it's disabled pending a per-task opt-in mechanism + else { + var data = $form.serialize() + '&' + $go.attr('name') + '=' + $go.attr('value'); + var url = $form.attr('action'); + url += (url.indexOf('?') < 0 ? '?' : '&') + 'snippet=json'; + clearTaskMenu(); + $.post(url, data, function(data) { + CRM.loadForm(data.userContext).on('crmFormSuccess', refresh); + enableTaskMenu(); + }, 'json'); + } + }); - // Add a specialized version of livepage functionality - $('#crm-main-content-wrapper') - // Open action links in a popup - .off('.crmLivePage') - .on('click.crmLivePage', active, CRM.popup) - .on('crmPopupFormSuccess.crmLivePage', active, refresh); + // Add a specialized version of livepage functionality + $('#crm-main-content-wrapper') + .on('crmLoad', function(e) { + if ($(e.target).is(this)) { + initForm(); + } + }) + // Open action links in a popup + .off('.crmLivePage') + .on('click.crmLivePage', active, CRM.popup) + .on('crmPopupFormSuccess.crmLivePage', active, refresh); + }); })(CRM.$, CRM._);