grunt
parent
2058501b7b
commit
afd334aa0c
|
@ -2214,6 +2214,12 @@ a:hover.text-button, a:focus.text-button {
|
|||
line-height: 1.5em;
|
||||
}
|
||||
|
||||
.calculated-setting-row {
|
||||
clear: both;
|
||||
height: 30px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
textarea.calculated-value-input {
|
||||
position: absolute;
|
||||
width: 400px;
|
||||
|
@ -2228,6 +2234,10 @@ ul.datasource-input-suffix {
|
|||
margin-left: 409px;
|
||||
}
|
||||
|
||||
.form-label .board-toolbar li {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.styled-select select {
|
||||
width: 414px;
|
||||
height: 30px;
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1295,6 +1295,67 @@ PluginEditor = function(jsEditor, valueEditor)
|
|||
return !isNaN(parseFloat(n)) && isFinite(n);
|
||||
}
|
||||
|
||||
function _appendCalculatedSettingRow(valueCell, newSettings, settingDef, currentValue, includeRemove)
|
||||
{
|
||||
var input = $('<textarea></textarea>');
|
||||
|
||||
if(settingDef.multi_input) {
|
||||
input.change(function() {
|
||||
var arrayInput = [];
|
||||
$(valueCell).find('textarea').each(function() {
|
||||
var thisVal = $(this).val();
|
||||
if(thisVal) {
|
||||
arrayInput = arrayInput.concat(thisVal);
|
||||
}
|
||||
});
|
||||
newSettings.settings[settingDef.name] = arrayInput;
|
||||
});
|
||||
} else {
|
||||
input.change(function() {
|
||||
newSettings.settings[settingDef.name] = $(this).val();
|
||||
});
|
||||
}
|
||||
|
||||
if(currentValue) {
|
||||
input.val(currentValue);
|
||||
}
|
||||
|
||||
valueEditor.createValueEditor(input);
|
||||
|
||||
var datasourceToolbox = $('<ul class="board-toolbar datasource-input-suffix"></ul>');
|
||||
var wrapperDiv = $('<div class="calculated-setting-row"></div>');
|
||||
wrapperDiv.append(input).append(datasourceToolbox);
|
||||
|
||||
var datasourceTool = $('<li><i class="icon-plus icon-white"></i><label>DATASOURCE</label></li>')
|
||||
.mousedown(function(e) {
|
||||
e.preventDefault();
|
||||
$(input).val("").focus().insertAtCaret("datasources[\"").trigger("freeboard-eval");
|
||||
});
|
||||
datasourceToolbox.append(datasourceTool);
|
||||
|
||||
var jsEditorTool = $('<li><i class="icon-fullscreen icon-white"></i><label>.JS EDITOR</label></li>')
|
||||
.mousedown(function(e) {
|
||||
e.preventDefault();
|
||||
jsEditor.displayJSEditor(input.val(), function(result) {
|
||||
input.val(result);
|
||||
input.change();
|
||||
});
|
||||
});
|
||||
datasourceToolbox.append(jsEditorTool);
|
||||
|
||||
if(includeRemove) {
|
||||
var removeButton = $('<li class="remove-setting-row"><i class="icon-minus icon-white"></i><label></label></li>')
|
||||
.mousedown(function(e) {
|
||||
e.preventDefault();
|
||||
wrapperDiv.remove();
|
||||
$(valueCell).find('textarea:first').change();
|
||||
});
|
||||
datasourceToolbox.prepend(removeButton);
|
||||
}
|
||||
|
||||
$(valueCell).append(wrapperDiv);
|
||||
}
|
||||
|
||||
function createPluginEditor(title, pluginTypes, currentTypeName, currentSettingsValues, settingsSavedCallback)
|
||||
{
|
||||
var newSettings = {
|
||||
|
@ -1515,43 +1576,31 @@ PluginEditor = function(jsEditor, valueEditor)
|
|||
{
|
||||
newSettings.settings[settingDef.name] = currentSettingsValues[settingDef.name];
|
||||
|
||||
|
||||
if(settingDef.type == "calculated")
|
||||
{
|
||||
var input = $('<textarea></textarea>').appendTo(valueCell).change(function()
|
||||
{
|
||||
newSettings.settings[settingDef.name] = $(this).val();
|
||||
});
|
||||
|
||||
if(settingDef.name in currentSettingsValues)
|
||||
{
|
||||
input.val(currentSettingsValues[settingDef.name]);
|
||||
if(settingDef.name in currentSettingsValues) {
|
||||
var currentValue = currentSettingsValues[settingDef.name];
|
||||
if(settingDef.multi_input && _.isArray(currentValue)) {
|
||||
var includeRemove = false;
|
||||
for(var i=0; i<currentValue.length; i++) {
|
||||
_appendCalculatedSettingRow(valueCell, newSettings, settingDef, currentValue[i], includeRemove);
|
||||
includeRemove = true;
|
||||
}
|
||||
} else {
|
||||
_appendCalculatedSettingRow(valueCell, newSettings, settingDef, currentValue, false);
|
||||
}
|
||||
} else {
|
||||
_appendCalculatedSettingRow(valueCell, newSettings, settingDef, null, false);
|
||||
}
|
||||
|
||||
valueEditor.createValueEditor(input);
|
||||
|
||||
var datasourceToolbox = $('<ul class="board-toolbar datasource-input-suffix"></ul>');
|
||||
|
||||
var datasourceTool = $('<li><i class="icon-plus icon-white"></i><label>DATASOURCE</label></li>').mousedown(function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
$(input).val("")
|
||||
.focus()
|
||||
.insertAtCaret("datasources[\"")
|
||||
.trigger("freeboard-eval");
|
||||
});
|
||||
|
||||
var jsEditorTool = $('<li><i class="icon-fullscreen icon-white"></i><label>.JS EDITOR</label></li>').mousedown(function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
|
||||
jsEditor.displayJSEditor(input.val(), function(result){
|
||||
input.val(result);
|
||||
input.change();
|
||||
});
|
||||
});
|
||||
|
||||
$(valueCell).append(datasourceToolbox.append([datasourceTool, jsEditorTool]));
|
||||
if(settingDef.multi_input) {
|
||||
var inputAdder = $('<ul class="board-toolbar"><li class="add-setting-row"><i class="icon-plus icon-white"></i><label>ADD</label></li></ul>')
|
||||
.mousedown(function(e) {
|
||||
e.preventDefault();
|
||||
_appendCalculatedSettingRow(valueCell, newSettings, settingDef, null, true);
|
||||
});
|
||||
$(valueCell).siblings('.form-label').append(inputAdder);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2173,6 +2222,11 @@ function WidgetModel(theFreeboardModel, widgetPlugins) {
|
|||
var script = currentSettings[settingDef.name];
|
||||
|
||||
if (!_.isUndefined(script)) {
|
||||
|
||||
if(_.isArray(script)) {
|
||||
script = "[" + script.join(",") + "]";
|
||||
}
|
||||
|
||||
// If there is no return, add one
|
||||
if ((script.match(/;/g) || []).length <= 1 && script.indexOf("return") == -1) {
|
||||
script = "return " + script;
|
||||
|
@ -2180,7 +2234,7 @@ function WidgetModel(theFreeboardModel, widgetPlugins) {
|
|||
|
||||
var valueFunction;
|
||||
|
||||
try {
|
||||
try {
|
||||
valueFunction = new Function("datasources", script);
|
||||
}
|
||||
catch (e) {
|
||||
|
@ -3876,7 +3930,8 @@ $.extend(freeboard, jQuery.eventEmitter);
|
|||
{
|
||||
name: "value",
|
||||
display_name: "Value",
|
||||
type: "calculated"
|
||||
type: "calculated",
|
||||
multi_input: "true"
|
||||
}
|
||||
],
|
||||
newInstance: function (settings, newInstanceCallback) {
|
||||
|
|
File diff suppressed because one or more lines are too long
122
js/freeboard.js
122
js/freeboard.js
|
@ -1295,6 +1295,67 @@ PluginEditor = function(jsEditor, valueEditor)
|
|||
return !isNaN(parseFloat(n)) && isFinite(n);
|
||||
}
|
||||
|
||||
function _appendCalculatedSettingRow(valueCell, newSettings, settingDef, currentValue, includeRemove)
|
||||
{
|
||||
var input = $('<textarea></textarea>');
|
||||
|
||||
if(settingDef.multi_input) {
|
||||
input.change(function() {
|
||||
var arrayInput = [];
|
||||
$(valueCell).find('textarea').each(function() {
|
||||
var thisVal = $(this).val();
|
||||
if(thisVal) {
|
||||
arrayInput = arrayInput.concat(thisVal);
|
||||
}
|
||||
});
|
||||
newSettings.settings[settingDef.name] = arrayInput;
|
||||
});
|
||||
} else {
|
||||
input.change(function() {
|
||||
newSettings.settings[settingDef.name] = $(this).val();
|
||||
});
|
||||
}
|
||||
|
||||
if(currentValue) {
|
||||
input.val(currentValue);
|
||||
}
|
||||
|
||||
valueEditor.createValueEditor(input);
|
||||
|
||||
var datasourceToolbox = $('<ul class="board-toolbar datasource-input-suffix"></ul>');
|
||||
var wrapperDiv = $('<div class="calculated-setting-row"></div>');
|
||||
wrapperDiv.append(input).append(datasourceToolbox);
|
||||
|
||||
var datasourceTool = $('<li><i class="icon-plus icon-white"></i><label>DATASOURCE</label></li>')
|
||||
.mousedown(function(e) {
|
||||
e.preventDefault();
|
||||
$(input).val("").focus().insertAtCaret("datasources[\"").trigger("freeboard-eval");
|
||||
});
|
||||
datasourceToolbox.append(datasourceTool);
|
||||
|
||||
var jsEditorTool = $('<li><i class="icon-fullscreen icon-white"></i><label>.JS EDITOR</label></li>')
|
||||
.mousedown(function(e) {
|
||||
e.preventDefault();
|
||||
jsEditor.displayJSEditor(input.val(), function(result) {
|
||||
input.val(result);
|
||||
input.change();
|
||||
});
|
||||
});
|
||||
datasourceToolbox.append(jsEditorTool);
|
||||
|
||||
if(includeRemove) {
|
||||
var removeButton = $('<li class="remove-setting-row"><i class="icon-minus icon-white"></i><label></label></li>')
|
||||
.mousedown(function(e) {
|
||||
e.preventDefault();
|
||||
wrapperDiv.remove();
|
||||
$(valueCell).find('textarea:first').change();
|
||||
});
|
||||
datasourceToolbox.prepend(removeButton);
|
||||
}
|
||||
|
||||
$(valueCell).append(wrapperDiv);
|
||||
}
|
||||
|
||||
function createPluginEditor(title, pluginTypes, currentTypeName, currentSettingsValues, settingsSavedCallback)
|
||||
{
|
||||
var newSettings = {
|
||||
|
@ -1515,43 +1576,31 @@ PluginEditor = function(jsEditor, valueEditor)
|
|||
{
|
||||
newSettings.settings[settingDef.name] = currentSettingsValues[settingDef.name];
|
||||
|
||||
|
||||
if(settingDef.type == "calculated")
|
||||
{
|
||||
var input = $('<textarea></textarea>').appendTo(valueCell).change(function()
|
||||
{
|
||||
newSettings.settings[settingDef.name] = $(this).val();
|
||||
});
|
||||
|
||||
if(settingDef.name in currentSettingsValues)
|
||||
{
|
||||
input.val(currentSettingsValues[settingDef.name]);
|
||||
if(settingDef.name in currentSettingsValues) {
|
||||
var currentValue = currentSettingsValues[settingDef.name];
|
||||
if(settingDef.multi_input && _.isArray(currentValue)) {
|
||||
var includeRemove = false;
|
||||
for(var i=0; i<currentValue.length; i++) {
|
||||
_appendCalculatedSettingRow(valueCell, newSettings, settingDef, currentValue[i], includeRemove);
|
||||
includeRemove = true;
|
||||
}
|
||||
} else {
|
||||
_appendCalculatedSettingRow(valueCell, newSettings, settingDef, currentValue, false);
|
||||
}
|
||||
} else {
|
||||
_appendCalculatedSettingRow(valueCell, newSettings, settingDef, null, false);
|
||||
}
|
||||
|
||||
valueEditor.createValueEditor(input);
|
||||
|
||||
var datasourceToolbox = $('<ul class="board-toolbar datasource-input-suffix"></ul>');
|
||||
|
||||
var datasourceTool = $('<li><i class="icon-plus icon-white"></i><label>DATASOURCE</label></li>').mousedown(function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
$(input).val("")
|
||||
.focus()
|
||||
.insertAtCaret("datasources[\"")
|
||||
.trigger("freeboard-eval");
|
||||
});
|
||||
|
||||
var jsEditorTool = $('<li><i class="icon-fullscreen icon-white"></i><label>.JS EDITOR</label></li>').mousedown(function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
|
||||
jsEditor.displayJSEditor(input.val(), function(result){
|
||||
input.val(result);
|
||||
input.change();
|
||||
});
|
||||
});
|
||||
|
||||
$(valueCell).append(datasourceToolbox.append([datasourceTool, jsEditorTool]));
|
||||
if(settingDef.multi_input) {
|
||||
var inputAdder = $('<ul class="board-toolbar"><li class="add-setting-row"><i class="icon-plus icon-white"></i><label>ADD</label></li></ul>')
|
||||
.mousedown(function(e) {
|
||||
e.preventDefault();
|
||||
_appendCalculatedSettingRow(valueCell, newSettings, settingDef, null, true);
|
||||
});
|
||||
$(valueCell).siblings('.form-label').append(inputAdder);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2173,6 +2222,11 @@ function WidgetModel(theFreeboardModel, widgetPlugins) {
|
|||
var script = currentSettings[settingDef.name];
|
||||
|
||||
if (!_.isUndefined(script)) {
|
||||
|
||||
if(_.isArray(script)) {
|
||||
script = "[" + script.join(",") + "]";
|
||||
}
|
||||
|
||||
// If there is no return, add one
|
||||
if ((script.match(/;/g) || []).length <= 1 && script.indexOf("return") == -1) {
|
||||
script = "return " + script;
|
||||
|
@ -2180,7 +2234,7 @@ function WidgetModel(theFreeboardModel, widgetPlugins) {
|
|||
|
||||
var valueFunction;
|
||||
|
||||
try {
|
||||
try {
|
||||
valueFunction = new Function("datasources", script);
|
||||
}
|
||||
catch (e) {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -979,7 +979,8 @@
|
|||
{
|
||||
name: "value",
|
||||
display_name: "Value",
|
||||
type: "calculated"
|
||||
type: "calculated",
|
||||
multi_input: "true"
|
||||
}
|
||||
],
|
||||
newInstance: function (settings, newInstanceCallback) {
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue