Completed
Pull Request — master (#3)
by
unknown
02:27
created

web/app.js   A

Complexity

Total Complexity 4
Complexity/F 1

Size

Lines of Code 35
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

3 Functions

Rating   Name   Duplication   Size   Complexity  
A NewFormButton.onClick 0 8 1
A NewFormButton.init 0 5 1
A NewFormButton.getNewForm 0 13 1
1
const NewFormButton = {
2
  BUTTON_QUERY: '#new-file',
3
  LAST_FORM_QUERY: '.code-form--file:last-of-type',
4
5
  init() {
6
    this.index = 0;
7
    const button = document.querySelector(this.BUTTON_QUERY);
8
    button.addEventListener('click', () => this.onClick());
9
  },
10
11
  onClick() {
12
    this.index += 1;
13
    const lastForm = document.querySelector(this.LAST_FORM_QUERY);
14
    const newForm = this.getNewForm();
15
    const formsWrapper = lastForm.parentNode;
16
17
    formsWrapper.insertBefore(newForm, lastForm.nextSibling);
18
  },
19
20
  getNewForm() {
21
    const newForm = document.createElement('fieldset');
22
    newForm.setAttribute('class', 'code-form--file');
23
    newForm.setAttribute('data-index', this.index);
24
25
    newForm.innerHTML =
26
      `<label class="code-form--label" for="name[${this.index}]">Nazwa pliku (opcjonalna)</label>
27
       <input type="text" id="name[${this.index}]" name="name[${this.index}]" class="code-form--control">
28
       <label for="content[${this.index}]" class="code-form--label">Treść pliku</label>
29
       <textarea name="content[${this.index}]" id="content[${this.index}]" rows="10" class="code-form--control code-form--control__textarea"></textarea>`;
30
31
    return newForm;
32
  },
33
};
34
35
NewFormButton.init();
36