Allows use of the window object, enabling opening and closing browser windows directly from Mashup
IDE.JS
TW.IDE.Widgets.WindowObject = function() {
this.widgetProperties = function() {
return {
'name': 'TW WindowObject',
'description': 'Allows use of the window object, enabling opening and closing browser windows directly from Mashup',
'defaultBindingTargetProperty': 'url',
'properties': {
'url': {
'baseType': 'STRING',
'description': 'URL to open in new window',
'isBindingTarget': true,
'warnIfNotBoundAsTarget': true
},
'opened': {
'baseType': 'BOOLEAN',
'description': 'Indicates whether the window is currently open',
'isBindingSource': true
},
},
'services': {
'OpenWindow': {
'description': 'Opens a new window with the given URL'
},
'CloseWindow': {
'description': 'Closes the previously opened window'
}
},
};
};
this.renderHtml = function() {
return '<div class="widget-content">🪟</div>';
};
};
RUNTIME.JS
TW.Runtime.Widgets.WindowObject = function () {
var thiz = this;
var openedWindow = null;
this.renderHtml = function () {
return '<div class="widget-content"></div>';
};
// Optional: If we want to react when the URL property changes
this.updateProperty = function (updatePropertyInfo) {
if (updatePropertyInfo.TargetProperty === "url") {
thiz.setProperty("url", updatePropertyInfo.SinglePropertyValue);
}
};
this.serviceInvoked = function (serviceName) {
if (serviceName === "OpenWindow") {
var url = thiz.getProperty("url");
if (url) {
openedWindow = window.open(url, "_blank");
thiz.setProperty("opened", true);
}
}
if (serviceName === "CloseWindow") {
if (openedWindow && !openedWindow.closed) {
openedWindow.close();
thiz.setProperty("opened", false);
}
}
};
};
MetaData.xml
<?xml version="1.0" encoding="UTF-8"?>
<Entities>
<ExtensionPackages>
<ExtensionPackage name="WindowObject_ExtensionPackage" description="WindowObject Widget" vendor="Vilia" packageVersion="1.0.0" minimumThingWorxVersion="7.4.0" />
</ExtensionPackages>
<Widgets>
<Widget name="WindowObject">
<UIResources>
<FileResource type="JS" file="WindowObject.ide.js" description="" isDevelopment="true" isRuntime="false" />
<FileResource type="JS" file="WindowObject.runtime.js" description="" isDevelopment="false" isRuntime="true" />
</UIResources>
</Widget>
</Widgets>
</Entities>
Thats how my extension looks. My goal is to that i need two events which can be bindable with my button from ui. so i would bind my button with openWiindow event it will open the window and if i bind a button with closeWindow the tab of browser needs to be closed.. I have no clue how i can create these two events in my extension. i am looking forward to hearing from anyone soon thanks

