Solved

activate tab panel based on xml data

Posted on 2013-05-28
10
240 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

910 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

23 Experts available now in Live!

Get 1:1 Help Now