Commit 27035d47 authored by JC Brand's avatar JC Brand

Remember toggle state of bookmarks list.

parent 55c2c383
......@@ -15,6 +15,7 @@
afterEach(function () {
converse_api.user.logout();
converse_api.listen.not();
test_utils.clearBrowserStorage();
});
......@@ -151,6 +152,7 @@
afterEach(function () {
converse_api.user.logout();
converse_api.listen.not();
test_utils.clearBrowserStorage();
});
......@@ -240,6 +242,7 @@
describe("and when autojoin is set", function () {
afterEach(function () {
converse_api.user.logout();
converse_api.listen.not();
test_utils.clearBrowserStorage();
});
......@@ -270,6 +273,7 @@
afterEach(function () {
converse_api.user.logout();
converse_api.listen.not();
test_utils.clearBrowserStorage();
});
......@@ -392,6 +396,7 @@
describe("The rooms panel", function () {
afterEach(function () {
converse_api.user.logout();
converse_api.listen.not();
test_utils.clearBrowserStorage();
});
......@@ -426,6 +431,30 @@
converse.connection._dataRecv(test_utils.createRequest(stanza));
expect($('#chatrooms dl.bookmarks dd').length).toBe(3);
}));
it("remembers the toggle state of the bookmarks list", mock.initConverse(function (converse) {
runs(function () {
converse.bookmarks.create({
'jid': 'theplay@conference.shakespeare.lit',
'autojoin': false,
'name': 'The Play',
'nick': ''
});
converse.emit('chatBoxesFetched');
test_utils.openControlBox().openRoomsPanel(converse);
});
waits(100);
runs(function () {
expect($('#chatrooms dl.bookmarks dd:visible').length).toBe(1);
expect(converse.bookmarksview.list_model.get('toggle-state')).toBe(converse.OPENED);
$('#chatrooms .bookmarks-toggle').click();
expect($('#chatrooms dl.bookmarks dd:visible').length).toBe(0);
expect(converse.bookmarksview.list_model.get('toggle-state')).toBe(converse.CLOSED);
$('#chatrooms .bookmarks-toggle').click();
expect($('#chatrooms dl.bookmarks dd:visible').length).toBe(1);
expect(converse.bookmarksview.list_model.get('toggle-state')).toBe(converse.OPENED);
});
}));
});
});
}));
......@@ -175,6 +175,12 @@
converse.Bookmark = Backbone.Model;
converse.BookmarksList = Backbone.Model.extend({
defaults: {
"toggle-state": converse.OPENED
}
});
converse.Bookmarks = Backbone.Collection.extend({
model: converse.Bookmark,
......@@ -330,15 +336,26 @@
initialize: function () {
this.model.on('add', this.renderBookmarkListElement, this);
this.model.on('remove', this.removeBookmarkListElement, this);
var cachekey = 'converse.room-bookmarks'+converse.bare_jid+'-list-model';
this.list_model = new converse.BookmarksList();
this.list_model.id = cachekey;
this.list_model.browserStorage = new Backbone.BrowserStorage[converse.storage](
b64_sha1(cachekey)
);
this.list_model.fetch();
this.render();
},
render: function (cfg) {
this.$el.html(converse.templates.bookmarks_list({
'toggle_state': converse.OPENED,
'toggle_state': this.list_model.get('toggle-state'),
'desc_bookmarks': __('Click to toggle the bookmarks list'),
'label_bookmarks': __('Bookmarked Rooms')
})).hide();
if (this.list_model.get('toggle-state') !== converse.OPENED) {
this.$('.bookmarks').hide();
}
this.model.each(this.renderBookmarkListElement, this);
var controlboxview = converse.chatboxviews.get('controlbox');
if (!_.isUndefined(controlboxview)) {
......@@ -381,11 +398,13 @@
if (ev && ev.preventDefault) { ev.preventDefault(); }
var $el = $(ev.target);
if ($el.hasClass("icon-opened")) {
this.$('.bookmarks').slideUp();
this.$('.bookmarks').slideUp('fast');
this.list_model.save({'toggle-state': converse.CLOSED});
$el.removeClass("icon-opened").addClass("icon-closed");
} else {
$el.removeClass("icon-closed").addClass("icon-opened");
this.$('.bookmarks').slideDown();
this.$('.bookmarks').slideDown('fast');
this.list_model.save({'toggle-state': converse.OPENED});
}
}
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment