Commit 81f3814e authored by JC Brand's avatar JC Brand

Refactor code out into backbone.overview

parent 76545632
...@@ -26,7 +26,8 @@ ...@@ -26,7 +26,8 @@
"requirejs-text": "~2.0.12", "requirejs-text": "~2.0.12",
"requirejs-tpl-jcbrand": "*", "requirejs-tpl-jcbrand": "*",
"momentjs": "~2.6.0", "momentjs": "~2.6.0",
"jquery.browser": "~0.0.6" "jquery.browser": "~0.0.6",
"backbone.overview": "*"
}, },
"exportsOverride": {} "exportsOverride": {}
} }
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* http://conversejs.org * http://conversejs.org
* *
* Copyright (c) 2012, Jan-Carel Brand <jc@opkode.com> * Copyright (c) 2012, Jan-Carel Brand <jc@opkode.com>
* Dual licensed under the MIT and GPL Licenses * Licensed under the Mozilla Public License (MPL)
*/ */
// AMD/global registrations // AMD/global registrations
...@@ -1339,6 +1339,7 @@ ...@@ -1339,6 +1339,7 @@
// the opposite of trim, i.e. restoring a trimmed chat box // the opposite of trim, i.e. restoring a trimmed chat box
this.$el.insertAfter(converse.chatboxviews.get("controlbox").$el).show(); this.$el.insertAfter(converse.chatboxviews.get("controlbox").$el).show();
this.focus(); this.focus();
converse.refreshWebkit();
this.model.trigger('grow', this.model); this.model.trigger('grow', this.model);
}, },
...@@ -2512,17 +2513,11 @@ ...@@ -2512,17 +2513,11 @@
} }
}); });
this.ChatBoxViews = Backbone.View.extend({ this.ChatBoxViews = Backbone.Overview.extend({
initialize: function () { initialize: function () {
var views = {};
this.get = function (id) { return views[id]; };
this.add = function (id, view) { views[id] = view; };
this.getAll = function () { return views; };
this.trimmed_chatboxes_view = new converse.TrimmedChatBoxesView({model: this.model}); this.trimmed_chatboxes_view = new converse.TrimmedChatBoxesView({model: this.model});
this.render(); this.render();
this.model.on("add", this.onChatAdded, this); this.model.on("add", this.onChatAdded, this);
this.model.on("grow", function (item) { this.model.on("grow", function (item) {
this.trimChats(this.get(item.get('id'))); this.trimChats(this.get(item.get('id')));
...@@ -2667,20 +2662,9 @@ ...@@ -2667,20 +2662,9 @@
} }
}); });
this.TrimmedChatBoxesView = Backbone.View.extend({ this.TrimmedChatBoxesView = Backbone.Overview.extend({
initialize: function () { initialize: function () {
var views = {};
this.get = function (id) { return views[id]; };
this.add = function (id, view) { views[id] = view; };
this.remove = function (id) {
var view = views[id];
if (view) {
view.remove();
delete views[id];
}
};
this.model.on("change:trimmed", function (item) { this.model.on("change:trimmed", function (item) {
var view; var view;
if (item.get('trimmed')) { if (item.get('trimmed')) {
...@@ -3125,15 +3109,11 @@ ...@@ -3125,15 +3109,11 @@
} }
}); });
this.RosterView = Backbone.View.extend({ this.RosterView = Backbone.Overview.extend({
tagName: 'dl', tagName: 'dl',
id: 'converse-roster', id: 'converse-roster',
initialize: function () { initialize: function () {
var views = {};
this.get = function (id) { return views[id]; };
this.add = function (id, view) { views[id] = view; };
this.model.on("add", function (item) { this.model.on("add", function (item) {
this.addRosterItemView(item).render(item); this.addRosterItemView(item).render(item);
if (!item.get('vcard_updated')) { if (!item.get('vcard_updated')) {
...@@ -3167,7 +3147,6 @@ ...@@ -3167,7 +3147,6 @@
}); });
} }
this.$el.hide().html(roster_markup); this.$el.hide().html(roster_markup);
this.model.fetch({add: true}); // Get the cached roster items from localstorage this.model.fetch({add: true}); // Get the cached roster items from localstorage
}, },
......
...@@ -8,6 +8,7 @@ config = { ...@@ -8,6 +8,7 @@ config = {
"underscore": "components/underscore/underscore", "underscore": "components/underscore/underscore",
"backbone": "components/backbone/backbone", "backbone": "components/backbone/backbone",
"backbone.localStorage": "components/backbone.localStorage/backbone.localStorage", "backbone.localStorage": "components/backbone.localStorage/backbone.localStorage",
"backbone.overview": "components/backbone.overview/backbone.overview",
"text": 'components/requirejs-text/text', "text": 'components/requirejs-text/text',
"tpl": 'components/requirejs-tpl-jcbrand/tpl', "tpl": 'components/requirejs-tpl-jcbrand/tpl',
"converse-templates": "src/templates", "converse-templates": "src/templates",
......
...@@ -3,6 +3,7 @@ define("converse-dependencies", [ ...@@ -3,6 +3,7 @@ define("converse-dependencies", [
"moment", "moment",
"locales", "locales",
"backbone.localStorage", "backbone.localStorage",
"backbone.overview",
"jquery.tinysort", "jquery.tinysort",
"jquery.browser", "jquery.browser",
"strophe", "strophe",
......
...@@ -2,6 +2,7 @@ define("converse-dependencies", [ ...@@ -2,6 +2,7 @@ define("converse-dependencies", [
"moment", "moment",
"locales", "locales",
"backbone.localStorage", "backbone.localStorage",
"backbone.overview",
"jquery.tinysort", "jquery.tinysort",
"jquery.browser", "jquery.browser",
"strophe", "strophe",
......
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