-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
185 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
We are using selectID.js (iobroker/node_modules/iobroker.admin/www/lib/js/selectID.js). | ||
|
||
|
||
/**********initSelectId ## How to use | ||
<!-- Somewhere in HTML --> | ||
<div id="dialog-select-member" style="display: none"></div> | ||
|
||
// In Javascript | ||
// Name "dialog-select-member" is important, because for that exist the CSS classes | ||
// Important to have "admin/img/info-big.png" in too, because this icon will be loaded if no icon found, elsewise we have endless loop | ||
let selectId; | ||
function initSelectId (cb) { | ||
if (selectId) return cb ? cb(selectId) : selectId; | ||
socket.emit('getObjects', function (err, res) { | ||
if (!err && res) { | ||
selectId = $('#dialog-select-member').selectId('init', { | ||
noMultiselect: true, | ||
objects: res, | ||
imgPath: '../../lib/css/fancytree/', | ||
filter: {type: 'state'}, | ||
name: 'adapter-select-state', | ||
texts: { | ||
select: _('Select'), | ||
cancel: _('Cancel'), | ||
all: _('All'), | ||
id: _('ID'), | ||
name: _('Name'), | ||
role: _('Role'), | ||
room: _('Room'), | ||
value: _('Value'), | ||
selectid: _('Select ID'), | ||
from: _('From'), | ||
lc: _('Last changed'), | ||
ts: _('Time stamp'), | ||
wait: _('Processing...'), | ||
ack: _('Acknowledged'), | ||
selectAll: _('Select all'), | ||
unselectAll: _('Deselect all'), | ||
invertSelection: _('Invert selection') | ||
}, | ||
columns: ['image', 'name', 'role', 'room', 'value'] | ||
}); | ||
cb && cb(selectId); | ||
} | ||
}); | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// This will be called by the admin adapter when the settings page loads | ||
function load(settings, onChange) { | ||
// example: select elements with id=key and class=value and insert value | ||
if (!settings) return; | ||
$('.value').each(function () { | ||
var $key = $(this); | ||
var id = $key.attr('id'); | ||
if ($key.attr('type') === 'checkbox') { | ||
// do not call onChange direct, because onChange could expect some arguments | ||
$key.prop('checked', settings[id]) | ||
.on('change', () => onChange()) | ||
; | ||
} else { | ||
// do not call onChange direct, because onChange could expect some arguments | ||
$key.val(settings[id]) | ||
.on('change', () => onChange()) | ||
.on('keyup', () => onChange()) | ||
; | ||
} | ||
}); | ||
|
||
$('#StateHomeSolarPowerPopUp').on('click', function () { | ||
initSelectId(function (sid) { | ||
sid.selectId('show', $('#StateHomeSolarPower').val(), function (newId) { | ||
if (newId) { | ||
$('#StateHomeSolarPower').val(newId).trigger('change'); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
$('#StateHomeBatSocPopUp').on('click', function () { | ||
initSelectId(function (sid) { | ||
sid.selectId('show', $('#StateHomeBatSoc').val(), function (newId) { | ||
if (newId) { | ||
$('#StateHomeBatSoc').val(newId).trigger('change'); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
$('#StateHomePowerConsumptionPopUp').on('click', function () { | ||
initSelectId(function (sid) { | ||
sid.selectId('show', $('#StateHomePowerConsumption').val(), function (newId) { | ||
if (newId) { | ||
$('#StateHomePowerConsumption').val(newId).trigger('change'); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
onChange(false); | ||
// reinitialize all the Materialize labels on the page if you are dynamically adding inputs: | ||
if (M) M.updateTextFields(); | ||
} | ||
|
||
|
||
// This will be called by the admin adapter when the user presses the save button | ||
function save(callback) { | ||
// example: select elements with class=value and build settings object | ||
var obj = { }; | ||
$('.value').each(function () { | ||
var $this = $(this); | ||
if ($this.attr('type') === 'checkbox') { | ||
obj[$this.attr('id')] = $this.prop('checked'); | ||
} else { | ||
obj[$this.attr('id')] = $this.val(); | ||
} | ||
}); | ||
callback(obj); | ||
} | ||
|
||
|
||
let selectId; | ||
function initSelectId(callback) { | ||
if (selectId) return callback(selectId); | ||
socket.emit('getObjects', function (err, objs) { | ||
if (!err && objs) { | ||
selectId = $('#dialog-select-member').selectId('init', { | ||
noMultiselect: true, | ||
objects: objs, | ||
imgPath: '../../lib/css/fancytree/', | ||
filter: { type: 'state' }, | ||
name: 'adapter-select-state', | ||
texts: { | ||
select: _('Select'), | ||
cancel: _('Cancel'), | ||
all: _('All'), | ||
id: _('ID'), | ||
name: _('Name'), | ||
role: _('Role'), | ||
room: _('Room'), | ||
value: _('Value'), | ||
selectid: _('Select ID'), | ||
from: _('From'), | ||
lc: _('Last changed'), | ||
ts: _('Time stamp'), | ||
wait: _('Processing...'), | ||
ack: _('Acknowledged'), | ||
selectAll: _('Select all'), | ||
unselectAll: _('Deselect all'), | ||
invertSelection: _('Invert selection') | ||
}, | ||
columns: ['image', 'name', 'role'] | ||
}); | ||
callback(selectId); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters