src/backgrid_modules/editors/cell.js   A
last analyzed

Complexity

Total Complexity 5
Complexity/F 2.5

Size

Lines of Code 60
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 0
c 2
b 0
f 0
nc 1
dl 0
loc 60
rs 10
wmc 5
mnd 1
bc 4
fnc 2
bpm 2
cpm 2.5
noi 3

2 Functions

Rating   Name   Duplication   Size   Complexity  
A Backbone.View.extend.initialize 0 9 2
A Backbone.View.extend.postRender 0 6 3
1
import Backbone from 'backbone';
0 ignored issues
show
introduced by
Definition for rule 'keyword-spacing' was not found
Loading history...
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")) {
0 ignored issues
show
introduced by
Use ‘===’ to compare with ‘null’.
Loading history...
Bug Best Practice introduced by
Apart from some edge-cases, it is generally advisable to use the strict comparison === instead of ==.

The loose comparison such as == or != might produce some weird results for some values, unless you explicitly want to have this behavior here, better use the strict alternative.

Learn more about loose comparison in Javascript.

Loading history...
52
      this.$el.focus();
53
    }
54
    return this;
55
  }
56
57
});
58
export {
59
  CellEditor
60
};
61