trash: groups, empty

This commit is contained in:
Antelle 2015-11-09 00:25:00 +03:00
parent e7ecea75f4
commit 2d0c626901
10 changed files with 90 additions and 16 deletions

View File

@ -4,7 +4,7 @@
- [x] improve open page UX
- [x] provide engineer error details on file open
- [ ] trash: groups/empty/untrash
- [ ] trash: delete
- [x] move groups/entries
- [ ] help/tips
- [ ] switch view

View File

@ -24,6 +24,7 @@ var AppModel = Backbone.Model.extend({
this.listenTo(Backbone, 'add-filter', this.addFilter);
this.listenTo(Backbone, 'set-sort', this.setSort);
this.listenTo(Backbone, 'close-file', this.closeFile);
this.listenTo(Backbone, 'empty-trash', this.emptyTrash);
},
addFile: function(file) {
@ -100,6 +101,13 @@ var AppModel = Backbone.Model.extend({
this.refresh();
},
emptyTrash: function() {
this.files.forEach(function(file) {
file.emptyTrash();
}, this);
this.refresh();
},
setFilter: function(filter) {
this.filter = filter;
this.filter.subGroups = this.settings.get('expandGroups');
@ -130,12 +138,26 @@ var AppModel = Backbone.Model.extend({
});
});
entries.sortEntries(this.sort);
if (this.filter.trash) {
this.addTrashGroups(entries);
}
if (entries.length) {
entries.setActive(entries.first());
}
return entries;
},
addTrashGroups: function(collection) {
this.files.forEach(function(file) {
var trashGroup = file.getTrashGroup();
if (trashGroup) {
trashGroup.getOwnSubGroups().forEach(function(group) {
collection.unshift(GroupModel.fromGroup(group, file, trashGroup));
});
}
});
},
prepareFilter: function() {
var filter = _.clone(this.filter);
if (filter.text) {

View File

@ -338,6 +338,19 @@ var FileModel = Backbone.Model.extend({
this.db.header.keyEncryptionRounds = rounds;
this.set('keyEncryptionRounds', rounds);
this.setModified();
},
emptyTrash: function() {
var trashGroup = this.getTrashGroup();
if (trashGroup) {
trashGroup.getOwnSubGroups().slice().forEach(function(group) {
this.db.move(group, null);
}, this);
trashGroup.group.entries.forEach(function(entry) {
this.db.move(entry, null);
}, this);
trashGroup.get('entries').reset();
}
}
});

View File

@ -86,6 +86,10 @@ var GroupModel = MenuItemModel.extend({
});
},
getOwnSubGroups: function() {
return this.group.groups;
},
removeEntry: function(entry) {
this.get('entries').remove(entry);
},
@ -122,7 +126,7 @@ var GroupModel = MenuItemModel.extend({
this.parentGroup.removeGroup(this);
var trashGroup = this.file.getTrashGroup();
if (trashGroup) {
//trashGroup.addGroup(this); // TODO: groups in trash are currently not displayed
trashGroup.addGroup(this);
this.parentGroup = trashGroup;
this.deleted = true;
}

View File

@ -8,20 +8,30 @@ var EntryPresenter = function(descField) {
};
EntryPresenter.prototype = {
present: function(entry) { this.entry = entry; return this; },
get id() { return this.entry.id; },
get icon() { return this.entry.icon; },
get color() { return this.entry.color; },
get title() { return this.entry.title; },
get notes() { return this.entry.notes; },
get url() { return this.entry.url; },
get user() { return this.entry.user; },
get active() { return this.entry.active; },
get created() { return Format.dtStr(this.entry.created); },
get updated() { return Format.dtStr(this.entry.updated); },
get expired() { return this.entry.expired; },
get deleted() { return this.entry.deleted; },
present: function(item) {
if (item.entry) {
this.entry = item;
} else {
this.group = item;
}
return this;
},
get id() { return this.entry ? this.entry.id : this.group.get('id'); },
get icon() { return this.entry ? this.entry.icon : this.group.get('icon'); },
get color() { return this.entry ? this.entry.color : undefined; },
get title() { return this.entry ? this.entry.title : this.group.get('title'); },
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 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; },
get deleted() { return this.entry ? this.entry.deleted : undefined; },
get description() {
if (!this.entry) {
return '[Group]';
}
switch (this.descField) {
case 'website':
return this.url || '(no website)';

View File

@ -1,6 +1,7 @@
'use strict';
var Backbone = require('backbone'),
GroupModel = require('../../models/group-model'),
Scrollable = require('../../mixins/scrollable'),
FieldViewText = require('../fields/field-view-text'),
FieldViewDate = require('../fields/field-view-date'),
@ -23,6 +24,7 @@ var Backbone = require('backbone'),
var DetailsView = Backbone.View.extend({
template: require('templates/details/details.html'),
emptyTemplate: require('templates/details/details-empty.html'),
groupTemplate: require('templates/details/details-group.html'),
fieldViews: null,
views: null,
@ -73,6 +75,10 @@ var DetailsView = Backbone.View.extend({
this.$el.html(this.emptyTemplate());
return;
}
if (this.model instanceof GroupModel) {
this.$el.html(this.groupTemplate());
return;
}
this.$el.html(this.template(this.model));
this.setSelectedColor(this.model.color);
this.addFieldViews();

View File

@ -16,6 +16,7 @@ var MenuItemView = Backbone.View.extend({
'click': 'selectItem',
'dblclick': 'expandItem',
'click .menu__item-edit': 'editItem',
'click .menu__item-empty-trash': 'emptyTrash',
'dragstart': 'dragstart',
'dragover': 'dragover',
'dragleave': 'dragleave',
@ -155,6 +156,18 @@ var MenuItemView = Backbone.View.extend({
}
},
emptyTrash: function(e) {
e.stopPropagation();
Alerts.yesno({
header: 'Empty trash?',
body: 'You will not be able to put items back',
icon: 'trash',
success: function() {
Backbone.trigger('empty-trash');
}
});
},
dropAllowed: function(e) {
return ['text/group', 'text/entry'].indexOf(e.dataTransfer.types[0]) >= 0;
},

View File

@ -122,7 +122,7 @@
}
}
&-edit {
&-edit, &-empty-trash {
display: none;
opacity: 0;
position: absolute;

View File

@ -0,0 +1,3 @@
<div class="empty-block muted-color">
<h1 class="empty-block__title">To restore this group, please drag it to any group outside trash</h1>
</div>

View File

@ -17,5 +17,8 @@
<% if (typeof editable !== 'undefined') { %>
<i class="menu__item-edit fa fa-cog"></i>
<% } %>
<% if (filterKey === 'trash') { %>
<i class="menu__item-empty-trash fa fa-minus-circle"></i>
<% } %>
</div>
</div>