X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=js%2FCommon.js;h=c2134fa8023c70e7a2767e77d91ddac82819d7b9;hb=972bd8974a95be4fc46957a7f748e5beab1583dc;hp=e60987d642362843ef29b134d579f7ae85ae17b3;hpb=1c4ab962045c29149292c4549620866d41816836;p=civicrm-core.git diff --git a/js/Common.js b/js/Common.js index e60987d642..c2134fa802 100644 --- a/js/Common.js +++ b/js/Common.js @@ -201,8 +201,9 @@ function showHideRow(index) { /* jshint ignore:end */ -CRM.utils = CRM.utils || {}; -CRM.strings = CRM.strings || {}; +if (!CRM.utils) CRM.utils = {}; +if (!CRM.strings) CRM.strings = {}; +if (!CRM.vars) CRM.vars = {}; (function ($, _, undefined) { "use strict"; @@ -607,7 +608,7 @@ CRM.strings = CRM.strings || {}; $clearLink = $(); if (settings.allowClear !== undefined ? settings.allowClear : !$dataField.is('.required, [required]')) { - $clearLink = $('') + $clearLink = $('') .insertAfter($dataField); } if (settings.time !== false) { @@ -681,6 +682,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) { @@ -843,6 +876,20 @@ CRM.strings = CRM.strings || {}; } }) .find('input.select-row:checked').parents('tr').addClass('crm-row-selected'); + $('table.crm-sortable', e.target).DataTable(); + $('table.crm-ajax-table', e.target).each(function() { + var + $table = $(this), + $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(); + }); + } else { + $table.crmAjaxTable(); + } + }); if ($("input:radio[name=radio_ts]").size() == 1) { $("input:radio[name=radio_ts]").prop("checked", true); } @@ -853,6 +900,16 @@ CRM.strings = CRM.strings || {}; $('form[data-warn-changes] :input', e.target).each(function() { $(this).data('crm-initial-value', $(this).is(':checkbox, :radio') ? $(this).prop('checked') : $(this).val()); }); + $('textarea.crm-form-wysiwyg', e.target) + .not('.crm-wysiwyg-enabled') + .addClass('crm-wysiwyg-enabled') + .each(function() { + if ($(this).hasClass("collapsed")) { + CRM.wysiwyg.createCollapsed(this); + } else { + CRM.wysiwyg.create(this); + } + }); }) .on('dialogopen', function(e) { var $el = $(e.target); @@ -863,7 +920,7 @@ CRM.strings = CRM.strings || {}; } // Add resize button if ($el.parent().hasClass('crm-container') && $el.dialog('option', 'resizable')) { - $el.parent().find('.ui-dialog-titlebar').append($('