admin icon indicating copy to clipboard operation
admin copied to clipboard

Modal window with confirmation action

Open MarcSky opened this issue 6 years ago • 2 comments

Hello everyone! I am trying to add a modal window with the text "Are you sure you want to perform this action?" add and edit buttons. I just can’t find in the documentation how this function is added. Could you show an example of how to make this modal window. Thanks.

MarcSky avatar Sep 06 '19 09:09 MarcSky

You can use Actions to achieve this functionality. We used it for creating pre-defined cancellation policies with a button. below is the sample code:

cancellationResource.Action(&admin.Action{
		Name: "R",
		Handler: func(argument *admin.ActionArgument) error {
			var db = configuration.GetDB(C.READ)
			productId := getIdFromURL(argument.Context.Context)
			if len(productId) == 0 {
				return errors.New("Some error occurred. Please try after some time")
			}
			var cpCount int
			var expiryDate string
			db.Raw(C.GET_CANCELLATION_COUNT, productId).Row().Scan(&cpCount)
			if cpCount == 0 {
				expiryDate = getProductExpiry(productId)
				if len(S.TrimSpace(expiryDate)) == 0 {
					expiryDate = time.Now().AddDate(1, 0, 0).Format(C.DATE_YYYY_MM_DD)
				}
				err := insertCancellationPolicies(expiryDate, productId, 0)
				if err != nil {
					return err
				}
			} else {
				return errors.New("Policy already exists")
			}
			return nil

		},
		Modes: []string{"collection"},
	})

Define ur own handler based on ur use case.

rohit-nahata avatar Oct 17 '19 11:10 rohit-nahata

@MarcSky

rohit-nahata avatar Oct 18 '19 04:10 rohit-nahata