Skip to content

Commit

Permalink
Reactivated old kind of template function
Browse files Browse the repository at this point in the history
  • Loading branch information
knowthelist committed Jan 19, 2018
1 parent 6df8181 commit 27d3345
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ See [examples](#label) of Label
- **data-set** : name of the reading to set on FHEM (\<command\> \<device\> **\<reading\>** \<value\>) (default '')
- **data-cmd** : name of the command to send to FHEM (**\<command\>** \<device\> \<reading\> \<value\>) (e.g. setstate, set, setreading, trigger) default: 'set'
- **data-value**: default value
- **class** : wider, w1x, w2x, w3x, large, big, notransmit
- **class** : wider, w1x, w2x, w3x, large, big, notransmit, autoclear, autoselect

data-device, data-get can be references (jQuery seletor) to select-widgets to change the source dynamically

Expand Down
41 changes: 32 additions & 9 deletions www/tablet/js/fhem-tablet-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* UI builder framework for FHEM
*
* Version: 2.6.37
* Version: 2.6.-37
*
* Copyright (c) 2015-2017 Mario Stephan <[email protected]>
* Under MIT License (http://www.opensource.org/licenses/mit-license.php)
Expand Down Expand Up @@ -187,6 +187,7 @@ var Modul_widget = function () {
elem.text(me.widgetname);
}

function reinit() {}

function init() {
ftui.log(1, "init widget: name=" + me.widgetname + " area=" + me.area);
Expand Down Expand Up @@ -240,6 +241,7 @@ var Modul_widget = function () {
widgetname: 'widget',
area: '',
init: init,
reinit: reinit,
init_attr: init_attr,
init_ui: init_ui,
update: update,
Expand Down Expand Up @@ -318,6 +320,15 @@ var plugins = {
ftui.log(1, 'Load plugin "' + name + '" for area "' + area + '"');
return ftui.loadPlugin(name, area);
},

reinit: function () {
$.each(this.modules, function (index, module) {
//Iterate each module and run update function if module is available
if (typeof module === 'object') {
module.reinit();
}
});
},

update: function (dev, par) {

Expand All @@ -338,7 +349,7 @@ var plugins = {

var ftui = {

version: '2.6.37',
version: '2.6.-37',
config: {
DEBUG: false,
DEMO: false,
Expand Down Expand Up @@ -703,15 +714,27 @@ var ftui = {

ftui.initGridster(area);

//convert from template to include
$('[data-template]', area).each(function (index) {
var elem = $(this);
elem.attr('data-type', 'include');
elem.attr('data-url', elem.data('template'));
elem.removeAttr('data-template');
//include extern html code
var deferredArr = $.map($('[data-template]', area), function (templ, i) {
var templElem = $(templ);
return $.get(
templElem.data('template'), {},
function (data) {
var parValues = templElem.data('parameter');
for (var key in parValues) {
data = data.replace(new RegExp(key, 'g'), parValues[key]);
}
templElem.html(data);
}
);
});

ftui.initWidgets(area);
//get current values of readings not before all widgets are loaded
$.when.apply(this, deferredArr).then(function () {
//continue after loading the includes
ftui.initWidgets(area);
ftui.log(1, 'init templates - Done');
});
},

initWidgets: function (area) {
Expand Down
2 changes: 1 addition & 1 deletion www/tablet/js/fhem-tablet-ui.min.js

Large diffs are not rendered by default.

0 comments on commit 27d3345

Please sign in to comment.