Pankaj Berde | c4ae4b8 | 2013-01-12 09:56:47 -0800 | [diff] [blame^] | 1 | /* |
| 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 | |
| 17 | window.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 | |
| 38 | window.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 | |
| 55 | window.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 | this.model.bind("remove", this.render, this); |
| 61 | }, |
| 62 | |
| 63 | render:function (eventName) { |
| 64 | $(this.el).html(this.template({nswitches:swl.length})); |
| 65 | _.each(this.model.models, function (sw) { |
| 66 | $(this.el).find('table.switch-table > tbody') |
| 67 | .append(new SwitchListItemView({model:sw}).render().el); |
| 68 | }, this); |
| 69 | return this; |
| 70 | }, |
| 71 | |
| 72 | }); |
| 73 | |