2014-04-13 17:10:40 +00:00
|
|
|
define(function (require) {
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var $ = require('jquery'),
|
|
|
|
_ = require('underscore'),
|
|
|
|
Backbone = require('backbone'),
|
|
|
|
Marionette = require('marionette'),
|
2014-09-12 23:51:31 +00:00
|
|
|
Server = require('app/models/server'),
|
|
|
|
AddServerView = require('app/views/servers/form'),
|
2014-04-13 17:10:40 +00:00
|
|
|
EmptyView = require('app/views/servers/empty'),
|
|
|
|
ListItemView = require('app/views/servers/list_item'),
|
|
|
|
tpl = require('text!tpl/servers/list.html'),
|
|
|
|
|
|
|
|
template = _.template(tpl);
|
|
|
|
|
|
|
|
return Marionette.CompositeView.extend({
|
|
|
|
itemView: ListItemView,
|
|
|
|
itemViewContainer: "tbody",
|
|
|
|
template: template,
|
|
|
|
|
|
|
|
emptyView: EmptyView,
|
|
|
|
|
2014-06-04 22:29:31 +00:00
|
|
|
events: {
|
|
|
|
"click #add-server": "addServer"
|
|
|
|
},
|
|
|
|
|
2015-04-17 17:56:47 +00:00
|
|
|
initialize: function (options) {
|
|
|
|
this.listenTo(this.collection, "change reset", this.render);
|
|
|
|
},
|
|
|
|
|
2014-04-13 17:10:40 +00:00
|
|
|
buildItemView: function(item, ItemViewType, itemViewOptions){
|
|
|
|
// build the final list of options for the item view type
|
|
|
|
var options = _.extend({model: item}, itemViewOptions);
|
|
|
|
|
|
|
|
if (ItemViewType == EmptyView) {
|
|
|
|
options = _.extend({servers: this.collection}, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
// create the item view instance
|
|
|
|
var view = new ItemViewType(options);
|
|
|
|
// return it
|
|
|
|
return view;
|
|
|
|
},
|
2014-06-04 22:29:31 +00:00
|
|
|
|
|
|
|
addServer: function () {
|
2014-09-12 23:51:31 +00:00
|
|
|
var view = new AddServerView({model: new Server(), servers: this.collection});
|
2014-06-04 22:29:31 +00:00
|
|
|
new Backbone.BootstrapModal({ content: view, servers: this.collection }).open()
|
|
|
|
},
|
2014-04-13 17:10:40 +00:00
|
|
|
});
|
|
|
|
});
|