X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=js%2FCommon.js;h=f6f87b1d2abf211c0c33920cbb45cc569acb5719;hb=cf595fa5ef40de4dcbfd3dcedebe08d5303b6b43;hp=1b08d777f7072a47f6f42b9dbe3f17d0d191f0ff;hpb=35242121138edd363d672a34fefb0b1d03ead90b;p=civicrm-core.git diff --git a/js/Common.js b/js/Common.js index 1b08d777f7..f6f87b1d2a 100644 --- a/js/Common.js +++ b/js/Common.js @@ -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) { @@ -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 + '

'; }); @@ -822,6 +856,8 @@ 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).crmAjaxTable(); if ($("input:radio[name=radio_ts]").size() == 1) { $("input:radio[name=radio_ts]").prop("checked", true); } @@ -1308,12 +1344,7 @@ CRM.strings = CRM.strings || {}; $().crmtooltip(); }); - /** - * @deprecated - */ - $.fn.crmAccordions = function () { - CRM.console('warn', 'Warning: $.crmAccordions was called. This function is deprecated and should not be used.'); - }; + /** * Collapse or expand an accordion * @param speed @@ -1333,11 +1364,12 @@ CRM.strings = CRM.strings || {}; /** * Clientside currency formatting * @param number value + * @param [optional] boolean onlyNumber - if true, we return formated amount without currency sign * @param [optional] string format - currency representation of the number 1234.56 * @return string */ var currencyTemplate; - CRM.formatMoney = function(value, format) { + CRM.formatMoney = function(value, onlyNumber, format) { var decimal, separator, sign, i, j, result; if (value === 'init' && format) { currencyTemplate = format; @@ -1355,6 +1387,9 @@ CRM.strings = CRM.strings || {}; i = parseInt(value = Math.abs(value).toFixed(2)) + ''; j = ((j = i.length) > 3) ? j % 3 : 0; result = sign + (j ? i.substr(0, j) + separator : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + separator) + (2 ? decimal + Math.abs(value - i).toFixed(2).slice(2) : ''); + if ( onlyNumber ) { + return result; + } return format.replace(/1.*234.*56/, result); }; @@ -1374,4 +1409,11 @@ CRM.strings = CRM.strings || {}; CRM.checkPerm = function(perm) { return CRM.permissions[perm]; }; + + // Round while preserving sigfigs + CRM.sigfig = function(n, digits) { + var len = ("" + n).length; + var scale = Math.pow(10.0, len-digits); + return Math.round(n / scale) * scale; + }; })(jQuery, _);