/** * Created by mdonnel on 10/04/2017. */ let EventModel = Backbone.Model.extend({ initialize: function () { this.update(); }, getDays : function(startdate, enddate) { let r, s, e; s = startdate.getTime(); e = enddate.getTime(); r = (e - s) / (24 * 60 * 60 * 1000); return r; }, update: function () { const now = new Date const mod = 3600000 - (now.getTime() % 3600000) let data = {}; data.days = Math.ceil(this.getDays(now, this.get('event'))); data.weeks = Math.ceil(this.getDays(now, this.get('event')) / 7); this.set('data', data); const clockFn = function () { this.update() } setTimeout(clockFn.bind(this), mod + 10) } }); let EventView = Backbone.View.extend({ tagName: 'div', initialize: function () { _.bindAll(this, 'render'); this.model.bind('change', this.render); this.id = 'e_' + Math.random().toString(36).substr(2, 9); this.$events = $('#events'); this.$myEvent = null; this.$el = this.$events; this.initView(); this.render(); }, render: function () { let label = this.model.get('label'); let data = this.model.get('data'); let str = `${label} ${data.days} days / ${data.weeks} weeks`; this.$myEvent.empty().append(str); }, initView: function () { let html = `
`; this.$html = $(html); this.$events.append(this.$html); this.$myEvent = $(`#${this.id}`); } });