Commits

Rich Manalang [Atlassian]  committed a811a3c

converted to coffee

  • Participants
  • Parent commits 1d98568

Comments (0)

Files changed (4)

File css/styles.css

   background:#fff;
   position:absolute;
   top:45px;
-  left:173px;
+  left:206px;
   -webkit-transform: translate(100px) rotate(45deg);
   -webkit-transform-origin: 60% 100%;
 }

File js/app.coffee

+formatDate = (date) ->
+  Date.create(date)
+    .format "{Weekday} {Month} {d}, {yyyy}"
+
+getRate = (from, to) ->
+  $('#currscript').remove()
+  script = document.createElement 'script'
+  script.setAttribute 'src', 
+    "http://query.yahooapis.com/v1/public/yql?q=select%20rate%2Cname%20from%20csv%20where%20url%3D'http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes%3Fs%3D#{from}#{to}%253DX%26f%3Dl1n'%20and%20columns%3D'rate%2Cname'&format=json&callback=parseExchangeRate"
+  script.setAttribute 'id', 'currscript'
+  document.body.appendChild script
+
+window.parseExchangeRate = (data) ->
+  name = data.query.results.row.name
+  rate = parseFloat data.query.results.row.rate, 10
+  $('#costin').html (parseFloat $('#cost').val() * rate)
+    .round(2)
+    .format(2) + 
+    " AUD"
+
+class AddTripView extends Backbone.View
+  el: $ '#addtrip'
+
+  template: _.template $('#addtrip-template').html()
+
+  initialize: ->
+    @render()
+
+  events:
+    'changeDate .date':   'renderFriendlyDate'
+    'change #cost':       'updateConvertedRate'
+    'change #curr':       'updateConvertedRate'
+    'changeDate .date':   'validateTripDates'
+
+  render: ->
+    @$el.html(@.template())
+    $('#depart-date').datepicker()
+    $('#return-date').datepicker()
+    $('#approver').typeahead
+      source: [
+        "Jay Simons"
+        "Mike Cannon-Brookes"
+        "Scott Farquar"
+        "Daniel Freeman"
+      ]
+
+    $('#cost, #curr').on('change keyup', =>)
+
+  renderFriendlyDate: (e) ->
+    $('.hint',e.currentTarget).html formatDate(e.date)
+
+  updateConvertedRate: ->
+    getRate $('#curr').val(), 'AUD'
+
+  validateTripDates: (e) ->
+    dep = @$('#depart-date')
+    ret = @$('#return-date')
+    if dep.data('date').valueOf() >
+       ret.data('date').valueOf() and
+       dep.find('input').val() != '' and
+       ret.find('input').val() != ''
+      @flash = new FlashView
+        flash: 
+          class:    'alert-error'
+          title:    'Error'
+          message:  "Return date can't be before depart date"
+
+
+class FlashView extends Backbone.View
+  tagName: "div"
+  
+  className: "alert"
+  
+  template: _.template $('#flash-template').html()
+  
+  initialize: ->
+    @render()
+  
+  render: ->
+    @$el.addClass @options.flash.class
+    @$el.html(@template(@options.flash)).prependTo('#flash')
+
+
+
+class AppRouter extends Backbone.Router
+  routes:
+    ''        : 'addTrip'
+    'mytrips' : 'myTrips'
+
+  before: ->
+    @cleanUpFlash()
+
+  addTrip: ->
+    new AddTripView
+
+  myTrips: ->
+    @flash = new FlashView
+      flash: 
+        class:    'alert-error'
+        title:    'Error'
+        message:  'Not yet my son.'
+
+  cleanUpFlash: ->
+    @flash.remove() if @flash
+
+appRouter = new AppRouter
+Backbone.history.start()
-function formatDate(date){
-  return Date.create(date).format("{Weekday} {Month} {d}, {yyyy}");
-}
-function getRate(from, to) {
-  $('#currscript').remove();
-  var script = document.createElement('script');
-  script.setAttribute('src', "http://query.yahooapis.com/v1/public/yql?q=select%20rate%2Cname%20from%20csv%20where%20url%3D'http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes%3Fs%3D"+from+to+"%253DX%26f%3Dl1n'%20and%20columns%3D'rate%2Cname'&format=json&callback=parseExchangeRate");
-  script.setAttribute('id','currscript');
-  document.body.appendChild(script);
-}
-function parseExchangeRate(data) {
-  var name = data.query.results.row.name;
-  var rate = parseFloat(data.query.results.row.rate, 10);
-  $('#costin').html((parseFloat($('#cost').val()) * rate).round(2).format(2) + " AUD");
-}
-
-var AddTripView = Backbone.View.extend({
-  el:$('#addtrip'),
-  template:_.template($('#addtrip-template').html()),
-  initialize: function(){
-    this.render();
-  },
-  events:{
-    'changeDate .date': 'renderFriendlyDate',
-    'change #cost': 'updateConvertedRate',
-    'change #curr': 'updateConvertedRate'
-  },
-  render: function(){
-    this.$el.html(this.template());
-    $('#depart-date').datepicker();
-    $('#return-date').datepicker();
-    $('#approver').typeahead({
-      source: [
-        "Jay Simons",
-        "Mike Cannon-Brookes",
-        "Scott Farquar",
-        "Daniel Freeman"
-      ]
-    });
-    $('#cost, #curr').on('change keyup',function(){
-    });
-  },
-  renderFriendlyDate:function(e){
-    $('.hint',e.currentTarget).html(formatDate(e.date));
-  },
-  updateConvertedRate: function(){
-    getRate($('#curr').val(),'AUD');    
-  }
-});
-
-var FlashView = Backbone.View.extend({
-  tagName: "div",
-  className: "alert",
-  template: _.template($('#flash-template').html()),
-  initialize:function(){
-    this.render();
-  },
-  render: function(){
-    this.$el.addClass(this.options.flash.class);
-    this.$el.html(this.template(this.options.flash)).prependTo('#flash');
-  }
-});
-
-var AppRouter = Backbone.Router.extend({
-  routes: {
-    '':         'addTrip',
-    'mytrips':  'myTrips'
-  },
-  before: function(){
-    this.cleanUpFlash();
-  },
-  addTrip: function(){
-    new AddTripView();    
-  },
-  myTrips: function(){
-    this.flash = new FlashView({flash:{class:'alert-error', title: "Error", message:"Not yet my son."}});
-  },
-  cleanUpFlash: function(){
-    if(this.flash) this.flash.remove();
-  }
-});
-
-var appRouter = new AppRouter();
-Backbone.history.start();
+(function() {
+  var AddTripView, AppRouter, FlashView, appRouter, formatDate, getRate,
+    __hasProp = Object.prototype.hasOwnProperty,
+    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
+
+  formatDate = function(date) {
+    return Date.create(date).format("{Weekday} {Month} {d}, {yyyy}");
+  };
+
+  getRate = function(from, to) {
+    var script;
+    $('#currscript').remove();
+    script = document.createElement('script');
+    script.setAttribute('src', "http://query.yahooapis.com/v1/public/yql?q=select%20rate%2Cname%20from%20csv%20where%20url%3D'http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes%3Fs%3D" + from + to + "%253DX%26f%3Dl1n'%20and%20columns%3D'rate%2Cname'&format=json&callback=parseExchangeRate");
+    script.setAttribute('id', 'currscript');
+    return document.body.appendChild(script);
+  };
+
+  window.parseExchangeRate = function(data) {
+    var name, rate;
+    name = data.query.results.row.name;
+    rate = parseFloat(data.query.results.row.rate, 10);
+    return $('#costin').html((parseFloat($('#cost').val() * rate)).round(2).format(2) + " AUD");
+  };
+
+  AddTripView = (function(_super) {
+
+    __extends(AddTripView, _super);
+
+    function AddTripView() {
+      AddTripView.__super__.constructor.apply(this, arguments);
+    }
+
+    AddTripView.prototype.el = $('#addtrip');
+
+    AddTripView.prototype.template = _.template($('#addtrip-template').html());
+
+    AddTripView.prototype.initialize = function() {
+      return this.render();
+    };
+
+    AddTripView.prototype.events = {
+      'changeDate .date': 'renderFriendlyDate',
+      'change #cost': 'updateConvertedRate',
+      'change #curr': 'updateConvertedRate',
+      'changeDate .date': 'validateTripDates'
+    };
+
+    AddTripView.prototype.render = function() {
+      var _this = this;
+      this.$el.html(this.template());
+      $('#depart-date').datepicker();
+      $('#return-date').datepicker();
+      $('#approver').typeahead({
+        source: ["Jay Simons", "Mike Cannon-Brookes", "Scott Farquar", "Daniel Freeman"]
+      });
+      return $('#cost, #curr').on('change keyup', function() {});
+    };
+
+    AddTripView.prototype.renderFriendlyDate = function(e) {
+      return $('.hint', e.currentTarget).html(formatDate(e.date));
+    };
+
+    AddTripView.prototype.updateConvertedRate = function() {
+      return getRate($('#curr').val(), 'AUD');
+    };
+
+    AddTripView.prototype.validateTripDates = function(e) {
+      var dep, ret;
+      dep = this.$('#depart-date');
+      ret = this.$('#return-date');
+      if (dep.data('date').valueOf() > ret.data('date').valueOf() && dep.find('input').val() !== '' && ret.find('input').val() !== '') {
+        return this.flash = new FlashView({
+          flash: {
+            "class": 'alert-error',
+            title: 'Error',
+            message: "Return date can't be before depart date"
+          }
+        });
+      }
+    };
+
+    return AddTripView;
+
+  })(Backbone.View);
+
+  FlashView = (function(_super) {
+
+    __extends(FlashView, _super);
+
+    function FlashView() {
+      FlashView.__super__.constructor.apply(this, arguments);
+    }
+
+    FlashView.prototype.tagName = "div";
+
+    FlashView.prototype.className = "alert";
+
+    FlashView.prototype.template = _.template($('#flash-template').html());
+
+    FlashView.prototype.initialize = function() {
+      return this.render();
+    };
+
+    FlashView.prototype.render = function() {
+      this.$el.addClass(this.options.flash["class"]);
+      return this.$el.html(this.template(this.options.flash)).prependTo('#flash');
+    };
+
+    return FlashView;
+
+  })(Backbone.View);
+
+  AppRouter = (function(_super) {
+
+    __extends(AppRouter, _super);
+
+    function AppRouter() {
+      AppRouter.__super__.constructor.apply(this, arguments);
+    }
+
+    AppRouter.prototype.routes = {
+      '': 'addTrip',
+      'mytrips': 'myTrips'
+    };
+
+    AppRouter.prototype.before = function() {
+      return this.cleanUpFlash();
+    };
+
+    AppRouter.prototype.addTrip = function() {
+      return new AddTripView;
+    };
+
+    AppRouter.prototype.myTrips = function() {
+      return this.flash = new FlashView({
+        flash: {
+          "class": 'alert-error',
+          title: 'Error',
+          message: 'Not yet my son.'
+        }
+      });
+    };
+
+    AppRouter.prototype.cleanUpFlash = function() {
+      if (this.flash) return this.flash.remove();
+    };
+
+    return AppRouter;
+
+  })(Backbone.Router);
+
+  appRouter = new AppRouter;
+
+  Backbone.history.start();
+
+}).call(this);

File js/app.js.original

+function formatDate(date) {
+  return Date.create(date).format("{Weekday} {Month} {d}, {yyyy}");
+}
+
+function getRate(from, to) {
+  $('#currscript').remove();
+  var script = document.createElement('script');
+  script.setAttribute('src', "http://query.yahooapis.com/v1/public/yql?q=select%20rate%2Cname%20from%20csv%20where%20url%3D'http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes%3Fs%3D" + from + to + "%253DX%26f%3Dl1n'%20and%20columns%3D'rate%2Cname'&format=json&callback=parseExchangeRate");
+  script.setAttribute('id', 'currscript');
+  document.body.appendChild(script);
+}
+
+function parseExchangeRate(data) {
+  var name = data.query.results.row.name;
+  var rate = parseFloat(data.query.results.row.rate, 10);
+  $('#costin').html((parseFloat($('#cost').val()) * rate).round(2).format(2) + " AUD");
+}
+
+var AddTripView = Backbone.View.extend({
+  el: $('#addtrip'),
+  template: _.template($('#addtrip-template').html()),
+  initialize: function() {
+    this.render();
+  },
+  events: {
+    'changeDate .date': 'renderFriendlyDate',
+    'change #cost': 'updateConvertedRate',
+    'change #curr': 'updateConvertedRate',
+  },
+  render: function() {
+    this.$el.html(this.template());
+    $('#depart-date').datepicker();
+    $('#return-date').datepicker();
+    $('#approver').typeahead({
+      source: ["Jay Simons", "Mike Cannon-Brookes", "Scott Farquar", "Daniel Freeman"]
+    });
+    $('#cost, #curr').on('change keyup', function() {});
+  },
+  renderFriendlyDate: function(e) {
+    $('.hint', e.currentTarget).html(formatDate(e.date));
+    // Trip duration
+    // if($('#depart-date input').val() && $('#return-date input').val()) {
+    //   $('#tripdays')
+    //     .html(Math.round((Date.create($('#return-date input').val()) - Date.create($('#depart-date input').val()))/(1000 * 60 * 60 * 24)) + ' days');
+    // }
+  },
+  updateConvertedRate: function() {
+    getRate($('#curr').val(), 'AUD');
+  }
+});
+
+var FlashView = Backbone.View.extend({
+  tagName: "div",
+  className: "alert",
+  template: _.template($('#flash-template').html()),
+  initialize: function() {
+    this.render();
+  },
+  render: function() {
+    this.$el.addClass(this.options.flash.class);
+    this.$el.html(this.template(this.options.flash)).prependTo('#flash');
+  }
+});
+
+var AppRouter = Backbone.Router.extend({
+  routes: {
+    '': 'addTrip',
+    'mytrips': 'myTrips'
+  },
+  before: function() {
+    this.cleanUpFlash();
+  },
+  addTrip: function() {
+    new AddTripView();
+  },
+  myTrips: function() {
+    this.flash = new FlashView({
+      flash: {
+        class: 'alert-error',
+        title: "Error",
+        message: "Not yet my son."
+      }
+    });
+  },
+  cleanUpFlash: function() {
+    if (this.flash) this.flash.remove();
+  }
+});
+
+var appRouter = new AppRouter();
+Backbone.history.start();