Bruce Gust
asked on
Why does this switch / case not work?
Here's my code:
What you see is put into motion with a JavaScript code that changes the class assignment to different "<li>'s." That looks like this:
When I say "Everything works," I'm talking about all of the cases except for the one that I've been asked to add to the mix. That one is "personal_payments." When I click on the box like what you see pictured below...
Nothing happens. I'm needing all of the transactions that don't have a green "P" to slip out of sight and nothing happens.
What am I missing?
<?
switch($eventtype){
case "comment":
case "text":
case "note":
?>
<?=$content?>
<?
break;
case "statement":
$dir_exists = $demo ? true : is_dir($dir);
$file_exists = $demo ? true : file_exists($dir . $file);
if($file_exists && $dir_exists) {
?>
<a href='<?=$demo?'/admin/statement/?accountid='.$demo:'/admin/statement/load/'.$content?>' target='_statement'><img src='/assets/images/pdf_hover.png'/>View Statement</a>
<?
} else if($dir_exists) {
?>
<span class="error">Failed to send.</span>
<?
} else {
?>
<span class="pending">Attempted to send... Pending feedback.</span>
<?
}
break;
case "transaction":
?>
<div class='amount'><?=GlobalFunctions::formatMoney($amount)?><span class='float'>
<span class='payer <?=$payer?>'><?=$payer?></span><span class='transtype <?=$transactiontype?>'><?=$transactiontype?></span>
</div>
<?if($dos !== null && $dos !=='1900-01-01'){?><div class="dos"><?='DOS : ' . date('M d, Y',strtotime($dos))?></div><?}?>
<div class='encounter'><?if($encountercode != null){?>Encounter Code <?=$encountercode?><?}else{?>No encounter<?}?></div>
<div class='description'>
<?=$content?>
</div>
<?
break;
case "transactions":
?>
<ul>
<?foreach($transactions as $txn){
?>
<li>
<div class='amount'><?=GlobalFunctions::formatMoney($txn['amount'])?><span class='float'>
<span class='payer <?=$txn['payer']?>'><?=$txn['payer']?></span><span class='transtype <?=$txn['transactiontype']?>'><?=$txn['transactiontype']?></span>
</div>
<?if($txn['dos'] !== null && $txn['dos'] !=='1900-01-01'){?><div class="dos"><?='DOS : ' . date('M d, Y',strtotime($txn['dos']))?></div><?}?>
<div class='encounter'><?if($txn['encountercode'] != null){?>Encounter Code <?=$txn['encountercode']?><?}else{?>No encounter<?}?></div>
<div class='description'>
<?=$txn['content']?>
</div>
<div class='txntime'><?=Date('h:i A',strtotime($txn['eventdate']))?></div>
<?/*if(isset($txn['runningbal'])){?>
<div class='runningbal'>Running balance : <span><?=$txn['runningbal']?></span></div>
<?}*/?>
</li>
<?}?>
</ul>
<?
break;
case "personal_payments":
?>
<ul>
<?foreach($transactions as $txn_payer){
if($txn_payer['payer']<>"I")
{
continue;
}
else
{
?>
<li>
<div class='amount'><?=GlobalFunctions::formatMoney($txn_payer['amount'])?><span class='float'>
<span class='payer <?=$txn_payer['payer']?>'><?=$txn_payer['payer']?></span><span class='transtype <?=$txn_payer['transactiontype']?>'><?=$txn_payer['transactiontype']?></span>
</div>
<?if($txn_payer['dos'] !== null && $txn_payer['dos'] !=='1900-01-01'){?><div class="dos"><?='DOS : ' . date('M d, Y',strtotime($txn_payer['dos']))?></div><?}?>
<div class='encounter'><?if($txn_payer['encountercode'] != null){?>Encounter Code <?=$txn_payer['encountercode']?><?}else{?>No encounter<?}?></div>
<div class='description'>
<?=$txn_payer['content']?>
</div>
<div class='txntime'><?=Date('h:i A',strtotime($txn_payer['eventdate']))?></div>
<?/*if(isset($txn_payer['runningbal'])){?>
<div class='runningbal'>Running balance : <span><?=$txn_payer['runningbal']?></span></div>
<?}*/?>
</li>
<?
}
}?>
</ul>
<?php
}
?>
What you see is put into motion with a JavaScript code that changes the class assignment to different "<li>'s." That looks like this:
$('input[name="filt"]').on('change',function(){
if(this.value=='all'){
if($(this).is(':checked')) $('input[name="filt"]').attr('checked', true);
else $('input[name="filt"]').attr('checked', false);
} else {
$('input[name="filt"][value="all"]').attr('checked', false);
}
var show = [];
var left = true;
$('input[name="filt"]:checked').each(function(){
show.push($(this).val());
});
var year = '';
var month = '';
$('.at_timeline_list li').each(function(){
if($(this).hasClass('yearheader')){
if(year && year.data('delete')) year.slideUp();
else if(year) year.slideDown();
year = $(this);
year.data('delete', true);
} else if($(this).hasClass('monthheader')){
if(month && month.data('delete')) month.slideUp();
else if(month) month.slideDown();
month = $(this);
month.data('delete', true);
} else if($(this).hasClass('event')){
if(show.indexOf($(this).data('type'))!=-1){
$(this).removeClass('left').removeClass('right');
$(this).addClass(left?'left':'right');
left=!left;
if($(this).css('display')!='list-item') $(this).slideDown();
year.data('delete',false);
month.data('delete',false);
} else {
if($(this).css('display')=='list-item') $(this).slideUp();
}
}
});
if(year && year.data('delete')) year.slideUp();
else if(year) year.slideDown();
if(month && month.data('delete')) month.slideUp();
else if(month) month.slideDown();
});
When I say "Everything works," I'm talking about all of the cases except for the one that I've been asked to add to the mix. That one is "personal_payments." When I click on the box like what you see pictured below...
Nothing happens. I'm needing all of the transactions that don't have a green "P" to slip out of sight and nothing happens.
What am I missing?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ok, everything under the sun in there including angular .... and judging by the code submitted this is not really a proper Angular application - there is only one controller in that source and it is confined to the <h2> - I can't even begin to imagine how the rest of the code has been structured.
Bottom line without a working link or the full code base we are going to be hard pressed to help you.
From the source
Bottom line without a working link or the full code base we are going to be hard pressed to help you.
From the source
// This is crazy that I have to do this much to make this happen.
// Eventually the pf library will be rebuilt and made sensible, and I'll use a modular
// and Angular approach to build iteration 2.
ASKER
Julian!
I'm going to close this question, just because there's more to it than what's fair to ask any ninja to deconstruct, however... And Kim, this is for you as well:
I still need to understand what's in front of me, so I'm breaking the JS that I have down bit by bit. The first question is at https://www.experts-exchange.com/questions/28961513/How-does-this-Javascript-work.html. Feel free to weigh in.
And Julian, where is the Angular? I looked that up to see what it is, but I don't recognize what I've got above as having anything than just your basic JS. Let me know if you would.
Thanks, guys!
I'm going to close this question, just because there's more to it than what's fair to ask any ninja to deconstruct, however... And Kim, this is for you as well:
I still need to understand what's in front of me, so I'm breaking the JS that I have down bit by bit. The first question is at https://www.experts-exchange.com/questions/28961513/How-does-this-Javascript-work.html. Feel free to weigh in.
And Julian, where is the Angular? I looked that up to see what it is, but I don't recognize what I've got above as having anything than just your basic JS. Let me know if you would.
Thanks, guys!
Take a look at line 48 - require is trying to load the angular 1.2.6 library. Also refer to the comment I cut from the code - in my previous post.
Angular in 10 seconds ...
It is a JavaScript framework for building client side applications (often called Single Page Applications). It is based on an MVC framework and a methodology called 2 way binding - you create your model (basically JS objects) and you bind those to the view (HTML Templates) - Angular handles the two way interaction between the two. So if you change the model - say with an AJAX call - the view automatically updates. Likewise - if you change the view (click something or type something into a control) it automatically updates the model. It takes a bit of getting used to but once you have a handle on it there is no other way to build web based applications (in my view).
This project looks like something that has grown and been added to overtime and is overdue for a refactor - or rewrite.
If the page you are wanting to change is Angular based - then you would need to look in the model and controller for the page to see how to interact with the new checkbox.
If it is not using Angular then you would need to find where the click on the filt checkboxes is handled and deal with it there.
Angular in 10 seconds ...
It is a JavaScript framework for building client side applications (often called Single Page Applications). It is based on an MVC framework and a methodology called 2 way binding - you create your model (basically JS objects) and you bind those to the view (HTML Templates) - Angular handles the two way interaction between the two. So if you change the model - say with an AJAX call - the view automatically updates. Likewise - if you change the view (click something or type something into a control) it automatically updates the model. It takes a bit of getting used to but once you have a handle on it there is no other way to build web based applications (in my view).
This project looks like something that has grown and been added to overtime and is overdue for a refactor - or rewrite.
If the page you are wanting to change is Angular based - then you would need to look in the model and controller for the page to see how to interact with the new checkbox.
If it is not using Angular then you would need to find where the click on the filt checkboxes is handled and deal with it there.
ASKER
Open in new window
I'm looking for the JavaScript code that coincides with the "filt" variable (Kim, I see your observation and I'll look into that here in a little bit).
Ray, you're right. I'll change that. That's peppered throughout this entire app.
Thank you, gentlemen. We are poised on the threshold of great things!