Indicate whether a chatroom has been bookmarked.
This commit is contained in:
parent
3363041625
commit
7ca7943706
|
@ -27,7 +27,6 @@
|
||||||
var view = converse.chatboxviews.get(jid);
|
var view = converse.chatboxviews.get(jid);
|
||||||
spyOn(view, 'renderBookmarkForm').andCallThrough();
|
spyOn(view, 'renderBookmarkForm').andCallThrough();
|
||||||
spyOn(view, 'cancelConfiguration').andCallThrough();
|
spyOn(view, 'cancelConfiguration').andCallThrough();
|
||||||
spyOn(view, 'onBookmarkAdded').andCallThrough();
|
|
||||||
spyOn(view, 'onBookmarkError').andCallThrough();
|
spyOn(view, 'onBookmarkError').andCallThrough();
|
||||||
|
|
||||||
var $bookmark = view.$el.find('.icon-pushpin');
|
var $bookmark = view.$el.find('.icon-pushpin');
|
||||||
|
@ -72,11 +71,13 @@
|
||||||
* </pubsub>
|
* </pubsub>
|
||||||
* </iq>
|
* </iq>
|
||||||
*/
|
*/
|
||||||
|
expect(view.model.get('bookmarked')).toBeFalsy();
|
||||||
var $form = view.$el.find('.chatroom-form');
|
var $form = view.$el.find('.chatroom-form');
|
||||||
$form.find('input[name="name"]').val('Play's the Thing');
|
$form.find('input[name="name"]').val('Play's the Thing');
|
||||||
$form.find('input[name="autojoin"]').prop('checked', true);
|
$form.find('input[name="autojoin"]').prop('checked', true);
|
||||||
$form.find('input[name="nick"]').val('JC');
|
$form.find('input[name="nick"]').val('JC');
|
||||||
$form.submit();
|
$form.submit();
|
||||||
|
expect(view.model.get('bookmarked')).toBeTruthy();
|
||||||
expect($bookmark.hasClass('on-button'), true);
|
expect($bookmark.hasClass('on-button'), true);
|
||||||
|
|
||||||
expect(sent_stanza.toLocaleString()).toBe(
|
expect(sent_stanza.toLocaleString()).toBe(
|
||||||
|
@ -118,16 +119,25 @@
|
||||||
'id':IQ_id
|
'id':IQ_id
|
||||||
});
|
});
|
||||||
converse.connection._dataRecv(test_utils.createRequest(stanza));
|
converse.connection._dataRecv(test_utils.createRequest(stanza));
|
||||||
expect(view.onBookmarkAdded).toHaveBeenCalled();
|
// We ignore this IQ stanza... (unless it's an error stanza), so
|
||||||
|
// nothing to test for here.
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when bookmarked", function () {
|
describe("when bookmarked", function () {
|
||||||
it("displays that it's bookmarked through its bookmark icon", function () {
|
it("displays that it's bookmarked through its bookmark icon", function () {
|
||||||
// TODO
|
runs(function () {
|
||||||
// Mock bookmark data received from the server.
|
test_utils.openChatRoom('lounge', 'localhost', 'dummy');
|
||||||
// Open the room
|
});
|
||||||
// Check that the icon has 'button-on' class.
|
waits(100);
|
||||||
|
runs(function () {
|
||||||
|
var view = converse.chatboxviews.get('lounge@localhost');
|
||||||
|
var $bookmark_icon = view.$('.icon-pushpin');
|
||||||
|
expect($bookmark_icon.hasClass('button-on')).toBeFalsy();
|
||||||
|
view.model.set('bookmarked', true);
|
||||||
|
expect($bookmark_icon.hasClass('button-on')).toBeTruthy();
|
||||||
|
view.model.set('bookmarked', false);
|
||||||
|
expect($bookmark_icon.hasClass('button-on')).toBeFalsy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can be unbookmarked", function () {
|
it("can be unbookmarked", function () {
|
||||||
|
|
|
@ -699,7 +699,7 @@
|
||||||
|
|
||||||
it("can be closed again by clicking a DOM element with class 'close-chatbox-button'", function () {
|
it("can be closed again by clicking a DOM element with class 'close-chatbox-button'", function () {
|
||||||
test_utils.openChatRoom('lounge', 'localhost', 'dummy');
|
test_utils.openChatRoom('lounge', 'localhost', 'dummy');
|
||||||
var view = this.chatboxviews.get('lounge@localhost');
|
var view = converse.chatboxviews.get('lounge@localhost');
|
||||||
spyOn(view, 'close').andCallThrough();
|
spyOn(view, 'close').andCallThrough();
|
||||||
spyOn(converse, 'emit');
|
spyOn(converse, 'emit');
|
||||||
spyOn(view, 'leave');
|
spyOn(view, 'leave');
|
||||||
|
@ -711,9 +711,9 @@
|
||||||
runs(function () {
|
runs(function () {
|
||||||
expect(view.close).toHaveBeenCalled();
|
expect(view.close).toHaveBeenCalled();
|
||||||
expect(view.leave).toHaveBeenCalled();
|
expect(view.leave).toHaveBeenCalled();
|
||||||
expect(this.emit).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
|
expect(converse.emit).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
|
||||||
}.bind(converse));
|
});
|
||||||
}.bind(converse));
|
});
|
||||||
}.bind(converse));
|
}.bind(converse));
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -49,15 +49,25 @@
|
||||||
'click .toggle-bookmark': 'toggleBookmark'
|
'click .toggle-bookmark': 'toggleBookmark'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
initialize: function () {
|
||||||
|
this.__super__.initialize.apply(this, arguments);
|
||||||
|
this.model.on('change:bookmarked', this.onBookmarked, this);
|
||||||
|
},
|
||||||
|
|
||||||
render: function (options) {
|
render: function (options) {
|
||||||
this.__super__.render.apply(this, arguments);
|
this.__super__.render.apply(this, arguments);
|
||||||
var label_bookmark = _('Bookmark this room');
|
var label_bookmark = _('Bookmark this room');
|
||||||
// TODO: check if bookmarked, and if so, add button-on class
|
var button = '<a class="chatbox-btn toggle-bookmark icon-pushpin '+
|
||||||
this.$el.find('.chat-head-chatroom .icon-wrench').before(
|
(this.model.get('bookmarked') ? 'button-on"' : '"') +
|
||||||
'<a class="chatbox-btn toggle-bookmark icon-pushpin" title="'+label_bookmark+'"></a>');
|
'title="'+label_bookmark+'"></a>';
|
||||||
|
this.$el.find('.chat-head-chatroom .icon-wrench').before(button);
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onBookmarked: function () {
|
||||||
|
this.$('.icon-pushpin').toggleClass('button-on');
|
||||||
|
},
|
||||||
|
|
||||||
renderBookmarkForm: function () {
|
renderBookmarkForm: function () {
|
||||||
var $body = this.$('.chatroom-body');
|
var $body = this.$('.chatroom-body');
|
||||||
$body.children().addClass('hidden');
|
$body.children().addClass('hidden');
|
||||||
|
@ -77,14 +87,13 @@
|
||||||
|
|
||||||
addBookmark: function (ev) {
|
addBookmark: function (ev) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
|
|
||||||
converse.bookmarks.create({
|
converse.bookmarks.create({
|
||||||
'id': this.model.get('id'),
|
'jid': this.model.get('jid'),
|
||||||
'autojoin': this.$el.find('.chatroom-form').find('input[name=autojoin]').val(),
|
'autojoin': this.$el.find('.chatroom-form').find('input[name=autojoin]').val(),
|
||||||
'name': this.$el.find('.chatroom-form').find('input[name=name]').val(),
|
'name': this.$el.find('.chatroom-form').find('input[name=name]').val(),
|
||||||
'nick': this.$el.find('.chatroom-form').find('input[name=nick]').val()
|
'nick': this.$el.find('.chatroom-form').find('input[name=nick]').val()
|
||||||
});
|
});
|
||||||
this.$('.icon-pushpin').addClass('button-on');
|
this.model.save('bookmarked', true);
|
||||||
|
|
||||||
var that = this,
|
var that = this,
|
||||||
$form = $(ev.target);
|
$form = $(ev.target);
|
||||||
|
@ -127,17 +136,13 @@
|
||||||
.c('value').t('true').up().up()
|
.c('value').t('true').up().up()
|
||||||
.c('field', {'var':'pubsub#access_model'})
|
.c('field', {'var':'pubsub#access_model'})
|
||||||
.c('value').t('whitelist');
|
.c('value').t('whitelist');
|
||||||
converse.connection.sendIQ(stanza, this.onBookmarkAdded, this.onBookmarkError);
|
converse.connection.sendIQ(stanza, null, this.onBookmarkError.bind(this));
|
||||||
},
|
|
||||||
|
|
||||||
onBookmarkAdded: function (iq) {
|
|
||||||
converse.log("Bookmark successfully added");
|
|
||||||
converse.log(iq);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onBookmarkError: function (iq) {
|
onBookmarkError: function (iq) {
|
||||||
converse.log("Error while trying to add bookmark");
|
converse.log("Error while trying to add bookmark", "error");
|
||||||
converse.log(iq);
|
converse.log(iq);
|
||||||
|
this.model.save('bookmarked', false);
|
||||||
window.alert(__("Sorry, something went wrong while trying to save your bookmark."));
|
window.alert(__("Sorry, something went wrong while trying to save your bookmark."));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -163,30 +168,46 @@
|
||||||
* loaded by converse.js's plugin machinery.
|
* loaded by converse.js's plugin machinery.
|
||||||
*/
|
*/
|
||||||
var converse = this.converse;
|
var converse = this.converse;
|
||||||
|
|
||||||
converse.Bookmarks = Backbone.Collection.extend({
|
converse.Bookmarks = Backbone.Collection.extend({
|
||||||
|
|
||||||
onCachedBookmarksFetched: function () {
|
onCachedBookmarksFetched: function () {
|
||||||
if (!window.sessionStorage.getItem(this.browserStorage.name) || this.models.length > 0) {
|
if (!window.sessionStorage.getItem(this.browserStorage.name)) {
|
||||||
// There weren't any cached bookmarks, so we query to XMPP
|
// There aren't any cached bookmarks, so we query the
|
||||||
// server
|
// XMPP server.
|
||||||
var stanza = $iq({
|
var stanza = $iq({
|
||||||
'from': converse.connection.jid,
|
'from': converse.connection.jid,
|
||||||
'type': 'get',
|
'type': 'get',
|
||||||
}).c('pubsub', {'xmlns': Strophe.NS.PUBSUB})
|
}).c('pubsub', {'xmlns': Strophe.NS.PUBSUB})
|
||||||
.c('items', {'node': 'storage:bookmarks'});
|
.c('items', {'node': 'storage:bookmarks'});
|
||||||
converse.connection.sendIQ(stanza, this.onBookmarksReceived.bind(this), this.onBookmarksReceivedError);
|
converse.connection.sendIQ(
|
||||||
|
stanza,
|
||||||
|
this.onBookmarksReceived.bind(this),
|
||||||
|
this.onBookmarksReceivedError
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
this.models.each(this.markRoomAsBookmarked);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
markRoomAsBookmarked: function (bookmark) {
|
||||||
|
var room = converse.chatboxes.get(bookmark.get('jid'));
|
||||||
|
if (!_.isUndefined(room)) {
|
||||||
|
room.save('bookmarked', true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onBookmarksReceived: function (iq) {
|
onBookmarksReceived: function (iq) {
|
||||||
var rooms = $(iq).find('items[node="storage:bookmarks"] item[id="current"] storage conference');
|
var bookmarks = $(iq).find(
|
||||||
_.each(rooms, function (room) {
|
'items[node="storage:bookmarks"] item[id="current"] storage conference'
|
||||||
this.create({
|
);
|
||||||
'jid': room.jid,
|
_.each(bookmarks, function (bookmark) {
|
||||||
'name': room.name,
|
this.markRoomAsBookmarked(this.create({
|
||||||
'autojoin': room.autojoin,
|
'jid': bookmark.getAttribute('jid'),
|
||||||
'nick': room.querySelector('nick').text
|
'name': bookmark.getAttribute('name'),
|
||||||
});
|
'autojoin': bookmark.getAttribute('autojoin'),
|
||||||
|
'nick': bookmark.querySelector('nick').textContent
|
||||||
|
}));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user