Products

Solutions

Resources

Partners

Community

About

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesConfirm Module ActionConfirm Module Action
Previous
 
Next
New Post
3/3/2019 3:45 AM
 

Hi all,

in a module I want to add an action to delete a bunch of records. This is not a real challenge, and I found a good blog contribution by Joe Brinkman here (the Url Postback example).

What I want to do is adding a dnnConfirm plugin to confirm the deletion.

Any idea how to do this?

My code so far:

public ModuleActionCollection ModuleActions
{
   get
   {
      ModuleActionCollection actions = new ModuleActionCollection();
      // some other actions...
      actions.Add(GetNextActionID(),
         Localization.GetString("DeleteResults.Action", LocalResourceFile),
         "DeleteStuff",
         "cancel",
         IconController.IconURL("Delete"),
         string.Empty,
         true,
         SecurityAccessLevel.Edit,
         true,
         false);
      return actions;
   }
}

protected override void OnInit(EventArgs e)
{
   // some other stuff here...
   AddActionHandler(MyActions_Click);
   base.OnInit(e);
}

private void MyActions_Click(object sender, ActionEventArgs e)
{
   switch (e.Action.CommandName)
   {
      case "DeleteStuff":
         if (e.Action.CommandArgument != "cancel")
         {
            // Call controller, do the deletes;
         }
         else
         {
            // Do nothing or display a cancel message or whatever
         }
         break;
      default:
         break;
   }
}

Any help is appreciated...

Happy DNNing!
Michael


Michael Tobisch
DNN★MVP

dnn-Connect.org - The most vibrant community around the DNN-platform
 
New Post
3/3/2019 9:48 AM
 

OK, got it.

There is a lot of problems to solve, main thing is to reach the menu item in the actions menu, because there is no client ID for that. Therefore, the item hgas to be reached by the href property of the link - which is a bit complicated. Finally I found out that the href is

  __doPostBack('dnn$ctr421$ModuleActions$actionButton', '6')

421 is the ModuleId, that was not hard to find. I suspected that '6' is the ID of the ModuleAction, but when investigating, I found out that this ID changed with every refresch - and even with every "? ModuleActions.GetActionByCommandName("DeleteStuff").ID" in the Direct Window at the same breakpoint:

? ModuleActions.GetActionByCommandName("DeleteStuff").ID
29
? ModuleActions.GetActionByCommandName("DeleteStuff").ID
33
? ModuleActions.GetActionByCommandName("DeleteStuff").ID
37

????

Finally I found out that '6' is the ActionID when creating the item - and that is NOT a (public) property of the ModuleAction. Again ???. Therefore I added a property "DeleteStuffActionID" and changed my code to in the ModuleActions property to:

   DeleteStuffActionID = GetNextActionID();
   actions.Add(DeleteStuffActionID, Localization.GetString("DeleteStuff.Action",
      LocalResourceFile), "DeleteStuff", "Delete", IconController.IconURL("Delete"),
      string.Empty, true, SecurityAccessLevel.Edit, true, false);

In the PreRender Event I added some JavaScript injection to hook on this link:

            StringBuilder confirmDeleteScriptBuilder = new StringBuilder();
            confirmDeleteScriptBuilder.Append("$(document).ready(function() {\r\n");
            confirmDeleteScriptBuilder.Append(string.Format("   var deleteLink = $(\"a[href='  __doPostBack(\\\\\\\'dnn$ctr{0}$ModuleActions$actionButton\\\\\\\', \\\\\\\'{1}\\\\\\\')']\");\r\n", ModuleId, DeleteStuffActionID));
            confirmDeleteScriptBuilder.Append("   deleteLink.dnnConfirm({\r\n");
            confirmDeleteScriptBuilder.Append(string.Format("      text: \"{0}\",\r\n", Localization.GetString("ConfirmStuffDelete.Text", LocalResourceFile)));
            confirmDeleteScriptBuilder.Append(string.Format("      yesText: \"{0}\",\r\n", Localization.GetString("Yes.Text")));
            confirmDeleteScriptBuilder.Append(string.Format("      noText: \"{0}\",\r\n", Localization.GetString("No.Text")));
            confirmDeleteScriptBuilder.Append(string.Format("      title: \"{0}\"\r\n", Localization.GetString("DeleteStuff.Action", LocalResourceFile)));
            confirmDeleteScriptBuilder.Append("   });\r\n");
            confirmDeleteScriptBuilder.Append("});\r\n");

            if (!(Page.ClientScript.IsStartupScriptRegistered("ConfirmDeleteScript")))
               Page.ClientScript.RegisterStartupScript(GetType(), "ConfirmDeleteScript", confirmDeleteScriptBuilder.ToString(), true);

If anyone wonders about the amount of backslashes: the escape sequence for \ is \\, and the Javascript needs \\\' for ', and in a string in C# this is getting \\\\\\\' - three backslashes and one ' :-)

Any less complicated way to achieve this would be appreciated...

Happy DNNing
Michael


Michael Tobisch
DNN★MVP

dnn-Connect.org - The most vibrant community around the DNN-platform
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesConfirm Module ActionConfirm Module Action


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out