blob: 178dd99bba9021ac1675a17a46af2e77dc90e7f3 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/*
2 Copyright 2012 IBM
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17window.SwitchView = Backbone.View.extend({
18
19 initialize:function () {
20 this.template = _.template(tpl.get('switch'));
21 this.model.bind("change", this.render, this);
22 //this.model.bind("destroy", this.close, this);
23
24 // some parts of the model are large and are only needed in detail view
25 this.model.loadPorts();
26 this.model.loadFlows();
27 },
28
29 render:function (eventName) {
30 $(this.el).html(this.template(this.model.toJSON()));
31 $(this.el).find('#port-list').html(new PortListView({model:this.model.ports}).render().el);
32 $(this.el).find('#flow-list').html(new FlowListView({model:this.model.flows}).render().el);
33 return this;
34 }
35
36});
37
38window.SwitchListItemView = Backbone.View.extend({
39
40 tagName:"tr",
41
42 initialize:function () {
43 this.template = _.template(tpl.get('switch-list-item'));
44 this.model.bind("change", this.render, this);
45 //this.model.bind("destroy", this.close, this);
46 },
47
48 render:function (eventName) {
49 $(this.el).html(this.template(this.model.toJSON()));
50 return this;
51 }
52
53});
54
55window.SwitchListView = Backbone.View.extend({
56
57 initialize:function () {
58 this.template = _.template(tpl.get('switch-list'));
59 this.model.bind("change", this.render, this);
60 },
61
62 render:function (eventName) {
63 $(this.el).html(this.template({nswitches:swl.length}));
64 _.each(this.model.models, function (sw) {
65 $(this.el).find('table.switch-table > tbody')
66 .append(new SwitchListItemView({model:sw}).render().el);
67 }, this);
68 return this;
69 },
70
71});
72