function Customs(main) { 'use strict'; var STR_DIFFERENT = '__different__'; var that = this; this.main = main; this.$dialog = $('#dialog-customs'); this.customEnabled = null; this.currentCustoms = null; // Id of the currently shown customs dialog var $table; var $outer; var hdr; var lastHistoryTimeStamp; var $tableDateFrom; var $tableDateTo; var $tableTimeFrom; var $tableTimeTo; var $chartDateFrom; var $chartDateTo; var $chartTimeFrom; var $chartTimeTo; var $historyTableInstance; var $historyChartInstance; // ----------------------------- CUSTOMS ------------------------------------------------ this.check = function () { var found = false; for (var u = 0; u < this.main.instances.length; u++) { if (this.main.objects[this.main.instances[u]].common && (this.main.objects[this.main.instances[u]].common.type === 'storage' || this.main.objects[this.main.instances[u]].common.supportCustoms) && this.main.objects[this.main.instances[u]].common.enabled) { if (this.customEnabled !== null && this.customEnabled !== true) { this.customEnabled = true; // update customs buttons if (this.inited) { this.init(null, true); } } else { this.customEnabled = true; } found = true; return; } } if (this.customEnabled !== null && this.customEnabled !== false) { this.customEnabled = false; // update custom button if (this.inited) { this.init(null, true); } } else { this.customEnabled = false; } }; this.stateChange = function (id /*, state */) { if (this.currentCustoms === id) { updateTable(); } }; this.initCustomsTabs = function (ids, instances) { var $customTabs = this.$dialog.find('#customs-tabs'); ids = ids || []; $customTabs.html(''); var wordDifferent = _(STR_DIFFERENT); this.defaults = {}; var collapsed = this.main.config['object-customs-collapsed']; collapsed = collapsed ? collapsed.split(',') : []; var commons = {}; var type = null; var role = null; // calculate common settings for (var i = 0; i < instances.length; i++) { var inst = instances[i].replace(/^system\.adapter\./, ''); commons[inst] = {}; for (var id = 0; id < ids.length; id++) { var custom = main.objects[ids[id]].common.custom; var sett = custom ? custom[inst] : null; if (main.objects[ids[id]].common) { if (type === null) { type = main.objects[ids[id]].common.type; } else if (type !== '' && type !== main.objects[ids[id]].common.type) { type = ''; } if (role === null) { role = main.objects[ids[id]].common.role; } else if (role !== '' && role !== main.objects[ids[id]].common.role) { role = ''; } } if (sett) { for (var _attr in sett) { if (!sett.hasOwnProperty(_attr)) continue; if (commons[inst][_attr] === undefined) { commons[inst][_attr] = sett[_attr]; } else if (commons[inst][_attr] !== sett[_attr]) { commons[inst][_attr] = STR_DIFFERENT; } } } else { var a = inst.split('.')[0]; var _default = null; // Try to get default values if (defaults[a]) { if (typeof defaults[a] === 'function') { _default = defaults[a](that.main.objects[ids[id]], that.main.objects['system.adapter.' + inst]); } else { _default = defaults[a]; } } else { _default = this.defaults[a]; } for (var attr in _default) { if (!_default.hasOwnProperty(attr)) continue; if (commons[inst][attr] === undefined) { commons[inst][attr] = _default[attr]; } else if (commons[inst][attr] !== _default[attr]) { commons[inst][attr] = STR_DIFFERENT; } } } } } // add all tabs to div for (var j = 0; j < instances.length; j++) { // try to find settings var parts = instances[j].split('.'); var adapter = parts[2]; var instance = parts[3]; var data = adapter + '.' + instance; var img = this.main.objects['system.adapter.' + adapter].common.icon; img = '/adapter/' + adapter + '/' + img; var tab = '