IActionableDNN框架提供给模块制作者一个简单的菜单管理接口。这里主要讨论怎么使用它。

使用方法:

在声明类的时候在类名后面声明Implements Entities.Modules.IActionable,然后在下面实现它里面的必须实现的一个属性:Entities.Modules.IActionable.ModuleActions。例如:

        Public ReadOnly Property ModuleActions() As Entities.Modules.Actions.ModuleActionCollection Implements Entities.Modules.IActionable.ModuleActions

            Get

                Dim Actions As New Entities.Modules.Actions.ModuleActionCollection

                Actions.Add(GetNextActionID, Localization.GetString(Entities.Modules.Actions.ModuleActionType.AddContent, LocalResourceFile), Entities.Modules.Actions.ModuleActionType.AddContent, "", "", EditUrl(), True, Security.SecurityAccessLevel.Edit, True, False)

                Return Actions

            End Get

        End Property

ModuleActionCollectionadd方法有两个重载,这里总结一下其中一个:

Property

Value

Sample Data

ID As Integer [Each module action must have a unique ID. Use the GetNextActionID method to generate a unique id]

GetNextActionID

3

Title As String [Sets the text displayed on the menu]

Localization.GetString(Entities.Modules.Actions .ModuleActionType.AddContent, LocalResourceFile)

"Add Question"

CmdName As String [The command name passed to the client when this action is clicked. Used for JavaScript]

Entities.Modules.Actions.ModuleActionType.AddContent

"AddContent.Action"

CmdArg As String [The command argument passed to the client when this action is clicked. Used for additional parameters passed to JavaScript]

""

""

Icon As String [The URL of the Icon to place next to this action]

""

""

Url As String [The destination URL to redirect the client browser when this action is clicked.]

EditUrl()

"http://localhost/DotNetNuke/Home/tabid/36/ ctl/Edit/mid/423/Default.aspx"

UseActionEvent As Boolean [Determines whether client will receive an event notification]

False

       

Secure As DotNetNuke.Security.SecurityAccessLevel [The security access level required for access to this action]

SecurityAccessLevel.Edit

1

Visible As Boolean [Whether this action will be displayed]

True

True

NewWindow As Boolean [Whether this action will be displayed in a new window]

False

False

另一个请参见ModuleActionCollection

       这里说以下URL的参数的值,它用EditUrl()返回一个链接给它,而我们经常看见的点击设置或者编辑按钮就会跳转到相应的设置页面或者编辑页面,也是用EditUrl()这个方法的。这个方法怎么跳转至设置控件,请参见DNN自带的文档《DotNetNuke 4.0 Module Development (Part 1)》的NavigateURL: How to make a link部分(p74)。

       按照参数和格式写了实现代码後,自己的模块的下拉菜单部分就有了自己增加的菜单项了。

可是有时候我们不需要它跳转至某个设置页而是执行我们想要的动作怎么办?(比如显隐某部分)这时就需要用到它的自定义逻辑功能了。分几步实现这个功能:

首先需要告诉框架我们需要不需要自定义逻辑功能,这里是ModuleActionCollectionadd方法的参数UseActionEvent设置为true就可以了。

在当前模块的后台代码中注册页面事件。这里以HTML模块为例子:

在处理load事件的方法的后面写下下面的注册语句,记住ModuleAction_Click

                ' menu action handler

                Dim ParentSkin As UI.Skins.Skin = UI.Skins.Skin.GetParentSkin(Me)

                'We should always have a ParentSkin, but need to make sure

                If Not ParentSkin Is Nothing Then

                    'Register our EventHandler as a listener on the ParentSkin so that it may tell us when a menu has been clicked.

                    ParentSkin.RegisterModuleActionEvent(Me.ModuleId, AddressOf ModuleAction_Click)

                End If

定义处理事件函数ModuleAction_Click

Public Sub ModuleAction_Click(ByVal sender As Object, ByVal e As Entities.Modules.Actions.ActionEventArgs)注意这里的eActionEventArgs类,它有两个属性可以使用: ActionModuleConfiguration,分别是ModuleActionModuleInfo类型。这两个类型包含了很多信息,比如刚才点击的是什么菜单项的信息,那么用select case判断以后就可以分别处理各个菜单项的点击後所要发生的事情了。最后如果是跳转的话仍要给予它跳转:

            If e.Action.Url.Length > 0 Then

                Response.Redirect(e.Action.Url, True)

            End If

       这里总结一下ModuleActionModuleInfo类型有的属性,具体请分别参见两个类。

ModuleAction

            ID

            Title

            CmdName

            CmdArg

            Icon

           Url

            ClientScript

            UseActionEvent

            Secure

            Visible

            NewWindow

ModuleInfo:(写的虽然是私有方法,是为了拷贝方便才考这些,有相应的公共属性的)

        Private _PortalID As Integer

        Private _TabID As Integer

        Private _TabModuleID As Integer

              Private _ModuleID As Integer

              Private _ModuleDefID As Integer

              Private _ModuleOrder As Integer

              Private _PaneName As String

              Private _ModuleTitle As String

              Private _AuthorizedEditRoles As String

              Private _CacheTime As Integer

              Private _AuthorizedViewRoles As String

              Private _Alignment As String

              Private _Color As String

              Private _Border As String

              Private _IconFile As String

              Private _AllTabs As Boolean

              Private _Visibility As VisibilityState

              Private _AuthorizedRoles As String

              Private _IsDeleted As Boolean

              Private _Header As String

              Private _Footer As String

              Private _StartDate As Date

              Private _EndDate As Date

        Private _ContainerSrc As String

        Private _DisplayTitle As Boolean

        Private _DisplayPrint As Boolean

        Private _DisplaySyndicate As Boolean

        Private _InheritViewPermissions As Boolean

              Private _ModulePermissions As Security.Permissions.ModulePermissionCollection

        Private _DesktopModuleID As Integer

        Private _FolderName As String

        Private _FriendlyName As String

        Private _Description As String

              Private _Version As String

              Private _IsPremium As Boolean

              Private _IsAdmin As Boolean

              Private _BusinessControllerClass As String

        Private _ModuleName As String

        Private _SupportedFeatures As Integer

        Private _CompatibleVersions As String

        Private _Dependencies As String

        Private _Permissions As String

        Private _DefaultCacheTime As Integer

        Private _ModuleControlId As Integer

        Private _ControlSrc As String

        Private _ControlType As SecurityAccessLevel

        Private _ControlTitle As String

        Private _HelpUrl As String

        Private _SupportsPartialRendering As Boolean

        Private _ContainerPath As String

        Private _PaneModuleIndex As Integer

        Private _PaneModuleCount As Integer

        Private _IsDefaultModule As Boolean

        Private _AllModules As Boolean