Completed
Pull Request — master (#81)
by
unknown
02:10
created

src/cli/cms/editor/handlebars/printInput.js   D

Complexity

Total Complexity 62
Complexity/F 4.77

Size

Lines of Code 220
Function Count 13

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
c 0
b 0
f 0
nc 1
dl 0
loc 220
rs 4.8235
noi 29
wmc 62
mnd 6
bc 22
fnc 13
bpm 1.6923
cpm 4.7692

10 Functions

Rating   Name   Duplication   Size   Complexity  
A printInput.js ➔ getLabel 0 6 2
C printInput.js ➔ getAttributes 0 18 15
A printInput.js ➔ createInputFile 0 5 1
A printInput.js ➔ createInputImage 0 15 1
F printInput.js ➔ printInput 0 36 16
C printInput.js ➔ createInputSource 0 48 12
A printInput.js ➔ createInputText 0 8 1
A printInput.js ➔ createInputTextarea 0 3 1
A printInput.js ➔ createInputLink 0 8 1
A printInput.js ➔ createInputRich 0 52 2

How to fix   Complexity   

Complexity

Complex classes like src/cli/cms/editor/handlebars/printInput.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
import sourceAutocomplete   from './sourceAutocomplete'
2
import sourceOption   from './sourceOption'
3
import {
4
  abeExtend
5
  ,User
6
} from '../../../'
7
8
export function getAttributes(params) {
9
  var attributes = ''
10
  if(params.key != null) attributes += `id="${params.key}" data-id="${params.key}"`
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...
11
  if(params.value != null) attributes += ` value="${params.value}"`
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...
12
  if(params['max-length'] != null) attributes += ` data-maxlength="${params['max-length']}"`
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...
13
  if(params.reload != null) attributes += ` reload="${params.reload}"`
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...
14
  if(params.order != null) attributes += ` tabIndex="${params.order}"`
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...
15
  if(params.required != null) attributes += ` data-required="${params.required}"`
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...
16
  if(params.display != null) attributes += ` data-display="${params.display}"`
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...
17
  if(params.visible != null) attributes += ` data-visible="${params.visible}"`
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...
18
  if(params.autocomplete != null) attributes += ` data-autocomplete="${params.autocomplete}"`
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...
19
  if(params.placeholder != null) attributes += ` placeholder="${params.placeholder}"`
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...
20
  if(params.thumbs != null) attributes += ` data-size="${params.thumbs}"`
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...
21
  if(params.toolbar != null) attributes += ` data-toolbar="${params.toolbar}"`
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...
22
  if(params.multiple != null) attributes += ` ${params.multiple}`
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...
23
  if(params.disabled != null) attributes += ` ${params.disabled}`
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...
24
  return attributes
25
}
26
27
export function getLabel(params) {
28
  var desc = params.desc + ((params.required) ? ' *' : '')
29
  return `<label class="control-label" for="${params.key}" >
30
            ${desc}
31
          </label>`
32
}
33
34
export function createInputSource(attributes, inputClass, params) {
35
  var inputSource = ''
36
  var lastValues
37
  if(params.autocomplete != null && params.autocomplete === 'true') {
38
    if(params.sourceString.indexOf('http') === 0) lastValues = params.source
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...
39
    else lastValues = JSON.stringify(params.source).replace(/\'/g, '&quote;')
40
    inputSource += '<div class="autocomplete-result-wrapper">'
41
    if(params.autocomplete != null && params.autocomplete === 'true' && params.prefill === 'true') {
42
      inputSource += `<div  class="autocomplete-refresh" value=''
43
                            data-autocomplete-refresh="true"
44
                            data-autocomplete-refresh-sourcestring="${params.sourceString}"
45
                            data-autocomplete-refresh-prefill-quantity="${params['prefill-quantity']}"
46
                            data-autocomplete-refresh-key="${params.key}"
47
                            data-autocomplete-data-display="${params.display}" >
48
                        <span class="glyphicon glyphicon-refresh"></span>
49
                      </div>`
50
    }
51
    Array.prototype.forEach.call(params.value, (val) => {
52
      inputSource += sourceAutocomplete(val, params)
53
    })
54
    inputSource += `</div><input value="" type="text" autocomplete="off" data-value='${lastValues}' ${attributes} class="${inputClass}" />`
55
  }
56
  else {
57
    lastValues = JSON.stringify(params.value).replace(/\'/g, '&quote;')
58
    inputSource += `<select ${attributes} class="${inputClass}" last-values='${lastValues}'>`
59
60
    // if (!params.required) inputSource += '<option value=\'\'></option>'
61
    var options = ''
62
    if(typeof params.source === 'object' && Object.prototype.toString.call(params.source) === '[object Array]') {
63
      Array.prototype.forEach.call(params.source, (val) => {
64
        options += sourceOption(val, params)
65
      })
66
    }else{
67
      options += sourceOption(params.source, params)
68
    }
69
70
    var defaultValueSelected = 'selected=selected'
71
    if (options.indexOf('selected') > -1) {
72
      defaultValueSelected = ''
73
    }
74
    if (params.required) inputSource += `<option value=\'\' value="" disabled ${defaultValueSelected}>Select ${params.desc.toLowerCase()}...</option>`
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...
75
    if (!params.required) inputSource += `<option value=\'\' value="" ${defaultValueSelected}></option>`
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...
76
    inputSource += options
77
78
    inputSource += '</select>'
79
  }
80
  return inputSource
81
}
82
83
export function createInputRich(attributes, inputClass, params) {
84
  var buttons = [
85
    { icon: "bold",                  title: "Bold (Ctrl+B)",          action: "bold",         param: "",         hotkey: "b",     key:"b" },
86
    { icon: "ti-Italic",             title: "Italic (Ctrl+I)",        action: "italic",       param: "",         hotkey: "i" },
87
    { icon: "ti-underline",          title: "Underline (Ctrl+U)",     action: "underline",    param: "",         hotkey: "u" },
88
    { icon: "strikethrough",         title: "Strikethrough",          action: "strikethrough",param: "" ,                         key:"s" },
89
    { icon: "ti-paint-bucket",       title: "Text color",             action: "forecolor",    param: "",         popup: "color" },
90
    { icon: "ti-paint-bucket bg",    title: "Background color",       action: "highlight",    param: "",         popup: "color" },
91
    { icon: "ti-align-left",         title: "Left",                   action: "align",        param: "left" },
92
    { icon: "ti-align-center",       title: "Center",                 action: "align",        param: "center" },
93
    { icon: "ti-align-right",        title: "Right",                  action: "align",        param: "right" },
94
    { icon: "ti-align-justify",      title: "Justify",                action: "align",        param: "justify" },
95
    { icon: "ti-text ti-text-sub",   title: "Subscript",              action: "subscript",    param: "" },
96
    { icon: "ti-text ti-text-sup",   title: "Superscript",            action: "superscript",  param: "" },
97
    { icon: "ti-shift-right-alt",    title: "Indent",                 action: "indent",       param: "" },
98
    { icon: "ti-shift-left-alt",     title: "Outdent",                action: "indent",       param: "outdent" },
99
    { icon: "ti-list",               title: "Unordered list",         action: "list",         param: "" },
100
    { icon: "ti-list-ol",            title: "Ordered list",           action: "list",         param: "ordered" },
101
    { icon: "ti-eraser",             title: "Remove format",          action: "removeFormat", param: "" },
102
    { icon: "ti-link",               title: "Add link",               action: "insertLink",   param: "",         popup: "link" },
103
    { icon: "console",               title: "Code style",             action: "code",         param: "",                          key:"{code}" },
104
    { icon: "ti-image",              title: "media",                  action: "media",        param: "",         popup: "image" },
105
    { icon: "ti-face-smile",         title: "smiley",                 action: "smiley",       param: "",         popup: "smiley" },
106
  ];
107
  if(params.toolbar !== '*') params.toolbar = params.toolbar.split(',')
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...
108
  var inputRich = `<div class="wysiwyg-container rich">
109
                    <div class="wysiwyg-toolbar wysiwyg-toolbar-top">`
110
111
  buttons.forEach(function (button) {
112
    if(params.toolbar === '*' || params.toolbar.indexOf(button.action) > -1){
113
      var hotkey = (button.hotkey != null) ? `hotkey="${button.hotkey}"` : ''
114
      var popup = (button.popup != null) ? `data-popup="${button.popup}"` : ''
115
      if (button.popup === 'image') button.action = 'insertImage'
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...
116
      if (button.action === 'list') button.action = 'insertList'
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...
117
      inputRich += `<a  class="wysiwyg-toolbar-icon parent-${button.icon}" 
118
                        data-action="${button.action}"
119
                        data-param="${button.param}"
120
                        title="${button.title}"
121
                        ${hotkey}
122
                        ${popup}
123
                        href="#">
124
                      <span class="glyphicon theme-icon ${button.icon}">${(button.key) ? button.key : ''}</span>
125
                    </a>`
126
    }
127
  })
128
129
  inputRich +=    `</div>
130
                  <textarea class="${inputClass} form-rich" ${attributes} rows="4">${params.value}</textarea>
131
                </div>`
132
133
  return inputRich
134
}
135
136
export function createInputFile(attributes, inputClass, params) {
137
  return `<input class="form-control" ${attributes} name="${params.key}" type="file" />
138
          <span class="percent"></span>
139
          <input type="text" ${attributes} class="${inputClass} hidden" />`
140
}
141
142
export function createInputTextarea(attributes, inputClass, params) {
143
  return `<textarea class="${inputClass}" ${attributes} rows="4">${params.value}</textarea>`
144
}
145
146
export function createInputLink(attributes, inputClass) {
147
  return `<div class="input-group">
148
            <div class="input-group-addon link">
149
              <span class="glyphicon glyphicon-link" aria-hidden="true"></span>
150
            </div>
151
            <input type="text" ${attributes} class="${inputClass}" />
152
          </div>`
153
}
154
155
export function createInputImage(attributes, inputClass, params) {
156
  return `<div class="input-group img-upload">
157
            <div class="input-group-addon image">
158
              <span class="glyphicon glyphicon-picture" aria-hidden="true"></span>
159
            </div>
160
            <input type="text" ${attributes} class="${inputClass} image-input" />
161
            <div class="upload-wrapper">
162
              <input class="form-control" ${attributes} name="${params.key}" type="file" title="upload an image"/>
163
              <span class="percent">
164
                <span class="glyphicon glyphicon-upload" aria-hidden="true"></span>
165
              </span>
166
            </div>
167
          </div>
168
          <div class="input-error"></div>`
169
}
170
171
export function createInputText(attributes, inputClass) {
172
  return `<div class="input-group">
173
          <div class="input-group-addon">
174
            <span class="glyphicon glyphicon-font" aria-hidden="true"></span>
175
            </div>
176
            <input type="text" ${attributes} class="${inputClass}" />
177
          </div>`
178
}
179
180
/**
181
 * Print form input based on input data type {Textarea | text | meta | link | image | ...}
182
 * && add appropriate attributs / data-attributs
183
 * @return {String|html} input / input group ...
184
 */
185
export function printInput (params, root) {
186
  params = abeExtend.hooks.instance.trigger('beforeEditorInput', params)
187
  var userWorkflow = (root.user != null) ? root.user.role.workflow : ''
188
  var res = `<div class="form-group" data-precontrib-templates="${params.precontribTemplate}">`
189
  var inputClass = 'form-control form-abe'
190
  res += getLabel(params)
191
192
  params.placeholder = params.placeholder || ''
193
  params.value = params.value || ''
194
  
195
  if(typeof params.value === 'string') params.value = params.value.replace(/\"/g, '&quot;')
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...
196
  if(!(params.toolbar != null)) params.toolbar = '*'
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...
197
198
  params.disabled = ''
199
  if (params.tab !== 'slug' && !User.utils.isUserAllowedOnRoute(userWorkflow, `/abe/operations/edit/${params.status}`)) {
200
    params.disabled = 'disabled="disabled"'
201
  }
202
  var attributes = getAttributes(params)
203
204
  if(params.source != null) {
205
    params.multiple = ((params['max-length'] == null || params['max-length'] > 1) && params.source.length > 0) ? 'multiple' : ''
206
    params.disabled = (params.source.length <= 0) ? 'disabled' : ''
207
    res += createInputSource(getAttributes(params), inputClass, params)
208
  }
209
  else if (params.type.indexOf('rich') >= 0) res += createInputRich(attributes, inputClass, params)
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...
210
  else if (params.type.indexOf('file') >= 0) res += createInputFile(attributes, inputClass, params)
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...
211
  else if (params.type.indexOf('textarea') >= 0) res += createInputTextarea(attributes, inputClass, params)
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...
212
  else if (params.type.indexOf('link') >= 0) res += createInputLink(attributes, inputClass, params)
0 ignored issues
show
Bug introduced by
The call to createInputLink seems to have too many arguments starting with params.
Loading history...
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...
213
  else if (params.type.indexOf('image') >= 0) res += createInputImage(attributes, inputClass, params)
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...
214
  else res += createInputText(attributes, inputClass, params)
0 ignored issues
show
Bug introduced by
The call to createInputText seems to have too many arguments starting with params.
Loading history...
215
216
  res += '</div>'
217
  res = abeExtend.hooks.instance.trigger('afterEditorInput', res, params)
218
219
  return res
220
}