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

atramhasis/static/admin/src/app/ui/dialogs/LanguageDialog.js   A

Complexity

Total Complexity 13
Complexity/F 1.3

Size

Lines of Code 103
Function Count 10

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
nc 2
dl 0
loc 103
rs 10
c 1
b 0
f 0
wmc 13
mnd 2
bc 16
fnc 10
bpm 1.6
cpm 1.3
noi 2

1 Function

Rating   Name   Duplication   Size   Complexity  
B LanguageDialog.js ➔ define 0 95 1
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