diff --git a/CHANGELOG b/CHANGELOG index 564005a73f..71b8b16ab5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add sum of records on list view * Add shortcuts to Date and DateTime widgets * Use limit to expand tree * Use spellcheck and lang attributes for textbox widget diff --git a/src/common.js b/src/common.js index 15c8407f5e..e72948550e 100644 --- a/src/common.js +++ b/src/common.js @@ -3353,4 +3353,14 @@ var ellipsis = Sao.i18n.gettext('...'); return string.slice(0, length - ellipsis.length) + ellipsis; }; + + Sao.common.debounce = function(func, wait) { + return function() { + var args = [].slice(arguments); + clearTimeout(func._debounceTimeout); + func._debounceTimeout = setTimeout(function() { + func.apply(this, args); + }.bind(this), wait); + }.bind(this); + }; }()); diff --git a/src/sao.js b/src/sao.js index 15e3f60b52..4e3844b1e9 100644 --- a/src/sao.js +++ b/src/sao.js @@ -464,6 +464,7 @@ var Sao = {}; init: function(favorite) { this.field = favorite; this.header = jQuery(''); + this.footers = []; this.attributes = jQuery.extend({}, this.field.description); this.attributes.name = this.field.name; diff --git a/src/sao.less b/src/sao.less index fcf2dc77a4..44dc6e300e 100644 --- a/src/sao.less +++ b/src/sao.less @@ -120,6 +120,10 @@ img.icon { width: 1em; height: 1em; } + + & tr.more-row { + text-align: center; + } } & .editabletree-char, .editabletree-date, .editabletree-datetime, .editabletree-integer, .editabletree-float, .editabletree-selection, @@ -137,9 +141,6 @@ img.icon { & .expander { cursor: pointer; } - & .treefooter { - text-align: center; - } & label { font-weight: normal; display: inline; @@ -324,7 +325,10 @@ input.column-boolean { table.responsive > thead > tr > th:not(.invisible), table.responsive > tbody, table.responsive > tbody > tr, - table.responsive > tbody > tr > td:not(.invisible) { + table.responsive > tbody > tr > td:not(.invisible), + table.responsive > tfoot, + table.responsive > tfoot > tr, + table.responsive > tfoot > tr > td:not(.invisible) { display: block !important; } table.responsive { @@ -343,6 +347,13 @@ input.column-boolean { display: block; } } + + & tfoot { + > tr > td:empty, + > tr > td > label { + display: none !important; + } + } } table.responsive-noheader { & > tbody > tr > td { @@ -353,13 +364,15 @@ input.column-boolean { > tbody > tr { border: 1px solid #ccc; } - & > tbody > tr > td { + & > tbody > tr > td, + & > tfoot > tr > td { /* Behave like a "row" */ border: none; border-bottom: 1px solid #eee; position: relative; } - & > tbody > tr { + & > tbody > tr, + & > tfoot > tr { & > td:before { /* Now like a table header */ position: absolute; diff --git a/src/view/tree.js b/src/view/tree.js index cc764eba1b..fa58a476f3 100644 --- a/src/view/tree.js +++ b/src/view/tree.js @@ -53,6 +53,7 @@ init: function(screen, xml, children_field) { Sao.View.Tree._super.init.call(this, screen, xml); this.view_type = 'tree'; + this.sum_widgets = {}; this.selection_mode = (screen.attributes.selection_mode || Sao.common.SELECTION_MULTIPLE); this.el = jQuery('
', { @@ -88,6 +89,17 @@ th.append(this.selection); tr.append(th); this.thead.append(tr); + + this.tfoot = null; + var sum_row; + if (!jQuery.isEmptyObject(this.sum_widgets)) { + sum_row = jQuery(''); + sum_row.append(jQuery('')); + this.tfoot = jQuery(''); + this.tfoot.append(sum_row); + this.table.append(this.tfoot); + } + this.columns.forEach(function(column) { th = jQuery('', { 'class': column.attributes.widget, @@ -116,26 +128,28 @@ } tr.append(th.append(label)); column.header = th; + + column.footers = []; + if (!jQuery.isEmptyObject(this.sum_widgets)) { + var field_name = column.attributes.name; + var total_cell = jQuery('', { + 'class': column.class_, + }); + if (field_name in this.sum_widgets) { + var sum_label = this.sum_widgets[field_name][0]; + var sum_div = this.sum_widgets[field_name][1]; + total_cell.append(label); + total_cell.append(sum_div); + total_cell.attr('data-title', label.text()); + } + sum_row.append(total_cell); + column.footers.push(total_cell); + } }, this); this.tbody = jQuery(''); this.table.append(this.tbody); - // Footer for more - var footer = jQuery('
', { - 'class': 'treefooter' - }); - this.more = jQuery('