Commits

Nicolás Echániz committed 1d83653

minor code cleanup

Comments (0)

Files changed (2)

_attachments/js/map.js

         center = new OpenLayers.LonLat(coords['lon'], coords['lat']);
         zoom_level = 15;
 
-//        this._map = new OpenLayers.Map(this._el, options);
-
         map_layers = [ new OpenLayers.Layer.OSM("OpenStreetMap"),
                        new OpenLayers.Layer.Google(
                            "Google Hybrid",
                     'featureunselected': function(evt){
                         marker = evt.feature;
                         this._map.removePopup(marker.popup);
-                        //        map._map.removePopup(marker.popup);
                         marker.popup.destroy();
                         delete marker.popup;
                     },
 
         this._map.addLayer(this.nodesLayer);
 
-        this.nodeSelector = new OpenLayers.Control.SelectFeature(
-            [this.nodesLayer],
-//            {geometryTypes: ['OpenLayers.Geometry.LineString']},
-            {clickout: true, toggle: true, multiple: false, hover: false}
-        );
-
-        this._map.addControl(this.nodeSelector);
-        this.nodeSelector.activate();
-
-        this._map.nodeDraw = new OpenLayers.Control.DrawFeature(
-            this.nodesLayer,
-            OpenLayers.Handler.Point)
-        this._map.nodeDraw.featureAdded = this.positionNodeMarker
-        this._map.addControl(this._map.nodeDraw);
-
-
         this.wifiLinksLayer = new OpenLayers.Layer.Vector(
             "WifiLinks", {
                 styleMap: new OpenLayers.StyleMap({'default':{
             })
 
         this._map.addLayer(this.wifiLinksLayer);
-        this.wifiLinkSelector = new OpenLayers.Control.SelectFeature(
-            [this.wifiLinksLayer],
-//            {geometryTypes: ['OpenLayers.Geometry.Point']},
+
+        this.selector = new OpenLayers.Control.SelectFeature(
+            [this.nodesLayer, this.wifiLinksLayer],
+            {geometryTypes: ['OpenLayers.Geometry.LineString',
+                             'OpenLayers.Geometry.Point']},
             {clickout: true, toggle: true, multiple: false, hover: false}
         );
 
-        this._map.addControl(this.wifiLinkSelector);
-//        this.wifiLinkSelector.activate();
+        this._map.addControl(this.selector);
+        this.selector.activate();
+
+        this._map.nodeDraw = new OpenLayers.Control.DrawFeature(
+            this.nodesLayer,
+            OpenLayers.Handler.Point)
+        this._map.nodeDraw.featureAdded = this.positionNodeMarker
+        this._map.addControl(this._map.nodeDraw);
 
         this._map.addControl(new OpenLayers.Control.LayerSwitcher());
 
     },
 
     displayLinkLine: function(link){
-        var source_point = new OpenLayers.Geometry.Point(link.source_coords.lon, link.source_coords.lat).transform( this._map.displayProjection, this._map.projection);
-        var target_point = new OpenLayers.Geometry.Point(link.target_coords.lon, link.target_coords.lat).transform( this._map.displayProjection, this._map.projection);
+        var source_point = new OpenLayers.Geometry.Point(
+            link.source_coords.lon, link.source_coords.lat).transform(
+                this._map.displayProjection, this._map.projection);
+        var target_point = new OpenLayers.Geometry.Point(
+            link.target_coords.lon, link.target_coords.lat).transform(
+                this._map.displayProjection, this._map.projection);
         var linestring = new OpenLayers.Geometry.LineString([source_point, target_point]);
         var line = new OpenLayers.Feature.Vector(linestring);
         line.link = link;
     displayNodeMarker: function(node){
         var coords = node.get('coords');
 //        if (coords == undefined) coords = NETWORK_COORDS;
-        var point = new OpenLayers.Geometry.Point(coords.lon, coords.lat).transform( this._map.displayProjection, this._map.projection);
+        var point = new OpenLayers.Geometry.Point(coords.lon, coords.lat).transform(
+            this._map.displayProjection, this._map.projection);
         var marker = new OpenLayers.Feature.Vector(point);
         marker.node = node;
-//        node.marker = marker
         this.nodesLayer.addFeatures([marker]);
         return marker
     },
             floating_node.marker = feature;
             feature.destroy();
             delete feature
-            //                app_router.navigate('#node/' + floating_node.id, {trigger: true})
-            floating_node = null;
-//            app_router.navigate('/', {trigger: true})
+            CURRENT_NODE = null;
         }
         map.nodeDraw.deactivate();
     },
     },
 
     selectNodeMarker: function(marker){
-        this.nodeSelector.unselectAll();
-        this.nodeSelector.select(marker)
+        this.selector.unselectAll();
+        this.selector.select(marker)
     },
 
     removeNodeMarker: function(marker){

_attachments/js/nodes.js

 Backbone.couch_connector.config.ddoc_name = "altermap";
 Backbone.couch_connector.config.global_changes = false;
 
-// setup array-query  / https://npmjs.org/package/array-query
-//Backbone.Collection.prototype.query = function(field) {
-//    return query.select(@models).where(field);
-//}
 
 // Enables Mustache.js-like templating.
 _.templateSettings = {
 };
 
 var CURRENT_NODE = null;
-/*
-var dispatcher = _.clone(Backbone.Events)
 
-dispatcher.on('setCurrentNode', function(node){
-    current_node = node
-    console.log('current'+ node.get('name'))
-})
-*/
-
-// var BatmanLink = Backbone.Model.extend({
-// });
-
-// var BatmanLinks = Backbone.Collection.extend({
-// //    url: "http://10.5.1.1:8000/ql_2012-10-13-T.json",
-//     model: BatmanLink,
-//     parse: function(response){
-//         response.each(function(row){
-//             console.log('row content'+ row[0]);
-//         });
-//     }
-// });
-
-//bl = new BatmanLinks();
-//bl.fetch();
 
 var WifiLink = Backbone.Model.extend({
     url : function() {
 var LinkLineView = Backbone.View.extend({
     initialize : function(){
         _.bindAll(this, 'render', 'remove', '_nodeFromMAC');
-        this.model.bind('remove', this.remove);
-        //            this.model.bind('change', this.render);
+        this.model.on('remove', this.remove);
     },
     _nodeFromMAC: function (macaddr){
         var iface = interfaces.where({'macaddr':macaddr})[0];
-        var device = devices.where({'_id': iface.get('device_id')})[0];
+        var device = devices.get(iface.get('device_id'));
+        console.log("Device id: "+ iface.get('device_id') + " | Device obj: "+ device);
         var node = nodes.where({'_id': device.get('node_id')})[0]
         return node;        
     },
         }
     },
     remove: function(){
-        map.removeLinkLine(this.model.lilne);
+        map.removeLinkLine(this.model.line);
     },
 })
 
 var WifiLinksView =  Backbone.View.extend({
     initialize: function(collection){
         _.bindAll(this, 'addLine', 'refreshed');
-        wifilinks.bind("reset", this.refreshed, this);
-        wifilinks.bind("add", this.addLine);
+        wifilinks.on("reset", this.refreshed, this);
+        wifilinks.on("add", this.addLine);
     },
     addLine : function(wifilink){
         if (wifilink.line == undefined){
         // POST to '/nodes' and PUT to '/nodes/:id'
         return this.id ? '/nodes/' + this.id : '/nodes';
     },
-/*
-    initialize : function(){
-        _.bindAll(this, 'saveToCoords');
-    },
-    saveToCoords: function(coords){
-        this.set({coords: coords});
-        this.save({wait: true});
-    },
-*/
 });
 
 var NodesCollection = Backbone.Collection.extend({
     },
     url: "/nodes",
     model: Node,
-    // byMac: function(mac) {
-    //     return this.filter(function(mac) {
-    //         return task.get('list') == null;
-    //     });
-    // },
 });
 
 var Device = Backbone.Model.extend({
 
     initialize : function(){
         _.bindAll(this, 'render', 'selectNode', 'remove');
-        this.model.bind('change', this.render);
-        this.model.bind('remove', this.remove);
+        this.model.on('change', this.render);
+        this.model.on('remove', this.remove);
     },
     render: function(){
         var content = this.model.toJSON();
 
     initialize: function(collection){
         _.bindAll(this, 'refreshed', 'addRow');
-        nodes.bind("reset", this.refreshed);
-        nodes.bind("add", this.addRow);
+        nodes.on("reset", this.refreshed);
+        nodes.on("add", this.addRow);
         this._viewPointers = [];
     },
     addRow : function(node){
 var NodeMarkerView = Backbone.View.extend({
     initialize : function(){
         _.bindAll(this, 'render', 'remove');
-        this.model.bind('remove', this.remove);
+        this.model.on('remove', this.remove);
         
-        //            this.model.bind('change', this.render);
+        //            this.model.on('change', this.render);
     },
     render: function(){
         if (this.model.marker == undefined){
 var NodeMarkersView =  Backbone.View.extend({
     initialize: function(collection){
         _.bindAll(this, 'addMarker', 'refreshed');
-        nodes.bind("reset", this.refreshed, this);
-        nodes.bind("add", this.addMarker);
+        nodes.on("reset", this.refreshed, this);
+        nodes.on("add", this.addMarker);
     },
     addMarker : function(node){
         if (node.marker == undefined){
                         interfaces.fetch({success: function(){
                             console.log('interfaces loaded');
                             wifilinks.fetch({success: function(){
-                                console.log('wifilinks '+wifilinks.models);
+                                console.log('wifilinks loaded');
                             }});
                         }});
                     }});
     },
     selectNode: function(node_id){
         console.log('select by URL');
-        // nodes.fetch({success: function(){
-        //     map.selectNodeMarker(node.marker);
-        // }});
-        // map.nodeSelector.unselectAll();
-        // var node = nodes.get(node_id);
-        // map.selectNodeMarker(node.marker);
-////        dispatcher.trigger('setCurrentNode', node);
     },
 });