Total Complexity | 5 |
Complexity/F | 2.5 |
Lines of Code | 60 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | import Backbone from 'backbone'; |
||
|
|||
2 | |||
3 | import { |
||
4 | Column |
||
5 | } from '../column.js'; |
||
6 | /* |
||
7 | backgrid |
||
8 | http://github.com/wyuenho/backgrid |
||
9 | |||
10 | Copyright (c) 2013 Jimmy Yuen Ho Wong and contributors |
||
11 | Licensed under the MIT license. |
||
12 | */ |
||
13 | |||
14 | /** |
||
15 | Generic cell editor base class. Only defines an initializer for a number of |
||
16 | required parameters. |
||
17 | |||
18 | @abstract |
||
19 | @class Backgrid.CellEditor |
||
20 | @extends Backbone.View |
||
21 | */ |
||
22 | var CellEditor = Backbone.View.extend({ |
||
23 | |||
24 | /** |
||
25 | Initializer. |
||
26 | |||
27 | @param {Object} options |
||
28 | @param {Backgrid.CellFormatter} options.formatter |
||
29 | @param {Backgrid.Column} options.column |
||
30 | @param {Backbone.Model} options.model |
||
31 | |||
32 | @throws {TypeError} If `formatter` is not a formatter instance, or when |
||
33 | `model` or `column` are undefined. |
||
34 | */ |
||
35 | initialize: function (options) { |
||
36 | this.formatter = options.formatter; |
||
37 | this.column = options.column; |
||
38 | if (!(this.column instanceof Column)) { |
||
39 | this.column = new Column(this.column); |
||
40 | } |
||
41 | |||
42 | this.listenTo(this.model, "backgrid:editing", this.postRender); |
||
43 | }, |
||
44 | |||
45 | /** |
||
46 | Post-rendering setup and initialization. Focuses the cell editor's `el` in |
||
47 | this default implementation. **Should** be called by Cell classes after |
||
48 | calling Backgrid.CellEditor#render. |
||
49 | */ |
||
50 | postRender: function (model, column) { |
||
51 | if (column == null || column.get("name") == this.column.get("name")) { |
||
52 | this.$el.focus(); |
||
53 | } |
||
54 | return this; |
||
55 | } |
||
56 | |||
57 | }); |
||
58 | export { |
||
59 | CellEditor |
||
60 | }; |
||
61 |