1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Add oneditresize function definition

This commit is contained in:
Nick O'Leary 2016-01-04 16:53:32 +00:00
parent aed89d82fb
commit 2e9d445d36
8 changed files with 115 additions and 204 deletions

View File

@ -348,6 +348,10 @@ RED.editor = (function() {
resize: function(e,ui) { resize: function(e,ui) {
if (editing_node) { if (editing_node) {
$(this).dialog('option',"sizeCache-"+editing_node.type,ui.size); $(this).dialog('option',"sizeCache-"+editing_node.type,ui.size);
if (editing_node._def.oneditresize) {
var form = $("#dialog-form");
editing_node._def.oneditresize.call(editing_node,{width:form.width(),height:form.height()});
}
} }
}, },
open: function(e) { open: function(e) {
@ -364,6 +368,12 @@ RED.editor = (function() {
$(this).dialog('option','width',size.width); $(this).dialog('option','width',size.width);
$(this).dialog('option','height',size.height); $(this).dialog('option','height',size.height);
} }
if (editing_node._def.oneditresize) {
setTimeout(function() {
var form = $("#dialog-form");
editing_node._def.oneditresize.call(editing_node,{width:form.width(),height:form.height()});
},0);
}
} }
}, },
close: function(e) { close: function(e) {

View File

@ -22,7 +22,7 @@
<option value="target" data-i18n="catch.scope.selected"></options> <option value="target" data-i18n="catch.scope.selected"></options>
</select> </select>
</div> </div>
<div class="form-row node-input-target-row" style="display: none;"> <div class="form-row node-input-target-row" style="display: none;min-height: 100px;">
<div id="node-input-catch-target-container-div" style="position: relative; box-sizing: border-box; border-radius: 2px; height: 180px; border: 1px solid #ccc;overflow:hidden; "> <div id="node-input-catch-target-container-div" style="position: relative; box-sizing: border-box; border-radius: 2px; height: 180px; border: 1px solid #ccc;overflow:hidden; ">
<div style="box-sizing: border-box; line-height: 20px; font-size: 0.8em; border-bottom: 1px solid #ddd; height: 20px;"> <div style="box-sizing: border-box; line-height: 20px; font-size: 0.8em; border-bottom: 1px solid #ddd; height: 20px;">
<input type="checkbox" data-i18n="[title]catch.label.selectAll" id="node-input-target-node-checkbox-all" style="width: 30px; margin: 0 2px 1px 2px;"> <input type="checkbox" data-i18n="[title]catch.label.selectAll" id="node-input-target-node-checkbox-all" style="width: 30px; margin: 0 2px 1px 2px;">
@ -114,6 +114,17 @@
oneditprepare: function() { oneditprepare: function() {
var nodeList = $("#node-input-catch-target-container"); var nodeList = $("#node-input-catch-target-container");
var node = this; var node = this;
this.resize = function() {
var rows = $("#dialog-form>div:not(.node-input-target-row)");
var height = $("#dialog-form").height();
for (var i=0;i<rows.size();i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-input-target-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
$("#node-input-catch-target-container-div").css("height",height+"px");
}
function createNodeList() { function createNodeList() {
var scope = node.scope || []; var scope = node.scope || [];
nodeList.empty(); nodeList.empty();
@ -238,6 +249,7 @@
} else { } else {
$(".node-input-target-row").hide(); $(".node-input-target-row").hide();
} }
node.resize();
}); });
if (this.scope == null) { if (this.scope == null) {
$("#node-input-scope-select").val("all"); $("#node-input-scope-select").val("all");
@ -245,31 +257,6 @@
$("#node-input-scope-select").val("target"); $("#node-input-scope-select").val("target");
} }
$("#node-input-scope-select").change(); $("#node-input-scope-select").change();
function dialogResize() {
var rows = $("#dialog-form>div:not(.node-input-target-row)");
var height = $("#dialog-form").height();
for (var i=0;i<rows.size();i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-input-target-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
$("#node-input-catch-target-container-div").css("height",height+"px");
};
$( "#dialog" ).on("dialogresize", dialogResize);
$( "#dialog" ).one("dialogopen", function(ev) {
var size = $( "#dialog" ).dialog('option','sizeCache-catch');
if (size) {
$("#dialog").dialog('option','width',size.width);
$("#dialog").dialog('option','height',size.height);
dialogResize();
}
});
$( "#dialog" ).one("dialogclose", function(ev,ui) {
$( "#dialog" ).off("dialogresize",dialogResize);
});
}, },
oneditsave: function() { oneditsave: function() {
var scope = $("#node-input-scope-select").children("option:selected").val(); var scope = $("#node-input-scope-select").children("option:selected").val();
@ -283,8 +270,10 @@
node.scope.push($(this).data('node-id')); node.scope.push($(this).data('node-id'));
} }
}) })
} }
},
oneditresize: function(size) {
this.resize();
} }
}); });
</script> </script>

View File

@ -22,7 +22,7 @@
<option value="target" data-i18n="status.scope.selected"></options> <option value="target" data-i18n="status.scope.selected"></options>
</select> </select>
</div> </div>
<div class="form-row node-input-target-row" style="display: none;"> <div class="form-row node-input-target-row" style="display: none; min-height: 100px;">
<div id="node-input-status-target-container-div" style="position: relative; box-sizing: border-box; border-radius: 2px; height: 180px; border: 1px solid #ccc;overflow:hidden; "> <div id="node-input-status-target-container-div" style="position: relative; box-sizing: border-box; border-radius: 2px; height: 180px; border: 1px solid #ccc;overflow:hidden; ">
<div style="box-sizing: border-box; line-height: 20px; font-size: 0.8em; border-bottom: 1px solid #ddd; height: 20px;"> <div style="box-sizing: border-box; line-height: 20px; font-size: 0.8em; border-bottom: 1px solid #ddd; height: 20px;">
<input type="checkbox" data-i18n="[title]status.label.selectAll" id="node-input-target-node-checkbox-all" style="width: 30px; margin: 0 2px 1px 2px;"> <input type="checkbox" data-i18n="[title]status.label.selectAll" id="node-input-target-node-checkbox-all" style="width: 30px; margin: 0 2px 1px 2px;">
@ -105,6 +105,17 @@
oneditprepare: function() { oneditprepare: function() {
var nodeList = $("#node-input-status-target-container"); var nodeList = $("#node-input-status-target-container");
var node = this; var node = this;
this.resize = function() {
var rows = $("#dialog-form>div:not(.node-input-target-row)");
var height = $("#dialog-form").height();
for (var i=0;i<rows.size();i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-input-target-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
$("#node-input-status-target-container-div").css("height",height+"px");
}
function createNodeList() { function createNodeList() {
var scope = node.scope || []; var scope = node.scope || [];
nodeList.empty(); nodeList.empty();
@ -219,8 +230,6 @@
$(".node-input-target-node-checkbox").prop('checked',this.checked); $(".node-input-target-node-checkbox").prop('checked',this.checked);
}) })
$("#node-input-scope-select").change(function(e) { $("#node-input-scope-select").change(function(e) {
var scope = $(this).children("option:selected").val(); var scope = $(this).children("option:selected").val();
if (scope === "target") { if (scope === "target") {
@ -229,6 +238,7 @@
} else { } else {
$(".node-input-target-row").hide(); $(".node-input-target-row").hide();
} }
node.resize();
}); });
if (this.scope == null) { if (this.scope == null) {
$("#node-input-scope-select").val("all"); $("#node-input-scope-select").val("all");
@ -236,31 +246,6 @@
$("#node-input-scope-select").val("target"); $("#node-input-scope-select").val("target");
} }
$("#node-input-scope-select").change(); $("#node-input-scope-select").change();
function dialogResize() {
var rows = $("#dialog-form>div:not(.node-input-target-row)");
var height = $("#dialog-form").height();
for (var i=0;i<rows.size();i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-input-target-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
$("#node-input-status-target-container-div").css("height",height+"px");
};
$( "#dialog" ).on("dialogresize", dialogResize);
$( "#dialog" ).one("dialogopen", function(ev) {
var size = $( "#dialog" ).dialog('option','sizeCache-status');
if (size) {
$("#dialog").dialog('option','width',size.width);
$("#dialog").dialog('option','height',size.height);
dialogResize();
}
});
$( "#dialog" ).one("dialogclose", function(ev,ui) {
$( "#dialog" ).off("dialogresize",dialogResize);
});
}, },
oneditsave: function() { oneditsave: function() {
var scope = $("#node-input-scope-select").children("option:selected").val(); var scope = $("#node-input-scope-select").children("option:selected").val();
@ -276,6 +261,9 @@
}) })
} }
},
oneditresize: function(size) {
this.resize();
} }
}); });
</script> </script>

View File

@ -88,31 +88,6 @@
min:1 min:1
}); });
function functionDialogResize() {
var rows = $("#dialog-form>div:not(.node-text-editor-row)");
var height = $("#dialog-form").height();
for (var i=0;i<rows.size();i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-text-editor-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
$(".node-text-editor").css("height",height+"px");
that.editor.resize();
}
$( "#dialog" ).on("dialogresize", functionDialogResize);
$( "#dialog" ).one("dialogopen", function(ev) {
var size = $( "#dialog" ).dialog('option','sizeCache-function');
if (size) {
$("#dialog").dialog('option','width',size.width);
$("#dialog").dialog('option','height',size.height);
functionDialogResize();
}
});
$( "#dialog" ).one("dialogclose", function(ev,ui) {
var height = $( "#dialog" ).dialog('option','height');
$( "#dialog" ).off("dialogresize",functionDialogResize);
});
this.editor = RED.editor.createEditor({ this.editor = RED.editor.createEditor({
id: 'node-input-func-editor', id: 'node-input-func-editor',
mode: 'ace/mode/javascript', mode: 'ace/mode/javascript',
@ -141,6 +116,17 @@
} }
$("#node-input-func").val(this.editor.getValue()); $("#node-input-func").val(this.editor.getValue());
delete this.editor; delete this.editor;
},
oneditresize: function(size) {
var rows = $("#dialog-form>div:not(.node-text-editor-row)");
var height = $("#dialog-form").height();
for (var i=0;i<rows.size();i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-text-editor-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
$(".node-text-editor").css("height",height+"px");
this.editor.resize();
} }
}); });
</script> </script>

View File

@ -88,30 +88,6 @@
typeField: $("#node-input-fieldType") typeField: $("#node-input-fieldType")
}); });
function templateDialogResize() {
var rows = $("#dialog-form>div:not(.node-text-editor-row)");
var height = $("#dialog-form").height();
for (var i=0;i<rows.size();i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-text-editor-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
$(".node-text-editor").css("height",height+"px");
that.editor.resize();
};
$( "#dialog" ).on("dialogresize", templateDialogResize);
$( "#dialog" ).one("dialogopen", function(ev) {
var size = $( "#dialog" ).dialog('option','sizeCache-template');
if (size) {
$("#dialog").dialog('option','width',size.width);
$("#dialog").dialog('option','height',size.height);
templateDialogResize();
}
});
$( "#dialog" ).one("dialogclose", function(ev,ui) {
var height = $( "#dialog" ).dialog('option','height');
$( "#dialog" ).off("dialogresize",templateDialogResize);
});
this.editor = RED.editor.createEditor({ this.editor = RED.editor.createEditor({
id: 'node-input-template-editor', id: 'node-input-template-editor',
mode: 'ace/mode/html', mode: 'ace/mode/html',
@ -136,6 +112,17 @@
oneditsave: function() { oneditsave: function() {
$("#node-input-template").val(this.editor.getValue()) $("#node-input-template").val(this.editor.getValue())
delete this.editor; delete this.editor;
},
oneditresize: function(size) {
var rows = $("#dialog-form>div:not(.node-text-editor-row)");
var height = $("#dialog-form").height();
for (var i=0;i<rows.size();i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-text-editor-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
$(".node-text-editor").css("height",height+"px");
this.editor.resize();
} }
}); });
</script> </script>

View File

@ -58,30 +58,6 @@
$( "#node-input-outputs" ).spinner({ $( "#node-input-outputs" ).spinner({
min:1 min:1
}); });
function functionDialogResize() {
var rows = $("#dialog-form>div:not(.node-text-editor-row)");
var height = $("#dialog-form").height();
for (var i=0;i<rows.size();i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-text-editor-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
$(".node-text-editor").css("height",height+"px");
that.editor.resize();
};
$( "#dialog" ).on("dialogresize", functionDialogResize);
$( "#dialog" ).one("dialogopen", function(ev) {
var size = $( "#dialog" ).dialog('option','sizeCache-function');
if (size) {
$("#dialog").dialog('option','width',size.width);
$("#dialog").dialog('option','height',size.height);
functionDialogResize();
}
});
$( "#dialog" ).one("dialogclose", function(ev,ui) {
var height = $( "#dialog" ).dialog('option','height');
$( "#dialog" ).off("dialogresize",functionDialogResize);
});
this.editor = RED.editor.createEditor({ this.editor = RED.editor.createEditor({
id: 'node-input-info-editor', id: 'node-input-info-editor',
mode: 'ace/mode/markdown', mode: 'ace/mode/markdown',
@ -92,6 +68,17 @@
oneditsave: function() { oneditsave: function() {
$("#node-input-info").val(this.editor.getValue()); $("#node-input-info").val(this.editor.getValue());
delete this.editor; delete this.editor;
},
oneditresize: function(size) {
var rows = $("#dialog-form>div:not(.node-text-editor-row)");
var height = $("#dialog-form").height();
for (var i=0;i<rows.size();i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-text-editor-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
$(".node-text-editor").css("height",height+"px");
this.editor.resize();
} }
}); });
</script> </script>

View File

@ -65,6 +65,7 @@
return this.name||"switch"; return this.name||"switch";
}, },
oneditprepare: function() { oneditprepare: function() {
var node = this;
$("#node-input-property").typedInput({default:this.propertyType||'msg',types:['msg','flow','global']}); $("#node-input-property").typedInput({default:this.propertyType||'msg',types:['msg','flow','global']});
var operators = [ var operators = [
{v:"eq",t:"=="}, {v:"eq",t:"=="},
@ -86,7 +87,7 @@
var andLabel = this._("switch.and"); var andLabel = this._("switch.and");
var caseLabel = this._("switch.ignorecase"); var caseLabel = this._("switch.ignorecase");
function resizeRule(rule,width) { this.resizeRule = function(rule,newWidth) {
var selectField = rule.find("select"); var selectField = rule.find("select");
var type = selectField.children("option:selected").val(); var type = selectField.children("option:selected").val();
var valueField = rule.find(".node-input-rule-value"); var valueField = rule.find(".node-input-rule-value");
@ -104,13 +105,13 @@
if (type === "btwn") { if (type === "btwn") {
var labelWidth = rule.find(".node-input-rule-btwn-label").width(); var labelWidth = rule.find(".node-input-rule-btwn-label").width();
btwnField1.typedInput("width",(width-selectWidth-120)); btwnField1.typedInput("width",(newWidth-selectWidth-120));
btwnField2.typedInput("width",(width-selectWidth-120)); btwnField2.typedInput("width",(newWidth-selectWidth-120));
} else { } else {
if (type === "true" || type === "false" || type === "null" || type === "nnull" || type === "else") { if (type === "true" || type === "false" || type === "null" || type === "nnull" || type === "else") {
// valueField.hide(); // valueField.hide();
} else { } else {
valueField.typedInput("width",(width-selectWidth-120)); valueField.typedInput("width",(newWidth-selectWidth-120));
} }
} }
} }
@ -143,9 +144,8 @@
$('<label/>',{for:"node-input-rule-case-"+i,style:"margin-left: 3px;"}).text(caseLabel).appendTo(row2); $('<label/>',{for:"node-input-rule-case-"+i,style:"margin-left: 3px;"}).text(caseLabel).appendTo(row2);
selectField.change(function() { selectField.change(function() {
var width = $("#node-input-rule-container").width(); var width = $("#node-input-rule-container").width();
resizeRule(container,width);
var type = selectField.children("option:selected").val(); var type = selectField.children("option:selected").val();
node.resizeRule(container,width);
if (type === "btwn") { if (type === "btwn") {
valueField.parent().hide(); valueField.parent().hide();
btwnValueField.parent().show(); btwnValueField.parent().show();
@ -210,23 +210,6 @@
generateRule(i+1,rule); generateRule(i+1,rule);
} }
function switchDialogResize() {
var rows = $("#dialog-form>div:not(.node-input-rule-container-row)");
var height = $("#dialog-form").height();
for (var i=0;i<rows.size();i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-input-rule-container-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
$("#node-input-rule-container-div").css("height",height+"px");
var rules = $("#node-input-rule-container").children();
var newWidth = $("#node-input-rule-container").width();
rules.each(function(i) {
resizeRule($(this),newWidth);
})
};
$( "#node-input-rule-container" ).sortable({ $( "#node-input-rule-container" ).sortable({
axis: "y", axis: "y",
update: function( event, ui ) { update: function( event, ui ) {
@ -239,21 +222,6 @@
cursor: "move" cursor: "move"
}); });
$( "#node-input-rule-container .node-input-rule-handle" ).disableSelection(); $( "#node-input-rule-container .node-input-rule-handle" ).disableSelection();
$( "#dialog" ).on("dialogresize", switchDialogResize);
$( "#dialog" ).one("dialogopen", function(ev) {
var size = $( "#dialog" ).dialog('option','sizeCache-switch');
if (size) {
$("#dialog").dialog('option','width',size.width);
$("#dialog").dialog('option','height',size.height);
switchDialogResize();
} else {
setTimeout(switchDialogResize,10);
}
});
$( "#dialog" ).one("dialogclose", function(ev,ui) {
$( "#dialog" ).off("dialogresize",switchDialogResize);
});
}, },
oneditsave: function() { oneditsave: function() {
var rules = $("#node-input-rule-container").children(); var rules = $("#node-input-rule-container").children();
@ -282,6 +250,23 @@
}); });
this.outputs = node.rules.length; this.outputs = node.rules.length;
this.propertyType = $("#node-input-property").typedInput('type'); this.propertyType = $("#node-input-property").typedInput('type');
},
oneditresize: function(size) {
var rows = $("#dialog-form>div:not(.node-input-rule-container-row)");
var height = size.height;
for (var i=0;i<rows.size();i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-input-rule-container-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
$("#node-input-rule-container-div").css("height",height+"px");
var rules = $("#node-input-rule-container").children();
var newWidth = $("#node-input-rule-container").width();
var node = this;
rules.each(function(i) {
node.resizeRule($(this),newWidth);
})
} }
}); });
</script> </script>

View File

@ -100,11 +100,6 @@
var replace = this._("change.action.replace"); var replace = this._("change.action.replace");
var regex = this._("change.label.regex"); var regex = this._("change.label.regex");
function resizeRule(rule,width) {
rule.find('input[type="text"]:not(.red-ui-typedInput)').width(width-180);
rule.find('.red-ui-typedInput').typedInput("width",width-180);
}
function generateRule(rule) { function generateRule(rule) {
if (rule.t === "change" && rule.re) { if (rule.t === "change" && rule.re) {
@ -151,7 +146,6 @@
selectField.change(function() { selectField.change(function() {
var width = $("#node-input-rule-container").width(); var width = $("#node-input-rule-container").width();
resizeRule(container,width);
var type = $(this).val(); var type = $(this).val();
if (type == "set") { if (type == "set") {
row2.show(); row2.show();
@ -215,38 +209,6 @@
for (var i=0;i<this.rules.length;i++) { for (var i=0;i<this.rules.length;i++) {
generateRule(this.rules[i]); generateRule(this.rules[i]);
} }
function changeDialogResize() {
var rows = $("#dialog-form>div:not(.node-input-rule-container-row)");
var height = $("#dialog-form").height();
for (var i=0;i<rows.size();i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-input-rule-container-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
$("#node-input-rule-container-div").css("height",height+"px");
var rules = $("#node-input-rule-container").children();
var newWidth = $("#node-input-rule-container").width();
rules.each(function(i) {
resizeRule($(this),newWidth);
})
$("#node-input-name").width(newWidth-130);
};
$( "#dialog" ).on("dialogresize", changeDialogResize);
$( "#dialog" ).one("dialogopen", function(ev) {
var size = $( "#dialog" ).dialog('option','sizeCache-change');
if (size) {
$("#dialog").dialog('option','width',size.width);
$("#dialog").dialog('option','height',size.height);
changeDialogResize();
} else {
setTimeout(changeDialogResize,10);
}
});
$( "#dialog" ).one("dialogclose", function(ev,ui) {
$( "#dialog" ).off("dialogresize",changeDialogResize);
});
}, },
oneditsave: function() { oneditsave: function() {
var rules = $("#node-input-rule-container").children(); var rules = $("#node-input-rule-container").children();
@ -272,6 +234,23 @@
} }
node.rules.push(r); node.rules.push(r);
}); });
},
oneditresize: function(size) {
var rows = $("#dialog-form>div:not(.node-input-rule-container-row)");
var height = size.height;
for (var i=0;i<rows.size();i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-input-rule-container-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
$("#node-input-rule-container-div").css("height",height+"px");
var rules = $("#node-input-rule-container").children();
var newWidth = $("#node-input-rule-container").width();
rules.each(function(i) {
$(this).find('.red-ui-typedInput').typedInput("width",newWidth-180);
})
$("#node-input-name").width(newWidth-130);
} }
}); });
</script> </script>