Solved

activate tab panel based on xml data

Posted on 2013-05-28
10
239 Views
Last Modified: 2013-05-31
One change is when a team is up to bat I need the tab to be activated based on visitor up to bat or hometeam up to bat. The tab i'm talking about is tab panel with table of players.
So I started thinking I just want this to occur one time a inning. So What if I used 3 outs then start off with a# visitor then next 3 outs b# home get activated. or do you think nextbatter team id and if nextbatter team id = visitor #a becomes active else if nextbatter team id = home then b# becomes active. What do you think what approach is better or do you have a better idea. Sample code I'm just not sure of setting variable part TO COMPARE with team at bat.

var intOuts = d.find('Play').attr("Outs") || 0;
        if (intOuts === "3") {
    var sTeam = objNode.attributes.getNamedItem('vh').value;	
if (sTeam == 'A')	
 $mytabs.tabs('select', 0);         
 else if if (sTeam == 'H')	
 $mytabs.tabs('select', 1);         
 

        }
        

Open in new window


or  

 var players = $(data).find("Player");
		 var d = $(data);
   var Batter = d.find('NextBatter');
        if (Batter.size() > 0) {

          var nextbatterteam = Batter.attr('TeamID');
          var nextbatterid = Batter.attr('ID');
 var sTeam = objNode.attributes.getNamedItem('vh').value;	

}
		}

Open in new window

LineupcardGame2.html
37504.xml
development-bundle.zip
0
Comment
Question by:powerztom
  • 5
  • 5
10 Comments
 
LVL 18

Expert Comment

by:nap0leon
ID: 39202287
Since the next batter's team ID is not know until after the 3rd out, that would be the most reliable indicator to use and is a check that could be run every time you poll the XML.

Not saying this would happen, but it conceivably could... If you were to switch innings when the Out total became "3", what happens if the XML file was actually incorrect and they change it back to "2 outs"?

Anyway... just seems safer to use the ID of the next batter, since that will always tell you the team that is currently (or on their way up) to bat.

var d = $(data);
var Batter = d.find('NextBatter');
if (Batter.size() > 0) {
	var nextbatterteam = Batter.attr('TeamID');
	var nextbatterid = Batter.attr('ID');
}

Open in new window


Now that you have the ID of the team that is headed up to bat, you can use the team's ID to find out home or away to make sure the correct tab is active.

Edit:  From a usability perspective, you should probably only use this to activate a tab when the page first loads and when the Next Batter's team is different from the most recent "Current Batter". (Since a user can manually switch which team's panel is active, you don't want to keep switching it back to the the "at bat" team every 3 seconds.  only switch it when the at-bat team changes.)
0
 

Author Comment

by:powerztom
ID: 39205035
I 'm trying to construct the statement but I'm having a issue check it out

   function SetTab() {
	 var d = $(data);
   var Batter = d.find('NextBatter');
        if (Batter.size() > 0) {

          var nextbatterteam = Batter.attr('TeamID');
          var nextbatterid = Batter.attr('ID');
		  var Batter = d.find('NextBatter');
        if (Batter.size() > 0) {

          var batterteam = Batter.attr('TeamID');
          var batterid = Batter.attr('ID');
		  if (nextbatterid == batterteamid); 
		  $mytabs.tabs('select', 0);
		  else if
		   $mytabs.tabs('select', 1);
		}
		}
		}
}

Open in new window

0
 
LVL 18

Expert Comment

by:nap0leon
ID: 39205515
The next batter's team will always be the same as the current batter's team (unless there is no current batter... Maybe that will work in your comparison), but I would go with finding the "home team ID" or "away team ID" and use that in your comparison for which tab to select (you probably only need one team's ID for tab-selection, but it may be useful elsewhere as you add more functionality)
0
 

Author Comment

by:powerztom
ID: 39206238
You got me headed in the right path Can you write code?
0
 
LVL 18

Expert Comment

by:nap0leon
ID: 39209218
I adjusted the pathing to match my local system and also removed the interval timer.

I don't know how to work the UI selectors you are trying to use - they threw an error... but I have the code working for determining which team is home or away and comparing the next batter's team.  Messages are in console.log.  So where you see
console.log('select Away team');

Open in new window

that's where you want activate the away team's tab, etc.
LineupcardGame.html
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 18

Accepted Solution

by:
nap0leon earned 500 total points
ID: 39209230
Here is the correct syntax for selecting the team's tab

				if (nextbatterteam == awayTeamID) { 
					console.log('select Away team');
					$("#myTabs").tabs('select',0)
				} else {
					console.log('select Home team');
					$("#myTabs").tabs('select',1)
				}

Open in new window

0
 

Author Closing Comment

by:powerztom
ID: 39210649
Thank You Sir. Great work
0
 

Author Comment

by:powerztom
ID: 39211357
It broke the code I'll give you a zip of everything you need to test. The xml file is Home so activated tab such be the White Sox. What happened all the players were gone but now you have all necessary files. Your help is greatly appreciated
Lineup-Card1.zip
0
 
LVL 18

Expert Comment

by:nap0leon
ID: 39211416
A few issues...
1- the pathing to the jquery-ui-1.8.9.custom.css was incorrect
2- the pathing to the xml file was incorrect
3- the name of the xml file was incorrect
4- you did not have any (?) of the changes I made... like setting the homeTeamID and awayTeamID or the changes to select the correct tab
5- the xml file you sent has the Cubs at bat, not the WhiteSox, so the Cubs tab is activated.

Attached is the updated HTML file that you should be able to drop into the folder that you zipped.
LineupcardGame.html
0
 

Author Comment

by:powerztom
ID: 39211588
You did it great work. I am grateful
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article discusses how to create an extensible mechanism for linked drop downs.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now