(function($, _, undefined) {
"use strict";
var selected = 0,
- form = 'form.crm-search-form';
+ form = 'form.crm-search-form',
+ active = 'a.button, a.action-item:not(.crm-enable-disable), a.crm-popup';
function clearTaskMenu() {
$('select#task', form).val('').select2('val', '').prop('disabled', true).select2('disable');
});
}
+ /**
+ * Refresh the current page
+ */
+ function refresh() {
+ // Clear cached search results using force=1 argument
+ var location = $('#crm-main-content-wrapper').crmSnippet().crmSnippet('option', 'url');
+ if (!(location.match(/[?&]force=1/))) {
+ location += '&force=1';
+ }
+ $('#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
})
// When selecting a task
.on('change', 'select#task', function() {
- $(this).siblings('input[type=submit]').click();
+ 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);
+
})(CRM.$, CRM._);