X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=js%2FCommon.js;h=f6f87b1d2abf211c0c33920cbb45cc569acb5719;hb=cf595fa5ef40de4dcbfd3dcedebe08d5303b6b43;hp=f91072d13cfb829ad1cac4c2e89f9e4707c530e5;hpb=e7ed2ed6dfa73a6225b7d2a2d09529edec03f974;p=civicrm-core.git diff --git a/js/Common.js b/js/Common.js index f91072d13c..f6f87b1d2a 100644 --- a/js/Common.js +++ b/js/Common.js @@ -216,7 +216,7 @@ CRM.strings = CRM.strings || {}; // Workaround for https://github.com/ivaynberg/select2/issues/1246 $.ui.dialog.prototype._allowInteraction = function(e) { - return !!$(e.target).closest('.ui-dialog, .ui-datepicker, .select2-drop, .cke_dialog').length; + return !!$(e.target).closest('.ui-dialog, .ui-datepicker, .select2-drop, .cke_dialog, #civicrm-menu').length; }; // Implements jQuery hook.prop @@ -281,8 +281,8 @@ CRM.strings = CRM.strings || {}; _.each(options, function(option) { if (option.children) { rendered += '' + - CRM.utils.renderOptions(option.children, val) + - ''; + CRM.utils.renderOptions(option.children, val) + + ''; } else { var selected = ($.inArray('' + option.key, val) > -1) ? 'selected="selected"' : ''; rendered += ''; @@ -311,11 +311,11 @@ CRM.strings = CRM.strings || {}; } } -/** - * Compare Form Input values against cached initial value. - * - * @return {Boolean} true if changes have been made. - */ + /** + * Compare Form Input values against cached initial value. + * + * @return {Boolean} true if changes have been made. + */ CRM.utils.initialValueChanged = function(el) { var isDirty = false; $(':input:visible, .select2-container:visible+:input:hidden', el).not('[type=submit], [type=button], .crm-action-menu, :disabled').each(function () { @@ -329,7 +329,7 @@ CRM.strings = CRM.strings || {}; }); return isDirty; }; - + /** * This provides defaults for ui.dialog which either need to be calculated or are different from global defaults * @@ -356,7 +356,7 @@ CRM.strings = CRM.strings || {}; } return settings; }; - + /** * Wrapper for select2 initialization function; supplies defaults * @param options object @@ -429,7 +429,7 @@ CRM.strings = CRM.strings || {}; minimumInputLength: 1, formatResult: CRM.utils.formatSelect2Result, formatSelection: function(row) { - return row.label; + return (row.prefix !== undefined ? row.prefix + ' ' : '') + row.label + (row.suffix !== undefined ? ' ' + row.suffix : ''); }, escapeMarkup: function (m) {return m;}, initSelection: function($el, callback) { @@ -503,7 +503,7 @@ CRM.strings = CRM.strings || {}; .on('click.crmEntity', 'a.crm-add-entity', function(e) { $el.select2('close'); CRM.loadForm($(this).attr('href'), { - dialog: {width: 500, height: 'auto'} + dialog: {width: 500, height: 220} }).on('crmFormSuccess', function(e, data) { if (data.status === 'success' && data.id) { CRM.status(ts('%1 Created', {1: data.label})); @@ -662,6 +662,38 @@ CRM.strings = CRM.strings || {}; }); }; + $.fn.crmAjaxTable = function() { + return $(this).each(function() { + //Declare the defaults for DataTables + var defaults = { + "processing": true, + "serverSide": true, + "dom": '<"crm-datatable-pager-top"lfp>rt<"crm-datatable-pager-bottom"ip>', + "pageLength": 25, + "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')); + //Make the DataTables call + $(this).DataTable(settings); + }); + }; + CRM.utils.formatSelect2Result = function (row) { var markup = '
'; if (row.image !== undefined) { @@ -670,8 +702,10 @@ CRM.strings = CRM.strings || {}; else if (row.icon_class) { markup += '
'; } - markup += '
' + row.label + '
'; - markup += '
'; + markup += '
' + + (row.prefix !== undefined ? row.prefix + ' ' : '') + row.label + (row.suffix !== undefined ? ' ' + row.suffix : '') + + '
' + + '
'; $.each(row.description || [], function(k, text) { markup += '

' + text + '

'; }); @@ -732,11 +766,11 @@ CRM.strings = CRM.strings || {}; } var markup = '
' + '   ' + '