diff options
author | Reinis Detlavs <reinis.detlavs@zabbix.com> | 2022-04-12 11:08:00 +0300 |
---|---|---|
committer | Reinis Detlavs <reinis.detlavs@zabbix.com> | 2022-04-12 11:08:00 +0300 |
commit | 5368cec46b11f687c436ee250ae8e62782830db5 (patch) | |
tree | 7d717e4911ce31ac8720363640e2e208d934c2f8 | |
parent | 2268b2a928f55bf7f87093ba405742201e343a90 (diff) | |
parent | 21da0d506ff945a224304fb05ab206186ee8fb5f (diff) |
..F....... [DEV-1933] refactored CVisibilityBox
* commit '21da0d506ff945a224304fb05ab206186ee8fb5f':
..F....... [ZBXNEXT-7525] removed function duplicate and fixed coding style
..F....... [DEV-1933] Refactored CVisibilityBox
-rw-r--r-- | ui/app/views/js/popup.massupdate.js.php | 30 | ||||
-rw-r--r-- | ui/app/views/popup.lldoperation.php | 3 | ||||
-rw-r--r-- | ui/app/views/popup.massupdate.host.php | 3 | ||||
-rw-r--r-- | ui/app/views/popup.massupdate.item.php | 3 | ||||
-rw-r--r-- | ui/app/views/popup.massupdate.service.php | 3 | ||||
-rw-r--r-- | ui/app/views/popup.massupdate.template.php | 3 | ||||
-rw-r--r-- | ui/app/views/popup.massupdate.trigger.php | 3 | ||||
-rw-r--r-- | ui/include/classes/html/CVisibilityBox.php | 5 | ||||
-rw-r--r-- | ui/include/js.inc.php | 43 | ||||
-rw-r--r-- | ui/include/views/js/configuration.host.discovery.edit.overr.js.php | 1 | ||||
-rw-r--r-- | ui/js/common.js | 37 |
11 files changed, 39 insertions, 95 deletions
diff --git a/ui/app/views/js/popup.massupdate.js.php b/ui/app/views/js/popup.massupdate.js.php index ec1cb547f4c..393148ad94e 100644 --- a/ui/app/views/js/popup.massupdate.js.php +++ b/ui/app/views/js/popup.massupdate.js.php @@ -357,36 +357,6 @@ $('#tabs').on('tabsactivate', (event, ui) => { toggleVisible(obj, obj.querySelector('[name=valuemap_massupdate]:checked').value); })(); -function visibility_status_changeds(value, obj_id, replace_to) { - const obj = document.getElementById(obj_id); - if (obj === null) { - throw `Cannot find objects with name [${obj_id}]`; - } - - if (replace_to && replace_to != '') { - if (obj.originalObject) { - const old_obj = obj.originalObject; - old_obj.originalObject = obj; - obj.parentNode.replaceChild(old_obj, obj); - } - else if (!value) { - const new_obj = document.createElement('span'); - new_obj.setAttribute('name', obj.name); - new_obj.setAttribute('id', obj.id); - - new_obj.innerHTML = replace_to; - new_obj.originalObject = obj; - obj.parentNode.replaceChild(new_obj, obj); - } - else { - throw 'Missing originalObject for restoring'; - } - } - else { - obj.style.visibility = value ? 'visible' : 'hidden'; - } -} - if (!CR && !GK) { $("textarea[maxlength]").bind("paste contextmenu change keydown keypress keyup", function() { var elem = $(this); diff --git a/ui/app/views/popup.lldoperation.php b/ui/app/views/popup.lldoperation.php index 054a3769adb..312cbe42439 100644 --- a/ui/app/views/popup.lldoperation.php +++ b/ui/app/views/popup.lldoperation.php @@ -23,9 +23,6 @@ * @var CView $this */ -// Visibility box javascript is already added in main page. It should not be added in popup response. -define('CVISIBILITYBOX_JAVASCRIPT_INSERTED', 1); - $output = [ 'header' => $data['title'] ]; diff --git a/ui/app/views/popup.massupdate.host.php b/ui/app/views/popup.massupdate.host.php index 321ad09e26b..0a7fe333594 100644 --- a/ui/app/views/popup.massupdate.host.php +++ b/ui/app/views/popup.massupdate.host.php @@ -23,9 +23,6 @@ * @var CView $this */ -// Visibility box javascript is already added. It should not be added in popup response. -define('CVISIBILITYBOX_JAVASCRIPT_INSERTED', 1); - // create form $form = (new CForm()) ->setId('massupdate-form') diff --git a/ui/app/views/popup.massupdate.item.php b/ui/app/views/popup.massupdate.item.php index 60dab355873..e850ed410dc 100644 --- a/ui/app/views/popup.massupdate.item.php +++ b/ui/app/views/popup.massupdate.item.php @@ -23,9 +23,6 @@ * @var CView $this */ -// Visibility box javascript is already added. It should not be added in popup response. -define('CVISIBILITYBOX_JAVASCRIPT_INSERTED', 1); - // Create form. $form = (new CForm()) ->setId('massupdate-form') diff --git a/ui/app/views/popup.massupdate.service.php b/ui/app/views/popup.massupdate.service.php index e67314bec37..c2b4a30d270 100644 --- a/ui/app/views/popup.massupdate.service.php +++ b/ui/app/views/popup.massupdate.service.php @@ -23,9 +23,6 @@ * @var CView $this */ -// Visibility box javascript is already added. It should not be added in popup response. -define('CVISIBILITYBOX_JAVASCRIPT_INSERTED', 1); - // create form $form = (new CForm()) ->setId('massupdate-form') diff --git a/ui/app/views/popup.massupdate.template.php b/ui/app/views/popup.massupdate.template.php index c03c4262d07..9f426a725c3 100644 --- a/ui/app/views/popup.massupdate.template.php +++ b/ui/app/views/popup.massupdate.template.php @@ -23,9 +23,6 @@ * @var CView $this */ -// Visibility box javascript is already added. It should not be added in popup response. -define('CVISIBILITYBOX_JAVASCRIPT_INSERTED', 1); - // Create form. $form = (new CForm()) ->setId('massupdate-form') diff --git a/ui/app/views/popup.massupdate.trigger.php b/ui/app/views/popup.massupdate.trigger.php index 4bed8a3afaf..e320f350496 100644 --- a/ui/app/views/popup.massupdate.trigger.php +++ b/ui/app/views/popup.massupdate.trigger.php @@ -23,9 +23,6 @@ * @var CView $this */ -// Visibility box javascript is already added. It should not be added in popup response. -define('CVISIBILITYBOX_JAVASCRIPT_INSERTED', 1); - // Create form. $form = (new CForm()) ->setId('massupdate-form') diff --git a/ui/include/classes/html/CVisibilityBox.php b/ui/include/classes/html/CVisibilityBox.php index 9e1af6b7453..15ab93e5e90 100644 --- a/ui/include/classes/html/CVisibilityBox.php +++ b/ui/include/classes/html/CVisibilityBox.php @@ -26,9 +26,8 @@ class CVisibilityBox extends CCheckBox { $this->replace_to = unpack_object($replace_to); parent::__construct($name); - $this->onClick('visibility_status_changeds(this.checked, '.zbx_jsvalue($this->object_id).', '. + $this->onClick('visibilityStatusChanges(this.checked, '.zbx_jsvalue($this->object_id).', '. zbx_jsvalue($this->replace_to).');'); - insert_javascript_for_visibilitybox(); } /** @@ -47,7 +46,7 @@ class CVisibilityBox extends CCheckBox { public function toString($destroy = true) { if (!isset($this->attributes['checked'])) { - zbx_add_post_js('visibility_status_changeds(false, '.zbx_jsvalue($this->object_id).', '. + zbx_add_post_js('visibilityStatusChanges(false, '.zbx_jsvalue($this->object_id).', '. zbx_jsvalue($this->replace_to).');'); } diff --git a/ui/include/js.inc.php b/ui/include/js.inc.php index 76aa7cffc32..2ed91c094a2 100644 --- a/ui/include/js.inc.php +++ b/ui/include/js.inc.php @@ -75,49 +75,6 @@ function zbx_jsvalue($value, $as_object = false, $addQuotes = true) { return $is_object ? '{'.implode(',', $value).'}' : '['.implode(',', $value).']'; } -function insert_javascript_for_visibilitybox() { - if (defined('CVISIBILITYBOX_JAVASCRIPT_INSERTED')) { - return null; - } - define('CVISIBILITYBOX_JAVASCRIPT_INSERTED', 1); - - $js = ' - function visibility_status_changeds(value, obj_id, replace_to) { - var obj = document.getElementById(obj_id); - if (is_null(obj)) { - throw "Cannot find objects with name [" + obj_id +"]"; - } - - if (replace_to && replace_to != "") { - if (obj.originalObject) { - var old_obj = obj.originalObject; - old_obj.originalObject = obj; - obj.parentNode.replaceChild(old_obj, obj); - } - else if (!value) { - try { - var new_obj = document.createElement("span"); - new_obj.setAttribute("name", obj.name); - new_obj.setAttribute("id", obj.id); - } - catch(e) { - throw "Cannot create new element"; - } - new_obj.innerHTML = replace_to; - new_obj.originalObject = obj; - obj.parentNode.replaceChild(new_obj, obj); - } - else { - throw "Missing originalObject for restoring"; - } - } - else { - obj.style.visibility = value ? "visible" : "hidden"; - } - }'; - insert_js($js); -} - function insert_js($script, $jQueryDocumentReady = false) { echo get_js($script, $jQueryDocumentReady); } diff --git a/ui/include/views/js/configuration.host.discovery.edit.overr.js.php b/ui/include/views/js/configuration.host.discovery.edit.overr.js.php index 0d37346ebaa..20b2d831a8f 100644 --- a/ui/include/views/js/configuration.host.discovery.edit.overr.js.php +++ b/ui/include/views/js/configuration.host.discovery.edit.overr.js.php @@ -22,7 +22,6 @@ /** * @var CView $this */ -insert_javascript_for_visibilitybox(); ?> <script type="text/x-jquery-tmpl" id="lldoverride-row-templated"> <?= (new CRow([ diff --git a/ui/js/common.js b/ui/js/common.js index 715010914f0..367cd988cbc 100644 --- a/ui/js/common.js +++ b/ui/js/common.js @@ -1032,6 +1032,43 @@ function openMassupdatePopup(action, parameters = {}, { } /** + * @param {boolean} value + * @param {string} objectid + * @param {string} replace_to + */ +function visibilityStatusChanges(value, objectid, replace_to) { + const obj = document.getElementById(objectid); + + if (obj === null) { + throw `Cannot find objects with name [${objectid}]`; + } + + if (replace_to && replace_to != '') { + if (obj.originalObject) { + const old_obj = obj.originalObject; + old_obj.originalObject = obj; + + obj.parentNode.replaceChild(old_obj, obj); + } + else if (!value) { + const new_obj = document.createElement('span'); + new_obj.setAttribute('name', obj.name); + new_obj.setAttribute('id', obj.id); + new_obj.innerHTML = replace_to; + new_obj.originalObject = obj; + + obj.parentNode.replaceChild(new_obj, obj); + } + else { + throw 'Missing originalObject for restoring'; + } + } + else { + obj.style.visibility = value ? 'visible' : 'hidden'; + } +} + +/** * Clears session storage from markers of checked table rows. * Or keeps only accessible IDs in the list of checked rows. * |