Completed
Pull Request — master (#5)
by Ronan
07:31
created

src/Resources/public/js/Json/Renderer/SelectFromUrl.js   A

Complexity

Total Complexity 8
Complexity/F 1.33

Size

Lines of Code 78
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 32
dl 0
loc 78
rs 10
c 1
b 0
f 0
cc 0
nc 2
mnd 1
bc 7
fnc 6
bpm 1.1666
cpm 1.3333
noi 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A SelectFromUrl.js ➔ define 0 72 1
1
define(
2
    [
3
        'flagbit/JsonGenerator/Observer',
4
        'oro/translator',
5
    ],
6
    function(JsonGeneratorObserver, __) {
7
8
        /**
9
         * @class
10
         * @param {Boolean} $editable
11
         * @param {HTMLElement} $container
12
         */
13
        var JsonGeneratorRendererSelectFromUrl = function($editable, $container) {
14
15
            /**
16
             * @public
17
             * @type {JsonGeneratorObserver}
18
             */
19
            this.observer = new JsonGeneratorObserver();
20
21
            /**
22
             * @public
23
             * @param {Object} $data
24
             */
25
            this.render = function($data) {
26
27
                var $label = document.createElement('label');
28
                $label.innerText = __('flagbit_attribute_table_simpleselect_options_url_label');
29
                var $input = document.createElement('input');
30
                $input.type = 'text';
31
                $input.className = 'AknTextField';
32
                $input.name = 'options_url';
33
                $input.value = $data['options_url'] ? $data['options_url'] : '';
34
                if(!$editable) {
35
                    $input.disabled = true;
36
                }
37
                observeChanges($input);
38
39
                $container.appendChild($label);
40
                $container.appendChild($input);
41
            };
42
43
44
            /**
45
             * @public
46
             * @returns {Object}
47
             */
48
            this.read = function() {
49
50
                var $data = {};
51
52
                $data['options_url'] = $container.querySelector('input[name="options_url"]').value;
53
54
                return $data;
55
            };
56
57
            /**
58
             * @protected
59
             * @param {HTMLInputElement} $input
60
             */
61
            var observeChanges = function($input) {
62
                $input.addEventListener('keyup', notify);
63
                $input.addEventListener('blur', notify);
64
            }.bind(this);
0 ignored issues
show
unused-code introduced by
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
65
66
67
            /**
68
             * @protected
69
             */
70
            var notify = function() {
71
72
                this.observer.notify('update');
73
            }.bind(this);
74
        };
75
76
        return JsonGeneratorRendererSelectFromUrl;
77
    }
78
);
79