I would like to get the userID of the current logged on user in DotNetNuke on a custom module. It's important not to use any functions from the code behind. Any ideas?
If your ASCX File inherits from PortalModuleBase (or a class that ultimately inherits from that) you can use something like
<%= UserId %>
That will spit it out on the page.
edit: updated to include the right code
Related
I'm writing my custom property type for module 2sxc. I mean I'd added a js file inside my app at path "/system/field-string-my-custom-field/index.js" and I'm writing my code there.
And I need to get id (or guid) and entity type of a current edited/created entity in modal window. I didn't find neither id, nor guid of that entity. The only place I've noticed in the html inside iframe that could tell type of entity is title on top of modal window, but that's also not good to take it from there, since it's actually a label, not the name of the entity, which might be different from the actual entity name. When I checked the code that is executed on submit button click - it has object formBuilderRef, which contains all the listed data I need (current entity's id, guid, type). But I didn't succeed in accessing it from my code for now.
Additional info:
I'm creating a custom property like this one. So on editing entity with my custom property type there's this modal window. Modal image is from internet but it should be enough to get an idea.
iframe's src property contains EntityId, but it looks like a bad place to take id from, since it contains an id of the entity used to open modal window of 2sxc module, but I could go to app settings and start editing totally different entity that is not on a current page at all. So I need an id of that currently edited entity and correct type, not a label.
So how do I get the data I need from there?
You can get them on
context.target.entity.id and context.target.entity.guid
see also: https://docs.2sxc.org/js-code/edit-form/formulas/context.html
while developing formulas, it's best to also watch the console, because on test-runs it will output all relevant objects data and context to the console.
I have a Snippet model that I'm using ModelAdmin to create, edit, and list in Wagtail. I'd like to create a copy function, and I can see that wagtail supports this out of the box for Page objects:
Before I write custom code to do this, I thought I'd ask if there is any way to easily do this within Wagtail. I didn't find any hooks that would even easily allow adding more buttons, and while I did find modeladmin-list-display-add-buttons, it seems to only allow me to change the placement of the default edit and delete buttons.
It is possible to achieve this. However, it will require custom code, and various overrides and additions in different places. Here are some steps that should help you on your way, with some links to some example code in the wagtailmenus extension, which does this exact thing:
Adding the custom view:
Create a custom CopyView view (subclassing wagtail.contrib.modeladmin.views.EditView will probably be your best starting point). For inspiration, you might want to take a look at one I created for wagtailmenus: https://github.com/rkhleics/wagtailmenus/blob/master/wagtailmenus/views.py#L141
Integrate the view with your ModelAdmin class, by adding a copy_view() method that instantiates your custom view. For example:
https://github.com/rkhleics/wagtailmenus/blob/master/wagtailmenus/modeladmin.py#L78
Override your ModelAdmin class's get_admin_urls_for_registration() method, to make the view accessible via a URL. For example: https://github.com/rkhleics/wagtailmenus/blob/master/wagtailmenus/modeladmin.py#L82
Getting the button to show in the listing:
Create a custom ButtonHelper class by subclassing wagtail.contrib.modeladmin.helpers.ButtonHelper.
Add a copy_button() method to it, that can provide all of the necessary details to create the button. For example: https://github.com/rkhleics/wagtailmenus/blob/master/wagtailmenus/modeladmin.py#L38/
Override the get_buttons_for_obj() method to output the copy button in the listing along with the others, depending on the user's permissions (e.g. https://github.com/rkhleics/wagtailmenus/blob/master/wagtailmenus/modeladmin.py#L49)
Finally, get your ModelAdmin class to use your custom ButtonHelper instead of the default one, by changing the button_helper_class attribute to reference your custom class.
If you'd like to understand more about all of the various classes within wagtail.contrib.modeladmin, I'd suggest reading the modeladmin customisation primer page from the official Wagtail documentation.
For example, to create or edit an object, when I want to add or change some value to one specific field, I need to refer another website to retrieve some info.In this way, may I add one button or link on the edit page?
The help link of SalesForce is here: https://help.salesforce.com/apex/htviewhelpdoc?id=co_edit.htm&language=en_US
Thanks.
Custom buttons and links don't display on new/edit page layouts so even if you'd make one, it will be visible only on detail view.
Not too invasive option would be to create a URL or text fied, set it's default value to your link, make sure it's displayed on the page but readonly. Haven't tried it but should work (you'll have to test it as somebody other than System Administrator because you'll bypass the readonly property of the page layout).
More invasive option would be to override the new and edit page layouts with Visualforce. More work but somewhat clean solution.
Really crazy option would be to embed a piece of Javascript into section header on the standard page layout or even into sidebar. It's an ugly hack but it works, I've used it for example to disable editing of Name field.
To use method #3:
create new section header, add something to the section (blank space is fine, you need something otherwise headers for blank sections aren't rendered), mark the section as visible on edit pages only.
Section name has limit of 80 characters but can contain code like <script>document.getElementById('Name').disabled = true;</script>. You need longer script though to somehow create an URL at runtime and append it somewhere on the page near your "special" field.
Upload a static resource with your script, then use this as the section header: <script src="filename.js" type="text/javascript"></script>
I'm not too proud of this hack and if you can - go with custom Visualforce new & edit page. It's quick & dirty, probably should be used only when you're not allowed to override pages.. but it works.
i want to use the active "tab"-name or page name inside my DNN Skin.
I can't find anything on the web about it (which is slightly odd). I'm looking for a control or sth. which i could use inside my ascx-file.
I don't think that there is a built-in skin object for displaying the name of the page. You can use this snippet in your skin to get the page's name:
<%= Server.HtmlEncode(PortalSettings.ActiveTab.TabName) %>
You can also get the page's title (the text displayed in the browser window title) via
<%= Server.HtmlEncode(PortalSettings.ActiveTab.Title) %>
Basically I have my Model, View and Controller working perfectly for Users, but I'm trying to find out how and where the "Actions" sidebar gets generated? I'm basically trying to add to it for the Users view. Thanks in advance.
It's in the corresponding view file, e.g. /views/users/index.ctp. Remove/edit it there.
Removing the code from the view will get rid of the text but the actual sidebar will remain. To remove that for all views edit webroot/css/cake.generic.css. To modify only a particular view, create your own .css stylesheet and call it from the controller method or view. The bakery has helpful article for this.