// https://civicrm.org/licensing
+/* global CRM:true */
var CRM = CRM || {};
var cj = CRM.$ = jQuery;
CRM._ = _;
*/
function ts(text, params) {
"use strict";
- text = CRM.strings[text] || text;
+ var d = (params && params.domain) ? ('strings::' + params.domain) : null;
+ if (d && CRM[d] && CRM[d][text]) {
+ text = CRM[d][text];
+ }
+ else if (CRM.strings[text]) {
+ text = CRM.strings[text];
+ }
if (typeof(params) === 'object') {
for (var i in params) {
if (typeof(params[i]) === 'string' || typeof(params[i]) === 'number') {
return text;
}
+// Legacy code - ignore warnings
+/* jshint ignore:start */
+
/**
* This function is called by default at the bottom of template files which have forms that have
* conditionally displayed/hidden sections and elements. The PHP is responsible for generating
return false;
}
+/* jshint ignore:end */
+
CRM.utils = CRM.utils || {};
CRM.strings = CRM.strings || {};
(function ($, _, undefined) {
"use strict";
+ /* jshint validthis: true */
// Theme classes for unattached elements
$.fn.select2.defaults.dropdownCssClass = $.ui.dialog.prototype.options.dialogClass = 'crm-container';
return !!$(e.target).closest('.ui-dialog, .ui-datepicker, .select2-drop, .cke_dialog').length;
};
+ // Implements jQuery hook.prop
+ $.propHooks.disabled = {
+ set: function (el, value, name) {
+ // Sync button enabled status with wrapper css
+ if ($(el).is('span.crm-button > input.crm-form-submit')) {
+ $(el).parent().toggleClass('crm-button-disabled', !!value);
+ }
+ // Sync button enabled status with dialog button
+ if ($(el).is('.ui-dialog input.crm-form-submit')) {
+ $(el).closest('.ui-dialog').find('.ui-dialog-buttonset button[data-identifier='+ $(el).attr('name') +']').prop('disabled', value);
+ }
+ if ($(el).is('.crm-form-date-wrapper .crm-hidden-date')) {
+ $(el).siblings().prop('disabled', value);
+ }
+ }
+ };
+
/**
* Populate a select list, overwriting the existing options except for the placeholder.
* @param select jquery selector - 1 or more select elements
});
return isDirty;
};
-
+
+ /**
+ * This provides defaults for ui.dialog which either need to be calculated or are different from global defaults
+ *
+ * @param settings
+ * @returns {*}
+ */
+ CRM.utils.adjustDialogDefaults = function(settings) {
+ settings = $.extend({width: '65%', height: '65%', modal: true}, settings || {});
+ // Support relative height
+ if (typeof settings.height === 'string' && settings.height.indexOf('%') > 0) {
+ settings.height = parseInt($(window).height() * (parseFloat(settings.height)/100), 10);
+ }
+ // Responsive adjustment - increase percent width on small screens
+ if (typeof settings.width === 'string' && settings.width.indexOf('%') > 0) {
+ var screenWidth = $(window).width(),
+ percentage = parseInt(settings.width.replace('%', ''), 10),
+ gap = 100-percentage;
+ if (screenWidth < 701) {
+ settings.width = '100%';
+ }
+ else if (screenWidth < 1400) {
+ settings.width = '' + parseInt(percentage+gap-((screenWidth - 700)/7*(gap)/100), 10) + '%';
+ }
+ }
+ return settings;
+ };
+
/**
* Wrapper for select2 initialization function; supplies defaults
* @param options object
return combined;
}
+ function copyAttributes($source, $target, attributes) {
+ _.each(attributes, function(name) {
+ if ($source.attr(name)) {
+ $target.attr(name, $source.attr(name));
+ }
+ });
+ }
+
+ $.fn.crmDatepicker = function(options) {
+ return $(this).each(function() {
+ if ($(this).is('.crm-form-date-wrapper .crm-hidden-date')) {
+ // Already initialized
+ return;
+ }
+ var
+ $dataField = $(this).wrap('<span class="crm-form-date-wrapper" />'),
+ settings = $.extend({}, $dataField.data('datepicker') || {}, options || {}),
+ $dateField = $(),
+ $timeField = $(),
+ $clearLink = $();
+
+ if (settings.allowClear !== undefined ? settings.allowClear : !$dataField.hasClass('required')) {
+ $clearLink = $('<a class="crm-hover-button crm-clear-link" title="'+ ts('Clear') +'"><span class="icon ui-icon-close"></span></a>')
+ .insertAfter($dataField);
+ }
+ if (settings.time !== false) {
+ $timeField = $('<input>').insertAfter($dataField);
+ copyAttributes($dataField, $timeField, ['class', 'disabled']);
+ $timeField
+ .addClass('crm-form-text crm-form-time')
+ .attr('placeholder', $dataField.attr('time-placeholder') === undefined ? ts('Time') : $dataField.attr('time-placeholder'))
+ .change(updateDataField)
+ .timeEntry({
+ spinnerImage: '',
+ show24Hours: settings.time === true || settings.time === undefined ? CRM.config.timeIs24Hr : settings.time == '24'
+ });
+ }
+ if (settings.date !== false) {
+ $dateField = $('<input>').insertAfter($dataField);
+ copyAttributes($dataField, $dateField, ['placeholder', 'style', 'class', 'disabled']);
+ $dateField.addClass('crm-form-text crm-form-date');
+ settings.dateFormat = settings.dateFormat || CRM.config.dateInputFormat;
+ settings.changeMonth = _.includes('m', settings.dateFormat);
+ settings.changeYear = _.includes('y', settings.dateFormat);
+ $dateField.datepicker(settings).change(updateDataField);
+ }
+ function updateInputFields(e, context) {
+ var val = $dataField.val(),
+ time = null;
+ if (context !== 'userInput' && context !== 'crmClear') {
+ if ($dateField.length) {
+ $dateField.datepicker('setDate', _.includes(val, '-') ? $.datepicker.parseDate('yy-mm-dd', val) : null);
+ }
+ if ($timeField.length) {
+ if (val.length === 8) {
+ time = val;
+ } else if (val.length === 19) {
+ time = val.split(' ')[1];
+ }
+ $timeField.timeEntry('setTime', time);
+ }
+ }
+ $clearLink.css('visibility', val ? 'visible' : 'hidden');
+ }
+ function updateDataField(e, context) {
+ if (context !== 'crmClear') {
+ var val = '';
+ if ($dateField.val()) {
+ val = $.datepicker.formatDate('yy-mm-dd', $dateField.datepicker('getDate'));
+ }
+ if ($timeField.val()) {
+ val += (val ? ' ' : '') + $timeField.timeEntry('getTime').toTimeString().substr(0, 8);
+ }
+ $dataField.val(val).trigger('change', ['userInput']);
+ }
+ }
+ $dataField.hide().addClass('crm-hidden-date').on('change', updateInputFields);
+ updateInputFields();
+ });
+ };
+
CRM.utils.formatSelect2Result = function (row) {
var markup = '<div class="crm-select2-row">';
if (row.image !== undefined) {
});
$el.dialog('option', {width: '100%', height: ($(window).height() - menuHeight), position: {my: "top", at: "top+"+menuHeight, of: window}});
}
+ $el.trigger('dialogresize');
e.preventDefault();
});
}
$('#crm-container #mainTabContainer').addClass('narrowpage');
$('#crm-container #mainTabContainer.narrowpage #contactTopBar td').each(function (index) {
if (index > 1) {
- if (index % 2 == 0) {
+ if (index % 2 === 0) {
$(this).parent().after('<tr class="narrowadded"></tr>');
}
var item = $(this);
var nitem = $(this);
var parent = $(this).parent();
$(this).parent().prev().append(nitem);
- if (parent.children().size() == 0) {
+ if (parent.children().size() === 0) {
parent.remove();
}
});
$(this).addClass('crm-processed');
$(this).addClass('crm-tooltip-active');
var topDistance = e.pageY - $(window).scrollTop();
- if (topDistance < 300 | topDistance < $(this).children('.crm-tooltip-wrapper').height()) {
+ if (topDistance < 300 || topDistance < $(this).children('.crm-tooltip-wrapper').height()) {
$(this).addClass('crm-tooltip-down');
}
if (!$(this).children('.crm-tooltip-wrapper').length) {
message: ts('Are you sure you want to continue?'),
url: null,
width: 'auto',
- modal: true,
+ height: 'auto',
resizable: false,
dialogClass: 'crm-container crm-confirm',
close: function () {
yes: ts('Continue')
}
};
+ if (options && options.url) {
+ settings.resizable = true;
+ settings.height = '50%';
+ }
$.extend(settings, ($.isFunction(options) ? arguments[1] : options) || {});
+ settings = CRM.utils.adjustDialogDefaults(settings);
if (!settings.buttons && $.isPlainObject(settings.options)) {
$.each(settings.options, function(op, label) {
buttons.push({
};
};
+ CRM.addStrings = function(domain, strings) {
+ var bucket = (domain == 'civicrm' ? 'strings' : 'strings::' + domain);
+ CRM[bucket] = CRM[bucket] || {};
+ _.extend(CRM[bucket], strings);
+ };
+
/**
* @see https://wiki.civicrm.org/confluence/display/CRMDOC/Notification+Reference
*/
expires: 0
};
if ($(this).length) {
- if (title == '') {
+ if (title === '') {
var label = $('label[for="' + $(this).attr('name') + '"], label[for="' + $(this).attr('id') + '"]').not('[generated=true]');
if (label.length) {
label.addClass('crm-error');
var $label = label.clone();
- if (text == '' && $('.crm-marker', $label).length > 0) {
+ if (text === '' && $('.crm-marker', $label).length > 0) {
text = $('.crm-marker', $label).attr('title');
}
$('.crm-marker', $label).remove();
// Handle clear button for form elements
.on('click', 'a.crm-clear-link', function() {
- $(this).css({visibility: 'hidden'}).siblings('.crm-form-radio:checked').prop('checked', false).change();
- $(this).siblings('input:text').val('').change();
+ $(this).css({visibility: 'hidden'}).siblings('.crm-form-radio:checked').prop('checked', false).trigger('change', ['crmClear']);
+ $(this).siblings('input:text').val('').trigger('change', ['crmClear']);
return false;
})
.on('change', 'input.crm-form-radio:checked', function() {
}
}
};
+
+ // Determine if a user has a given permission.
+ // @see CRM_Core_Resources::addPermissions
+ CRM.checkPerm = function(perm) {
+ return CRM.permissions[perm];
+ };
})(jQuery, _);