;(function() { var Form = Backbone.Form, Base = Form.editors.Base, createTemplate = Form.helpers.createTemplate, triggerCancellableEvent = Form.helpers.triggerCancellableEvent, exports = {}; /** * Additional editors that depend on jQuery UI */ exports.Date = Base.extend({ className: 'bbf-date', initialize: function(options) { Base.prototype.initialize.call(this, options); if (!this.value) { var date = new Date(); date.setSeconds(0); date.setMilliseconds(0); this.value = date; } }, render: function() { var el = $(this.el); el.html(''); var input = $('input', el); input.datepicker({ dateFormat: 'dd/mm/yy', showButtonPanel: true }); //Make sure setValue of this object is called, not of any objects extending it (e.g. DateTime) exports.Date.prototype.setValue.call(this, this.value); return this; }, /** * @return {Date} Selected date */ getValue: function() { var input = $('input', this.el), date = input.datepicker('getDate'); return date; }, setValue: function(value) { $('input', this.el).datepicker('setDate', value); } }); exports.DateTime = exports.Date.extend({ className: 'bbf-datetime', template: createTemplate(' : '), render: function() { function pad(n) { return n < 10 ? '0' + n : n } //Render the date element first exports.Date.prototype.render.call(this); //Setup hour options var hours = _.range(0, 24), hoursOptions = []; _.each(hours, function(hour) { hoursOptions.push(''); }); //Setup minute options var minsInterval = this.schema.minsInterval || 15, mins = _.range(0, 60, minsInterval), minsOptions = []; _.each(mins, function(min) { minsOptions.push(''); }); //Render time selects $(this.el).append(this.template({ hours: hoursOptions.join(), mins: minsOptions.join() })); //Store references to selects this.$hours = $('select:eq(0)', this.el); this.$mins = $('select:eq(1)', this.el); //Set time this.setValue(this.value); return this; }, /** * @return {Date} Selected datetime */ getValue: function() { var input = $('input', this.el), date = input.datepicker('getDate'); date.setHours(this.$hours.val()); date.setMinutes(this.$mins.val()); date.setMilliseconds(0); return date; }, setValue: function(date) { exports.Date.prototype.setValue.call(this, date); this.$hours.val(date.getHours()); this.$mins.val(date.getMinutes()); } }); exports.List = Base.extend({ className: 'bbf-list', //Note: The extra div around the