1. powersurge360
  2. groupGo

Commits

powersurge360  committed 611fc88

Added a departure time and got the pins working a little better.

  • Participants
  • Parent commits 7196993
  • Branches master

Comments (0)

Files changed (6)

File groupGo/apps/organizations/migrations/0005_auto__add_field_carpooler_arrival_time__chg_field_carpooler_departure_.py

View file
  • Ignore whitespace
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        # Adding field 'CarPooler.arrival_time'
+        db.add_column(u'organizations_carpooler', 'arrival_time',
+                      self.gf('django.db.models.fields.TimeField')(default='5:00'),
+                      keep_default=False)
+
+
+        # Changing field 'CarPooler.departure_time'
+        db.alter_column(u'organizations_carpooler', 'departure_time', self.gf('django.db.models.fields.TimeField')())
+
+    def backwards(self, orm):
+        # Deleting field 'CarPooler.arrival_time'
+        db.delete_column(u'organizations_carpooler', 'arrival_time')
+
+
+        # Changing field 'CarPooler.departure_time'
+        db.alter_column(u'organizations_carpooler', 'departure_time', self.gf('django.db.models.fields.DateTimeField')())
+
+    models = {
+        u'organizations.carpooler': {
+            'Meta': {'object_name': 'CarPooler'},
+            'arrival_latitude': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),
+            'arrival_longitude': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),
+            'arrival_time': ('django.db.models.fields.TimeField', [], {}),
+            'car_description': ('django.db.models.fields.TextField', [], {}),
+            'departure_latitude': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),
+            'departure_longitude': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),
+            'departure_time': ('django.db.models.fields.TimeField', [], {}),
+            'going_to': ('django.db.models.fields.TextField', [], {}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'leaving_from': ('django.db.models.fields.TextField', [], {}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '254'}),
+            'organization': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'carpoolers'", 'to': u"orm['organizations.Organization']"})
+        },
+        u'organizations.organization': {
+            'Meta': {'object_name': 'Organization'},
+            'description': ('django.db.models.fields.TextField', [], {}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'latitude': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),
+            'location': ('django.db.models.fields.TextField', [], {}),
+            'longitude': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '254'})
+        }
+    }
+
+    complete_apps = ['organizations']

File groupGo/apps/organizations/models.py

View file
  • Ignore whitespace
 
 class CarPooler(models.Model):
     name = models.CharField(max_length=254)
-    departure_time = models.DateTimeField()
+    arrival_time = models.TimeField()
+    departure_time = models.TimeField()
     car_description = models.TextField()
     leaving_from = models.TextField()
     going_to = models.TextField()

File groupGo/staticfiles/js/app/router.js

View file
  • Ignore whitespace
             ;
             collection.orgID = id;
             collection.fetch().success(function(elements) {
-                self.createCarpoolerPins(collection);
+                self.createCarpoolerArrivingPins(collection);
             });
         },
 
         "car_departing": function(id) {
             this.changeHandlers();
+            var self = this;
+            var collection = new carpool.CarpoolerCollection();
+            collection.orgID = id;
+            collection.fetch().success(function(elements) {
+                self.createCarpoolerDeparturePins(collection);
+            });
         },
 
         // Utility functions
                 this.organizationPins = [];
             }
 
+            if (this.carPoolArrivingPins.length > 0) {
+                _.each(this.carPoolArrivingPins, function(pin) {
+                    pin.destroy();
+                });
+            }
+
+            if (this.carPoolDepartingPins.length > 0) {
+                _.each(this.carPoolDepartingPins, function(pin) {
+                    pin.destroy();
+                });
+            }
+
             this.setUpMap();
         },
 
             });
         },
 
-        "createCarpoolerPins": function(collection) {
+        "createCarpoolerArrivingPins": function(collection) {
             var self = this;
             collection.each(function(element) {
                 var pin = new views.CarpoolerArrivingPin({
                 });
 
                 if (pin.assignMap(self.map).render() === true) {
-                    self.carPoolPins.push(pin);
+                    self.carPoolArrivingPins.push(pin);
+                }
+            });
+        },
+
+        "createCarpoolerDeparturePins": function(collection) {
+            var self = this;
+            collection.each(function(element) {
+                var pin = new views.CarpoolerDepartingPin({
+                    "model": element
+                });
+
+                if (pin.assignMap(self.map).render() === true) {
+                    self.carPoolDepartingPins.push(pin);
                 }
             });
         },
 
         "setUpMap": function() {
             if (this.mapIsSetup === true) {
-                //return;
+                return;
             }
 
             this.mapIsSetup = true;

File groupGo/staticfiles/js/app/templates/carpool_pin.html

View file
  • Ignore whitespace
+<div class="google-dialog">
+    <p>
+        <%= name %>
+    </p>
+</div>

File groupGo/staticfiles/js/app/templates/organization_pin.html

View file
  • Ignore whitespace
 <div class="google-dialog">
-    <a href="#car/arriving/1">Cars arriving</a>
-    <a href="#car/departing/2">Cars leaving</a>
+    <p>
+        <%= name %>
+    </p>
+    <p>
+        <%= description %>
+    </p>
+    <a href="#car/arriving/<%= id %>">Arriving here</a>
+    <a href="#car/departing/<%= id %>">Leaving here</a>
 </div>

File groupGo/staticfiles/js/app/views.js

View file
  • Ignore whitespace
 define([
     "app/vendor/gmaps",
     "backbone",
-    "text!app/templates/organization_pin.html"
-], function(gmaps, Backbone, template) {
+    "underscore",
+    "text!app/templates/organization_pin.html",
+    "text!app/templates/carpool_pin.html"
+], function(gmaps, Backbone, _, organizationTemplate, carpoolTemplate) {
     "use strict";
 
     var OrganizationPin = Backbone.View.extend({
+        "template": _.template(organizationTemplate),
+
         "assignMap": function(map) {
             this.map = map;
 
                 });
 
                 var infoWindow = new gmaps.InfoWindow({
-                    "content": template
+                    "content": this.template(this.model.toJSON())
                 });
 
                 var self = this;
     });
 
     var CarpoolerArrivingPin = Backbone.View.extend({
+        "template": _.template(carpoolTemplate),
+
         "assignMap": function(map) {
             this.map = map;
 
         "render": function() {
             if (this.model.get("arrival_latitude") && this.model.get("arrival_longitude")) {
                 this.pin = new gmaps.Marker({
+                    "position": new gmaps.LatLng(this.model.get("arrival_latitude"), this.model.get("arrival_longitude")),
+                    "map": this.map
+                });
+
+                var infoWindow = new gmaps.InfoWindow({
+                    "content": this.template(this.model.toJSON())
+                });
+
+                var self = this;
+                gmaps.event.addListener(this.pin, "click", function() {
+                    infoWindow.open(self.map, self.pin);
+                });
+                return true;
+            }
+
+            return false;
+        },
+
+        "destroy": function() {
+            this.pin.setMap(null);
+        }
+    });
+
+    var CarpoolerDepartingPin = Backbone.View.extend({
+        "template": _.template(carpoolTemplate),
+
+        "assignMap": function(map) {
+            this.map = map;
+
+            return this;
+        },
+
+        "render": function() {
+            if (this.model.get("departure_latitude") && this.model.get("departure_longitude")) {
+                this.pin = new gmaps.Marker({
                     "position": new gmaps.LatLng(this.model.get("departure_latitude"), this.model.get("departure_longitude")),
                     "map": this.map
                 });
 
                 var infoWindow = new gmaps.InfoWindow({
-                    "content": template
+                    "content": this.template(this.model.toJSON())
                 });
 
                 var self = this;
 
     return {
         "OrganizationPin": OrganizationPin,
-        "CarpoolerArrivingPin": CarpoolerArrivingPin
+        "CarpoolerArrivingPin": CarpoolerArrivingPin,
+        "CarpoolerDepartingPin": CarpoolerDepartingPin
     };
 });