pull/78/head
Jim Heising 2014-09-29 11:51:00 -07:00
parent b6ac25061f
commit fdc3464710
6 changed files with 108 additions and 184 deletions

View File

@ -1930,10 +1930,15 @@ ValueEditor = function(theFreeboardModel)
}
}).focus(function()
{
$(element).css({"z-index" : 3001});
_resizeValueEditor(element);
}).focusout(function()
{
$(element).css({height: ""});
$(element).css({
"height": "",
"z-index" : 3000
});
$(element).next("ul#value-selector").remove();
dropdown = null;
selectedOptionIndex = -1;
@ -1993,14 +1998,10 @@ ValueEditor = function(theFreeboardModel)
}
}
function WidgetModel(theFreeboardModel, widgetPlugins)
{
function disposeWidgetInstance()
{
if(!_.isUndefined(self.widgetInstance))
{
if(_.isFunction(self.widgetInstance.onDispose))
{
function WidgetModel(theFreeboardModel, widgetPlugins) {
function disposeWidgetInstance() {
if (!_.isUndefined(self.widgetInstance)) {
if (_.isFunction(self.widgetInstance.onDispose)) {
self.widgetInstance.onDispose();
}
@ -2017,18 +2018,14 @@ function WidgetModel(theFreeboardModel, widgetPlugins)
this.fillSize = ko.observable(false);
this.type = ko.observable();
this.type.subscribe(function(newValue)
{
this.type.subscribe(function (newValue) {
disposeWidgetInstance();
if((newValue in widgetPlugins) && _.isFunction(widgetPlugins[newValue].newInstance))
{
if ((newValue in widgetPlugins) && _.isFunction(widgetPlugins[newValue].newInstance)) {
var widgetType = widgetPlugins[newValue];
function finishLoad()
{
widgetType.newInstance(self.settings(), function(widgetInstance)
{
function finishLoad() {
widgetType.newInstance(self.settings(), function (widgetInstance) {
self.fillSize((widgetType.fill_size === true));
self.widgetInstance = widgetInstance;
@ -2039,22 +2036,18 @@ function WidgetModel(theFreeboardModel, widgetPlugins)
}
// Do we need to load any external scripts?
if(widgetType.external_scripts)
{
if (widgetType.external_scripts) {
head.js(widgetType.external_scripts.slice(0), finishLoad); // Need to clone the array because head.js adds some weird functions to it
}
else
{
else {
finishLoad();
}
}
});
this.settings = ko.observable({});
this.settings.subscribe(function(newValue)
{
if(!_.isUndefined(self.widgetInstance) && _.isFunction(self.widgetInstance.onSettingsChanged))
{
this.settings.subscribe(function (newValue) {
if (!_.isUndefined(self.widgetInstance) && _.isFunction(self.widgetInstance.onSettingsChanged)) {
self.widgetInstance.onSettingsChanged(newValue);
}
@ -2062,74 +2055,58 @@ function WidgetModel(theFreeboardModel, widgetPlugins)
self._heightUpdate.valueHasMutated();
});
this.processDatasourceUpdate = function(datasourceName)
{
this.processDatasourceUpdate = function (datasourceName) {
var refreshSettingNames = self.datasourceRefreshNotifications[datasourceName];
if(_.isArray(refreshSettingNames))
{
_.each(refreshSettingNames, function(settingName)
{
if (_.isArray(refreshSettingNames)) {
_.each(refreshSettingNames, function (settingName) {
self.processCalculatedSetting(settingName);
});
}
}
this.callValueFunction = function(theFunction)
{
this.callValueFunction = function (theFunction) {
return theFunction.call(undefined, theFreeboardModel.datasourceData);
}
this.processSizeChange = function()
{
if(!_.isUndefined(self.widgetInstance) && _.isFunction(self.widgetInstance.onSizeChanged))
{
this.processSizeChange = function () {
if (!_.isUndefined(self.widgetInstance) && _.isFunction(self.widgetInstance.onSizeChanged)) {
self.widgetInstance.onSizeChanged();
}
}
this.processCalculatedSetting = function(settingName)
{
if(_.isFunction(self.calculatedSettingScripts[settingName]))
{
this.processCalculatedSetting = function (settingName) {
if (_.isFunction(self.calculatedSettingScripts[settingName])) {
var returnValue = undefined;
try
{
try {
returnValue = self.callValueFunction(self.calculatedSettingScripts[settingName]);
}
catch(e)
{
catch (e) {
var rawValue = self.settings()[settingName];
// If there is a reference error and the value just contains letters and numbers, then
if(e instanceof ReferenceError && (/^\w+$/).test(rawValue))
{
if (e instanceof ReferenceError && (/^\w+$/).test(rawValue)) {
returnValue = rawValue;
}
}
if(!_.isUndefined(self.widgetInstance) && _.isFunction(self.widgetInstance.onCalculatedValueChanged) && !_.isUndefined(returnValue))
{
try
{
if (!_.isUndefined(self.widgetInstance) && _.isFunction(self.widgetInstance.onCalculatedValueChanged) && !_.isUndefined(returnValue)) {
try {
self.widgetInstance.onCalculatedValueChanged(settingName, returnValue);
}
catch(e)
{
catch (e) {
console.log(e.toString());
}
}
}
}
this.updateCalculatedSettings = function()
{
this.updateCalculatedSettings = function () {
self.datasourceRefreshNotifications = {};
self.calculatedSettingScripts = {};
if(_.isUndefined(self.type()))
{
if (_.isUndefined(self.type())) {
return;
}
@ -2138,28 +2115,22 @@ function WidgetModel(theFreeboardModel, widgetPlugins)
var datasourceRegex = new RegExp("datasources.([\\w_-]+)|datasources\\[['\"]([^'\"]+)", "g");
var currentSettings = self.settings();
_.each(settingsDefs, function(settingDef)
{
if(settingDef.type == "calculated")
{
_.each(settingsDefs, function (settingDef) {
if (settingDef.type == "calculated") {
var script = currentSettings[settingDef.name];
if(!_.isUndefined(script))
{
if (!_.isUndefined(script)) {
// If there is no return, add one
if((script.match(/;/g) || []).length <= 1 && script.indexOf("return") == -1)
{
if ((script.match(/;/g) || []).length <= 1 && script.indexOf("return") == -1) {
script = "return " + script;
}
var valueFunction;
try
{
try {
valueFunction = new Function("datasources", script);
}
catch(e)
{
catch (e) {
var literalText = currentSettings[settingDef.name].replace(/"/g, '\\"').replace(/[\r\n]/g, ' \\\n');
// If the value function cannot be created, then go ahead and treat it as literal text
@ -2172,13 +2143,11 @@ function WidgetModel(theFreeboardModel, widgetPlugins)
// Are there any datasources we need to be subscribed to?
var matches;
while(matches = datasourceRegex.exec(script))
{
var dsName = (matches[1] || matches[2]);
while (matches = datasourceRegex.exec(script)) {
var dsName = (matches[1] || matches[2]);
var refreshSettingNames = self.datasourceRefreshNotifications[dsName];
if(_.isUndefined(refreshSettingNames))
{
if (_.isUndefined(refreshSettingNames)) {
refreshSettingNames = [];
self.datasourceRefreshNotifications[dsName] = refreshSettingNames;
}
@ -2192,12 +2161,10 @@ function WidgetModel(theFreeboardModel, widgetPlugins)
this._heightUpdate = ko.observable();
this.height = ko.computed({
read: function()
{
read: function () {
self._heightUpdate();
if(!_.isUndefined(self.widgetInstance) && _.isFunction(self.widgetInstance.getHeight))
{
if (!_.isUndefined(self.widgetInstance) && _.isFunction(self.widgetInstance.getHeight)) {
return self.widgetInstance.getHeight();
}
@ -2206,32 +2173,27 @@ function WidgetModel(theFreeboardModel, widgetPlugins)
});
this.shouldRender = ko.observable(false);
this.render = function(element)
{
this.render = function (element) {
self.shouldRender(false);
if(!_.isUndefined(self.widgetInstance) && _.isFunction(self.widgetInstance.render))
{
if (!_.isUndefined(self.widgetInstance) && _.isFunction(self.widgetInstance.render)) {
self.widgetInstance.render(element);
self.updateCalculatedSettings();
}
}
this.dispose = function()
{
this.dispose = function () {
}
this.serialize = function()
{
this.serialize = function () {
return {
title : self.title(),
type : self.type(),
title: self.title(),
type: self.type(),
settings: self.settings()
};
}
this.deserialize = function(object)
{
this.deserialize = function (object) {
self.title(object.title);
self.settings(object.settings);
self.type(object.type);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1930,10 +1930,15 @@ ValueEditor = function(theFreeboardModel)
}
}).focus(function()
{
$(element).css({"z-index" : 3001});
_resizeValueEditor(element);
}).focusout(function()
{
$(element).css({height: ""});
$(element).css({
"height": "",
"z-index" : 3000
});
$(element).next("ul#value-selector").remove();
dropdown = null;
selectedOptionIndex = -1;
@ -1993,14 +1998,10 @@ ValueEditor = function(theFreeboardModel)
}
}
function WidgetModel(theFreeboardModel, widgetPlugins)
{
function disposeWidgetInstance()
{
if(!_.isUndefined(self.widgetInstance))
{
if(_.isFunction(self.widgetInstance.onDispose))
{
function WidgetModel(theFreeboardModel, widgetPlugins) {
function disposeWidgetInstance() {
if (!_.isUndefined(self.widgetInstance)) {
if (_.isFunction(self.widgetInstance.onDispose)) {
self.widgetInstance.onDispose();
}
@ -2017,18 +2018,14 @@ function WidgetModel(theFreeboardModel, widgetPlugins)
this.fillSize = ko.observable(false);
this.type = ko.observable();
this.type.subscribe(function(newValue)
{
this.type.subscribe(function (newValue) {
disposeWidgetInstance();
if((newValue in widgetPlugins) && _.isFunction(widgetPlugins[newValue].newInstance))
{
if ((newValue in widgetPlugins) && _.isFunction(widgetPlugins[newValue].newInstance)) {
var widgetType = widgetPlugins[newValue];
function finishLoad()
{
widgetType.newInstance(self.settings(), function(widgetInstance)
{
function finishLoad() {
widgetType.newInstance(self.settings(), function (widgetInstance) {
self.fillSize((widgetType.fill_size === true));
self.widgetInstance = widgetInstance;
@ -2039,22 +2036,18 @@ function WidgetModel(theFreeboardModel, widgetPlugins)
}
// Do we need to load any external scripts?
if(widgetType.external_scripts)
{
if (widgetType.external_scripts) {
head.js(widgetType.external_scripts.slice(0), finishLoad); // Need to clone the array because head.js adds some weird functions to it
}
else
{
else {
finishLoad();
}
}
});
this.settings = ko.observable({});
this.settings.subscribe(function(newValue)
{
if(!_.isUndefined(self.widgetInstance) && _.isFunction(self.widgetInstance.onSettingsChanged))
{
this.settings.subscribe(function (newValue) {
if (!_.isUndefined(self.widgetInstance) && _.isFunction(self.widgetInstance.onSettingsChanged)) {
self.widgetInstance.onSettingsChanged(newValue);
}
@ -2062,74 +2055,58 @@ function WidgetModel(theFreeboardModel, widgetPlugins)
self._heightUpdate.valueHasMutated();
});
this.processDatasourceUpdate = function(datasourceName)
{
this.processDatasourceUpdate = function (datasourceName) {
var refreshSettingNames = self.datasourceRefreshNotifications[datasourceName];
if(_.isArray(refreshSettingNames))
{
_.each(refreshSettingNames, function(settingName)
{
if (_.isArray(refreshSettingNames)) {
_.each(refreshSettingNames, function (settingName) {
self.processCalculatedSetting(settingName);
});
}
}
this.callValueFunction = function(theFunction)
{
this.callValueFunction = function (theFunction) {
return theFunction.call(undefined, theFreeboardModel.datasourceData);
}
this.processSizeChange = function()
{
if(!_.isUndefined(self.widgetInstance) && _.isFunction(self.widgetInstance.onSizeChanged))
{
this.processSizeChange = function () {
if (!_.isUndefined(self.widgetInstance) && _.isFunction(self.widgetInstance.onSizeChanged)) {
self.widgetInstance.onSizeChanged();
}
}
this.processCalculatedSetting = function(settingName)
{
if(_.isFunction(self.calculatedSettingScripts[settingName]))
{
this.processCalculatedSetting = function (settingName) {
if (_.isFunction(self.calculatedSettingScripts[settingName])) {
var returnValue = undefined;
try
{
try {
returnValue = self.callValueFunction(self.calculatedSettingScripts[settingName]);
}
catch(e)
{
catch (e) {
var rawValue = self.settings()[settingName];
// If there is a reference error and the value just contains letters and numbers, then
if(e instanceof ReferenceError && (/^\w+$/).test(rawValue))
{
if (e instanceof ReferenceError && (/^\w+$/).test(rawValue)) {
returnValue = rawValue;
}
}
if(!_.isUndefined(self.widgetInstance) && _.isFunction(self.widgetInstance.onCalculatedValueChanged) && !_.isUndefined(returnValue))
{
try
{
if (!_.isUndefined(self.widgetInstance) && _.isFunction(self.widgetInstance.onCalculatedValueChanged) && !_.isUndefined(returnValue)) {
try {
self.widgetInstance.onCalculatedValueChanged(settingName, returnValue);
}
catch(e)
{
catch (e) {
console.log(e.toString());
}
}
}
}
this.updateCalculatedSettings = function()
{
this.updateCalculatedSettings = function () {
self.datasourceRefreshNotifications = {};
self.calculatedSettingScripts = {};
if(_.isUndefined(self.type()))
{
if (_.isUndefined(self.type())) {
return;
}
@ -2138,28 +2115,22 @@ function WidgetModel(theFreeboardModel, widgetPlugins)
var datasourceRegex = new RegExp("datasources.([\\w_-]+)|datasources\\[['\"]([^'\"]+)", "g");
var currentSettings = self.settings();
_.each(settingsDefs, function(settingDef)
{
if(settingDef.type == "calculated")
{
_.each(settingsDefs, function (settingDef) {
if (settingDef.type == "calculated") {
var script = currentSettings[settingDef.name];
if(!_.isUndefined(script))
{
if (!_.isUndefined(script)) {
// If there is no return, add one
if((script.match(/;/g) || []).length <= 1 && script.indexOf("return") == -1)
{
if ((script.match(/;/g) || []).length <= 1 && script.indexOf("return") == -1) {
script = "return " + script;
}
var valueFunction;
try
{
try {
valueFunction = new Function("datasources", script);
}
catch(e)
{
catch (e) {
var literalText = currentSettings[settingDef.name].replace(/"/g, '\\"').replace(/[\r\n]/g, ' \\\n');
// If the value function cannot be created, then go ahead and treat it as literal text
@ -2172,13 +2143,11 @@ function WidgetModel(theFreeboardModel, widgetPlugins)
// Are there any datasources we need to be subscribed to?
var matches;
while(matches = datasourceRegex.exec(script))
{
var dsName = (matches[1] || matches[2]);
while (matches = datasourceRegex.exec(script)) {
var dsName = (matches[1] || matches[2]);
var refreshSettingNames = self.datasourceRefreshNotifications[dsName];
if(_.isUndefined(refreshSettingNames))
{
if (_.isUndefined(refreshSettingNames)) {
refreshSettingNames = [];
self.datasourceRefreshNotifications[dsName] = refreshSettingNames;
}
@ -2192,12 +2161,10 @@ function WidgetModel(theFreeboardModel, widgetPlugins)
this._heightUpdate = ko.observable();
this.height = ko.computed({
read: function()
{
read: function () {
self._heightUpdate();
if(!_.isUndefined(self.widgetInstance) && _.isFunction(self.widgetInstance.getHeight))
{
if (!_.isUndefined(self.widgetInstance) && _.isFunction(self.widgetInstance.getHeight)) {
return self.widgetInstance.getHeight();
}
@ -2206,32 +2173,27 @@ function WidgetModel(theFreeboardModel, widgetPlugins)
});
this.shouldRender = ko.observable(false);
this.render = function(element)
{
this.render = function (element) {
self.shouldRender(false);
if(!_.isUndefined(self.widgetInstance) && _.isFunction(self.widgetInstance.render))
{
if (!_.isUndefined(self.widgetInstance) && _.isFunction(self.widgetInstance.render)) {
self.widgetInstance.render(element);
self.updateCalculatedSettings();
}
}
this.dispose = function()
{
this.dispose = function () {
}
this.serialize = function()
{
this.serialize = function () {
return {
title : self.title(),
type : self.type(),
title: self.title(),
type: self.type(),
settings: self.settings()
};
}
this.deserialize = function(object)
{
this.deserialize = function (object) {
self.title(object.title);
self.settings(object.settings);
self.type(object.type);

2
js/freeboard.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long