1
|
|
|
import _ from 'underscore'; |
|
|
|
|
2
|
|
|
/* |
3
|
|
|
backgrid |
4
|
|
|
http://github.com/wyuenho/backgrid |
5
|
|
|
|
6
|
|
|
Copyright (c) 2013 Jimmy Yuen Ho Wong and contributors |
7
|
|
|
Licensed under the MIT license. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
Just a convenient class for interested parties to subclass. |
12
|
|
|
|
13
|
|
|
The default Cell classes don't require the formatter to be a subclass of |
14
|
|
|
Formatter as long as the fromRaw(rawData) and toRaw(formattedData) methods |
15
|
|
|
are defined. |
16
|
|
|
|
17
|
|
|
@abstract |
18
|
|
|
@class Backgrid.CellFormatter |
19
|
|
|
@constructor |
20
|
|
|
*/ |
21
|
|
|
var CellFormatter = function () {}; |
22
|
|
|
_.extend(CellFormatter.prototype, { |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
Takes a raw value from a model and returns an optionally formatted string |
26
|
|
|
for display. The default implementation simply returns the supplied value |
27
|
|
|
as is without any type conversion. |
28
|
|
|
|
29
|
|
|
@member Backgrid.CellFormatter |
30
|
|
|
@param {*} rawData |
31
|
|
|
@param {Backbone.Model} model Used for more complicated formatting |
32
|
|
|
@return {*} |
33
|
|
|
*/ |
34
|
|
|
fromRaw: function (rawData, model) { |
|
|
|
|
35
|
|
|
return rawData; |
36
|
|
|
}, |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
Takes a formatted string, usually from user input, and returns a |
40
|
|
|
appropriately typed value for persistence in the model. |
41
|
|
|
|
42
|
|
|
If the user input is invalid or unable to be converted to a raw value |
43
|
|
|
suitable for persistence in the model, toRaw must return `undefined`. |
44
|
|
|
|
45
|
|
|
@member Backgrid.CellFormatter |
46
|
|
|
@param {string} formattedData |
47
|
|
|
@param {Backbone.Model} model Used for more complicated formatting |
48
|
|
|
@return {*|undefined} |
49
|
|
|
*/ |
50
|
|
|
toRaw: function (formattedData, model) { |
|
|
|
|
51
|
|
|
return formattedData; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
}); |
55
|
|
|
|
56
|
|
|
export { |
57
|
|
|
CellFormatter |
58
|
|
|
}; |
59
|
|
|
|