Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion backgrid-moment-cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@

@cfg {string} [options.displayFormat=moment.defaultFormat] The format
this moment formatter should use to read/write dislay values.

@cfg {string} [options.displayFromNow=false] Return date format in
string fromNow format example: '17 seconds ago'.
*/
defaults: {
modelInUnixOffset: false,
Expand All @@ -89,7 +92,8 @@
displayInUnixTimestamp: false,
displayInUTC: true,
displayLang: moment.locale(),
displayFormat: moment.defaultFormat
displayFormat: moment.defaultFormat,
displayFromNow: false
},

/**
Expand All @@ -116,6 +120,8 @@

if (this.displayInUTC) m.utc(); else m.local();

if (this.displayFromNow) return m.fromNow();

if (this.displayFormat != moment.defaultFormat) {
return m.format(this.displayFormat);
}
Expand Down
30 changes: 11 additions & 19 deletions backgrid-moment-cell.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,7 @@ 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){/**
MomentFormatter converts bi-directionally any datetime values in any format
supported by [moment()](http://momentjs.com/docs/#/parsing/) to any
datetime format
[moment.fn.format()](http://momentjs.com/docs/#/displaying/format/)
supports.

@class Backgrid.Extension.MomentFormatter
@extends Backgrid.CellFormatter
@constructor
*/
var d=b.Extension.MomentFormatter=function(b){a.extend(this,this.defaults,b)},e="locale"in c&&a.isFunction(c,"locale");d.prototype=new b.CellFormatter,a.extend(d.prototype,{/**
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
Expand Down Expand Up @@ -58,38 +47,41 @@ var d=b.Extension.MomentFormatter=function(b){a.extend(this,this.defaults,b)},e=

@cfg {string} [options.displayFormat=moment.defaultFormat] The format
this moment formatter should use to read/write dislay values.

@cfg {string} [options.displayFromNow=false] Return date format in
string fromNow format example: '17 seconds ago'.
*/
defaults:{modelInUnixOffset:!1,modelInUnixTimestamp:!1,modelInUTC:!0,modelLang:e?c.locale():c.lang(),modelFormat:c.defaultFormat,displayInUnixOffset:!1,displayInUnixTimestamp:!1,displayInUTC:!0,displayLang:e?c.locale():c.lang(),displayFormat:c.defaultFormat},/**
defaults:{modelInUnixOffset:!1,modelInUnixTimestamp:!1,modelInUTC:!0,modelLang:c.locale(),modelFormat:c.defaultFormat,displayInUnixOffset:!1,displayInUnixTimestamp:!1,displayInUTC:!0,displayLang:c.locale(),displayFormat:c.defaultFormat,displayFromNow:!1},/**
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&&(e?b.locale(this.displayLang):b.lang(this.displayLang)),this.displayInUTC?b.utc():b.local(),b.format(this.displayFormat))},/**
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():b.local(),this.displayFromNow?b.fromNow():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&&(e?b.locale(this.modelLang):b.lang(this.modelLang)),this.modelInUTC?b.utc():b.local(),b.format(this.modelFormat))}});/**
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=b.Extension.MomentCell=b.Cell.extend({editor:b.InputCellEditor,/** @property */
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:d,/**
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=d.prototype.defaults,e=a.keys(c),g=a.pick(this,e),h=a.pick(b,e);
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})})}});a.extend(f.prototype,d.prototype.defaults)});
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});
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "backgrid-moment-cell",
"version": "0.3.8",
"name": "@estateagents/backgrid-moment-cell",
"version": "0.3.9",
"description": "Backgrid.js datetime cell type formatted via moment.js.",
"main": "backgrid-moment-cell.js",
"style": "backgrid-moment-cell.css",
Expand All @@ -9,7 +9,7 @@
},
"repository": {
"type": "git",
"url": "git://github.com/wyuenho/backgrid-moment-cell.git"
"url": "git@bitbucket.org:estateagents/backgrid-moment-cell.git"
},
"keywords": [
"backbone",
Expand Down