Create base composite view

This commit is contained in:
Dmitriy Simushev 2013-01-29 08:59:53 +00:00
parent 2a656a58d5
commit dd79c9aa21
3 changed files with 39 additions and 20 deletions

View File

@ -5,4 +5,4 @@
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(d,b,e){d.Views.CollectionBase=b.Marionette.CollectionView.extend({itemView:b.Marionette.ItemView,buildItemView:function(a,b,c){c=e.extend({model:a},c);return"function"!=typeof a.getModelType?new b(c):(a=a.getModelType())&&d.Views[a]?new d.Views[a](c):new b(c)}})})(Mibew,Backbone,_);
(function(d,a,f){var e=function(b,a,c){c=f.extend({model:b},c);return"function"!=typeof b.getModelType?new a(c):(b=b.getModelType())&&d.Views[b]?new d.Views[b](c):new a(c)};d.Views.CollectionBase=a.Marionette.CollectionView.extend({itemView:a.Marionette.ItemView,buildItemView:e});d.Views.CompositeBase=a.Marionette.CompositeView.extend({buildItemView:e})})(Mibew,Backbone,_);

View File

@ -26,5 +26,5 @@ b.Server.prototype.registerFunction=function(a,b){a in this.functions||(this.fun
(function(b,c,d){b.Views.Control=c.Marionette.ItemView.extend({template:d.templates.default_control,modelEvents:{change:"render"},events:{mouseover:"mouseOver",mouseleave:"mouseLeave"},attributes:function(){var a=[];a.push("control");this.className&&(a.push(this.className),this.className="");var b=this.getDashedControlType();b&&a.push(b);return{"class":a.join(" ")}},mouseOver:function(){var a=this.getDashedControlType();this.$el.addClass("active"+(a?"-"+a:""))},mouseLeave:function(){var a=this.getDashedControlType();
this.$el.removeClass("active"+(a?"-"+a:""))},getDashedControlType:function(){"undefined"==typeof this.dashedControlType&&(this.dashedControlType=b.Utils.toDashFormat(this.model.getModelType())||"");return this.dashedControlType}})})(Mibew,Backbone,Handlebars);
(function(a,b,c){a.Views.Sound=b.Marionette.ItemView.extend({template:c.templates.sound,className:"sound-player",modelEvents:{"sound:play":"render"}})})(Mibew,Backbone,Handlebars);
(function(d,b,e){d.Views.CollectionBase=b.Marionette.CollectionView.extend({itemView:b.Marionette.ItemView,buildItemView:function(a,b,c){c=e.extend({model:a},c);return"function"!=typeof a.getModelType?new b(c):(a=a.getModelType())&&d.Views[a]?new d.Views[a](c):new b(c)}})})(Mibew,Backbone,_);
(function(d,a,f){var e=function(b,a,c){c=f.extend({model:b},c);return"function"!=typeof b.getModelType?new a(c):(b=b.getModelType())&&d.Views[b]?new d.Views[b](c):new a(c)};d.Views.CollectionBase=a.Marionette.CollectionView.extend({itemView:a.Marionette.ItemView,buildItemView:e});d.Views.CompositeBase=a.Marionette.CompositeView.extend({buildItemView:e})})(Mibew,Backbone,_);
(function(a){a.Views.ControlsCollection=a.Views.CollectionBase.extend({itemView:a.Views.Control,className:"controls-collection"})})(Mibew);

View File

@ -8,6 +8,31 @@
(function(Mibew, Backbone, _){
/**
* Return special contructor for an item view if it exists or the
* default constructor otherwise. Use in Mibew.Views.CollectionBase and
* Mibew.Views.CompositeBase
* @private
* @param {Backbone.Model} item Collection item
* @param {Function} ItemViewType Default item view constructor
* @param {Object} itemViewOptions Additional item view options
* @returns Item view instance
*/
var buildItemView = function(item, ItemViewType, itemViewOptions) {
// Build options object
var options = _.extend({model: item}, itemViewOptions);
// Try to find special view for this model
if (typeof item.getModelType != 'function') {
return new ItemViewType(options);
}
var modelType = item.getModelType();
if (modelType && Mibew.Views[modelType]) {
return new Mibew.Views[modelType](options);
} else {
return new ItemViewType(options);
}
}
/**
* @class Represents base collection view
*/
@ -23,25 +48,19 @@
/**
* Return special contructor for an item view if it exists or the
* default constructor otherwise.
* @param {Backbone.Model} item Collection item
* @param {Function} ItemViewType Default item view constructor
* @param {Object} itemViewOptions Additional item view options
* @returns Item view instance
*/
buildItemView: function(item, ItemViewType, itemViewOptions) {
// Build options object
var options = _.extend({model: item}, itemViewOptions);
// Try to find special view for this model
if (typeof item.getModelType != 'function') {
return new ItemViewType(options);
}
var modelType = item.getModelType();
if (modelType && Mibew.Views[modelType]) {
return new Mibew.Views[modelType](options);
} else {
return new ItemViewType(options);
}
}
buildItemView: buildItemView
}
);
Mibew.Views.CompositeBase = Backbone.Marionette.CompositeView.extend(
/** @lends Mibew.Views.CompositeBase.prototype */
{
/**
* Return special contructor for an item view if it exists or the
* default constructor otherwise.
*/
buildItemView: buildItemView
}
);