-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMyModalWebViewViewModel.cs
More file actions
38 lines (31 loc) · 1.34 KB
/
MyModalWebViewViewModel.cs
File metadata and controls
38 lines (31 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System.ComponentModel;
using Mendix.StudioPro.ExtensionsAPI.Model;
using Mendix.StudioPro.ExtensionsAPI.Model.DomainModels;
using Mendix.StudioPro.ExtensionsAPI.UI.Dialogs;
using Mendix.StudioPro.ExtensionsAPI.UI.Services;
using Mendix.StudioPro.ExtensionsAPI.UI.WebView;
namespace MyCompany.MyProject.MendixExtension;
public class MyModalWebViewViewModel(
string title,
IModel currentApp,
IDialogService dialogService,
IMessageBoxService messageBoxService,
Uri webServerBaseUrl) : WebViewModalDialogViewModel(title)
{
public override void InitWebView(IWebView webView)
{
webView.MessageReceived += Browser_MessageReceived;
OnClosing = HandleOnClosed;
webView.Address = new Uri(webServerBaseUrl + "index");
}
void HandleOnClosed(CancelEventArgs cancelEventArgs) => messageBoxService.ShowInformation("Entity was created.");
void Browser_MessageReceived(object? sender, MessageReceivedEventArgs e)
{
using var transaction = currentApp.StartTransaction("create entity from modal");
var entity = currentApp.Create<IEntity>();
entity.Name = e.Message.Replace("\\", "").Replace("\"", "");
currentApp.Root.GetModules().First(m => m.Name == "MyFirstModule").DomainModel.AddEntity(entity);
transaction.Commit();
dialogService.CloseDialog(this);
}
}