diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:47:21 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:47:21 +0000 |
commit | 1ac4a2050c8076eb96e07e83721ebc9db864db94 (patch) | |
tree | da9b32212bf99154450a7668f61a75f65617a9fa /public/js/module.js | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-toplevelview-1ac4a2050c8076eb96e07e83721ebc9db864db94.tar.xz icingaweb2-module-toplevelview-1ac4a2050c8076eb96e07e83721ebc9db864db94.zip |
Adding upstream version 0.3.3.upstream/0.3.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | public/js/module.js | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/public/js/module.js b/public/js/module.js new file mode 100644 index 0000000..49816bd --- /dev/null +++ b/public/js/module.js @@ -0,0 +1,91 @@ +;(function (Icinga) { + + var Toplevelview = function (module) { + this.module = module; + this.initialize(); + }; + + Toplevelview.prototype = { + initialize: function () { + var addCSSRule = function (sheet, selector, rules, index) { + if ('insertRule' in sheet) { + sheet.insertRule(selector + '{' + rules + '}', index); + } else if ('addRule' in sheet) { + sheet.addRule(selector, rules, index); + } else { + Icinga.module.icinga.logger.debug('Can\'t insert CSS rule'); + } + }; + + var sheet = (function () { + var style = document.createElement('style'); + // WebKit hack + style.appendChild(document.createTextNode('')); + document.head.appendChild(style); + return style.sheet; + })(); + + addCSSRule( + sheet, + '#layout.twocols.wide-layout #col1.module-toplevelview,' + + '#layout.twocols.wide-layout #col1.module-toplevelview ~ #col2', + 'width: 50%', + 0 + ); + + this.module.on('click', '.tlv-view-tree .tlv-tree-node', this.processTreeNodeClick); + this.module.on('click', 'div[href].action', this.buttonClick, this); + this.module.on('rendered', this.rendered); + }, + + rendered: function (ev) { + this.collapseOnLoad(ev); + var $container = $(ev.currentTarget); + $container.find('.codemirror').each(function (i, el) { + var mode = el.getAttribute('data-codemirror-mode'); + var editor = CodeMirror.fromTextArea(el, { + lineNumbers: true, + mode: mode + }); + // avoid entering tab chars + editor.setOption('extraKeys', { + Tab: function(cm) { + var spaces = new Array(cm.getOption('indentUnit') + 1).join(' '); + cm.replaceSelection(spaces); + }, + 'Ctrl-F': 'findPersistent' + }); + }); + }, + + processTreeNodeClick: function (event) { + event.stopPropagation(); + var $el = $(event.currentTarget); + var $parent = $el.parents('.tlv-tree-node'); + var $all = $el.find('.tlv-tree-node'); + if (($parent.length === 0 && $all.hasClass('tlv-collapsed')) || $el.hasClass('tlv-collapsed')) { + $el.removeClass('tlv-collapsed'); + $all.removeClass('tlv-collapsed'); + } else { + $el.addClass('tlv-collapsed'); + $all.addClass('tlv-collapsed'); + } + }, + + collapseOnLoad: function (event) { + var $el = $(event.currentTarget); + $el.find('.tlv-view-tree .tlv-tree-node.tlv-collapsible.ok').addClass('tlv-collapsed'); + }, + + buttonClick: function (event) { + event.stopPropagation(); + var $el = $(event.currentTarget); + var $links = $el.find('a[href]'); + if ($links.length > 0) { + $links[0].click(); + } + } + }; + + Icinga.availableModules.toplevelview = Toplevelview; +}(Icinga)); |