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

Resize change/switch rules with the dialog

This commit is contained in:
Nick O'Leary 2015-10-03 22:30:28 +01:00
parent 8f414ce458
commit ddedea8b90
2 changed files with 53 additions and 9 deletions

View File

@ -82,6 +82,34 @@
{v:"else",t:this._("switch.rules.else")} {v:"else",t:this._("switch.rules.else")}
]; ];
function resizeRule(rule,width) {
var selectField = rule.find("select");
var type = selectField.children("option:selected").val();
var valueField = rule.find(".node-input-rule-value");
var btwnField1 = rule.find(".node-input-rule-btwn-value");
var btwnField2 = rule.find(".node-input-rule-btwn-value2");
var selectWidth;
if (type.length < 4) {
selectWidth = 60;
} else if (type === "regex") {
selectWidth = 147;
} else {
selectWidth = 120;
}
selectField.width(selectWidth);
if (type === "btwn") {
btwnField1.width((width-288)/2);
btwnField2.width((width-288)/2);
} else {
if (type === "true" || type === "false" || type === "null" || type === "nnull" || type === "else") {
// valueField.hide();
} else {
valueField.width(width-selectWidth-120);
}
}
}
function generateRule(i,rule) { function generateRule(i,rule) {
var container = $('<li/>',{style:"background: #fff; margin:0; padding:8px 0px; border-bottom: 1px solid #ccc;"}); var container = $('<li/>',{style:"background: #fff; margin:0; padding:8px 0px; border-bottom: 1px solid #ccc;"});
var row = $('<div/>').appendTo(container); var row = $('<div/>').appendTo(container);
@ -106,14 +134,10 @@
$('<i/>',{class:"fa fa-remove"}).appendTo(deleteButton); $('<i/>',{class:"fa fa-remove"}).appendTo(deleteButton);
selectField.change(function() { selectField.change(function() {
var width = $("#node-input-rule-container").width();
resizeRule(container,width);
var type = selectField.children("option:selected").val(); var type = selectField.children("option:selected").val();
if (type.length < 4) {
selectField.css({"width":"60px"});
} else if (type === "regex") {
selectField.css({"width":"147px"});
} else {
selectField.css({"width":"120px"});
}
if (type === "btwn") { if (type === "btwn") {
valueField.hide(); valueField.hide();
btwnField.show(); btwnField.show();
@ -127,7 +151,6 @@
} }
}); });
deleteButton.click(function() { deleteButton.click(function() {
container.css({"background":"#fee"}); container.css({"background":"#fee"});
container.fadeOut(300, function() { container.fadeOut(300, function() {
@ -170,6 +193,12 @@
var editorRow = $("#dialog-form>div.node-input-rule-container-row"); var editorRow = $("#dialog-form>div.node-input-rule-container-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom"))); height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
$("#node-input-rule-container-div").css("height",height+"px"); $("#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({
@ -192,6 +221,8 @@
$("#dialog").dialog('option','width',size.width); $("#dialog").dialog('option','width',size.width);
$("#dialog").dialog('option','height',size.height); $("#dialog").dialog('option','height',size.height);
switchDialogResize(); switchDialogResize();
} else {
setTimeout(switchDialogResize,10);
} }
}); });
$( "#dialog" ).one("dialogclose", function(ev,ui) { $( "#dialog" ).one("dialogclose", function(ev,ui) {

View File

@ -102,6 +102,10 @@
if (this.reg === null) { $("#node-input-reg").prop('checked', true); } if (this.reg === null) { $("#node-input-reg").prop('checked', true); }
$("#node-input-action").change(); $("#node-input-action").change();
function resizeRule(rule,width) {
rule.find('input[type="text"]').width(width-220);
}
function generateRule(rule) { function generateRule(rule) {
var container = $('<li/>',{style:"background: #fff; margin:0; padding:8px 0px; border-bottom: 1px solid #ccc;"}); var container = $('<li/>',{style:"background: #fff; margin:0; padding:8px 0px; border-bottom: 1px solid #ccc;"});
@ -143,8 +147,9 @@
selectField.change(function() { selectField.change(function() {
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();
row3.hide(); row3.hide();
@ -213,6 +218,12 @@
var editorRow = $("#dialog-form>div.node-input-rule-container-row"); var editorRow = $("#dialog-form>div.node-input-rule-container-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom"))); height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
$("#node-input-rule-container-div").css("height",height+"px"); $("#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);
})
}; };
$( "#dialog" ).on("dialogresize", changeDialogResize); $( "#dialog" ).on("dialogresize", changeDialogResize);
$( "#dialog" ).one("dialogopen", function(ev) { $( "#dialog" ).one("dialogopen", function(ev) {
@ -221,6 +232,8 @@
$("#dialog").dialog('option','width',size.width); $("#dialog").dialog('option','width',size.width);
$("#dialog").dialog('option','height',size.height); $("#dialog").dialog('option','height',size.height);
changeDialogResize(); changeDialogResize();
} else {
setTimeout(changeDialogResize,10);
} }
}); });
$( "#dialog" ).one("dialogclose", function(ev,ui) { $( "#dialog" ).one("dialogclose", function(ev,ui) {