|
| 1 | +/* ************************************************************************ |
| 2 | +
|
| 3 | + osparc - the simcore frontend |
| 4 | +
|
| 5 | + https://osparc.io |
| 6 | +
|
| 7 | + Copyright: |
| 8 | + 2035 IT'IS Foundation, https://itis.swiss |
| 9 | +
|
| 10 | + License: |
| 11 | + MIT: https://opensource.org/licenses/MIT |
| 12 | +
|
| 13 | + Authors: |
| 14 | + * Odei Maiz (odeimaiz) |
| 15 | +
|
| 16 | +************************************************************************ */ |
| 17 | + |
| 18 | +qx.Class.define("osparc.ui.table.cellrenderer.SVGButtonRenderer", { |
| 19 | + extend: osparc.ui.table.cellrenderer.Html, |
| 20 | + |
| 21 | + construct: function(id, icon) { |
| 22 | + this.base(arguments); |
| 23 | + }, |
| 24 | + |
| 25 | + properties: { |
| 26 | + clickAction: { |
| 27 | + check: "String", |
| 28 | + nullable: false, |
| 29 | + init: "clickAction", |
| 30 | + }, |
| 31 | + |
| 32 | + svgIcon: { |
| 33 | + check: "String", |
| 34 | + nullable: false, |
| 35 | + init: "osparc/offline.svg", // Default icon |
| 36 | + }, |
| 37 | + }, |
| 38 | + |
| 39 | + members: { |
| 40 | + // Override |
| 41 | + _getContentHtml: function(cellInfo) { |
| 42 | + const clickAction = this.getClickAction(); |
| 43 | + const iconPath = this.getSvgIcon(); |
| 44 | + const resMgr = qx.util.ResourceManager.getInstance(); |
| 45 | + const iconUrl = resMgr.toUri(iconPath); // Resolves to the correct URL of the asset |
| 46 | + |
| 47 | + // Button styling |
| 48 | + const buttonStyle = "background:none; border:none; padding:0; cursor:pointer; height:32px; width:32px; display:flex; align-items:center; justify-content:center;"; |
| 49 | + const imgStyle = "height:24px; width:24px;"; // Ensuring it fits nicely |
| 50 | + |
| 51 | + // Return the button with the image |
| 52 | + return ` |
| 53 | + <button style="${buttonStyle}" data-action="${clickAction}" data-row="${cellInfo.row}" title="View"> |
| 54 | + <img src="${iconUrl}" style="${imgStyle}" alt="icon" /> |
| 55 | + </button> |
| 56 | + `; |
| 57 | + }, |
| 58 | + |
| 59 | + /* |
| 60 | + // Helper method to get the correct FontAwesome icon as inline SVG |
| 61 | + _getFontAwesomeSvg: function(iconClass) { |
| 62 | + const iconMap = { |
| 63 | + "fa-cog": '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="24" height="24"><path d="M487.8 317.6l-53.7-31.1c7.3-17.7 11.6-36.9 11.6-56.5 0-19.7-4.3-38.8-11.6-56.5l53.7-31.1c10.7-6.1 13.5-19.8 7.4-30.4l-41.5-71.6c-6.1-10.7-19.8-13.5-30.4-7.4l-53.7 31.1c-17.7-13.1-37.1-23.6-58.4-30.5l-8.5-55.2c-2.2-14.2-15.4-24.3-29.8-24.3h-57.8c-14.4 0-27.6 10.1-29.8 24.3l-8.5 55.2c-21.3 6.9-40.7 17.4-58.4 30.5l-53.7-31.1c-10.7-6.1-24.3-3.3-30.4 7.4l-41.5 71.6c-6.1 10.7-3.3 24.3 7.4 30.4l53.7 31.1c-7.3 17.7-11.6 36.9-11.6 56.5 0 19.7 4.3 38.8 11.6 56.5l-53.7 31.1c-10.7 6.1-13.5 19.8-7.4 30.4l41.5 71.6c6.1 10.7 19.8 13.5 30.4 7.4l53.7-31.1c17.7 13.1 37.1 23.6 58.4 30.5l8.5 55.2c2.2 14.2 15.4 24.3 29.8 24.3h57.8c14.4 0 27.6-10.1 29.8-24.3l8.5-55.2c21.3-6.9 40.7-17.4 58.4-30.5l53.7 31.1c10.7 6.1 24.3 3.3 30.4-7.4l41.5-71.6c6.1-10.7 3.3-24.3-7.4-30.4z"/></svg>', |
| 64 | + // Add more icons as needed... |
| 65 | + }; |
| 66 | +
|
| 67 | + return iconMap[iconClass] || iconMap["fa-cog"]; // Default to "fa-cog" if iconClass is not found |
| 68 | + } |
| 69 | + */ |
| 70 | + } |
| 71 | +}); |
0 commit comments