DataView, ListView: fix order of the elements when adding new items.
This commit is contained in:
parent
fda9051a91
commit
c804638de6
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue