From c804638de63c1661e547d83393ce0c627879a118 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 11 Jan 2018 11:32:23 +0300 Subject: [PATCH] DataView, ListView: fix order of the elements when adding new items. --- apps/common/main/lib/component/DataView.js | 11 +++++++++-- apps/common/main/lib/component/ListView.js | 8 ++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/apps/common/main/lib/component/DataView.js b/apps/common/main/lib/component/DataView.js index b4d1811bf..507dc24bf 100644 --- a/apps/common/main/lib/component/DataView.js +++ b/apps/common/main/lib/component/DataView.js @@ -389,7 +389,7 @@ define([ return this.store.where({selected: true}); }, - onAddItem: function(record, index, opts) { + onAddItem: function(record, store, opts) { var view = new Common.UI.DataViewItem({ template: this.itemTemplate, model: record @@ -412,7 +412,8 @@ define([ innerEl.append(view.render().el); innerEl.find('.empty-text').remove(); - this.dataViewItems.push(view); + var idx = _.indexOf(this.store.models, record); + this.dataViewItems = this.dataViewItems.slice(0, idx).concat(view).concat(this.dataViewItems.slice(idx)); if (record.get('tip')) { var view_el = $(view.el); @@ -488,6 +489,12 @@ define([ }, onRemoveItem: function(view, record) { + var tip = view.$el.data('bs.tooltip'); + if (tip) { + if (tip.dontShow===undefined) + tip.dontShow = true; + (tip.tip()).remove(); + } this.stopListening(view); view.stopListening(); diff --git a/apps/common/main/lib/component/ListView.js b/apps/common/main/lib/component/ListView.js index 0c9e99262..226fe349e 100644 --- a/apps/common/main/lib/component/ListView.js +++ b/apps/common/main/lib/component/ListView.js @@ -67,7 +67,7 @@ define([ this.trigger('items:reset', this); }, - onAddItem: function(record, index) { + onAddItem: function(record, store, opts) { var view = new Common.UI.DataViewItem({ template: this.itemTemplate, model: record @@ -79,7 +79,8 @@ define([ if (view && this.innerEl) { this.innerEl.find('.empty-text').remove(); if (this.options.simpleAddMode) { - this.innerEl.append(view.render().el) + this.innerEl.append(view.render().el); + this.dataViewItems.push(view); } else { var idx = _.indexOf(this.store.models, record); var innerDivs = this.innerEl.find('> div'); @@ -89,9 +90,8 @@ define([ else { (innerDivs.length > 0) ? $(innerDivs[idx]).before(view.render().el) : this.innerEl.append(view.render().el); } - + this.dataViewItems = this.dataViewItems.slice(0, idx).concat(view).concat(this.dataViewItems.slice(idx)); } - this.dataViewItems.push(view); this.listenTo(view, 'change', this.onChangeItem); this.listenTo(view, 'remove', this.onRemoveItem); this.listenTo(view, 'click', this.onClickItem);