blob: 47ae4207e97fb2168c81e900e42f38ac853fe2c4 [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.Host = Backbone.Model.extend({
18
19 defaults: {
20 // vlan: -1,
21 lastSeen: 'never',
22 ip: ' ',
23 swport: ' ',
24 },
25
26 // initialize:function () {}
27
28});
29
30window.HostCollection = Backbone.Collection.extend({
31
32 model:Host,
33
34 initialize:function () {
35 var self = this;
36 //console.log("fetching host list")
37 $.ajax({
38 url:hackBase + "/wm/device/",
39 dataType:"json",
40 success:function (data) {
41 // console.log("fetched host list: " + data.length);
42 // console.log(data);
43 // data is a list of device hashes
44 _.each(data, function(h) {
45 if (h['attachmentPoint'].length > 0) {
46 h.id = h.mac[0];
47 h.swport = _.reduce(h['attachmentPoint'], function(memo, ap) {
48 return memo + ap.switchDPID + "-" + ap.port + " "}, "");
49 //console.log(h.swport);
50 h.lastSeen = new Date(h.lastSeen).toLocaleString();
51 self.add(h, {silent: true});
52 }
53 });
54 self.trigger('add'); // batch redraws
55 }
56 });
57
58 },
59
60 fetch:function () {
61 this.initialize();
62 }
63
64 /*
65 * findByName:function (key) { // TODO: Modify service to include firstName
66 * in search var url = (key == '') ? '/host/' : "/host/search/" + key;
67 * console.log('findByName: ' + key); var self = this; $.ajax({ url:url,
68 * dataType:"json", success:function (data) { console.log("search success: " +
69 * data.length); self.reset(data); } }); }
70 */
71
72});