Passed
Push — master ( 271bd5...3925ec )
by
unknown
02:06
created

src/cli/cms/editor/form.js   A

Size

Lines of Code 73

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
nc 1
dl 0
loc 73
rs 10
noi 7

1 Function

Rating   Name   Duplication   Size   Complexity  
A form.js ➔ ??? 0 6 1
1
import extend from 'extend'
2
3
export default class Form {
4
5
  constructor() {
6
    this._form = {
7
      
8
    }
9
    this._key = []
10
  }
11
12
  /**
13
   * Get all input from a template
14
   * @return {Array} array of input form
15
   */
16
  get form(){
17
    return this._form
18
  }
19
20
  /**
21
   * Check if key is not is the form array
22
   * @param  {[type]} key [description]
23
   * @return {[type]}     [description]
24
   */
25
  dontHaveKey(key){
26
    return typeof this._key[key] === 'undefined' || this._key[key] === null
27
  }
28
29
  /**
30
   * Add entry to abe engine form
31
   * @param {String} type        textarea | text | meta | link | image | ...
0 ignored issues
show
Documentation introduced by
The parameter type does not exist. Did you maybe forget to remove this comment?
Loading history...
32
   * @param {String} key         unique ID, no space allowed
0 ignored issues
show
Documentation introduced by
The parameter key does not exist. Did you maybe forget to remove this comment?
Loading history...
33
   * @param {String} desc        input description
0 ignored issues
show
Documentation introduced by
The parameter desc does not exist. Did you maybe forget to remove this comment?
Loading history...
34
   * @param {Int}    max-length   maximum characteres allowed inside input
0 ignored issues
show
Documentation introduced by
The parameter max-length does not exist. Did you maybe forget to remove this comment?
Loading history...
35
   * @param {String} tab         tab name
0 ignored issues
show
Documentation introduced by
The parameter tab does not exist. Did you maybe forget to remove this comment?
Loading history...
36
   * @param {String} jsonValue   
0 ignored issues
show
Documentation introduced by
The parameter jsonValue does not exist. Did you maybe forget to remove this comment?
Loading history...
37
   * @return {Void}
38
   */
39
  add(obj) {
40
    var defaultValues = {
41
      autocomplete: null,
42
      block:'',
43
      desc: '',
44
      display: null,
45
      editable: true,
46
      key: '',
47
      'max-length': null,
48
      order: 0,
49
      placeholder: '',
50
      prefill: false,
51
      'prefill-quantity': null,
52
      reload: false,
53
      required: false,
54
      source: null,
55
      tab: 'default',
56
      type: 'text',
57
      value: '',
58
      visible: true
59
    }
60
61
    obj = extend(true, defaultValues, obj)
62
    obj.key = obj.key.replace(/\./, '-')
63
64
    if(obj.key.indexOf('[') < 0 && obj.key.indexOf('.') > -1) {
65
      obj.block = obj.key.split('.')[0]
66
    }
67
68
    if(typeof this._form[obj.tab] === 'undefined' || this._form[obj.tab] === null) this._form[obj.tab] = {item:[]}
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
69
70
    this._key[obj.key] = true // save key for dontHaveKey()
71
    this._form[obj.tab].item.push(obj)
72
  }
73
}