mirror of https://github.com/keeweb/keeweb.git
fix #56: preserve selected entry after close
This commit is contained in:
parent
3dab9af066
commit
559489bbdc
|
@ -25,27 +25,10 @@ var EntryCollection = Backbone.Collection.extend({
|
|||
|
||||
defaultComparator: 'title',
|
||||
|
||||
activeEntry: null,
|
||||
|
||||
initialize: function() {
|
||||
this.comparator = this.comparators[this.defaultComparator];
|
||||
},
|
||||
|
||||
setActive: function(entry) {
|
||||
if (!(entry instanceof EntryModel)) {
|
||||
entry = this.get(entry);
|
||||
}
|
||||
this.forEach(function(entry) { entry.active = false; });
|
||||
if (entry) {
|
||||
entry.active = true;
|
||||
}
|
||||
this.activeEntry = entry;
|
||||
},
|
||||
|
||||
getActive: function() {
|
||||
return this.activeEntry;
|
||||
},
|
||||
|
||||
sortEntries: function(comparator) {
|
||||
this.comparator = this.comparators[comparator] || this.comparators[this.defaultComparator];
|
||||
this.sort();
|
||||
|
|
|
@ -25,6 +25,7 @@ var AppModel = Backbone.Model.extend({
|
|||
this.filter = {};
|
||||
this.sort = 'title';
|
||||
this.settings = AppSettingsModel.instance;
|
||||
this.activeEntryId = null;
|
||||
|
||||
this.listenTo(Backbone, 'refresh', this.refresh);
|
||||
this.listenTo(Backbone, 'set-filter', this.setFilter);
|
||||
|
@ -112,7 +113,7 @@ var AppModel = Backbone.Model.extend({
|
|||
this.menu.tagsSection.removeAllItems();
|
||||
this.menu.filesSection.removeAllItems();
|
||||
this.tags.splice(0, this.tags.length);
|
||||
this.setFilter({});
|
||||
this.filter = {};
|
||||
},
|
||||
|
||||
closeFile: function(file) {
|
||||
|
@ -134,8 +135,12 @@ var AppModel = Backbone.Model.extend({
|
|||
this.filter = filter;
|
||||
this.filter.subGroups = this.settings.get('expandGroups');
|
||||
var entries = this.getEntries();
|
||||
if (!this.activeEntryId || !entries.get(this.activeEntryId)) {
|
||||
var firstEntry = entries.first();
|
||||
this.activeEntryId = firstEntry ? firstEntry.id : null;
|
||||
}
|
||||
Backbone.trigger('filter', { filter: this.filter, sort: this.sort, entries: entries });
|
||||
Backbone.trigger('select-entry', entries.length ? entries.first() : null);
|
||||
Backbone.trigger('select-entry', entries.get(this.activeEntryId));
|
||||
},
|
||||
|
||||
refresh: function() {
|
||||
|
@ -163,9 +168,6 @@ var AppModel = Backbone.Model.extend({
|
|||
if (this.filter.trash) {
|
||||
this.addTrashGroups(entries);
|
||||
}
|
||||
if (entries.length) {
|
||||
entries.setActive(entries.first());
|
||||
}
|
||||
return entries;
|
||||
},
|
||||
|
||||
|
|
|
@ -2,10 +2,11 @@
|
|||
|
||||
var Format = require('../util/format');
|
||||
|
||||
var EntryPresenter = function(descField, noColor) {
|
||||
var EntryPresenter = function(descField, noColor, activeEntryId) {
|
||||
this.entry = null;
|
||||
this.descField = descField;
|
||||
this.noColor = noColor || '';
|
||||
this.activeEntryId = activeEntryId;
|
||||
};
|
||||
|
||||
EntryPresenter.prototype = {
|
||||
|
@ -25,7 +26,7 @@ EntryPresenter.prototype = {
|
|||
get notes() { return this.entry ? this.entry.notes : undefined; },
|
||||
get url() { return this.entry ? this.entry.url : undefined; },
|
||||
get user() { return this.entry ? this.entry.user : undefined; },
|
||||
get active() { return this.entry ? this.entry.active : this.group.active; },
|
||||
get active() { return this.entry ? this.entry.id === this.activeEntryId : this.group.active; },
|
||||
get created() { return this.entry ? Format.dtStr(this.entry.created) : undefined; },
|
||||
get updated() { return this.entry ? Format.dtStr(this.entry.updated) : undefined; },
|
||||
get expired() { return this.entry ? this.entry.expired : false; },
|
||||
|
|
|
@ -67,7 +67,7 @@ var ListView = Backbone.View.extend({
|
|||
var itemTemplate = this.getItemTemplate();
|
||||
var itemsTemplate = this.getItemsTemplate();
|
||||
var noColor = AppSettingsModel.instance.get('colorfulIcons') ? '' : 'grayscale';
|
||||
var presenter = new EntryPresenter(this.getDescField(), noColor);
|
||||
var presenter = new EntryPresenter(this.getDescField(), noColor, this.model.activeEntryId);
|
||||
var itemsHtml = '';
|
||||
this.items.forEach(function (item) {
|
||||
presenter.present(item);
|
||||
|
@ -116,16 +116,14 @@ var ListView = Backbone.View.extend({
|
|||
},
|
||||
|
||||
selectPrev: function() {
|
||||
var activeItem = this.items.getActive(),
|
||||
ix = this.items.indexOf(activeItem);
|
||||
var ix = this.items.indexOf(this.items.get(this.model.activeEntryId));
|
||||
if (ix > 0) {
|
||||
this.selectItem(this.items.at(ix - 1));
|
||||
}
|
||||
},
|
||||
|
||||
selectNext: function() {
|
||||
var activeItem = this.items.getActive(),
|
||||
ix = this.items.indexOf(activeItem);
|
||||
var ix = this.items.indexOf(this.items.get(this.model.activeEntryId));
|
||||
if (ix < this.items.length - 1) {
|
||||
this.selectItem(this.items.at(ix + 1));
|
||||
}
|
||||
|
@ -144,10 +142,10 @@ var ListView = Backbone.View.extend({
|
|||
},
|
||||
|
||||
selectItem: function(item) {
|
||||
this.items.setActive(item);
|
||||
this.model.activeEntryId = item.id;
|
||||
Backbone.trigger('select-entry', item);
|
||||
this.itemsEl.find('.list__item--active').removeClass('list__item--active');
|
||||
var itemEl = document.getElementById(item.get('id'));
|
||||
var itemEl = document.getElementById(item.id);
|
||||
itemEl.classList.add('list__item--active');
|
||||
var listEl = this.itemsEl[0],
|
||||
itemRect = itemEl.getBoundingClientRect(),
|
||||
|
|
|
@ -9,6 +9,7 @@ Release notes
|
|||
`+` #45: optional auto-lock on minimize
|
||||
`+` option to disable searching for group
|
||||
`+` #62: saving files with empty password
|
||||
`+` #56: preserve selected entry after close
|
||||
`-` #55: custom scrollbar issues
|
||||
|
||||
##### v0.4.6 (2015-11-25)
|
||||
|
|
Loading…
Reference in New Issue