2022-03-28 21:49:01 +00:00
|
|
|
package components
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/maxence-charriere/go-app/v9/pkg/app"
|
|
|
|
"github.com/mlctrez/goapp-mdc/pkg/button"
|
|
|
|
"github.com/mlctrez/goapp-mdc/pkg/dialog"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ModalDialog struct {
|
|
|
|
app.Compo
|
|
|
|
dialog *dialog.Dialog
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ModalDialog) Render() app.UI {
|
|
|
|
if m.dialog == nil {
|
|
|
|
m.dialog = &dialog.Dialog{Id: "notification-dialog"}
|
|
|
|
m.dialog.Title = []app.UI{app.Div().Text("Error")}
|
|
|
|
m.dialog.Content = []app.UI{}
|
|
|
|
m.dialog.Buttons = []app.UI{
|
|
|
|
&button.Button{Id: "notification-dialog-dismiss",
|
|
|
|
Dialog: true, DialogAction: "dismiss", Label: "dismiss"},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return m.dialog
|
|
|
|
}
|
|
|
|
|
2022-04-04 16:04:38 +00:00
|
|
|
func (m *ModalDialog) ShowError(msg ...string) {
|
2022-03-28 21:49:01 +00:00
|
|
|
if m.dialog == nil {
|
|
|
|
log.Debug("ModalDialog.dialog is nil, unable to display message", msg)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
m.dialog.Content = []app.UI{}
|
|
|
|
for _, s := range msg {
|
|
|
|
m.dialog.Content = append(m.dialog.Content, app.Div().Text(s))
|
|
|
|
}
|
|
|
|
m.dialog.Update()
|
|
|
|
m.dialog.Open()
|
|
|
|
}
|
2022-04-04 16:04:38 +00:00
|
|
|
|
|
|
|
func (m *ModalDialog) ShowDialog(title string, msg ...string) {
|
|
|
|
if m.dialog == nil {
|
|
|
|
log.Debug("ModalDialog.dialog is nil, unable to display message", msg)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
m.dialog.Title = []app.UI{app.Div().Text(title)}
|
|
|
|
m.dialog.Content = []app.UI{}
|
|
|
|
for _, s := range msg {
|
|
|
|
m.dialog.Content = append(m.dialog.Content, app.Div().Text(s))
|
|
|
|
}
|
|
|
|
m.dialog.Update()
|
|
|
|
m.dialog.Open()
|
|
|
|
}
|