From 964e917f4a697d163ed2ae77f79fd372ad247b60 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Thu, 18 Dec 2014 14:42:11 +0000 Subject: [PATCH] Provide easy way to override views in JS application --- .../collection_views/messages_collection.js | 22 +++++++---- .../collection_views/status_collection.js | 22 +++++++---- .../collection_views/controls_collection.js | 22 +++++++---- .../collection_views/messages_collection.js | 22 +++++++---- .../collection_views/agents_collection.js | 20 +++++++--- .../collection_views/threads_collection.js | 39 +++++++++++++------ .../collection_views/visitors_collection.js | 39 +++++++++++++------ 7 files changed, 128 insertions(+), 58 deletions(-) diff --git a/src/mibew/js/source/chat/collection_views/messages_collection.js b/src/mibew/js/source/chat/collection_views/messages_collection.js index b0243be7..fbf681a1 100644 --- a/src/mibew/js/source/chat/collection_views/messages_collection.js +++ b/src/mibew/js/source/chat/collection_views/messages_collection.js @@ -24,17 +24,25 @@ Mibew.Views.MessagesCollection = Mibew.Views.CollectionBase.extend( /** @lends Mibew.Views.MessagesCollection.prototype */ { - /** - * Default item view constructor. - * @type Function - */ - childView: Mibew.Views.Message, - /** * Class name for view's DOM element * @type String */ - className: 'messages-collection' + className: 'messages-collection', + + /** + * Returns default child view constructor. + * + * The function is used instead of "childView" property to provide + * an ability to override child view constructor without this class + * overriding. + * + * @param {Backbone.Model} model The model the view created for. + * @returns {Backbone.Marionette.ItemView} + */ + getChildView: function(model) { + return Mibew.Views.Message; + } } ); diff --git a/src/mibew/js/source/chat/collection_views/status_collection.js b/src/mibew/js/source/chat/collection_views/status_collection.js index c8017396..5b572354 100644 --- a/src/mibew/js/source/chat/collection_views/status_collection.js +++ b/src/mibew/js/source/chat/collection_views/status_collection.js @@ -24,17 +24,25 @@ Mibew.Views.StatusCollection = Mibew.Views.CollectionBase.extend( /** @lends Mibew.Views.StatusCollection.prototype */ { - /** - * Default item view constructor. - * @type Function - */ - childView: Mibew.Views.Status, - /** * Class name for view's DOM element * @type String */ - className: 'status-collection' + className: 'status-collection', + + /** + * Returns default child view constructor. + * + * The function is used instead of "childView" property to provide + * an ability to override child view constructor without this class + * overriding. + * + * @param {Backbone.Model} model The model the view created for. + * @returns {Backbone.Marionette.ItemView} + */ + getChildView: function(model) { + return Mibew.Views.Status; + } } ); diff --git a/src/mibew/js/source/default/collection_views/controls_collection.js b/src/mibew/js/source/default/collection_views/controls_collection.js index 99250b76..6716817f 100644 --- a/src/mibew/js/source/default/collection_views/controls_collection.js +++ b/src/mibew/js/source/default/collection_views/controls_collection.js @@ -24,17 +24,25 @@ Mibew.Views.ControlsCollection = Mibew.Views.CollectionBase.extend( /** @lends Mibew.Views.ControlsCollection.prototype */ { - /** - * Default item view constructor. - * @type Function - */ - childView: Mibew.Views.Control, - /** * Class name for view's DOM element * @type String */ - className: 'controls-collection' + className: 'controls-collection', + + /** + * Returns default child view constructor. + * + * The function is used instead of "childView" property to provide + * an ability to override child view constructor without this class + * overriding. + * + * @param {Backbone.Model} model The model the view created for. + * @returns {Backbone.Marionette.ItemView} + */ + getChildView: function(model) { + return Mibew.Views.Control; + } } ); diff --git a/src/mibew/js/source/thread_log/collection_views/messages_collection.js b/src/mibew/js/source/thread_log/collection_views/messages_collection.js index b0243be7..fbf681a1 100644 --- a/src/mibew/js/source/thread_log/collection_views/messages_collection.js +++ b/src/mibew/js/source/thread_log/collection_views/messages_collection.js @@ -24,17 +24,25 @@ Mibew.Views.MessagesCollection = Mibew.Views.CollectionBase.extend( /** @lends Mibew.Views.MessagesCollection.prototype */ { - /** - * Default item view constructor. - * @type Function - */ - childView: Mibew.Views.Message, - /** * Class name for view's DOM element * @type String */ - className: 'messages-collection' + className: 'messages-collection', + + /** + * Returns default child view constructor. + * + * The function is used instead of "childView" property to provide + * an ability to override child view constructor without this class + * overriding. + * + * @param {Backbone.Model} model The model the view created for. + * @returns {Backbone.Marionette.ItemView} + */ + getChildView: function(model) { + return Mibew.Views.Message; + } } ); diff --git a/src/mibew/js/source/users/collection_views/agents_collection.js b/src/mibew/js/source/users/collection_views/agents_collection.js index 1aad0a4c..d1b6732c 100644 --- a/src/mibew/js/source/users/collection_views/agents_collection.js +++ b/src/mibew/js/source/users/collection_views/agents_collection.js @@ -24,12 +24,6 @@ Mibew.Views.AgentsCollection = Mibew.Views.CollectionBase.extend( /** @lends Mibew.Views.AgentsCollection.prototype */ { - /** - * Default item view constructor. - * @type Function - */ - childView: Mibew.Views.Agent, - /** * Class name for view's DOM element * @type String @@ -44,6 +38,20 @@ 'sort add remove reset': 'render' }, + /** + * Returns default child view constructor. + * + * The function is used instead of "childView" property to provide + * an ability to override child view constructor without this class + * overriding. + * + * @param {Backbone.Model} model The model the view created for. + * @returns {Backbone.Marionette.ItemView} + */ + getChildView: function(model) { + return Mibew.Views.Agent; + }, + /** * View initializer */ diff --git a/src/mibew/js/source/users/collection_views/threads_collection.js b/src/mibew/js/source/users/collection_views/threads_collection.js index 913ffe83..7195d381 100644 --- a/src/mibew/js/source/users/collection_views/threads_collection.js +++ b/src/mibew/js/source/users/collection_views/threads_collection.js @@ -26,24 +26,12 @@ { template: Handlebars.templates['users/threads_collection'], - /** - * Default item view constructor. - * @type Function - */ - childView: Mibew.Views.QueuedThread, - /** * DOM element for collection items * @type String */ childViewContainer: '#threads-container', - /** - * Empty view constructor. - * @type Function - */ - emptyView: Mibew.Views.NoThreads, - /** * Class name for view's DOM element * @type String @@ -60,6 +48,33 @@ 'add': 'threadAdded' }, + /** + * Returns default child view constructor. + * + * The function is used instead of "childView" property to provide + * an ability to override child view constructor without this class + * overriding. + * + * @param {Backbone.Model} model The model the view created for. + * @returns {Backbone.Marionette.ItemView} + */ + getChildView: function(model) { + return Mibew.Views.QueuedThread; + }, + + /** + * Returns empty view constructor. + * + * The function is used instead of "emptyView" property to provide + * an ability to override empty view constructor without this class + * overriding. + * + * @returns {Backbone.Marionette.ItemView} + */ + getEmptyView: function() { + return Mibew.Views.NoThreads; + }, + /** * Pass some options to item view * @returns {Object} Options object diff --git a/src/mibew/js/source/users/collection_views/visitors_collection.js b/src/mibew/js/source/users/collection_views/visitors_collection.js index ecd3606a..8791b693 100644 --- a/src/mibew/js/source/users/collection_views/visitors_collection.js +++ b/src/mibew/js/source/users/collection_views/visitors_collection.js @@ -26,24 +26,12 @@ { template: Handlebars.templates['users/visitors_collection'], - /** - * Default item view constructor. - * @type Function - */ - childView: Mibew.Views.Visitor, - /** * DOM element for collection items * @type String */ childViewContainer: '#visitors-container', - /** - * Empty view constructor. - * @type Function - */ - emptyView: Mibew.Views.NoVisitors, - /** * Class name for view's DOM element * @type String @@ -58,6 +46,33 @@ 'sort': 'render' }, + /** + * Returns default child view constructor. + * + * The function is used instead of "childView" property to provide + * an ability to override child view constructor without this class + * overriding. + * + * @param {Backbone.Model} model The model the view created for. + * @returns {Backbone.Marionette.ItemView} + */ + getChildView: function(model) { + return Mibew.Views.Visitor; + }, + + /** + * Returns empty view constructor. + * + * The function is used instead of "emptyView" property to provide + * an ability to override empty view constructor without this class + * overriding. + * + * @returns {Backbone.Marionette.ItemView} + */ + getEmptyView: function() { + return Mibew.Views.NoVisitors; + }, + /** * Pass some options to item view * @returns {Object} Options object