src/assets/javascripts/gaelO.js   A
last analyzed

Complexity

Total Complexity 36
Complexity/F 1.71

Size

Lines of Code 167
Function Count 21

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 77
c 0
b 0
f 0
dl 0
loc 167
rs 9.52
wmc 36
mnd 15
bc 15
fnc 21
bpm 0.7141
cpm 1.7142
noi 11

10 Functions

Rating   Name   Duplication   Size   Complexity  
A gaelO.js ➔ downloadDocumentation 0 3 1
A gaelO.js ➔ alertifySuccess 0 3 1
A gaelO.js ➔ alertifyWarning 0 3 1
A gaelO.js ➔ alertifyError 0 3 1
A gaelO.js ➔ alertifyMessage 0 3 1
D gaelO.js ➔ changeColor 0 43 12
A gaelO.js ➔ µ 0 4 1
A gaelO.js ➔ allowAjaxDivLoading 0 4 1
B gaelO.js ➔ checkBrowserSupportDicomUpload 0 46 8
A gaelO.js ➔ preventAjaxDivLoading 0 14 5
1
/**
2
 Copyright (C) 2018-2020 KANOUN Salim
3
 This program is free software; you can redistribute it and/or modify
4
 it under the terms of the Affero GNU General Public v.3 License as published by
5
 the Free Software Foundation;
6
 This program is distributed in the hope that it will be useful,
7
 but WITHOUT ANY WARRANTY; without even the implied warranty of
8
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
 Affero GNU General Public Public for more details.
10
 You should have received a copy of the Affero GNU General Public Public along
11
 with this program; if not, write to the Free Software Foundation, Inc.,
12
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
13
 */
14
15
/**
16
 * check all require filds in a form before submit
17
 */
18
function checkForm(form) {
19
	 var inputs = form.elements;
20
		for (var i = 0; i < inputs.length; i++) {
21
			if(inputs[i].hasAttribute("required")){
22
		        if(inputs[i].value == ""){
23
		            // found an empty field
24
		        	alertifyError("Please fill in all fields");
25
		            return false;
26
		        }
27
			}
28
		}
29
	return true;
30
}
31
32
/**
33
 * Change color of key text value in the tables
34
 * @returns
35
 */
36
function changeColor(){
37
	
38
	//Polly fill for IE11 missing function
39
	if (!String.prototype.includes) {
40
		  Object.defineProperty(String.prototype, 'includes', {
41
		    value: function(search, start) {
42
		      if (typeof start !== 'number') {
43
		        start = 0
44
		      }
45
		      
46
		      if (start + search.length > this.length) {
47
		        return false
48
		      } else {
0 ignored issues
show
Comprehensibility introduced by
else is not necessary here since all if branches return, consider removing it to reduce nesting and make code more readable.
Loading history...
49
		        return this.indexOf(search, start) !== -1
50
		      }
51
		    }
52
		  })
53
	}
54
	
55
	
56
  //on parcours tout les tableaux (balises table)
57
  $("table:visible").each(function (i, el){
58
    //si la table a un id
59
    if(el.id != ""){
60
      //on parcours chaque clonne de la table (identifiée grace à son id)
61
      $('#'+el.id+' tr').each(function (i, el){
0 ignored issues
show
Unused Code introduced by
The parameter el 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...
Unused Code introduced by
The parameter i 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...
62
    	  
63
        $(this).find('td').each (function() {
64
          if( $(this).html().includes("Not Done") || $(this).html().includes("Refused") ){
65
            $(this).css('color', '#D53333');
66
          }
67
         else if( $(this).html().includes("Done") || $(this).html().includes("Accepted") ) {
68
            $(this).css('color', '#47B236)');
69
         }
70
         else if($(this).html().includes("Should be done") || $(this).html().includes("Wait Definitive Conclusion") || $(this).html().includes("Draft") || $(this).html().includes("Corrective Action Asked")){
71
            $(this).css('color', '#E29300');
72
        }
73
        });
74
      });
75
    }
76
77
  });
78
}
79
80
/**
81
 * Download documentation by id
82
 * @param id
83
 * @returns
84
 */
85
function downloadDocumentation(id){
86
	window.location="scripts/download_documentation.php?idDocumentation="+id;
87
}
88
89
function alertifyError(message){
90
	alertify.error(message);
0 ignored issues
show
Bug introduced by
The variable alertify seems to be never declared. If this is a global, consider adding a /** global: alertify */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
91
}
92
93
function alertifyWarning(message){
94
	alertify.warning(message);
0 ignored issues
show
Bug introduced by
The variable alertify seems to be never declared. If this is a global, consider adding a /** global: alertify */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
95
}
96
97
function alertifySuccess(message){
98
	alertify.success(message);
0 ignored issues
show
Bug introduced by
The variable alertify seems to be never declared. If this is a global, consider adding a /** global: alertify */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
99
}
100
101
function alertifyMessage(message) {
102
	alertify.message(message);
0 ignored issues
show
Bug introduced by
The variable alertify seems to be never declared. If this is a global, consider adding a /** global: alertify */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
103
}
104
105
function µ(str) {
106
	// Escape & < > " chars
107
	return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
108
}
109
110
function checkBrowserSupportDicomUpload(selectorDom) {
111
	var isSupported = {
112
		webKitDirectory: (function () {
113
			var elem = document.createElement('input'),
114
				dir = 'directory',
115
				domPrefixes = ["", "moz", "o", "ms", "webkit"],
116
				prefix;
117
118
			elem.type = 'file';
119
120
			for (prefix in domPrefixes) {
121
				if (domPrefixes[prefix] + dir in elem) {
122
					return true;
123
				}
124
			}
125
			return false;
126
		})(),
127
		ecmascript6: (function () {
128
			try {
129
				new Function("(a = 0) => a");
0 ignored issues
show
Performance Best Practice introduced by
Using new Function() to create a function is slow and difficult to debug. Such functions do not create a closure. Consider using another way to define your function.
Loading history...
Unused Code Best Practice introduced by
The object created with new Function("(a = 0) => a") is not used but discarded. Consider invoking another function instead of a constructor if you are doing this purely for side effects.
Loading history...
130
				return true;
131
			}
132
			catch (err) {
133
				return false;
134
			}
135
		})()
136
	}
137
138
	if (!isSupported['ecmascript6']) {
139
		$(selectorDom).append('\
140
			<div class="alert alert-danger" role="alert">\
141
				Sorry, your browser does not support the DICOM Uploader. Please use Firefox 54+, Opera 62+, Edge 17+, Safari 12+, Chrome 58+ or newer versions.\
142
			</div>\
143
		');
144
		throw 'ECMAScript6 not supported.';
145
	}
146
147
148
	if (!isSupported['webKitDirectory']) {
149
		$(selectorDom).append('\
150
			<div class="alert alert-warning" role="alert">\
151
				Be carefull, your browser does not support \'WebKitDirectory\'. Use drag and drop when importing files instead of using the browsing window. (You can also change your browser for Firefox 54+, Opera 62+, Edge 17+, Safari 12+, Chrome 58+ or newer versions)\
152
			</div>\
153
		');
154
	}
155
}
156
157
const preventDefault = function (event){
158
	event.preventDefault();
159
	event.returnValue = ''; // Needed for Chrome
160
}
161
162
/**
163
 * Set listeners on page changing and page refreshing
164
 * The user will be asked to confirm before updating the page
165
 */
166
function preventAjaxDivLoading() {
167
	// Prevent page changing
168
	window.addEventListener('beforeunload', preventDefault);
169
170
	// Prevent ajax div loading
171
	$(document).ajaxSend((evt, request, settings) => {
0 ignored issues
show
Unused Code introduced by
The parameter settings 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...
172
		request.abort();
173
		alertify.confirm('Close?', 'Your upload will be lost. Do you want to <strong>cancel the upload</strong>? </br> In that case, Click OK and redo your action.', () => {
0 ignored issues
show
Bug introduced by
The variable alertify seems to be never declared. If this is a global, consider adding a /** global: alertify */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
174
			//SK CANCEL DANS L UPLOADER?
175
			$(document).off('ajaxSend');
176
			refreshInvestigatorDiv();
177
		}, () => { });
178
	});
179
}
180
181
function allowAjaxDivLoading(){
182
	window.removeEventListener('beforeunload', preventDefault);
183
	$(document).off('ajaxSend');
184
}
185
186
187