X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=js%2FCommon.js;h=1dee5a526a7798292b3c9968c26ea618d98c299f;hb=dc673140ba474cdafcfa46466ec6f6d91dea7a65;hp=c090e9ceefe2b2b9f9cfb66db8fc14474045bca5;hpb=94585d7fd7abe84536857265a6a7ee39c0461452;p=civicrm-core.git
diff --git a/js/Common.js b/js/Common.js
index c090e9ceef..1dee5a526a 100644
--- a/js/Common.js
+++ b/js/Common.js
@@ -238,9 +238,13 @@ if (!CRM.vars) CRM.vars = {};
};
var scriptsLoaded = {};
- CRM.loadScript = function(url) {
+ CRM.loadScript = function(url, appendCacheCode) {
if (!scriptsLoaded[url]) {
- var script = document.createElement('script');
+ var script = document.createElement('script'),
+ src = url;
+ if (appendCacheCode !== false) {
+ src += (_.includes(url, '?') ? '&r=' : '?r=') + CRM.config.resourceCacheCode;
+ }
scriptsLoaded[url] = $.Deferred();
script.onload = function () {
// Give the script time to execute
@@ -256,7 +260,7 @@ if (!CRM.vars) CRM.vars = {};
CRM.CMSjQuery = window.jQuery;
window.jQuery = CRM.$;
}
- script.src = url + (_.includes(url, '?') ? '&r=' : '?r=') + CRM.config.resourceCacheCode;
+ script.src = src;
document.getElementsByTagName("head")[0].appendChild(script);
}
return scriptsLoaded[url];
@@ -574,7 +578,6 @@ if (!CRM.vars) CRM.vars = {};
};
$el.on('select2-open.crmEntity', function() {
var $el = $(this);
- renderEntityRefFilterValue($el);
$('#select2-drop')
.off('.crmEntity')
.on('click.crmEntity', 'a.crm-add-entity', function(e) {
@@ -605,7 +608,7 @@ if (!CRM.vars) CRM.vars = {};
filter.value = $(this).val();
$(this).toggleClass('active', !!filter.value);
$el.data('user-filter', filter);
- if (filter.value) {
+ if (filter.value && $(this).is('select')) {
// Once a filter has been chosen, rerender create links and refocus the search box
$el.select2('close');
$el.select2('open');
@@ -743,14 +746,14 @@ if (!CRM.vars) CRM.vars = {};
'' + entityRefFilterValueMarkup(filter, filterSpec) + '';
+ '' + entityRefFilterValueMarkup($el, filter, filterSpec) + '';
return markup;
}
/**
* Provide markup for entity ref filter value field
*/
- function entityRefFilterValueMarkup(filter, filterSpec) {
+ function entityRefFilterValueMarkup($el, filter, filterSpec) {
var markup = '';
if (filterSpec) {
var attrs = '',
@@ -764,7 +767,12 @@ if (!CRM.vars) CRM.vars = {};
attrs += ' ' + attr + '="' + val + '"';
});
if (filterSpec.type === 'select') {
- markup = '';
+ var fieldName = _.last(filter.key.split('.')),
+ options = [{key: '', value: ts('- select -')}];
+ if (filterSpec.options) {
+ options = options.concat(getEntityRefFilterOptions(fieldName, $el, filterSpec));
+ }
+ markup = '';
} else {
markup = '';
}
@@ -783,7 +791,7 @@ if (!CRM.vars) CRM.vars = {};
$valField = null;
if (filterSpec) {
$('.crm-entityref-filter-value', '#select2-drop').remove();
- $valField = $(entityRefFilterValueMarkup(filter, filterSpec));
+ $valField = $(entityRefFilterValueMarkup($el, filter, filterSpec));
$keyField.after($valField);
if (filterSpec.type === 'select') {
loadEntityRefFilterOptions(filter, filterSpec, $valField, $el);
@@ -798,10 +806,9 @@ if (!CRM.vars) CRM.vars = {};
*/
function loadEntityRefFilterOptions(filter, filterSpec, $valField, $el) {
// Fieldname may be prefixed with joins - strip those out
- var fieldName = _.last(filter.key.split('.')),
- params = $.extend({params: {}}, $el.data('api-params') || {}).params;
+ var fieldName = _.last(filter.key.split('.'));
if (filterSpec.options) {
- setEntityRefFilterOptions($valField, fieldName, params, filterSpec);
+ CRM.utils.setOptions($valField, getEntityRefFilterOptions(fieldName, $el, filterSpec), false, filter.value);
return;
}
$('.crm-entityref-filters select', '#select2-drop').prop('disabled', true);
@@ -811,19 +818,19 @@ if (!CRM.vars) CRM.vars = {};
// Store options globally so we don't have to look them up again
filterSpec.options = result.values;
$('.crm-entityref-filters select', '#select2-drop').prop('disabled', false);
- setEntityRefFilterOptions($valField, fieldName, params, filterSpec);
- $valField.val(filter.value || '');
+ CRM.utils.setOptions($valField, getEntityRefFilterOptions(fieldName, $el, filterSpec), false, filter.value);
});
}
- function setEntityRefFilterOptions($valField, fieldName, params, filterSpec) {
- var values = _.cloneDeep(filterSpec.options);
+ function getEntityRefFilterOptions(fieldName, $el, filterSpec) {
+ var values = _.cloneDeep(filterSpec.options),
+ params = $.extend({params: {}}, $el.data('api-params') || {}).params;
if (fieldName === 'contact_type' && params.contact_type) {
values = _.remove(values, function(option) {
return option.key.indexOf(params.contact_type + '__') === 0;
});
}
- CRM.utils.setOptions($valField, values);
+ return values;
}
//CRM-15598 - Override url validator method to allow relative url's (e.g. /index.htm)
@@ -920,6 +927,7 @@ if (!CRM.vars) CRM.vars = {};
})
.on('dialogopen', function(e) {
var $el = $(e.target);
+ $('body').addClass('ui-dialog-open');
// Modal dialogs should disable scrollbars
if ($el.dialog('option', 'modal')) {
$el.addClass('modal-dialog');
@@ -936,6 +944,9 @@ if (!CRM.vars) CRM.vars = {};
$(this).button('option', 'icons', {primary: 'fa-expand'});
} else {
var menuHeight = $('#civicrm-menu').outerHeight();
+ if ($('body').hasClass('crm-menubar-below-cms-menu')) {
+ menuHeight += $('#civicrm-menu').offset().top;
+ }
$el.data('origSize', {
position: {my: 'center', at: 'center center+' + (menuHeight / 2), of: window},
width: $el.dialog('option', 'width'),
@@ -954,6 +965,9 @@ if (!CRM.vars) CRM.vars = {};
if ($('.ui-dialog .modal-dialog:visible').not(e.target).length < 1) {
$('body').css({overflow: ''});
}
+ if ($('.ui-dialog-content:visible').not(e.target).length < 1) {
+ $('body').removeClass('ui-dialog-open');
+ }
})
.on('submit', function(e) {
// CRM-14353 - disable changes warn when submitting a form