move dateui to folder, add jquery-ui-datepicker
This commit is contained in:
142
src/inputs/dateui/dateui.js
Normal file
142
src/inputs/dateui/dateui.js
Normal file
@@ -0,0 +1,142 @@
|
||||
/**
|
||||
jQuery UI Datepicker
|
||||
Note: you can not use both date and dateui on the same page.
|
||||
|
||||
@class dateui
|
||||
@extends abstract
|
||||
**/
|
||||
(function ($) {
|
||||
|
||||
var DateUI = function (options) {
|
||||
this.init('dateui', options, DateUI.defaults);
|
||||
|
||||
//set popular options directly from settings or data-* attributes
|
||||
var directOptions = $.fn.editableform.utils.sliceObj(this.options, ['format', 'firstDay']);
|
||||
|
||||
//overriding datepicker config (as by default jQuery extend() is not recursive)
|
||||
this.options.datepicker = $.extend({}, DateUI.defaults.datepicker, directOptions, options.datepicker);
|
||||
|
||||
//by default viewformat equals to format
|
||||
if(!this.options.viewformat) {
|
||||
this.options.viewformat = this.options.datepicker.format;
|
||||
}
|
||||
|
||||
//correct formats: replace yyyy with yy
|
||||
this.options.viewformat = this.options.viewformat.replace('yyyy', 'yy');
|
||||
this.options.datepicker.format = this.options.datepicker.format.replace('yyyy', 'yy');
|
||||
|
||||
//copy format to dateFormat (dateFormat option required for ui datepicker).
|
||||
//This allows common option 'format' for all datepickers
|
||||
this.options.datepicker.dateFormat = this.options.datepicker.format;
|
||||
};
|
||||
|
||||
$.fn.editableform.utils.inherit(DateUI, $.fn.editableform.types.abstract);
|
||||
|
||||
$.extend(DateUI.prototype, {
|
||||
render: function () {
|
||||
DateUI.superclass.render.call(this);
|
||||
this.$input.datepicker(this.options.datepicker);
|
||||
},
|
||||
|
||||
value2html: function(value, element) {
|
||||
var text = $.datepicker.formatDate(this.options.viewformat, value);
|
||||
DateUI.superclass.value2html(text, element);
|
||||
},
|
||||
|
||||
html2value: function(html) {
|
||||
if(typeof html !== 'string') {
|
||||
return html;
|
||||
}
|
||||
|
||||
//if string does not match format, UI datepicker throws exception
|
||||
var d;
|
||||
try {
|
||||
d = $.datepicker.parseDate(this.options.viewformat, html);
|
||||
} catch(e) {}
|
||||
|
||||
return d;
|
||||
},
|
||||
|
||||
value2str: function(value) {
|
||||
return $.datepicker.formatDate(this.options.datepicker.dateFormat, value);
|
||||
},
|
||||
|
||||
str2value: function(str) {
|
||||
if(typeof str !== 'string') {
|
||||
return str;
|
||||
}
|
||||
|
||||
//if string does not match format, UI datepicker throws exception
|
||||
var d;
|
||||
try {
|
||||
d = $.datepicker.parseDate(this.options.datepicker.dateFormat, str);
|
||||
} catch(e) {}
|
||||
|
||||
return d;
|
||||
},
|
||||
|
||||
value2input: function(value) {
|
||||
this.$input.datepicker('setDate', value);
|
||||
},
|
||||
|
||||
input2value: function() {
|
||||
return this.$input.datepicker('getDate');
|
||||
},
|
||||
|
||||
activate: function() {
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
DateUI.defaults = $.extend({}, $.fn.editableform.types.abstract.defaults, {
|
||||
/**
|
||||
@property tpl
|
||||
@default <div style="float: left"></div>
|
||||
**/
|
||||
tpl:'<div style="float: left"></div>',
|
||||
/**
|
||||
@property inputclass
|
||||
@default ''
|
||||
**/
|
||||
inputclass: '',
|
||||
/**
|
||||
Format used for sending value to server. Also applied when converting date from <code>data-value</code> attribute.<br>
|
||||
Full <a href="http://docs.jquery.com/UI/Datepicker/formatDate">list of tokens</a>.
|
||||
|
||||
@property format
|
||||
@type string
|
||||
@default yyyy-mm-dd
|
||||
**/
|
||||
format:'yyyy-mm-dd',
|
||||
/**
|
||||
Format used for displaying date. If not specified equals to <code>format</code>
|
||||
|
||||
@property viewformat
|
||||
@type string
|
||||
@default null
|
||||
**/
|
||||
viewformat: null,
|
||||
|
||||
/**
|
||||
Configuration of datepicker.
|
||||
Full list of <a href="http://api.jqueryui.com/datepicker">possible options</a>.
|
||||
|
||||
@property datepicker
|
||||
@type object
|
||||
@default {
|
||||
firstDay: 0,
|
||||
changeYear: true,
|
||||
changeMonth: true
|
||||
}
|
||||
**/
|
||||
datepicker: {
|
||||
firstDay: 0,
|
||||
changeYear: true,
|
||||
changeMonth: true
|
||||
}
|
||||
});
|
||||
|
||||
$.fn.editableform.types.dateui = DateUI;
|
||||
$.fn.editableform.types.date = DateUI;
|
||||
|
||||
}(window.jQuery));
|
Reference in New Issue
Block a user