diff --git a/CHANGELOG b/CHANGELOG index 815f56ab7c..d831c1071d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add position and length on list view * Reset record to its original state when discarding the popup window * Add support of expand attribute on group tag * Add the context model name in the screen context diff --git a/src/model.js b/src/model.js index a3c1e610dd..8ea7c9692e 100644 --- a/src/model.js +++ b/src/model.js @@ -1226,6 +1226,19 @@ path.reverse(); return path; }, + get_index_path: function(group) { + var path = [], + record = this; + while (record) { + path.push(record.group.indexOf(record)); + if (record.group === group) { + break; + } + record = record.group.parent; + } + path.reverse(); + return path; + }, deleted: function() { return Boolean(~this.group.record_deleted.indexOf(this)); }, diff --git a/src/sao.less b/src/sao.less index bc1d22466b..b4295a4fc9 100644 --- a/src/sao.less +++ b/src/sao.less @@ -33,6 +33,15 @@ z-index: @zindex-navbar - 1; } + & .navbar-text { + & .badge { + max-width: 5em; + min-width: 5em; + overflow: hidden; + text-overflow: ellipsis; + } + } + & .navbar-btn { .badge { /* remove padding to not increase size of navbar-btn */ @@ -225,6 +234,13 @@ img.icon { & .form-one2many-toolbar, .form-many2many-toolbar { display: inline-table; float: right; + + & .badge { + max-width: 5em; + min-width: 5em; + overflow: hidden; + text-overflow: ellipsis; + } } } & .form-one2many-content, .form-many2many-content { diff --git a/src/screen.js b/src/screen.js index 2bbc9c9f50..1775285e9e 100644 --- a/src/screen.js +++ b/src/screen.js @@ -687,6 +687,7 @@ this._domain_parser = {}; this.pre_validate = false; this.tab = null; + this.message_callback = null; this.count_tab_domain(); }, load_next_view: function() { @@ -949,7 +950,22 @@ }, set_current_record: function(record) { this.current_record = record; - // TODO position + if (this.message_callback){ + var pos = null; + var record_id = null; + if (record) { + var i = this.group.indexOf(record); + if (i >= 0) { + pos = i + this.offset + 1; + } else { + pos = record.get_index_path(); + } + record_id = record.id; + } + var data = [pos || 0, this.group.length + this.offset, + this.search_count, record_id]; + this.message_callback(data); + } if (this.tab) { if (record) { record.get_attachment_count().always( diff --git a/src/tab.js b/src/tab.js index 8f272cba04..15a8ee9d75 100644 --- a/src/tab.js +++ b/src/tab.js @@ -221,6 +221,11 @@ this.buttons[item.id].click(this[item.id].bind(this)); }; this.menu_def().forEach(add_button.bind(this)); + this.status_label = jQuery('', { + 'class': 'badge', + }).appendTo(jQuery('
', { + 'class': 'navbar-text hidden-xs', + }).insertAfter(this.buttons.previous)); toolbar.find('.btn-toolbar > .btn-group').last().addClass( 'hidden-xs'); var tabs = jQuery('#tabs'); @@ -416,6 +421,8 @@ this.info_bar = new Sao.Window.InfoBar(); this.create_tabcontent(); + screen.message_callback = this.record_message.bind(this); + this.set_buttons_sensitive(); this.view_prm = this.screen.switch_view().done(function() { @@ -889,8 +896,30 @@ this.buttons.note.prop('disabled', record_id < 0 || record_id === null); }, - record_message: function() { + record_message: function(data) { + if (data) { + var name = "_"; + if (data[0] !== 0) { + name = data[0]; + } + var buttons = ['print', 'relate', 'attach']; + buttons.forEach(function(button_id){ + var button = this.buttons[button_id]; + if (button) { + var disabled = button.is(':disabled'); + button.prop('disabled', disabled || data[0] === 0); + } + }.bind(this)); + this.buttons.switch_.prop('disabled', + this.attributes.view_ids > 1); + var msg = name + ' / ' + data[1]; + if (data[1] < data[2]) { + msg += Sao.i18n.gettext(' of ') + data[2]; + } + this.status_label.text(msg).attr('title', msg); + } this.info_bar.message(); + // TODO activate_save }, action: function() { window.setTimeout(function() { diff --git a/src/view/form.js b/src/view/form.js index 63111e02b1..69b785b48c 100644 --- a/src/view/form.js +++ b/src/view/form.js @@ -2679,6 +2679,8 @@ function eval_pyson(value){ this._readonly = true; this._required = false; + this._position = 0; + this._length = 0; this.el = jQuery('', { 'class': this.class_ + ' panel panel-default' @@ -2741,9 +2743,10 @@ function eval_pyson(value){ this.but_previous.click(this.previous.bind(this)); this.label = jQuery('', { - 'class': 'btn' - }).appendTo(buttons); - this.label.text('(0, 0)'); + 'class': 'badge', + }).appendTo(jQuery('', { + 'class': 'btn hidden-xs', + }).appendTo(buttons)); this.but_next = jQuery('', { 'class': 'btn btn-default btn-sm', @@ -2843,6 +2846,8 @@ function eval_pyson(value){ pre_validate: attributes.pre_validate }); this.screen.pre_validate = attributes.pre_validate == 1; + + this.screen.message_callback = this.record_label.bind(this); this.prm = this.screen.switch_view(modes[0]).done(function() { this.content.append(this.screen.screen_container.el); }.bind(this)); @@ -2890,18 +2895,20 @@ function eval_pyson(value){ if (delete_ === undefined) { delete_ = true; } - // TODO position this.but_del.prop('disabled', this._readonly || !delete_ || - !access['delete']); - this.but_undel.prop('disabled', this._readonly || size_limit); - this.but_open.prop('disabled', !access.read); - // TODO but_next, but_previous + !access['delete'] || !this._position); + this.but_undel.prop('disabled', this._readonly || size_limit || + !this._position); + this.but_open.prop('disabled', !access.read || !this._position); + this.but_next.prop('disabled', (this.position > 0) && ( + this._position >= this._length)); + this.but_previous.prop('disabled', this._position <= 1); if (this.attributes.add_remove) { this.wid_text.prop('disabled', this._readonly); this.but_add.prop('disabled', this._readonly || size_limit || !access.write || !access.read); this.but_remove.prop('disabled', this._readonly || - !access.write || !access.read); + !this.position || !access.write || !access.read); } }, display: function(record, field) { @@ -3158,6 +3165,13 @@ function eval_pyson(value){ } }.bind(this)); }, + record_label: function(data) { + this._position = data[0]; + this._length = data[1]; + var message = data[0] + ' / ' + data[1]; + this.label.text(message).attr('title', message); + this._set_button_sensitive(); + }, validate: function() { var prm = jQuery.Deferred(); this.view.set_value(); @@ -3199,6 +3213,7 @@ function eval_pyson(value){ this._readonly = true; this._required = false; + this._position = 0; this.el = jQuery('', { 'class': this.class_ + ' panel panel-default' @@ -3273,6 +3288,7 @@ function eval_pyson(value){ row_activate: this.activate.bind(this), limit: null }); + this.screen.message_callback = this.record_label.bind(this); this.prm = this.screen.switch_view('tree').done(function() { this.content.append(this.screen.screen_container.el); }.bind(this)); @@ -3304,8 +3320,12 @@ function eval_pyson(value){ this.entry.prop('disabled', this._readonly); this.but_add.prop('disabled', this._readonly || size_limit); - // TODO position - this.but_remove.prop('disabled', this._readonly); + this.but_remove.prop('disabled', this._readonly || + this._position === 0); + }, + record_label: function(data) { + this._position = data[0]; + this._set_button_sensitive(); }, display: function(record, field) { Sao.View.Form.Many2Many._super.display.call(this, record, field);