Completed
Push — master ( 65994c...1e163f )
by Koen
8s
created

LanguageDialog.js ➔ define   B

Complexity

Conditions 1
Paths 2

Size

Total Lines 95

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
nc 2
nop 7
dl 0
loc 95
rs 8.4117
c 1
b 0
f 0

9 Functions

Rating   Name   Duplication   Size   Complexity  
A LanguageDialog.js ➔ ... ➔ declare.show 0 15 2
A LanguageDialog.js ➔ ... ➔ declare.hide 0 4 1
A LanguageDialog.js ➔ ... ➔ declare.startup 0 4 1
A LanguageDialog.js ➔ ... ➔ declare.postCreate 0 3 1
B LanguageDialog.js ➔ ... ➔ declare._okClick 0 24 3
A LanguageDialog.js ➔ ... ➔ declare.reset 0 4 1
A LanguageDialog.js ➔ ... ➔ declare._cancelClick 0 5 1
A LanguageDialog.js ➔ ... ➔ declare.setData 0 5 1
A LanguageDialog.js ➔ ... ➔ declare._validate 0 3 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
define([
2
  'dojo/_base/declare',
3
  'dijit/_TemplatedMixin',
4
  'dijit/_WidgetsInTemplateMixin',
5
  'dijit/Dialog',
6
  'dojo/topic',
7
  'dojo/text!./templates/LanguageDialog.html',
8
  '../../utils/DomUtils'
9
], function (
10
  declare,
11
  _TemplatedMixin,
12
  _WidgetsInTemplateMixin,
13
  Dialog,
14
  topic,
15
  template,
16
  DomUtils
0 ignored issues
show
Unused Code introduced by
The parameter DomUtils is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
17
) {
18
  return declare([Dialog, _TemplatedMixin, _WidgetsInTemplateMixin], {
19
20
    templateString: template,
21
    parentNode: null,
22
    baseClass: 'language-dialog',
23
    title: 'Edit language',
24
    language: null,
25
    edit: true,
26
27
    postCreate: function () {
28
      this.inherited(arguments);
29
    },
30
31
    startup: function () {
32
      this.inherited(arguments);
33
34
    },
35
36
    setData: function(language) {
37
      console.log(language);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
38
      this.codeInputNode.value = language.id;
39
      this.descriptionInputNode.value = language.name;
40
    },
41
42
    hide: function () {
43
      this.inherited(arguments);
44
      this.reset();
45
    },
46
47
    show: function (language) {
48
      this.inherited(arguments);
49
      this.reset();
50
      if (language) {
51
        this.setData(language);
52
        this.set('title', 'Edit language');
53
        this.okButtonNode.innerHTML = 'Edit';
54
        this.edit = true;
55
        this.language = language;
56
      } else {
57
        this.set('title', 'Add new language');
58
        this.okButtonNode.innerHTML = 'Add';
59
        this.edit = false;
60
      }
61
    },
62
63
    _okClick: function (evt) {
64
      console.debug('languageDialog::_okClick');
65
      evt.preventDefault();
66
      if (this._validate()) {
67
        this.language.id = this.codeInputNode.value;
68
        this.language.name = this.descriptionInputNode.value;
69
        if (this.edit) {
70
          this.emit('edit.language', {
71
            language: this.language,
72
          });
73
        } else {
74
          this.emit('add.language', {
75
            language: this.language
76
          });
77
        }
78
        this.hide();
79
      } else {
80
        topic.publish('dGrowl', 'Please fill in at least a language code.', {
81
          'title': 'Invalid language',
82
          'sticky': false,
83
          'channel': 'info'
84
        });
85
      }
86
    },
87
88
    _cancelClick: function (evt) {
89
      console.debug('languageDialog::_cancelClick');
90
      evt.preventDefault();
91
      this.hide();
92
    },
93
94
    reset: function () {
95
      this.codeInputNode.value = '';
96
      this.descriptionInputNode.value = '';
97
    },
98
99
    _validate: function () {
100
      return (this.codeInputNode.value.trim() !== null && this.codeInputNode.value.trim() !== '');
101
    }
102
  });
103
});
104