Completed
Push — master ( f67f14...be7dea )
by Koen
01:29
created

ManageSchemeDialog.js ➔ define   B

Complexity

Conditions 1
Paths 16

Size

Total Lines 164

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
nc 16
nop 15
dl 0
loc 164
rs 8.2857
c 1
b 0
f 0

10 Functions

Rating   Name   Duplication   Size   Complexity  
A ManageSchemeDialog.js ➔ ... ➔ declare.startup 0 5 1
A ManageSchemeDialog.js ➔ ... ➔ declare._cancel 0 4 2
A ManageSchemeDialog.js ➔ ... ➔ declare._close 0 4 1
A ManageSchemeDialog.js ➔ ... ➔ declare._createLabelsTab 0 11 1
A ManageSchemeDialog.js ➔ ... ➔ declare._reset 0 5 1
A ManageSchemeDialog.js ➔ ... ➔ declare._createNotesTab 0 11 1
A ManageSchemeDialog.js ➔ ... ➔ declare.showDialog 0 18 4
A ManageSchemeDialog.js ➔ ... ➔ declare._createSourcesTab 0 7 1
A ManageSchemeDialog.js ➔ ... ➔ declare.postCreate 0 16 1
B ManageSchemeDialog.js ➔ ... ➔ declare._saveScheme 0 30 4

How to fix   Long Method    Many Parameters   

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:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
define([
2
  'dojo/_base/declare',
3
  'dojo/_base/lang',
4
  'dojo/topic',
5
  'dojo/dom-attr',
6
  'dojo/on',
7
  'dijit/Dialog',
8
  'dijit/_Widget',
9
  'dijit/_TemplatedMixin',
10
  'dijit/_WidgetsInTemplateMixin',
11
  '../../utils/DomUtils',
12
  '../managers/LabelManager',
13
  '../managers/NoteManager',
14
  '../managers/SourcesManager',
15
  '../../utils/DomUtils',
16
  'dojo/text!./templates/ManageSchemeDialog.html',
17
  'dijit/layout/TabContainer',
18
  'dijit/layout/ContentPane'
19
], function (
20
  declare,
21
  lang,
22
  topic,
23
  domAttr,
24
  on,
25
  Dialog,
26
  _Widget,
27
  _TemplatedMixin,
28
  _WidgetsInTemplateMixin,
29
  DomUtils,
30
  LabelManager,
31
  NoteManager,
32
  SourcesManager,
33
  domUtils,
34
  template
35
) {
36
  return declare([_Widget, _TemplatedMixin, _WidgetsInTemplateMixin], {
37
38
    templateString: template,
39
    baseClass: 'edit-scheme-dialog',
40
    dialog: null,
41
    parent: null,
42
    scheme: null,
43
    languageController: null,
44
    listController: null,
45
    conceptSchemeController: null,
46
    _mode: 'edit',
47
48
    /**
49
     * Standaard widget functie
50
     */
51
    postCreate: function () {
52
      this.inherited(arguments);
53
      this.dialog = new Dialog({
54
        title: 'Edit scheme',
55
        style: 'width: 1000px; min-height: 650px;'
56
        //onHide: lang.hitch(this, function() {
57
        //  this.parent._closeAddDialog();
58
        //})
59
      });
60
      this.dialog.closeText.innerHTML = '<i class="fa fa-times"></i>';
61
      this.dialog.set('content', this);
62
63
      this._createLabelsTab();
64
      this._createNotesTab();
65
      this._createSourcesTab();
66
    },
67
68
    /**
69
     * Standaard widget functie
70
     */
71
    startup: function () {
72
      this.inherited(arguments);
73
      this.tabContainer.layout();
74
      this.dialog.resize();
75
    },
76
77
    /**
78
     * Toont het dialog
79
     */
80
    showDialog: function (scheme, mode) {
81
      if (mode) {
82
        this.mode = mode;
83
      }
84
      if (scheme) {
85
        if (scheme.id) {
86
          this.dialog.set('title', 'Edit <strong>' + scheme.label + '</strong>');
87
        }
88
        this.sourcesManager.setConcept(scheme);
89
        this.labelManager.setConcept(scheme);
90
        this.noteManager.setConcept(scheme);
91
        this.scheme = scheme;
92
      }
93
      this.dialog.show();
94
      this.tabContainer.selectChild(this.tabLabels);
95
      this.tabContainer.layout();
96
      this.dialog.resize();
97
    },
98
99
    /**
100
     * Sluit het dialog
101
     * @private
102
     */
103
    _close: function () {
104
      this._reset();
105
      this.dialog.hide();
106
    },
107
108
    _saveScheme: function(evt) {
109
      evt ? evt.preventDefault() : null;
110
      var scheme = {};
111
112
      if (this.scheme) {
113
        scheme.id = this.scheme.id || undefined;
114
        scheme.uri = this.scheme.uri || undefined;
115
      }
116
117
      //// mixin tab data
118
      var labelData = this.labelManager.getData();
119
      lang.mixin(scheme, labelData);
120
121
      var noteData = this.noteManager.getData();
122
      lang.mixin(scheme, noteData);
123
124
      var sourceData = this.sourcesManager.getData();
125
      lang.mixin(scheme, sourceData);
126
127
      if (this._mode === 'add') {
128
        // emit save event
129
        this.emit('new.scheme.save', {
130
          scheme: scheme
131
        });
132
      } else {
133
        this.emit('scheme.save', {
134
          scheme: scheme
135
        });
136
      }
137
    },
138
139
    _cancel: function(evt) {
140
      evt ? evt.preventDefault() : null;
141
      this._close();
142
    },
143
144
    _reset: function() {
145
      this.labelManager.reset();
146
      this.noteManager.reset();
147
      this.sourcesManager.reset();
148
    },
149
150
    _createLabelsTab: function(scheme) {
151
      this.languageController.getLanguageStore().fetch().then(lang.hitch(this, function(languages) {
152
        this.labelManager = new LabelManager({
153
          languageController: this.languageController,
154
          listController: this.listController,
155
          concept: scheme,
156
          languageList: languages
157
        }, this.labelsNode);
158
        this.labelManager.startup();
159
      }));
160
    },
161
162
    _createNotesTab: function(scheme) {
163
      this.languageController.getLanguageStore().fetch().then(lang.hitch(this, function(languages) {
164
        this.noteManager = new NoteManager({
165
          languageController: this.languageController,
166
          listController: this.listController,
167
          concept: scheme,
168
          languageList: languages
169
        }, this.notesNode);
170
        this.noteManager.startup();
171
      }));
172
    },
173
174
    _createSourcesTab: function(scheme) {
175
      this.sourcesManager = new SourcesManager({
176
        listController: this.listController,
177
        concept: scheme
178
      }, this.sourcesNode);
179
      this.sourcesManager.startup();
180
    }
181
  });
182
});