/** Bootstrap-datepicker. Description and examples: http://vitalets.github.com/bootstrap-datepicker. For localization you can include js file from here: https://github.com/eternicode/bootstrap-datepicker/tree/master/js/locales @class date @extends abstract @final @example 15/05/1984 **/ (function ($) { var Date = function (options) { this.init('date', options, Date.defaults); //set popular options directly from settings or data-* attributes var directOptions = $.fn.editableutils.sliceObj(this.options, ['format']); //overriding datepicker config (as by default jQuery extend() is not recursive) this.options.datepicker = $.extend({}, Date.defaults.datepicker, directOptions, options.datepicker); //by default viewformat equals to format if(!this.options.viewformat) { this.options.viewformat = this.options.datepicker.format; } //language this.options.datepicker.language = this.options.datepicker.language || 'en'; //store DPglobal this.dpg = $.fn.datepicker.DPGlobal; //store parsed formats this.parsedFormat = this.dpg.parseFormat(this.options.datepicker.format); this.parsedViewFormat = this.dpg.parseFormat(this.options.viewformat); }; $.fn.editableutils.inherit(Date, $.fn.editabletypes.abstract); $.extend(Date.prototype, { render: function () { Date.superclass.render.call(this); this.$input.datepicker(this.options.datepicker); if(this.options.clear) { this.$clear = $('').html(this.options.clear).click($.proxy(function(e){ e.preventDefault(); e.stopPropagation(); this.clear(); }, this)); } }, value2html: function(value, element) { var text = value ? this.dpg.formatDate(value, this.parsedViewFormat, this.options.datepicker.language) : ''; Date.superclass.value2html(text, element); }, html2value: function(html) { return html ? this.dpg.parseDate(html, this.parsedViewFormat, this.options.datepicker.language) : null; }, value2str: function(value) { return value ? this.dpg.formatDate(value, this.parsedFormat, this.options.datepicker.language) : ''; }, str2value: function(str) { return str ? this.dpg.parseDate(str, this.parsedFormat, this.options.datepicker.language) : null; }, value2submit: function(value) { return this.value2str(value); }, value2input: function(value) { this.$input.datepicker('update', value); }, input2value: function() { return this.$input.data('datepicker').date; }, activate: function() { }, clear: function() { this.$input.data('datepicker').date = null; this.$input.find('.active').removeClass('active'); }, autosubmit: function() { this.$input.on('changeDate', function(e){ var $form = $(this).closest('form'); setTimeout(function() { $form.submit(); }, 200); }); } }); Date.defaults = $.extend({}, $.fn.editabletypes.abstract.defaults, { /** @property tpl @default
**/ tpl:'
', /** @property inputclass @default editable-date well **/ inputclass: 'editable-date well', /** Format used for sending value to server. Also applied when converting date from data-value attribute.
Possible tokens are: d, dd, m, mm, yy, yyyy @property format @type string @default yyyy-mm-dd **/ format:'yyyy-mm-dd', /** Format used for displaying date. Also applied when converting date from element's text on init. If not specified equals to format @property viewformat @type string @default null **/ viewformat: null, /** Configuration of datepicker. Full list of options: http://vitalets.github.com/bootstrap-datepicker @property datepicker @type object @default { weekStart: 0, startView: 0, autoclose: false } **/ datepicker:{ weekStart: 0, startView: 0, autoclose: false }, /** Text shown as clear date button. If false clear button will not be rendered. @property clear @type boolean|string @default 'x clear' **/ clear: '× clear' }); $.fn.editabletypes.date = Date; }(window.jQuery));