Skip to content

Commit

Permalink
pref: use vxDialog instead of vDialog in Utils.go
Browse files Browse the repository at this point in the history
  • Loading branch information
danni-cool committed Sep 22, 2024
1 parent c772137 commit afd1510
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 89 deletions.
30 changes: 9 additions & 21 deletions presets/presets.go
Original file line number Diff line number Diff line change
Expand Up @@ -830,27 +830,15 @@ func (b *Builder) openConfirmDialog(ctx *web.EventContext) (er web.EventResponse

er.UpdatePortals = append(er.UpdatePortals, &web.PortalUpdate{
Name: portal,
Body: web.Scope(VDialog(
VCard(
VCardTitle(h.Text(promptText)).Class("pa-6"),
VCardActions(
VSpacer(),
VBtn(cancelText).
Size(SizeSmall).
Variant(VariantOutlined).
Class("ml-2").
On("click", "locals.show = false"),

VBtn(okText).
Size(SizeSmall).
Color("primary").
Variant(VariantFlat).
Theme(ThemeLight).
Attr("@click", fmt.Sprintf("%s; locals.show = false", confirmEvent)),
).Class("pb-6 px-6"),
),
).MaxWidth("400px").Class("common-dialog").
Attr("v-model", "locals.show"),
Body: web.Scope(
vuetifyx.VXDialog().

Check failure on line 834 in presets/presets.go

View workflow job for this annotation

GitHub Actions / build

undefined: vuetifyx.VXDialog
Size(vuetifyx.DialogSizeDefault).

Check failure on line 835 in presets/presets.go

View workflow job for this annotation

GitHub Actions / build

undefined: vuetifyx.DialogSizeDefault
Title("Confirm").
Text(promptText).
CancelText(cancelText).
OkText(okText).
Attr("@click:ok", fmt.Sprintf("%s; locals.show = false", confirmEvent)).
Attr("v-model", "locals.show"),
).VSlot("{ locals }").Init("{show: true}"),
})

Expand Down
11 changes: 8 additions & 3 deletions publish/version_compo.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,15 @@ func DefaultVersionComponentFunc(mb *presets.ModelBuilder, cfg ...VersionCompone
slug := primarySlugger.PrimarySlug()

div := h.Div().Class("tagList-bar-warp")

confirmDialogPayload := utils.UtilDialogPayloadType {
Text: msgr.Areyousure,
OkAction: web.Plaid().EventFunc(web.Var("locals.action")).Query(presets.ParamID, slug).Go(),
Msgr: utilsMsgr,
}

div.AppendChildren(
utils.ConfirmDialog(msgr.Areyousure, web.Plaid().EventFunc(web.Var("locals.action")).
Query(presets.ParamID, slug).Go(),
utilsMsgr),
utils.ConfirmDialog(confirmDialogPayload),
)

if !config.Top {
Expand Down
110 changes: 45 additions & 65 deletions utils/confirm_dialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@ import (
"github.com/qor5/admin/v3/presets"
"github.com/qor5/web/v3"
"github.com/qor5/x/v3/i18n"
. "github.com/qor5/x/v3/ui/vuetify"
vx "github.com/qor5/x/v3/ui/vuetifyx"
h "github.com/theplant/htmlgo"
"golang.org/x/text/language"
)

const I18nUtilsKey i18n.ModuleKey = "I18nUtilsKey"

type UtilDialogPayloadType struct {
Title string
TypeField vx.VXDialogType
Size vx.VXDialogSize
Text string
ContentEl h.HTMLComponent
OkAction string
CancelAction string
HideClose bool
Msgr *Messages
}

func Install(b *presets.Builder) {
b.GetI18n().
RegisterForModule(language.English, I18nUtilsKey, Messages_en_US).
Expand All @@ -24,81 +36,49 @@ func MustGetMessages(r *http.Request) *Messages {
return i18n.MustGetModuleMessages(r, I18nUtilsKey, Messages_en_US).(*Messages)
}

func ConfirmDialog(msg string, okAction string, msgr *Messages) h.HTMLComponent {
return VDialog(
VCard(
VCardTitle(h.Text(msg)),
VCardActions(
VSpacer(),
VBtn(msgr.Cancel).
Variant(VariantFlat).
Class("ml-2").
On("click", "locals.commonConfirmDialog = false"),
func ConfirmDialog(payload UtilDialogPayloadType) h.HTMLComponent {

if(payload.Title == "") {
payload.Title = payload.Msgr.ModalTitleConfirm
}

VBtn(msgr.OK).
Color("primary").
Variant(VariantFlat).
Theme(ThemeDark).
Attr("@click", okAction),
),
),
).MaxWidth("600px").
return vx.VXDialog().
Title(payload.Title).
Text(payload.Text).
HideClose(true).
OkText(payload.Msgr.OK).
CancelText(payload.Msgr.Cancel).
Attr("@click:ok", payload.OkAction).
Attr("v-model", "locals.commonConfirmDialog")
}

func DeleteDialog(msg string, okAction string, msgr *Messages) h.HTMLComponent {
return web.Scope(
VDialog(
VCard(
VCardTitle(h.Text(msg)),
VCardActions(
VSpacer(),
VBtn(msgr.Cancel).
Variant(VariantFlat).
Class("ml-2").
On("click", "locals.deleteConfirmation = false"),

VBtn(msgr.OK).
Color("primary").
Variant(VariantFlat).
Theme(ThemeDark).
Attr("@click", okAction),
),
),
).MaxWidth("600px").
Attr("v-model", "locals.deleteConfirmation"),
vx.VXDialog().
Title(msgr.ModalTitleConfirm).
Text(msg).
HideClose(true).
OkText(msgr.OK).
CancelText(msgr.Cancel).
Attr("@click:ok", okAction).
Attr("v-model", "locals.deleteConfirmation"),
).VSlot(" { locals }").Init(`{deleteConfirmation: true}`)
}

const CloseCustomDialog = "locals.customConfirmationDialog = false"

func CustomDialog(title h.HTMLComponent, content h.HTMLComponent, okAction string, msgr *Messages) h.HTMLComponent {
Vcard := VCard()
if title != nil {
Vcard.AppendChildren(VCardTitle(title))
}
if content != nil {
Vcard.AppendChildren(VCardText(content))
func CustomDialog(payload UtilDialogPayloadType) h.HTMLComponent {
if payload.Size == "" {
payload.Size = vx.DialogSizeLarge
}
Vcard.AppendChildren(
VCardActions(
VSpacer(),
VBtn(msgr.Cancel).
Variant(VariantFlat).
Class("ml-2").
On("click", CloseCustomDialog),

VBtn(msgr.OK).
Color("primary").
Variant(VariantFlat).
Theme(ThemeDark).
Attr("@click", okAction),
),
)
return web.Scope(
VDialog(
Vcard,
).MaxWidth("600px").
Attr("v-model", "locals.customConfirmationDialog"),
vx.VXDialog(
payload.ContentEl,
).Size(payload.Size).
Type(payload.TypeField).
Title(payload.Title).
OkText(payload.Msgr.OK).
CancelText(payload.Msgr.Cancel).
Attr("v-model", "locals.customConfirmationDialog").
Attr("@click:ok", payload.OkAction),
).VSlot(" { locals }").Init(`{ customConfirmationDialog: true }`)
}
4 changes: 4 additions & 0 deletions utils/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ package utils
type Messages struct {
OK string
Cancel string
ModalTitleConfirm string
}

var Messages_en_US = &Messages{
OK: "OK",
Cancel: "Cancel",
ModalTitleConfirm: "Confirm",
}

var Messages_zh_CN = &Messages{
OK: "确定",
Cancel: "取消",
ModalTitleConfirm: "确认",
}

var Messages_ja_JP = &Messages{
OK: "OK",
Cancel: "キャンセル",
ModalTitleConfirm: "確認",
}

0 comments on commit afd1510

Please sign in to comment.