var script = document.createElement('script');
scriptsLoaded[url] = $.Deferred();
script.onload = function () {
- scriptsLoaded[url].resolve();
+ // Give the script time to execute
+ window.setTimeout(function () {
+ if (window.jQuery === CRM.$ && CRM.CMSjQuery) {
+ window.jQuery = CRM.CMSjQuery;
+ }
+ scriptsLoaded[url].resolve();
+ }, 100);
};
+ // Make jQuery global available while script is loading
+ if (window.jQuery !== CRM.$) {
+ CRM.CMSjQuery = window.jQuery;
+ window.jQuery = CRM.$;
+ }
script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
}
function isValidDate() {
// FIXME: parseDate doesn't work with incomplete date formats; skip validation if no month, day or year in format
var lowerFormat = settings.dateFormat.toLowerCase();
- if (lowerFormat.indexOf('y') < 0 || lowerFormat.indexOf('m') < 0 || lowerFormat.indexOf('d') < 0) {
+ if (lowerFormat.indexOf('y') < 0 || lowerFormat.indexOf('m') < 0 || !dateHasDay()) {
return true;
}
try {
return false;
}
}
+
+ /**
+ * Does the date format contain the day.
+ *
+ * @returns {boolean}
+ */
+ function dateHasDay() {
+ var lowerFormat = settings.dateFormat.toLowerCase();
+ if (lowerFormat.indexOf('d') < 0) {
+ return false;
+ }
+ return true;
+ }
function updateInputFields(e, context) {
var val = $dataField.val(),
time = null;
if (context !== 'crmClear') {
var val = '';
if ($dateField.val()) {
- if (hasDatepicker && isValidDate()) {
+ if (hasDatepicker && isValidDate() && dateHasDay()) {
val = $.datepicker.formatDate('yy-mm-dd', $dateField.datepicker('getDate'));
$dateField.removeClass('crm-error');
} else if (!hasDatepicker) {
val = $dateField.val() + '-01-01';
+ }
+ else if (!dateHasDay()) {
+ // This would be a Year-month date (yyyy-mm)
+ // it could be argued it should not use a datepicker....
+ val = $dateField.val() + '-01';
} else {
$dateField.addClass('crm-error');
}
});
};
- $.fn.crmAjaxTable = function() {
- // Strip the ids from ajax urls to make pageLength storage more generic
- function simplifyUrl(ajax) {
- // Datatables ajax prop could be a url string or an object containing the url
- var url = typeof ajax === 'object' ? ajax.url : ajax;
- return typeof url === 'string' ? url.replace(/[&?]\w*id=\d+/g, '') : null;
- }
-
- return $(this).each(function() {
- // Recall pageLength for this table
- var url = simplifyUrl($(this).data('ajax'));
- if (url && window.localStorage && localStorage['dataTablePageLength:' + url]) {
- $(this).data('pageLength', localStorage['dataTablePageLength:' + url]);
- }
- // Declare the defaults for DataTables
- var defaults = {
- "processing": true,
- "serverSide": true,
- "order": [],
- "dom": '<"crm-datatable-pager-top"lfp>rt<"crm-datatable-pager-bottom"ip>',
- "pageLength": 25,
- "pagingType": "full_numbers",
- "drawCallback": function(settings) {
- //Add data attributes to cells
- $('thead th', settings.nTable).each( function( index ) {
- $.each(this.attributes, function() {
- if(this.name.match("^cell-")) {
- var cellAttr = this.name.substring(5);
- var cellValue = this.value;
- $('tbody tr', settings.nTable).each( function() {
- $('td:eq('+ index +')', this).attr( cellAttr, cellValue );
- });
- }
- });
- });
- //Reload table after draw
- $(settings.nTable).trigger('crmLoad');
- }
- };
- //Include any table specific data
- var settings = $.extend(true, defaults, $(this).data('table'));
- // Remember pageLength
- $(this).on('length.dt', function(e, settings, len) {
- if (settings.ajax && window.localStorage) {
- localStorage['dataTablePageLength:' + simplifyUrl(settings.ajax)] = len;
- }
- });
- //Make the DataTables call
- $(this).DataTable(settings);
- });
- };
-
CRM.utils.formatSelect2Result = function (row) {
var markup = '<div class="crm-select2-row">';
if (row.image !== undefined) {
$('table.crm-ajax-table', e.target).each(function() {
var
$table = $(this),
+ script = CRM.config.resourceBase + 'js/jquery/jquery.crmAjaxTable.js',
$accordion = $table.closest('.crm-accordion-wrapper.collapsed, .crm-collapsible.collapsed');
// For tables hidden by collapsed accordions, wait.
if ($accordion.length) {
$accordion.one('crmAccordion:open', function() {
- $table.crmAjaxTable();
+ CRM.loadScript(script).done(function() {
+ $table.crmAjaxTable();
+ });
});
} else {
- $table.crmAjaxTable();
+ CRM.loadScript(script).done(function() {
+ $table.crmAjaxTable();
+ });
}
});
if ($("input:radio[name=radio_ts]").size() == 1) {
$('.crm-form-text[data-crm-datepicker]', e.target).each(function() {
$(this).crmDatepicker($(this).data('crmDatepicker'));
});
+ $('.crm-editable', e.target).not('thead *').each(function() {
+ var $el = $(this);
+ CRM.loadScript(CRM.config.resourceBase + 'js/jquery/jquery.crmEditable.js').done(function() {
+ $el.crmEditable();
+ });
+ });
// Cache Form Input initial values
$('form[data-warn-changes] :input', e.target).each(function() {
$(this).data('crm-initial-value', $(this).is(':checkbox, :radio') ? $(this).prop('checked') : $(this).val());
if ($el.data('origSize')) {
$el.dialog('option', $el.data('origSize'));
$el.data('origSize', null);
+ $(this).button('option', 'icons', {primary: 'fa-expand'});
} else {
var menuHeight = $('#civicrm-menu').outerHeight();
$el.data('origSize', {
height: $el.dialog('option', 'height')
});
$el.dialog('option', {width: '100%', height: ($(window).height() - menuHeight), position: {my: "top", at: "top+"+menuHeight, of: window}});
+ $(this).button('option', 'icons', {primary: 'fa-compress'});
}
$el.trigger('dialogresize');
e.preventDefault();
$(this).siblings('input:text').val('').trigger('change', ['crmClear']);
return false;
})
- .on('change', 'input.crm-form-radio:checked, input[allowclear=1]', function(e, context) {
+ .on('change keyup', 'input.crm-form-radio:checked, input[allowclear=1]', function(e, context) {
if (context !== 'crmClear' && ($(this).is(':checked') || ($(this).is('[allowclear=1]') && $(this).val()))) {
$(this).siblings('.crm-clear-link').css({visibility: ''});
}
+ if (context !== 'crmClear' && $(this).is('[allowclear=1]') && $(this).val() === '') {
+ $(this).siblings('.crm-clear-link').css({visibility: 'hidden'});
+ }
})
// Allow normal clicking of links within accordions
return input;
case 'string':
- // convert iso format
- return $.datepicker.parseDate('yy-mm-dd', input.substr(0, 10));
+ // convert iso format with or without dashes
+ if (input.indexOf('-') > 0) {
+ return $.datepicker.parseDate('yy-mm-dd', input.substr(0, 10));
+ }
+ return $.datepicker.parseDate('yymmdd', input.substr(0, 8));
case 'number':
// convert unix timestamp