Completed
Push — master ( 395a8a...5b5be3 )
by greg
02:00
created

printInput.js ➔ ... ➔ buttons.forEach   B

Complexity

Conditions 8
Paths 9

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
c 0
b 0
f 0
nc 9
nop 1
dl 0
loc 17
rs 7.7777
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>'
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...
61
    if(typeof params.source === 'object' && Object.prototype.toString.call(params.source) === '[object Array]') {
62
      Array.prototype.forEach.call(params.source, (val) => {
63
        inputSource += sourceOption(val, params)
64
      })
65
    }
66
    else inputSource += sourceOption(params.source, 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...
67
    inputSource += '</select>'
68
  }
69
  return inputSource
70
}
71
72
export function createInputRich(attributes, inputClass, params) {
73
  var buttons = [
74
    { icon: "bold",                  title: "Bold (Ctrl+B)",          action: "bold",         param: "",         hotkey: "b",     key:"b" },
75
    { icon: "ti-Italic",             title: "Italic (Ctrl+I)",        action: "italic",       param: "",         hotkey: "i" },
76
    { icon: "ti-underline",          title: "Underline (Ctrl+U)",     action: "underline",    param: "",         hotkey: "u" },
77
    { icon: "strikethrough",         title: "Strikethrough",          action: "strikethrough",param: "" ,                         key:"s" },
78
    { icon: "ti-paint-bucket",       title: "Text color",             action: "forecolor",    param: "",         popup: "color" },
79
    { icon: "ti-paint-bucket bg",    title: "Background color",       action: "highlight",    param: "",         popup: "color" },
80
    { icon: "ti-align-left",         title: "Left",                   action: "align",        param: "left" },
81
    { icon: "ti-align-center",       title: "Center",                 action: "align",        param: "center" },
82
    { icon: "ti-align-right",        title: "Right",                  action: "align",        param: "right" },
83
    { icon: "ti-align-justify",      title: "Justify",                action: "align",        param: "justify" },
84
    { icon: "ti-text ti-text-sub",   title: "Subscript",              action: "subscript",    param: "" },
85
    { icon: "ti-text ti-text-sup",   title: "Superscript",            action: "superscript",  param: "" },
86
    { icon: "ti-shift-right-alt",    title: "Indent",                 action: "indent",       param: "" },
87
    { icon: "ti-shift-left-alt",     title: "Outdent",                action: "indent",       param: "outdent" },
88
    { icon: "ti-list",               title: "Unordered list",         action: "list",         param: "" },
89
    { icon: "ti-list-ol",            title: "Ordered list",           action: "list",         param: "ordered" },
90
    { icon: "ti-eraser",             title: "Remove format",          action: "removeFormat", param: "" },
91
    { icon: "ti-link",               title: "Add link",               action: "insertLink",   param: "",         popup: "link" },
92
    { icon: "console",               title: "Code style",             action: "code",         param: "",                          key:"{code}" },
93
    { icon: "ti-image",              title: "media",                  action: "media",        param: "",         popup: "image" },
94
    { icon: "ti-face-smile",         title: "smiley",                 action: "smiley",       param: "",         popup: "smiley" },
95
  ];
96
  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...
97
  var inputRich = `<div class="wysiwyg-container rich">
98
                    <div class="wysiwyg-toolbar wysiwyg-toolbar-top">`
99
100
  buttons.forEach(function (button) {
101
    if(params.toolbar === '*' || params.toolbar.indexOf(button.action) > -1){
102
      var hotkey = (button.hotkey != null) ? `hotkey="${button.hotkey}"` : ''
103
      var popup = (button.popup != null) ? `data-popup="${button.popup}"` : ''
104
      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...
105
      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...
106
      inputRich += `<a  class="wysiwyg-toolbar-icon parent-${button.icon}" 
107
                        data-action="${button.action}"
108
                        data-param="${button.param}"
109
                        title="${button.title}"
110
                        ${hotkey}
111
                        ${popup}
112
                        href="#">
113
                      <span class="glyphicon theme-icon ${button.icon}">${(button.key) ? button.key : ''}</span>
114
                    </a>`
115
    }
116
  })
117
118
  inputRich +=    `</div>
119
                  <textarea class="${inputClass} form-rich" ${attributes} rows="4">${params.value}</textarea>
120
                </div>`
121
122
  return inputRich
123
}
124
125
export function createInputFile(attributes, inputClass, params) {
126
  return `<input class="form-control" ${attributes} name="${params.key}" type="file" />
127
          <span class="percent"></span>
128
          <input type="text" ${attributes} class="${inputClass} hidden" />`
129
}
130
131
export function createInputTextarea(attributes, inputClass, params) {
132
  return `<textarea class="${inputClass}" ${attributes} rows="4">${params.value}</textarea>`
133
}
134
135
export function createInputLink(attributes, inputClass, params) {
0 ignored issues
show
Unused Code introduced by
The parameter params 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...
136
  return `<div class="input-group">
137
            <div class="input-group-addon link">
138
              <span class="glyphicon glyphicon-link" aria-hidden="true"></span>
139
            </div>
140
            <input type="text" ${attributes} class="${inputClass}" />
141
          </div>`
142
}
143
144
export function createInputImage(attributes, inputClass, params) {
145
  return `<div class="input-group img-upload">
146
            <div class="input-group-addon image">
147
              <span class="glyphicon glyphicon-picture" aria-hidden="true"></span>
148
            </div>
149
            <input type="text" ${attributes} class="${inputClass} image-input" />
150
            <div class="upload-wrapper">
151
              <input class="form-control" ${attributes} name="${params.key}" type="file" title="upload an image"/>
152
              <span class="percent">
153
                <span class="glyphicon glyphicon-upload" aria-hidden="true"></span>
154
              </span>
155
            </div>
156
          </div>
157
          <div class="input-error"></div>`
158
}
159
160
export function createInputText(attributes, inputClass, params) {
0 ignored issues
show
Unused Code introduced by
The parameter params 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...
161
  return `<div class="input-group">
162
          <div class="input-group-addon">
163
            <span class="glyphicon glyphicon-font" aria-hidden="true"></span>
164
            </div>
165
            <input type="text" ${attributes} class="${inputClass}" />
166
          </div>`
167
}
168
169
/**
170
 * Print form input based on input data type {Textarea | text | meta | link | image | ...}
171
 * && add appropriate attributs / data-attributs
172
 * @return {String|html} input / input group ...
173
 */
174
export function printInput (params, root) {
175
  params = abeExtend.hooks.instance.trigger('beforeEditorInput', params)
176
  var userWorkflow = (root.user != null) ? root.user.role.workflow : ''
177
  var res = `<div class="form-group" data-precontrib-templates="${params.precontribTemplate}">`
178
  var inputClass = 'form-control form-abe'
179
  res += getLabel(params)
180
181
  params.placeholder = params.placeholder || ''
182
  params.value = params.value || ''
183
  
184
  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...
185
  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...
186
187
  params.disabled = ''
188
  if (params.tab !== 'slug' && !User.utils.isUserAllowedOnRoute(userWorkflow, `/abe/operations/edit/${params.status}`)) {
189
    params.disabled = 'disabled="disabled"'
190
  }
191
  var attributes = getAttributes(params)
192
193
  if(params.source != null) {
194
    params.multiple = ((params['max-length'] == null || params['max-length'] > 1) && params.source.length > 0) ? 'multiple' : ''
195
    params.disabled = (params.source.length <= 0) ? 'disabled' : ''
196
    res += createInputSource(getAttributes(params), inputClass, params)
197
  }
198
  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...
199
  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...
200
  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...
201
  else if (params.type.indexOf('link') >= 0) res += createInputLink(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...
202
  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...
203
  else res += createInputText(attributes, inputClass, params)
204
205
  res += '</div>'
206
  res = abeExtend.hooks.instance.trigger('afterEditorInput', res, params)
207
208
  return res
209
}