Total Complexity | 8 |
Complexity/F | 1.33 |
Lines of Code | 78 |
Function Count | 6 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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); |
||
|
|||
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 |