mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #2881 from bartbutenaers/editableList-buttons
EditableList custom buttons
This commit is contained in:
commit
5809a3af0d
@ -857,7 +857,8 @@
|
||||
}
|
||||
},
|
||||
"editableList": {
|
||||
"add": "add"
|
||||
"add": "add",
|
||||
"addTitle": "add an item"
|
||||
},
|
||||
"search": {
|
||||
"empty": "No matches found",
|
||||
|
@ -18,6 +18,7 @@
|
||||
/**
|
||||
* options:
|
||||
* - addButton : boolean|string - text for add label, default 'add'
|
||||
* - buttons : array - list of custom buttons (objects with fields 'label', 'icon', 'title', 'click')
|
||||
* - height : number|'auto'
|
||||
* - resize : function - called when list as a whole is resized
|
||||
* - resizeItem : function(item) - called to resize individual item
|
||||
@ -67,24 +68,52 @@
|
||||
this.topContainer.addClass(this.options.class);
|
||||
}
|
||||
|
||||
var buttons = this.options.buttons || [];
|
||||
|
||||
if (this.options.addButton !== false) {
|
||||
var addLabel;
|
||||
var addLabel, addTittle;
|
||||
if (typeof this.options.addButton === 'string') {
|
||||
addLabel = this.options.addButton
|
||||
} else {
|
||||
if (RED && RED._) {
|
||||
addLabel = RED._("editableList.add");
|
||||
addTitle = RED._("editableList.addTitle");
|
||||
} else {
|
||||
addLabel = 'add';
|
||||
addTitle = 'add new item';
|
||||
}
|
||||
}
|
||||
$('<a href="#" class="red-ui-button red-ui-button-small red-ui-editableList-addButton" style="margin-top: 4px;"><i class="fa fa-plus"></i> '+addLabel+'</a>')
|
||||
.appendTo(this.topContainer)
|
||||
buttons.unshift({
|
||||
label: addLabel,
|
||||
icon: "fa fa-plus",
|
||||
click: function(evt) {
|
||||
that.addItem({});
|
||||
},
|
||||
title: addTitle
|
||||
});
|
||||
}
|
||||
|
||||
buttons.forEach(function(button) {
|
||||
var element = $('<a href="#" class="red-ui-button red-ui-button-small red-ui-editableList-addButton" style="margin-top: 4px; margin-right: 5px;"></a>')
|
||||
.appendTo(that.topContainer)
|
||||
.on("click", function(evt) {
|
||||
evt.preventDefault();
|
||||
that.addItem({});
|
||||
if (button.click !== undefined) {
|
||||
button.click(evt);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (button.title) {
|
||||
element.attr("title", button.title);
|
||||
}
|
||||
if (button.icon) {
|
||||
element.append($("<i></i>").attr("class", button.icon));
|
||||
}
|
||||
if (button.label) {
|
||||
element.append($("<span></span>").text(" " + button.label));
|
||||
}
|
||||
});
|
||||
|
||||
if (this.element.css("position") === "absolute") {
|
||||
["top","left","bottom","right"].forEach(function(s) {
|
||||
var v = that.element.css(s);
|
||||
|
Loading…
Reference in New Issue
Block a user