window.widget_item_form = new class { init({thresholds_colors}) { this._form = document.getElementById('widget-dialogue-form'); this._show_description = document.getElementById(`show_${}`); this._show_value = document.getElementById(`show_${}`); this._show_time = document.getElementById(`show_${}`); this._show_change_indicator = document.getElementById(`show_${}`); this._units_show = document.getElementById('units_show'); jQuery('#itemid').on('change', () => this.updateWarningIcon()); for (const colorpicker of this._form.querySelectorAll('. input')) { $(colorpicker).colorpicker({ appendTo: ".overlay-dialogue-body", use_default: !colorpicker.name.includes('thresholds'), onUpdate: ['up_color', 'down_color', 'updown_color'].includes(colorpicker.name) ? (color) => this.setIndicatorColor(colorpicker.name, color) : null }); } const show = [this._show_description, this._show_value, this._show_time, this._show_change_indicator]; for (const checkbox of show) { checkbox.addEventListener('change', (e) => { if (show.filter((checkbox) => checkbox.checked).length > 0) { this.updateForm(); } else { e.target.checked = true; } }); } this._units_show.addEventListener('change', () => this.updateForm()); colorPalette.setThemeColors(thresholds_colors); this.updateForm(); } updateForm() { for (const element of this._form.querySelectorAll('.fields-group-description')) { element.style.display = this._show_description.checked ? '' : 'none'; for (const input of element.querySelectorAll('input, textarea')) { input.disabled = !this._show_description.checked; } } for (const element of this._form.querySelectorAll('.fields-group-value')) { element.style.display = this._show_value.checked ? '' : 'none'; for (const input of element.querySelectorAll('input')) { input.disabled = !this._show_value.checked; } } for (const element of document.querySelectorAll('#units, #units_pos, #units_size, #units_bold, #units_color')) { element.disabled = !this._show_value.checked || !this._units_show.checked; } for (const element of this._form.querySelectorAll('.fields-group-time')) { element.style.display = this._show_time.checked ? '' : 'none'; for (const input of element.querySelectorAll('input')) { input.disabled = !this._show_time.checked; } } for (const element of this._form.querySelectorAll('.fields-group-change-indicator')) { element.style.display = this._show_change_indicator.checked ? '' : 'none'; for (const input of element.querySelectorAll('input')) { input.disabled = !this._show_change_indicator.checked; } } } updateWarningIcon() { const thresholds_warning = document.getElementById('item-value-thresholds-warning'); const ms_item_data = $('#itemid').multiSelect('getData'); thresholds_warning.style.display = 'none'; if (ms_item_data.length > 0) { const curl = new Curl('jsrpc.php'); curl.setArgument('method', 'item_value_type.get'); curl.setArgument('type', ); curl.setArgument('itemid', ms_item_data[0].id); fetch(curl.getUrl()) .then((response) => response.json()) .then((response) => { switch (response.result) { case '': case '': thresholds_warning.style.display = 'none'; break; default: thresholds_warning.style.display = ''; } }) .catch((exception) => { console.log('Could not get value data type of the item:', exception); }); } } setIndicatorColor(name, color) { const indicator_ids = { up_color: 'change-indicator-up', down_color: 'change-indicator-down', updown_color: 'change-indicator-updown' }; document.getElementById(indicator_ids[name]) .querySelector("polygon").style.fill = (color !== '') ? `#${color}` : ''; } };