-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackgrid-moment-cell.min.js
84 lines (70 loc) · 4.84 KB
/
backgrid-moment-cell.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
backgrid-moment-cell
http://github.com/wyuenho/backgrid
Copyright (c) 2013 Jimmy Yuen Ho Wong and contributors
Licensed under the MIT @license.
*/
!function(a,b){"function"==typeof define&&define.amd?
// AMD
define(["underscore","backgrid","moment"],b):"object"==typeof exports?
// CommonJS
module.exports=b(require("underscore"),require("backgrid"),require("moment")):
// Browser globals
b(a._,a.Backgrid,a.moment)}(this,function(a,b,c){"use strict";var d={},e=d.MomentFormatter=b.Extension.MomentFormatter=function(b){a.extend(this,this.defaults,b)};e.prototype=new b.CellFormatter,a.extend(e.prototype,{/**
@cfg {Object} options
@cfg {boolean} [options.modelInUnixOffset=false] Whether the model values
should be read/written as the number of milliseconds since UNIX Epoch.
@cfg {boolean} [options.modelInUnixTimestamp=false] Whether the model
values should be read/written as the number of seconds since UNIX Epoch.
@cfg {boolean} [options.modelInUTC=true] Whether the model values should
be read/written in UTC mode or local mode.
@cfg {string} [options.modelLang=moment.locale() moment>=2.8.0 |
moment.lang() moment<2.8.0] The locale the model values should be
read/written in.
@cfg {string} [options.modelFormat=moment.defaultFormat] The format this
moment formatter should use to read/write model values. Only meaningful if
the values are strings.
@cfg {boolean} [options.displayInUnixOffset=false] Whether the display
values should be read/written as the number of milliseconds since UNIX
Epoch.
@cfg {boolean} [options.displayInUnixTimestamp=false] Whether the display
values should be read/written as the number of seconds since UNIX Epoch.
@cfg {boolean} [options.displayInUTC=true] Whether the display values
should be read/written in UTC mode or local mode.
@cfg {string} [options.displayLang=moment.locale() moment>=2.8.0 |
moment.lang() moment<2.8.0] The locale the display values should be
read/written in.
@cfg {string} [options.displayFormat=moment.defaultFormat] The format
this moment formatter should use to read/write dislay values.
*/
defaults:{modelInUnixOffset:!1,modelInUnixTimestamp:!1,modelInUTC:!0,modelLang:c.locale(),modelFormat:c.defaultFormat,displayInUnixOffset:!1,displayInUnixTimestamp:!1,displayInUTC:!0,displayInTimezone:!1,displayLang:c.locale(),displayFormat:c.defaultFormat},/**
Converts datetime values from the model for display.
@member Backgrid.Extension.MomentFormatter
@param {*} rawData
@return {string}
*/
fromRaw:function(a){if(null==a)return"";var b=this.modelInUnixOffset?c(a):this.modelInUnixTimestamp?c.unix(a):this.modelInUTC?c.utc(a,this.modelFormat,this.modelLang):c(a,this.modelFormat,this.modelLang);return this.displayInUnixOffset?+b:this.displayInUnixTimestamp?b.unix():(this.displayLang&&b.locale(this.displayLang),this.displayInUTC?b.utc():this.displayInTimezone?b.parseZone():b.local(),this.displayFormat!=c.defaultFormat?b.format(this.displayFormat):b.format())},/**
Converts datetime values from user input to model values.
@member Backgrid.Extension.MomentFormatter
@param {string} formattedData
@return {string}
*/
toRaw:function(a){var b=this.displayInUnixOffset?c(+a):this.displayInUnixTimestamp?c.unix(+a):this.displayInUTC?c.utc(a,this.displayFormat,this.displayLang):c(a,this.displayFormat,this.displayLang);if(b&&b.isValid())return this.modelInUnixOffset?+b:this.modelInUnixTimestamp?b.unix():(this.modelLang&&b.locale(this.modelLang),this.modelInUTC?b.utc():b.local(),this.modelFormat!=c.defaultFormat?b.format(this.modelFormat):b.format())}});/**
Renders a datetime cell that uses a Backgrid.Extension.MomentFormatter to
convert and validate values.
@class Backgrid.Extension.MomentCell
@extends Backgrid.Cell
*/
var f=d.MomentCell=b.Extension.MomentCell=b.Cell.extend({editor:b.InputCellEditor,/** @property */
className:"moment-cell",/** @property {Backgrid.CellFormatter} [formatter=Backgrid.Extension.MomentFormatter] */
formatter:e,/**
Initializer. Accept Backgrid.Extension.MomentFormatter.options and
Backgrid.Cell.initialize required parameters.
*/
initialize:function(b){f.__super__.initialize.apply(this,arguments);var c=e.prototype.defaults,d=a.keys(c),g=a.pick(this,d),h=a.pick(b,d);
// Priority of the options for the formatter, from highest to lowerest
// 1. MomentCell instance options
// 2. MomentCell class attributes
// 3. MomentFormatter defaults
// this.formatter will have been instantiated now
a.extend(this.formatter,c,g,h),this.editor=this.editor.extend({attributes:a.extend({},this.editor.prototype.attributes||this.editor.attributes||{},{placeholder:this.formatter.displayFormat})})}});return a.extend(f.prototype,e.prototype.defaults),d});