X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=js%2Fcrm.searchForm.js;h=42a371dcecf42d18e90d97dae3038d2992d098b7;hb=d891a27350adb239c786c02d0f26decaea9bb328;hp=c1105213301532c0c3b47a0f74f3ba1af8c5bdcd;hpb=3181d053e2cb764e7fd0eae25e2d439871a019a8;p=civicrm-core.git
diff --git a/js/crm.searchForm.js b/js/crm.searchForm.js
index c110521330..42a371dcec 100644
--- a/js/crm.searchForm.js
+++ b/js/crm.searchForm.js
@@ -63,13 +63,13 @@
params.name = $('input.select-row').map(function() {return $(this).attr('id');}).get().join('-');
}
}
- $.getJSON(url, params, function(data) {
+ $.post(url, params, function(data) {
if (data && data.getCount !== undefined) {
selected = data.getCount;
displayCount();
enableTaskMenu();
}
- });
+ }, 'json');
}
/**
@@ -132,14 +132,50 @@
}
})
// When selecting a task
- .on('change', 'select#task', function() {
+ .on('change', 'select#task', function(e) {
var $form = $(this).closest('form'),
- $go = $('input.crm-search-go-button', $form);
- if (1) {
+ $go = $('input.crm-search-go-button', $form);
+ var $selectedOption = $(this).find(':selected');
+ if (!$selectedOption.val()) {
+ // do not blank refresh the empty option.
+ return;
+ }
+ if ($selectedOption.data('is_confirm')) {
+ var confirmed = false;
+ var refresh_fields = $selectedOption.data('confirm_refresh_fields');
+ var $message = '
' + (($selectedOption.data('confirm_message') !== undefined) ? $selectedOption.data('confirm_message') : '') + '
';
+ if (refresh_fields === undefined) {
+ refresh_fields = {};
+ }
+ $.each(refresh_fields, function (refreshIndex, refreshValue) {
+ var $refresh_field = $(refreshValue.selector);
+ var prependText = (refreshValue.prepend !== undefined) ? refreshValue.prepend : '';
+ var existingInput = $refresh_field.find('input').val();
+ $message = $message + '' + $refresh_field.html().replace(existingInput, prependText + existingInput) + '
';
+ });
+
+ CRM.confirm({
+ title: $selectedOption.data('confirm_title') ? $selectedOption.data('confirm_title') : ts('Confirm action'),
+ message: ''
+ })
+ .on('crmConfirm:yes', function() {
+ confirmed = true;
+ $.each(refresh_fields, function (refreshIndex, refreshValue) {
+ $('#' + refreshIndex).val($('.crm-confirm #' + refreshIndex).val());
+ });
+ $go.click();
+ })
+ .on('crmConfirm:no', function() {
+ $('#task').val('').change();
+ return;
+ });
+ }
+ else if (!$(this).find(':selected').data('supports_modal')) {
$go.click();
+ $('#task').val('').select2('val', '');
}
// 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
+ // So it's a per-task opt-in mechanism.
else {
var data = $form.serialize() + '&' + $go.attr('name') + '=' + $go.attr('value');
var url = $form.attr('action');