|
@@ -19,18 +19,29 @@
|
|
|
"converse-core",
|
|
|
"converse-api",
|
|
|
"converse-muc",
|
|
|
- "tpl!chatroom_bookmark_form"
|
|
|
+ "tpl!chatroom_bookmark_form",
|
|
|
+ "tpl!bookmark",
|
|
|
+ "tpl!bookmarks_list"
|
|
|
],
|
|
|
factory);
|
|
|
-}(this, function ($, _, moment, strophe, utils, converse, converse_api, muc, chatroom_bookmark_form) {
|
|
|
+}(this, function (
|
|
|
+ $, _, moment, strophe, utils,
|
|
|
+ converse, converse_api, muc,
|
|
|
+ tpl_chatroom_bookmark_form,
|
|
|
+ tpl_bookmark,
|
|
|
+ tpl_bookmarks_list
|
|
|
+ ) {
|
|
|
|
|
|
var __ = utils.__.bind(converse),
|
|
|
+ ___ = utils.___,
|
|
|
Strophe = converse_api.env.Strophe,
|
|
|
$iq = converse_api.env.$iq,
|
|
|
b64_sha1 = converse_api.env.b64_sha1;
|
|
|
|
|
|
// Add new HTML templates.
|
|
|
- converse.templates.chatroom_bookmark_form = chatroom_bookmark_form;
|
|
|
+ converse.templates.chatroom_bookmark_form = tpl_chatroom_bookmark_form;
|
|
|
+ converse.templates.bookmark = tpl_bookmark;
|
|
|
+ converse.templates.bookmarks_list = tpl_bookmarks_list;
|
|
|
|
|
|
converse_api.plugins.add('converse-bookmarks', {
|
|
|
overrides: {
|
|
@@ -40,10 +51,6 @@
|
|
|
//
|
|
|
// New functions which don't exist yet can also be added.
|
|
|
|
|
|
- RoomsPanel: {
|
|
|
- /* TODO: show bookmarked rooms in the rooms panel */
|
|
|
- },
|
|
|
-
|
|
|
ChatRoomView: {
|
|
|
events: {
|
|
|
'click .toggle-bookmark': 'toggleBookmark'
|
|
@@ -125,7 +132,6 @@
|
|
|
'nick': $form.find('input[name=nick]').val()
|
|
|
});
|
|
|
this.model.save('bookmarked', true);
|
|
|
- converse.bookmarks.sendBookmarkStanza();
|
|
|
this.$el.find('div.chatroom-form-container').hide(
|
|
|
function () {
|
|
|
$(this).remove();
|
|
@@ -143,9 +149,6 @@
|
|
|
this.renderBookmarkForm();
|
|
|
} else {
|
|
|
converse.bookmarks.remove(models);
|
|
|
- converse.bookmarks.sendBookmarkStanza().fail(
|
|
|
- _.partial(this.model.save, 'bookmarked', false)
|
|
|
- );
|
|
|
this.$('.icon-pushpin').removeClass('button-on');
|
|
|
}
|
|
|
}
|
|
@@ -166,7 +169,9 @@
|
|
|
initialize: function () {
|
|
|
this.on('add', this.markRoomAsBookmarked, this);
|
|
|
this.on('add', this.openBookmarkedRoom, this);
|
|
|
+ this.on('add', this.sendBookmarkStanza, this);
|
|
|
this.on('remove', this.markRoomAsUnbookmarked, this);
|
|
|
+ this.on('remove', this.sendBookmarkStanza, this);
|
|
|
|
|
|
this.browserStorage = new Backbone.BrowserStorage[converse.storage](
|
|
|
b64_sha1('converse.room-bookmarks'+converse.bare_jid)
|
|
@@ -288,9 +293,81 @@
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ converse.BookmarksView = Backbone.View.extend({
|
|
|
+ tagName: 'div',
|
|
|
+ className: 'bookmarks-list',
|
|
|
+ events: {
|
|
|
+ 'click .remove-bookmark': 'removebookmark',
|
|
|
+ 'click .bookmarks-toggle': 'toggleBookmarksList'
|
|
|
+ },
|
|
|
+
|
|
|
+ initialize: function () {
|
|
|
+ this.model.on('add', this.onBookmarkAdded, this);
|
|
|
+ },
|
|
|
+
|
|
|
+ render: function (cfg) {
|
|
|
+ this.$el.html(converse.templates.bookmarks_list({
|
|
|
+ 'toggle_state': converse.OPENED,
|
|
|
+ 'desc_bookmarks': __('Click to toggle the bookmarks list'),
|
|
|
+ 'label_bookmarks': __('Bookmarked Rooms')
|
|
|
+ }));
|
|
|
+ this.$bookmarks = this.$('.bookmarks');
|
|
|
+ var controlboxview = converse.chatboxviews.get('controlbox');
|
|
|
+ if (_.isUndefined(controlboxview)) {
|
|
|
+ return this.$el;
|
|
|
+ }
|
|
|
+ controlboxview.$('#chatrooms .bookmarks-list').remove();
|
|
|
+ this.$el.prependTo(controlboxview.$('#chatrooms'));
|
|
|
+ return this.$el;
|
|
|
+ },
|
|
|
+
|
|
|
+ removeBookmark: function (ev) {
|
|
|
+ ev.preventDefault();
|
|
|
+ var name = $(ev.target).data('bookmarkName');
|
|
|
+ var jid = $(ev.target).data('roomJid');
|
|
|
+ if (confirm(__(___("Are you sure you want to remove the bookmark \"%1$s\"?"), name))) {
|
|
|
+ var models = converse.bookmarks.where({'jid': jid});
|
|
|
+ converse.bookmarks.remove(models);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ onBookmarkAdded: function (item) {
|
|
|
+ if (_.isUndefined(this.$bookmarks)) {
|
|
|
+ this.render();
|
|
|
+ }
|
|
|
+ this.$bookmarks.append($(
|
|
|
+ converse.templates.bookmark({
|
|
|
+ 'name': item.get('name'),
|
|
|
+ 'jid': item.get('jid'),
|
|
|
+ 'open_title': __('Click to open this room'),
|
|
|
+ 'info_title': __('Show more information on this room'),
|
|
|
+ 'info_remove': __('Remove this bookmark')
|
|
|
+ })
|
|
|
+ ));
|
|
|
+ },
|
|
|
+
|
|
|
+ toggleBookmarksList: function (ev) {
|
|
|
+ if (ev && ev.preventDefault) { ev.preventDefault(); }
|
|
|
+ var $el = $(ev.target);
|
|
|
+ if ($el.hasClass("icon-opened")) {
|
|
|
+ this.$('.bookmarks').slideUp();
|
|
|
+ $el.removeClass("icon-opened").addClass("icon-closed");
|
|
|
+ } else {
|
|
|
+ $el.removeClass("icon-closed").addClass("icon-opened");
|
|
|
+ this.$('.bookmarks').slideDown();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
converse.initBookmarks = function () {
|
|
|
converse.bookmarks = new converse.Bookmarks();
|
|
|
+ converse.bookmarksview = new converse.BookmarksView(
|
|
|
+ {'model': converse.bookmarks}
|
|
|
+ );
|
|
|
converse.bookmarks.fetchBookmarks();
|
|
|
+ // TODO: think of performance here... we probably only want to
|
|
|
+ // show the bookmarks after they have been fetched
|
|
|
+ converse.bookmarksview.render();
|
|
|
};
|
|
|
converse.on('connected', converse.initBookmarks);
|
|
|
converse.on('reconnected', converse.initBookmarks);
|