Completed
Pull Request — master (#90)
by Janis
06:25
created

js/dist/ocrapp.js   F

Complexity

Total Complexity 147
Complexity/F 1.39

Size

Lines of Code 677
Function Count 106

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 147
dl 0
loc 677
rs 2.4195
c 0
b 0
f 0
cc 0
nc 147456
mnd 3
bc 140
fnc 106
bpm 1.3207
cpm 1.3867
noi 51

1 Function

Rating   Name   Duplication   Size   Complexity  
B ocrapp.js ➔ ?!? 0 41 1

How to fix   Complexity   

Complexity

Complex classes like js/dist/ocrapp.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
(function webpackUniversalModuleDefinition(root, factory) {
2
	if(typeof exports === 'object' && typeof module === 'object')
3
		module.exports = factory(require("underscore"), require("handlebars/runtime"), require("jQuery"));
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...
4
	else if(typeof define === 'function' && define.amd)
0 ignored issues
show
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ 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...
5
		define(["underscore", "handlebars/runtime", "jQuery"], factory);
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...
6
	else if(typeof exports === 'object')
7
		exports["Ocr"] = factory(require("underscore"), require("handlebars/runtime"), require("jQuery"));
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...
Coding Style introduced by
['Ocr'] could be written in dot notation.

You can rewrite this statement in dot notation:

var obj = { };
obj['foo'] = 'bar'; // Bad
obj.foo = 'bar'; // Good
Loading history...
8
	else
9
		root["OCA"] = root["OCA"] || {}, root["OCA"]["Ocr"] = factory(root["_"], root["Handlebars"], root["$"]);
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style introduced by
['OCA'] could be written in dot notation.

You can rewrite this statement in dot notation:

var obj = { };
obj['foo'] = 'bar'; // Bad
obj.foo = 'bar'; // Good
Loading history...
Coding Style introduced by
['Ocr'] could be written in dot notation.

You can rewrite this statement in dot notation:

var obj = { };
obj['foo'] = 'bar'; // Bad
obj.foo = 'bar'; // Good
Loading history...
Coding Style introduced by
['_'] could be written in dot notation.

You can rewrite this statement in dot notation:

var obj = { };
obj['foo'] = 'bar'; // Bad
obj.foo = 'bar'; // Good
Loading history...
Coding Style introduced by
['Handlebars'] could be written in dot notation.

You can rewrite this statement in dot notation:

var obj = { };
obj['foo'] = 'bar'; // Bad
obj.foo = 'bar'; // Good
Loading history...
Coding Style introduced by
['$'] could be written in dot notation.

You can rewrite this statement in dot notation:

var obj = { };
obj['foo'] = 'bar'; // Bad
obj.foo = 'bar'; // Good
Loading history...
Bug introduced by
Did you forget to assign or call a function?

This error message can for example pop up if you forget to assign the result of a function call to a variable or pass it to another function:

function someFunction(x) {
    (x > 0) ? callFoo() : callBar();
}

// JSHint expects you to assign the result to a variable:
function someFunction(x) {
    var rs = (x > 0) ? callFoo() : callBar();
}

// If you do not use the result, you could also use if statements in the
// case above.
function someFunction(x) {
    if (x > 0) {
        callFoo();
    } else {
        callBar();
    }
}
Loading history...
10
})(this, function(__WEBPACK_EXTERNAL_MODULE_5__, __WEBPACK_EXTERNAL_MODULE_10__, __WEBPACK_EXTERNAL_MODULE_11__) {
11
return /******/ (function(modules) { // webpackBootstrap
12
/******/ 	// The module cache
13
/******/ 	var installedModules = {};
14
15
/******/ 	// The require function
16
/******/ 	function __webpack_require__(moduleId) {
17
18
/******/ 		// Check if module is in cache
19
/******/ 		if(installedModules[moduleId])
20
/******/ 			return installedModules[moduleId].exports;
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
22
/******/ 		// Create a new module (and put it into the cache)
23
/******/ 		var module = installedModules[moduleId] = {
24
/******/ 			exports: {},
25
/******/ 			id: moduleId,
26
/******/ 			loaded: false
27
/******/ 		};
28
29
/******/ 		// Execute the module function
30
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
31
32
/******/ 		// Flag the module as loaded
33
/******/ 		module.loaded = true;
34
35
/******/ 		// Return the exports of the module
36
/******/ 		return module.exports;
37
/******/ 	}
38
39
40
/******/ 	// expose the modules object (__webpack_modules__)
41
/******/ 	__webpack_require__.m = modules;
42
43
/******/ 	// expose the module cache
44
/******/ 	__webpack_require__.c = installedModules;
45
46
/******/ 	// __webpack_public_path__
47
/******/ 	__webpack_require__.p = "";
48
49
/******/ 	// Load entry module and return exports
50
/******/ 	return __webpack_require__(0);
51
/******/ })
52
/************************************************************************/
53
/******/ ([
54
/* 0 */
55
/***/ (function(module, exports, __webpack_require__) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
56
57
	"use strict";
58
	Object.defineProperty(exports, "__esModule", { value: true });
59
	var util_1 = __webpack_require__(1);
60
	var http_service_1 = __webpack_require__(2);
61
	var oca_service_1 = __webpack_require__(3);
62
	var controller_1 = __webpack_require__(6);
63
	var view_1 = __webpack_require__(7);
64
	var configuration_1 = __webpack_require__(8);
65
	var handlebarsDropdownTemplate = __webpack_require__(9);
66
	var underscore_1 = __webpack_require__(5);
0 ignored issues
show
Unused Code introduced by
The variable underscore_1 seems to be never used. Consider removing it.
Loading history...
67
	var jquery_1 = __webpack_require__(11);
0 ignored issues
show
Unused Code introduced by
The variable jquery_1 seems to be never used. Consider removing it.
Loading history...
68
	var App = (function () {
69
	    function App() {
70
	        var _this = this;
71
	        _.delay(function () {
0 ignored issues
show
Bug introduced by
The variable _ seems to be never declared. If this is a global, consider adding a /** global: _ */ 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...
72
	            _this.config = new configuration_1.Configuration();
73
	            _this.util = new util_1.Util(_this.config);
74
	            _this.view = new view_1.View(OC.Notification, handlebarsDropdownTemplate, t, n, $, document);
0 ignored issues
show
Bug introduced by
The variable n seems to be never declared. If this is a global, consider adding a /** global: n */ 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...
Bug introduced by
The variable OC seems to be never declared. If this is a global, consider adding a /** global: OC */ 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...
Bug introduced by
The variable t seems to be never declared. If this is a global, consider adding a /** global: t */ 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...
75
	            _this.httpService = new http_service_1.HttpService(_this.util, _this.config, $);
76
	            _this.ocaService = new oca_service_1.OcaService(t, n, OC);
77
	            _this.controller = new controller_1.Controller(_this.util, _this.view, _this.httpService, _this.ocaService, t, n, document, $);
78
	            try {
79
	                _this.controller.init();
80
	            }
81
	            catch (e) {
82
	                console.error(e);
83
	                _this.view.displayError(e.message);
84
	            }
85
	        }, 1000);
86
	    }
87
	    return App;
88
	}());
89
	exports.App = App;
90
	exports.$app = new App();
91
92
93
/***/ }),
94
/* 1 */
95
/***/ (function(module, exports) {
96
97
	"use strict";
98
	Object.defineProperty(exports, "__esModule", { value: true });
99
	var Util = (function () {
100
	    function Util(config) {
101
	        this.config = config;
102
	    }
103
	    Util.prototype.filterFilesWithMimeTypes = function (files) {
104
	        var _this = this;
105
	        if (files === undefined) {
106
	            return [];
107
	        }
108
	        return files.filter(function (file) {
109
	            return _this.config.allowedMimetypes.indexOf(file.mimetype) === -1 ? false : true;
110
	        });
111
	    };
112
	    Util.prototype.shrinkFilesToReducedFiles = function (files) {
113
	        return files.map(function (file) {
114
	            return { id: file.id };
115
	        });
116
	    };
117
	    return Util;
118
	}());
119
	exports.Util = Util;
120
121
122
/***/ }),
123
/* 2 */
124
/***/ (function(module, exports) {
125
126
	"use strict";
127
	Object.defineProperty(exports, "__esModule", { value: true });
128
	var HttpService = (function () {
129
	    function HttpService(util, config, jquery) {
130
	        this.util = util;
131
	        this.config = config;
132
	        this.jquery = jquery;
133
	    }
134
	    HttpService.prototype.makeRequest = function (opts) {
135
	        return this.jquery.ajax(opts);
136
	    };
137
	    HttpService.prototype.process = function (files, languages) {
138
	        var reducedFiles = this.util.shrinkFilesToReducedFiles(files);
139
	        var options = {
140
	            data: {
141
	                files: reducedFiles,
142
	                languages: languages,
143
	            },
144
	            method: 'POST',
145
	            url: this.config.processingEndpoint,
146
	        };
147
	        return this.makeRequest(options);
148
	    };
149
	    HttpService.prototype.checkStatus = function () {
150
	        var options = {
151
	            method: 'GET',
152
	            url: this.config.statusEndpoint,
153
	        };
154
	        return this.makeRequest(options);
155
	    };
156
	    HttpService.prototype.loadAvailableLanguages = function () {
157
	        return ['deu', 'eng'];
158
	    };
159
	    return HttpService;
160
	}());
161
	exports.HttpService = HttpService;
162
163
164
/***/ }),
165
/* 3 */
166
/***/ (function(module, exports, __webpack_require__) {
167
168
	"use strict";
169
	Object.defineProperty(exports, "__esModule", { value: true });
170
	var file_poto_1 = __webpack_require__(4);
171
	var underscore_1 = __webpack_require__(5);
0 ignored issues
show
Unused Code introduced by
The variable underscore_1 seems to be never used. Consider removing it.
Loading history...
172
	var OcaService = (function () {
173
	    function OcaService(t, n, OC) {
174
	        this.t = t;
175
	        this.n = n;
176
	        this.OC = OC;
177
	    }
178
	    OcaService.prototype.destroy = function () {
179
	        OCA.Files.fileActions.clear();
0 ignored issues
show
Bug introduced by
The variable OCA seems to be never declared. If this is a global, consider adding a /** global: OCA */ 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...
180
	        OCA.Files.fileActions.registerDefaultActions();
181
	    };
182
	    OcaService.prototype.registerCheckBoxEvents = function (instance) {
183
	        OCA.Files.App.fileList.$fileList.on('change', 'td.filename>.selectCheckBox', _.bind(instance.toggleSelectedFilesActionButton, instance));
0 ignored issues
show
Bug introduced by
The variable _ seems to be never declared. If this is a global, consider adding a /** global: _ */ 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...
Bug introduced by
The variable OCA seems to be never declared. If this is a global, consider adding a /** global: OCA */ 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...
184
	        OCA.Files.App.fileList.$el.find('.select-all').click(_.bind(instance.toggleSelectedFilesActionButton, instance));
185
	        OCA.Files.App.fileList.$el.find('.delete-selected').click(_.bind(instance.hideSelectedFilesActionButton, instance));
186
	    };
187
	    OcaService.prototype.getSelectedFiles = function () {
188
	        return OCA.Files.App.fileList.getSelectedFiles();
0 ignored issues
show
Bug introduced by
The variable OCA seems to be never declared. If this is a global, consider adding a /** global: OCA */ 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...
189
	    };
190
	    OcaService.prototype.reloadFilelist = function () {
191
	        OCA.Files.App.fileList.reload();
0 ignored issues
show
Bug introduced by
The variable OCA seems to be never declared. If this is a global, consider adding a /** global: OCA */ 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...
192
	    };
193
	    OcaService.prototype.registerFileActions = function () {
194
	        OCA.Files.fileActions.registerAction({
0 ignored issues
show
Bug introduced by
The variable OCA seems to be never declared. If this is a global, consider adding a /** global: OCA */ 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...
195
	            actionHandler: this.fileActionHandler,
196
	            altText: t('ocr', 'OCR'),
197
	            displayName: t('ocr', 'OCR'),
198
	            iconClass: 'icon-ocr',
199
	            mime: 'application/pdf',
200
	            name: 'Ocr',
201
	            order: 100,
202
	            permissions: this.OC.PERMISSION_UPDATE,
203
	        });
204
	        OCA.Files.fileActions.registerAction({
205
	            actionHandler: this.fileActionHandler,
206
	            altText: t('ocr', 'OCR'),
207
	            displayName: t('ocr', 'OCR'),
208
	            iconClass: 'icon-ocr',
209
	            mime: 'image',
210
	            name: 'Ocr',
211
	            order: 100,
212
	            permissions: this.OC.PERMISSION_UPDATE,
213
	        });
214
	    };
215
	    OcaService.prototype.fileActionHandler = function (ocaFilesFileName, context) {
216
	        var file = new file_poto_1.File();
217
	        file.id = context.$file.attr('data-id');
218
	        file.mimetype = context.fileActions.getCurrentMimeType();
219
	        var files = new Array();
0 ignored issues
show
Coding Style Best Practice introduced by
Using the Array constructor is generally discouraged. Consider using an array literal instead.
Loading history...
Coding Style introduced by
The array literal notation [] is preferable.
Loading history...
220
	        files.push(file);
221
	        OCA.Ocr.$app.controller.selectedFiles = files;
0 ignored issues
show
Bug introduced by
The variable OCA seems to be never declared. If this is a global, consider adding a /** global: OCA */ 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...
222
	        OCA.Ocr.$app.view.renderFileAction(ocaFilesFileName, OCA.Ocr.$app.controller.availableLanguages);
223
	    };
224
	    return OcaService;
225
	}());
226
	exports.OcaService = OcaService;
227
228
229
/***/ }),
230
/* 4 */
231
/***/ (function(module, exports) {
232
233
	"use strict";
234
	Object.defineProperty(exports, "__esModule", { value: true });
235
	var File = (function () {
236
	    function File() {
237
	    }
238
	    Object.defineProperty(File.prototype, "id", {
239
	        get: function () {
240
	            return this._id;
241
	        },
242
	        set: function (value) {
243
	            this._id = value;
244
	        },
245
	        enumerable: true,
246
	        configurable: true
247
	    });
248
	    Object.defineProperty(File.prototype, "mimetype", {
249
	        get: function () {
250
	            return this._mimetype;
251
	        },
252
	        set: function (value) {
253
	            this._mimetype = value;
254
	        },
255
	        enumerable: true,
256
	        configurable: true
257
	    });
258
	    return File;
259
	}());
260
	exports.File = File;
261
262
263
/***/ }),
264
/* 5 */
265
/***/ (function(module, exports) {
266
267
	module.exports = __WEBPACK_EXTERNAL_MODULE_5__;
268
269
/***/ }),
270
/* 6 */
271
/***/ (function(module, exports) {
272
273
	"use strict";
274
	Object.defineProperty(exports, "__esModule", { value: true });
275
	var Controller = (function () {
276
	    function Controller(util, view, httpService, ocaService, t, n, document, jquery) {
277
	        this.util = util;
278
	        this.view = view;
279
	        this.httpService = httpService;
280
	        this.ocaService = ocaService;
281
	        this.t = t;
282
	        this.n = n;
283
	        this.document = document;
284
	        this.jquery = jquery;
285
	    }
286
	    Controller.prototype.init = function () {
287
	        this.availableLanguages = this.httpService.loadAvailableLanguages();
288
	        if (this.availableLanguages.length === 0) {
289
	            throw new Error(t('ocr', 'No languages available for OCR processing. Please make sure to setup the languages in the administration section.'));
290
	        }
291
	        this.registerEvents();
292
	        this.view.renderSelectedFilesActionButton();
293
	        this.loopForStatus();
294
	    };
295
	    Controller.prototype.destroy = function () {
296
	        this.view.destroy();
297
	        this.ocaService.destroy();
298
	    };
299
	    Controller.prototype.registerEvents = function () {
300
	        var _this = this;
301
	        this.document.addEventListener('click', function (event) {
302
	            _this.clickOnOtherEvent(event);
303
	        });
304
	        this.document.addEventListener('click', function (event) {
305
	            if (event.target.id === 'processOCR') {
306
	                _this.clickOnProcessButtonEvent();
307
	                event.preventDefault();
308
	                event.stopImmediatePropagation();
309
	            }
310
	        });
311
	        this.document.addEventListener('click', function (event) {
312
	            if (event.target.id === 'selectedFilesOCR' || event.target.parentNode.id === 'selectedFilesOCR') {
313
	                _this.clickOnTopBarSelectedFilesActionButton();
314
	                event.preventDefault();
315
	                event.stopImmediatePropagation();
316
	            }
317
	        });
318
	        this.ocaService.registerFileActions();
319
	        this.ocaService.registerCheckBoxEvents(this);
320
	    };
321
	    Controller.prototype.clickOnOtherEvent = function (event) {
322
	        if (this.view.checkClickOther(event)) {
323
	            this.selectedFiles = [];
324
	        }
325
	    };
326
	    Controller.prototype.clickOnProcessButtonEvent = function () {
327
	        var _this = this;
328
	        if (this.selectedFiles.length === 0) {
329
	            this.view.displayError(t('ocr', 'OCR processing failed:') + " " + t('ocr', 'No file(s) selected.'));
330
	            this.view.destroyDropdown();
331
	            return;
332
	        }
333
	        var filteredFiles = this.util.filterFilesWithMimeTypes(this.selectedFiles);
334
	        if (filteredFiles.length === 0) {
335
	            this.view.displayError(t('ocr', 'OCR processing failed:') + " " + t('ocr', 'Mimetype(s) not supported.'));
336
	            this.view.destroyDropdown();
337
	            return;
0 ignored issues
show
Unused Code introduced by
This return has no effect and can be removed.
Loading history...
338
	        }
339
	        else {
340
	            var selectedLanguages = this.view.getSelectTwoValues();
341
	            this.httpService.process(filteredFiles, selectedLanguages).done(function () {
342
	                _this.togglePendingState(true, filteredFiles.length);
343
	                _this.selectedFiles = [];
344
	                setTimeout(_this.jquery.proxy(_this.loopForStatus, _this), 4500);
345
	            }).fail(function (jqXHR) {
346
	                _this.view.displayError(t('ocr', 'OCR processing failed:') + " " + jqXHR.responseText);
347
	            }).always(function () {
348
	                _this.view.destroyDropdown();
349
	            });
350
	        }
351
	    };
352
	    Controller.prototype.clickOnTopBarSelectedFilesActionButton = function () {
353
	        this.view.renderFileAction(undefined, this.availableLanguages);
354
	        this.selectedFiles = this.ocaService.getSelectedFiles();
355
	    };
356
	    Controller.prototype.toggleSelectedFilesActionButton = function () {
357
	        var selFiles = this.util.filterFilesWithMimeTypes(this.ocaService.getSelectedFiles());
358
	        if (selFiles.length > 0) {
359
	            this.view.toggleSelectedFilesActionButton(true);
360
	            this.selectedFiles = selFiles;
361
	        }
362
	        else {
363
	            this.view.toggleSelectedFilesActionButton(false);
364
	            this.selectedFiles = [];
365
	        }
366
	    };
367
	    Controller.prototype.loopForStatus = function () {
368
	        var _this = this;
369
	        this.jquery.when(this.checkStatus()).done(function () {
370
	            if (_this.status.failed > 0) {
371
	                _this.view.displayError(n('ocr', 'OCR processing for %n file failed. For details please go to your personal settings.', 'OCR processing for %n files failed. For details please go to your personal settings.', _this.status.failed));
372
	            }
373
	            if (_this.status.pending > 0) {
374
	                if (_this.status.processed > 0) {
375
	                    _this.updateFileList();
376
	                }
377
	                _this.togglePendingState(false);
378
	                setTimeout(_this.jquery.proxy(_this.loopForStatus, _this), 4500);
379
	            }
380
	            else {
381
	                if (_this.status.processed > 0) {
382
	                    _this.updateFileList();
383
	                }
384
	                _this.togglePendingState(false);
385
	            }
386
	        }).fail(function (message) {
387
	            _this.view.displayError(t('ocr', 'OCR status could not be retrieved:') + " " + message);
388
	            setTimeout(_this.jquery.proxy(_this.loopForStatus, self), 4500);
0 ignored issues
show
Bug introduced by
The variable self seems to be never declared. If this is a global, consider adding a /** global: self */ 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...
389
	        });
390
	    };
391
	    Controller.prototype.updateFileList = function () {
392
	        this.ocaService.reloadFilelist();
393
	        this.toggleSelectedFilesActionButton();
394
	    };
395
	    Controller.prototype.togglePendingState = function (force, initialcount) {
396
	        this.view.togglePendingNotification(force, initialcount !== undefined ? initialcount : this.status.pending);
397
	    };
398
	    Controller.prototype.hideSelectedFilesActionButton = function () {
399
	        this.view.toggleSelectedFilesActionButton(false);
400
	        this.selectedFiles = [];
401
	    };
402
	    Controller.prototype.checkStatus = function () {
403
	        var _this = this;
404
	        var deferred = this.jquery.Deferred();
405
	        this.httpService.checkStatus().done(function (status) {
406
	            _this.status = status;
407
	            deferred.resolve(status);
408
	        }).fail(function (jqXHR) {
409
	            deferred.reject(jqXHR.responseText);
410
	        });
411
	        return deferred.promise();
412
	    };
413
	    Object.defineProperty(Controller.prototype, "status", {
414
	        get: function () {
415
	            return this._status;
416
	        },
417
	        set: function (value) {
418
	            this._status = value;
419
	        },
420
	        enumerable: true,
421
	        configurable: true
422
	    });
423
	    Object.defineProperty(Controller.prototype, "availableLanguages", {
424
	        get: function () {
425
	            return this._availableLanguages;
426
	        },
427
	        set: function (value) {
428
	            this._availableLanguages = value;
429
	        },
430
	        enumerable: true,
431
	        configurable: true
432
	    });
433
	    Object.defineProperty(Controller.prototype, "selectedFiles", {
434
	        get: function () {
435
	            return this._selectedFiles;
436
	        },
437
	        set: function (value) {
438
	            this._selectedFiles = value;
439
	        },
440
	        enumerable: true,
441
	        configurable: true
442
	    });
443
	    return Controller;
444
	}());
445
	exports.Controller = Controller;
446
447
448
/***/ }),
449
/* 7 */
450
/***/ (function(module, exports) {
451
452
	"use strict";
453
	Object.defineProperty(exports, "__esModule", { value: true });
454
	var View = (function () {
455
	    function View(notification, ocrDropdownTemplateFunction, t, n, jquery, document) {
456
	        this.notification = notification;
457
	        this.ocrDropdownTemplateFunction = ocrDropdownTemplateFunction;
458
	        this.t = t;
459
	        this.n = n;
460
	        this.jquery = jquery;
461
	        this.document = document;
462
	        this._templateOCRSelectedFileAction = "\n    <span id=\"selectedActionsOCRId\" class=\"selectedActionsOCR hidden\">\n        <a id=\"selectedFilesOCR\" href=\"\" class=\"ocr\">\n            <span class=\"icon icon-ocr\"></span>\n            <span class=\"pad-for-icon\">" + t('ocr', 'OCR') + "</span>\n        </a>\n    </span>";
463
	        this._notificationRow = undefined;
464
	    }
465
	    View.prototype.displayError = function (message) {
466
	        this.notification.showHtml("<div>" + message + "</div>", { timeout: 10, type: 'error' });
467
	    };
468
	    View.prototype.renderDropdown = function (languages) {
469
	        this.destroyDropdown();
470
	        var template = this.ocrDropdownTemplateFunction;
471
	        return template({ languages: languages, buttonText: t('ocr', 'Process') });
472
	    };
473
	    View.prototype.destroyDropdown = function () {
474
	        var dropdown = this.document.getElementById('ocrDropdown');
475
	        if (dropdown) {
476
	            this.removeElement(dropdown);
477
	        }
478
	    };
479
	    View.prototype.togglePendingNotification = function (force, count) {
480
	        var html;
481
	        if (force) {
482
	            html = "<span class=\"icon icon-loading-small ocr-row-adjustment\"></span>&nbsp;<span> " + n('ocr', 'OCR started: %n new file in queue.', 'OCR started: %n new files in queue.', count) + "</span>";
483
	        }
484
	        else {
485
	            html = "<span class=\"icon icon-loading-small ocr-row-adjustment\"></span>&nbsp;<span> " + n('ocr', 'OCR: %n currently pending file in queue.', 'OCR: %n currently pending files in queue.', count) + "</span>";
486
	        }
487
	        if (count > 0 || force) {
488
	            if (this.notificationRow !== undefined) {
489
	                this.notification.hide(this.notificationRow);
490
	            }
491
	            this.notificationRow = this.notification.showHtml(html);
492
	        }
493
	        else {
494
	            if (this.notificationRow !== undefined) {
495
	                this.notification.hide(this.notificationRow);
496
	                this.notificationRow = undefined;
497
	            }
498
	        }
499
	    };
500
	    View.prototype.toggleSelectedFilesActionButton = function (show) {
501
	        var selectedActionsOCR = this.document.getElementById('selectedActionsOCRId');
502
	        if (show) {
503
	            this.removeClass(selectedActionsOCR, 'hidden');
504
	        }
505
	        else {
506
	            this.addClass(selectedActionsOCR, 'hidden');
507
	        }
508
	    };
509
	    View.prototype.renderFileAction = function (fileName, languages) {
510
	        var html = this.renderDropdown(languages);
511
	        if (fileName !== undefined) {
512
	            var trs = [].slice.call(this.document.querySelectorAll('tr'));
513
	            var tr = trs.filter(function (element) {
514
	                return element.getAttribute('data-file') === fileName;
515
	            });
516
	            var tds = tr[0].querySelectorAll('td.filename');
517
	            this.appendHtmlToElement(html, tds);
518
	        }
519
	        else {
520
	            this.appendHtmlToElement(html, this.document.querySelectorAll('tr th.column-name'));
521
	        }
522
	        this.renderSelectTwo();
523
	    };
524
	    View.prototype.checkClickOther = function (event) {
525
	        if (!event.target.closest('#ocrDropdown')) {
526
	            this.destroyDropdown();
527
	            return true;
528
	        }
529
	        else {
530
	            return false;
531
	        }
532
	    };
533
	    View.prototype.renderSelectedFilesActionButton = function () {
534
	        this.appendHtmlToElement(this.templateOCRSelectedFileAction, this.document.getElementById('headerName-container'));
535
	    };
536
	    View.prototype.destroy = function () {
537
	        this.destroySelectedFilesActionButton();
538
	        this.destroyDropdown();
539
	    };
540
	    View.prototype.destroySelectedFilesActionButton = function () {
541
	        this.removeElement(this.document.getElementById('selectedActionsOCRId'));
542
	    };
543
	    View.prototype.getSelectTwoValues = function () {
544
	        return this.jquery('#ocrLanguage').select2('val');
545
	    };
546
	    View.prototype.renderSelectTwo = function () {
547
	        var _this = this;
0 ignored issues
show
Unused Code introduced by
The variable _this seems to be never used. Consider removing it.
Loading history...
548
	        this.jquery('#ocrLanguage').select2({
549
	            formatNoMatches: function () {
550
	                return t('ocr', 'No matches found.');
551
	            },
552
	            placeholder: t('ocr', 'Select language'),
553
	            width: 'element',
554
	        });
555
	    };
556
	    View.prototype.appendHtmlToElement = function (html, el) {
557
	        this.jquery(html).appendTo(el);
558
	    };
559
	    View.prototype.removeClass = function (el, className) {
560
	        if (el.classList) {
561
	            el.classList.remove(className);
562
	        }
563
	        else {
564
	            el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
565
	        }
566
	    };
567
	    View.prototype.addClass = function (el, className) {
568
	        if (el.classList) {
569
	            el.classList.add(className);
570
	        }
571
	        else {
572
	            el.className += ' ' + className;
573
	        }
574
	    };
575
	    View.prototype.removeElement = function (el) {
576
	        el.parentNode.removeChild(el);
577
	    };
578
	    Object.defineProperty(View.prototype, "notificationRow", {
579
	        get: function () {
580
	            return this._notificationRow;
581
	        },
582
	        set: function (value) {
583
	            this._notificationRow = value;
584
	        },
585
	        enumerable: true,
586
	        configurable: true
587
	    });
588
	    Object.defineProperty(View.prototype, "templateOCRSelectedFileAction", {
589
	        get: function () {
590
	            return this._templateOCRSelectedFileAction;
591
	        },
592
	        enumerable: true,
593
	        configurable: true
594
	    });
595
	    return View;
596
	}());
597
	exports.View = View;
598
599
600
/***/ }),
601
/* 8 */
602
/***/ (function(module, exports) {
603
604
	"use strict";
605
	Object.defineProperty(exports, "__esModule", { value: true });
606
	var Configuration = (function () {
607
	    function Configuration() {
608
	        this._statusEndpoint = OC.generateUrl('/apps/ocr/status');
0 ignored issues
show
Bug introduced by
The variable OC seems to be never declared. If this is a global, consider adding a /** global: OC */ 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...
609
	        this._processingEndpoint = OC.generateUrl('/apps/ocr');
610
	        this._allowedMimetypes = ['application/pdf', 'image/png', 'image/jpeg', 'image/tiff', 'image/jp2', 'image/jpm', 'image/jpx', 'image/webp', 'image/gif'];
611
	    }
612
	    Object.defineProperty(Configuration.prototype, "statusEndpoint", {
613
	        get: function () {
614
	            return this._statusEndpoint;
615
	        },
616
	        enumerable: true,
617
	        configurable: true
618
	    });
619
	    Object.defineProperty(Configuration.prototype, "processingEndpoint", {
620
	        get: function () {
621
	            return this._processingEndpoint;
622
	        },
623
	        enumerable: true,
624
	        configurable: true
625
	    });
626
	    Object.defineProperty(Configuration.prototype, "allowedMimetypes", {
627
	        get: function () {
628
	            return this._allowedMimetypes;
629
	        },
630
	        enumerable: true,
631
	        configurable: true
632
	    });
633
	    return Configuration;
634
	}());
635
	exports.Configuration = Configuration;
636
637
638
/***/ }),
639
/* 9 */
640
/***/ (function(module, exports, __webpack_require__) {
641
642
	var Handlebars = __webpack_require__(10);
643
	function __default(obj) { return obj && (obj.__esModule ? obj["default"] : obj); }
0 ignored issues
show
introduced by
The function __default does not seem to be used and can be removed.
Loading history...
644
	module.exports = (Handlebars["default"] || Handlebars).template({"1":function(container,depth0,helpers,partials,data) {
0 ignored issues
show
Unused Code introduced by
The parameter data 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 partials 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 helpers 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...
645
	    var alias1=container.lambda, alias2=container.escapeExpression;
646
647
	  return "                <option value=\""
648
	    + alias2(alias1(depth0, depth0))
0 ignored issues
show
Bug introduced by
There seems to be a bad line break before +.
Loading history...
649
	    + "\">"
0 ignored issues
show
Bug introduced by
There seems to be a bad line break before +.
Loading history...
650
	    + alias2(alias1(depth0, depth0))
0 ignored issues
show
Bug introduced by
There seems to be a bad line break before +.
Loading history...
651
	    + "</option>\n";
0 ignored issues
show
Bug introduced by
There seems to be a bad line break before +.
Loading history...
652
	},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
653
	    var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {});
0 ignored issues
show
Coding Style introduced by
It is recommended to use !== to compare with null.

Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator.

Read more about comparison operations.

Loading history...
654
655
	  return "<div id=\"ocrDropdown\" class=\"ocrUserInterface\">\n    <select id=\"ocrLanguage\" class=\"multiselect\" multiple=\"multiple\">\n"
656
	    + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.languages : depth0),{"name":"each","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
0 ignored issues
show
Bug introduced by
There seems to be a bad line break before +.
Loading history...
Coding Style introduced by
It is recommended to use !== to compare with null.

Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator.

Read more about comparison operations.

Loading history...
657
	    + "        </select>\n    <input type=\"button\" id=\"processOCR\" class=\"processOCRButton\" value=\""
0 ignored issues
show
Bug introduced by
There seems to be a bad line break before +.
Loading history...
658
	    + container.escapeExpression(((helper = (helper = helpers.buttonText || (depth0 != null ? depth0.buttonText : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(alias1,{"name":"buttonText","hash":{},"data":data}) : helper)))
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Bug introduced by
There seems to be a bad line break before +.
Loading history...
Coding Style introduced by
It is recommended to use !== to compare with null.

Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator.

Read more about comparison operations.

Loading history...
659
	    + "\" />\n</div>";
0 ignored issues
show
Bug introduced by
There seems to be a bad line break before +.
Loading history...
660
	},"useData":true});
661
662
/***/ }),
663
/* 10 */
664
/***/ (function(module, exports) {
665
666
	module.exports = __WEBPACK_EXTERNAL_MODULE_10__;
667
668
/***/ }),
669
/* 11 */
670
/***/ (function(module, exports) {
671
672
	module.exports = __WEBPACK_EXTERNAL_MODULE_11__;
673
674
/***/ })
675
/******/ ])
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
676
});
677
;
0 ignored issues
show
Coding Style introduced by
This semicolons seems to be unnecessary.
Loading history...