I have sharepoint site and i want read in code global navigation information.
On properties page:
/_layouts/AreaNavigationSettings.aspx
I added "location","organization","98" nodes.
But when i am trying to get those nodes in code
using (var site = new Microsoft.SharePoint.SPSite(URL))
{
using (var currentWeb = site.OpenWeb())
{
return currentWeb.Navigation.GlobalNodes;
}
}
I have always those nodes:
Home
Quick launch
SharePoint Top Navbar
Why i have those strange nodes and how to get real globan naviigation/?
SharePoint's navigation is hierarchical. The hierarchy has exactly three nodes:
Home — represents the single 'home' icon in the upper left;
Quick launch — represents the quick launch menu at the left side of the page;
Top navigation bar — represents the navigation bar at the top of the page.
You have to delve into subnodes of these node to find your three nodes — see the SPNavigationNode.Children property. SharePoint lacks unique identifiers for navigation nodes so you have to rely on titles (display names).
UPDATE: Also please note that your code contains a serious design flaw. You are returning an object that's logically nested within a SPWeb out of the scope where the SPWeb instance is alive—i.e. out of the using statement. While this may work for navigation nodes generally such behavior will lead to errors. Those errors are often handled internally by SharePoint and result 'only' in logged error messages, but that's definitelly what your code should produce.
This works for me:
var pubWeb = PublishingWeb.GetPublishingWeb(web);
foreach (SPNavigationNode navigationNode in pubWeb.Navigation.GlobalNavigationNodes)
{
//do stuff
}
Related
Say that when I have 5 links on the toolbar and there's a table in the middle of the page.
As of right now I plan on making this a single page application. When I click a link on the left (Say from Entertainment to All) I would like it to be highlighted such as the All link on the left. The contents of the table will then change based on the link highlighted on the left.
Ex: If I click entertainment, only the categories with entertainment will be showed.
The highlighted status is due to having the "active" class for that particular div.
How would you implement that in MeteorJS? I can only figure out how to implement it with JQuery
One of the nice things that Meteor offers is session variables, changed and accessed via something like:
Session.set('activeLink', 'All')
Session.get('activeLink')
Meteor is automatically set to listen to Session variables and update your template helper functions when they change, so all you'd have to do is set your HTML to have a class equal to a helper function:
<a class={{isActive}}>
Then the helper would be something like:
Template.navLink.helpers({
"isActive": function() {
if (Session.get('activeLink') === Template.currentData().linkText) {
return "activeLink"
}
}
})
(Or however it is that you are storing the link information in the data context of each link).
I'm testing a website that opens in-browser pop-ups to display object details. These pop-ups are sometimes modal, by which I mean that they render the rest of the screen inoperative and trigger a gray transparent overlay that covers everything but the pop-up. This overlay is intended behavior, which means that I need a way to detect whether or not it was correctly triggered.
However, I am not familiar enough with the implementation of such overlays to determine where in the DOM I should look to find the properties that govern such behavior. As such, I was hoping someone with more information on how such overlays are usually configured could point me in the right direction.
The obvious solution is to simply try to click a button and see what happens but I was hoping to write a method that I could implement throughout the test suite rather than having to write a different check for each circumstance.
For those interested I'm scripting in Java using Selenium.
I know this is old, but it may still help someone else. I had just recently solved a similar problem for our React site. I believe we were using the react-block-ui module to implement our blocking overlays.
Basically, I was able to detect a certain element was blocked by an overlay because of 2 known facts:
The element was within a containing div ("the overlay") that followed a certain naming convention. In our case, it was section-overlay-X.
This overlay would have a class attribute (named av-block-ui) if it was blocking.
(Hopefully, you have access to this information, too... or something similarly useful.)
With this information, I wrote up a couple utility methods to help me determine whether or not that particular WebElement is blocked by an overlay. If it was blocked, throw a ElementNotInteractableException.
For Java:
...
By SECTION_OVERLAY_ANCESTOR_LOCATOR = By.xpath("./ancestor::div[contains(#id, 'section-overlay-')][1]");
...
private WebElement findUnblockedElement(By by) {
WebElement element = driver.findElement(by);
if (isBlockedByOverlay(element)) {
throw new ElementNotInteractableException(String.format("Element [%s] is blocked by overlay", element.getAttribute("id")));
} else {
return element;
}
}
private boolean isBlockedByOverlay(WebElement element) {
List<WebElement> ancestors = element.findElements(SECTION_OVERLAY_ANCESTOR_LOCATOR);
WebElement overlayAncestor = ancestors.get(0);
String overlayClass = overlayAncestor.getAttribute("class");
return !StringUtils.isBlank(overlayClass);
}
Here's my snippet on it:
https://bitbucket.org/snippets/v_dev/BAd9dq/findunblockedelement
This won't work in all situations, but I solved this problem by checking the overflow value of the body element. The flavor of modal I was trying to get past disabled scrolling of the page while it was active.
Setup: My Flex application is one consisting of several "subapps". Basically, the main application area is an ApplicationControlBar with buttons for each of the subapps. The rest of the area is a canvas where the subapps are displayed. Only one subapp is visible at a time. When switching between subapps, we do a canvas.removeAllChildren(), then canvas.addChild(subAppSwitchedTo). It's essentially a manual implementation of a ViewStack (the pros and cons of which are not the topic of this, so refrain from commenting on this).
Problem: In one of my subapps (let's say subapp "A"), I have a search function where results are displayed in a TitleWindow that gets popped up. Workflow is like enter search criteria, click search button, TitleWindow pops up with results (multiple selection datagrid), choose desired result(s), click OK, popup goes away (PopUpManager.removePopUp), and continue working. This all works fine. The problem is if I switch to a different subapp (say "B" -- where A gets removeAllChildren()'d and B gets added), then switch back to A and search again, when the results TitleWindow pops open, there will be TWO stacked on top of each other. If I continue to navigate away and back to A, every time I search, there will be an additional popup in the "stack" of popups (one for each time A gets addChild()'d).
Has anyone else experienced this? I'm not sure what to do about it and it's causing a serious usability bug in my application. Does this ring any bells to anyone? It's like I somehow need to flush the PopUpManager or something (even though I'm correctly calling removePopUp() to remove the TitleWindow). Please help!
EDIT
Flex SDK = 4.5.1
// Subapp "A"
if (!certificateSearchTitleWindow)
{
certificateSearchTitleWindow = new CertificateSearchTitleWindow;
certificateSearchTitleWindow.addEventListener("searchAccept", searchOKPopupHandler);
certificateSearchTitleWindow.addEventListener("searchCancel", searchClosePopupHandler);
}
PopUpManager.addPopUp(certificateSearchTitleWindow, this, true);
My guess is that the popup is removed from the main display list when you remove its parent (this in the PopUpManager.addPopup() method), but not from its parent display list. Why don't you listen, in your subapps, to the Event.REMOVED event, and then remove your popup ? That would be :
private var pp:CertificateSearchTitleWindow;
private function onCreationComplete():void
{
addEventListener(Event.REMOVED, onRemovede);
}
private function addPopUp():void
{
if (!pp) {
pp = new CertificateSearchTitleWindow();
PopUpManager.addPopUp(pp, this, true);
}
}
private function onRemoved(event:Event):void
{
if (pp) {
PopupManager.removePopUp(pp);
pp = null;
}
}
Thank you to those who gave suggestions. It turned out I was re-registering an eventListener over and over.
I am using a singleton to act as "shared memory" between the subapps. I was setting singleton.addEventListener(someType, listener) in subapp A's creationComplete callback. So everytime I navigated back to A, the creationComplete was running and re-adding this listener. After the search, the listener method (that opened the popup) was being called multiple times, i.e., as many times as the event had been added.
xref: http://forums.adobe.com/message/3941163
I am using MenuBuilder with code like this:
public static MenuItem MainMenu(UrlHelper url)
{
Menu.DefaultIconDirectory = url.Content("~/Public/Images/");
Menu.DefaultDisabledClass = "disabled";
Menu.DefaultSelectedClass = "current";
return Menu.Begin(
Menu.Items("",
Menu.Action<HomeController>(p => p.Index(), "Home")
),
Menu.Items("",
Menu.Secure<HomeController>(p => p.About(), "About")
),
Menu.Items("",
Menu.Action<RegulationController>(p => p.Index(null), "Compliance")
)/* This is in the Compliance area */
).SetListClass("menu");
}
But I am also using MvcContib Areas and in the code above the final menu item is in an 'Area' called 'Compliance'.
(There are two other areas in the Mvc application and the first in the list of registered areas is called 'Legislation')
What happens is the following:
When a page is rendered (I am using the standard WebFormsViewEngine) the Urls are all rendered using the 'Legislation' area!!?
E.g. http://localhost:1337/Legislation/Home or http://localhost:1337/Legislation/Home/About
and finally http://localhost:1337/Legislation/Regulation
The first two links should not pick up the 'Legislation' area. The last menu item should be in the 'Compliance' area.
How do I prevent the erroneous Area (Legislation) being rendered on the first two links?
How do I get the MenuBuilder markup in the Site.Master to accept an 'area' attribute or get it picked up automatically from the Controller for each link?
It seems that MvcContrib MenuBuilder does not play well with Areas. In the end I took the Areas out and the problem went away.
However, I recognise there may have been some other issue in the Mvc application which may indeed have been related to the older (beta?) version of Mvc dll that MvcContrib was referencing.
So for anyone that comes across this it may indeed be a none issue.
I asked a related question on this yesterday, and was told what not to do, but not what I should do.
I've got a master page that I'll call "TheMaster". I've got 2 sub master pages "Sub1" and "Sub2". They both have a Masterpage directive of "TheMaster". Web Forms have a Masterpage directive of "Sub1" or "Sub2". These aren't the real names.
In "TheMaster", I figure out what page the user is on, find out where in the Web.sitemap they are, and using that, I have the Web.sitemap node and the parent and the parent's parent, if they all exist. I use this to build navigation dynamically and highlight the current page.
Now, our designers have several places this navigation appears. Top nav, sub nav, teritiary nav on the left, and a "breadcrumb" style showing home -> parentparentnode -> parentnode -> currentpage
I can NOT define all of this in "TheMaster" due to layout constraints.
So, in "TheMaster", I find their current node, and save that as a public property of "TheMaster" (along with several other pieces of info.
In Sub1, even though it is using "TheMaster" as it's masterpage, it does not appear to be able to find my public properties from "TheMaster".
Any ideas on how I can get this info to be available all the way through this house of cards?
I've tried
Page.Master.myProp (nope)
Parent.myProp (nope)
I can't think of anyything else to get this to work. "TheMaster" has basically no knowledge of "Sub1", so I can't set a property on Sub1 and have it go down the tree, and the nodes down the tree are apparently oblivious to their parents...???
Cast Parent or Page.Master to your actual MasterPage class.
((MyMaster)Page.Master).myProp // found!
Casting gets you there, but it isn't so clean nor maintainable in the long run. I've done very, very complex versions of this using a series of interfaces to abstract things. See this blog post for a simplified version with one layer. The trick to adding more layers is just adding some more interfaces and abstract classes as appropriate.