Rails view dependent on time - html

I'd like to have a div in my view, that shows a piece of text, if the current time is between 9am-5pm GMT, Monday-Friday. But a button if it's outside of that time.
How can I achieve this?

You have helpers for time and day like Time.now to get the current time and Time.now.wday that returns the integer corresponding the week day. Just compare then with your rule in your view and you are good to go.

Something like this should work
# Time.now.utc may work
now = Time.now.in_time_zone('GMT') as well
if time.wday.in?(1..5) && time.hour.in?(9..16)
# show text
else
# show button
Make sure you modify this code for the templating engine you use (ERB or HAML) appropriately.

In your controller, you can check something like #open = (1..4).include?(Time.now.wday) && (9..17).include?(Time.now.hour)
You get true, or false. Now, you are able to use #open to show the button (false), or the text (true)

Related

ms access dynamically adding textbox for amount of goals

Good evening,
I'm completely stuck in ms access, trying to create dynamically added fields.
I've got a form called frmMatch.
It contains 6 fields called:
MatchDate - Date field
CompetitionType - ComboBox
Location - Input field
TeamName - Input field
ResultHome - Input field
ResultAway - Input field
Now what I would like to create is just a simple button called something like Add Scored Players
The problem is, I have no clue on how to get VBA to run through the ResultHome field if it is a Home game or through ResultAway if it is an Away game.
For example when a home game end up with a 3-1 win I would like VBA to run through a loop until it hits the ResultHome value, in this case 3.
And adds the amount of text box in according with the ResultHome value.
So I can put in the names from a combobox or textbox and the time he scored.
I hope you guys can help me out with this.
Ive searched on this form as well as other website but I cant find anything that would help me.
What you need here is not to "add textboxes", but rather to make them visible.
So, what you'll need to do is to create all your textboxes and set their Visible property to "False". Name them with numbers, like "tbScore1", "tbScore2", "tbScore3", etc...
Then, you'll need to add some VBA behind your button to make the proper number of textboxes visible. Something like:
'If both scores are 0, no need to show anything
If ResultHome.Value = 0 and ResultAway.Value = 0 then
exit sub
else
'Otherwise, set the value of the loop to whatever the score is
If ResultHome.Value <> 0 then
LoopVal = ResultHome.Value
else
LoopVal = ResultAway.Value
endif
endif
'Make as many textboxes visible as necessary
For i = 1 To LoopVal
MyFormName.Controls("tbScore" & i).Visible = True
Next
Note: this is all "aircode" and is not tested, so it may require some tweaking to make it work. But this is the logic structure you can use to achieve your results.

<%#Eval %> in asp.net to move page

Like other 'List' page, I'm making a <a> tag on td, and 3buttons 'Go up','Go down','Go list'.
I succeed after click this link, go another page.
<%#Eval("Title")%>
Now, the problem is here. To make Go up/down pages, I guess put the number +1 on the link to calculate page number.
<%#Eval("Title")%>
Then, when I check address, result just show +1 not calculate.
//address : http://localhost:61375/NoticeDetail.aspx?seq=+1
How can I calculate on Eval Databinding data and show that? or, do you know how to make a function up/down page with Eval?
If you have a string value in the database and you expect it to always be an integer and it shouldn't be null, then you should use int.Parse()
<%#Eval("Title")%>
Otherwise if you don't know the type of data and you don't sure about the null values then should use Convert.ToInt32(). Convert.ToInt32() returns 0 for null, while int.Parse() throws a ArgumentNullException
<%#Eval("Title")%>
You're not parsing the int, try this (if your int is nullable though, make sure you check for that first):
<a href='NoticeDetail.aspx?seq=<%# int.Parse(Eval("Seq").ToString()) + 1 %>'><%#Eval("Title")%></a>

Receiving click events from separate lines with AS3

I want to receive separate click events from separate lines in a text field, and every time a certain line is clicked by the user, I would like to highlight it and have an event happen.
I would ideally like this to happen with dynamic text, and not have to break the text apart by hand. Using the htmlText property is an option, but I am unsure as to how to bind clickEvents to separate elements.
Where do I begin?
There is no ready to use solution for this. But you can make it yourself using a few things:
set CLICK listener for the whole text field
listen for click and check the caretIndex property
use getLineIndexOfChar to check what's the line of the current caret position
use getLineOffset and getLineLength to get the position of the first and last character of that line
use setSelection to highlight this line
There might be some faster and easier way, but this is what works for sure :)
EDIT: decided to post the solution code, as I was wondering how exactly it works.. and it would be a shame to just leave it unpublished and make you do it instead :)
field.addEventListener(MouseEvent.CLICK, onTfClicked);
function onTfClicked(e:MouseEvent):void {
trace (field.caretIndex);
var line:uint = field.getLineIndexOfChar(field.caretIndex);
var start:uint = field.getLineOffset(line);
var end:uint = start + field.getLineLength(line);
field.setSelection(start, end);
}

Displaying selected OPTION in HTML dropdown menu on refresh, not value - possible?

My drop down menu has genres that it displays, but numbers as the values, eg
<option value=240>Alternative Rock</option>
My POST data deals with just the value - that's all I need for my database, and it works fine.
However, I'd like to display the selected option after submission, which I would normally do like this if the option and value are the same...
if ( isset($_POST['genre']) && $_POST['genre'] != "" && $_POST['genre'] != "undefined" ) echo stripslashes(htmlentities($_POST['genre'])); else echo 'All';
But since they are not the same, after submission the above example now displays "240" as it's selection, not "Alternative Rock".
How do I get it to remember the display option, not just the value, while still getting the numerical value that my database queries need?
Thanks for taking a look.
The POST is not going to include the disable value by default. There are a couple options... You can store all the options on the server side while the original page is being created (for example, in a session variable), and then look up the display value when the POST comes in. Or you can use JavaScript to set a hidden form element with the display value, when the user submits the form.

Only allowing one Drilldown in SSRS

It took me hours of searching and putting together piecemeal parts to find the solution to this, so I figured I'd post it on here in the hopes of helping someone else.
The Problem: We need to display a report, with proper grouping and drilldowns. However, we should only allow one group to be drilled down at one time.
SSRS doesn't exactly have robust scripting options - for instance, you can't close other groups "on click" or anything like that. So how do you do it?
In My example i'm using the AdventureworksDW database. I want to have a dataset that includes the total sales for each group and region. My Stored Procedure looks something like this:
SELECT dst.SalesTerritoryGroup,
dst.SalesTerritoryRegion,
SUM(fis.SalesAmount) AS SaleTotal,
DATEPART(YEAR,fis.OrderDate) AS OrderYear
FROM [dbo].FactInternetSales AS fis
INNER JOIN [dbo].DimSalesTerritory AS dst
ON fis.SalesTerritoryKey = dst.SalesTerritoryKey
WHERE fis.OrderDate < #QueryEndDate
GROUP BY
dst.SalesTerritoryGroup,
dst.SalesTerritoryRegion,
DATEPART(YEAR,fis.OrderDate)
UNION ALL /*The ResellerSales table. Same info.*/
From there I added a table with two groups: SalesTerritoryRegion and its parent, SalesTerritoryGroup. I also added a column to the left INSIDE the SalesTerritoryGroup, with an X (this can also be an image if you'd like). This is the "Drilldown" button that we'll use.
Create a string parameter, mine was #ExpandedGroup. Set the Default to an empty string (so that all the groups start out collapsed). Right click on the SalesTerritoryRegion group, or whatever your subgroup is, and go to the visibility tab. Click "Show or Hide based on Expression" and enter something like this:
=iif(Parameters!ExpandedGroup.Value="" or
Fields!SalesTerritoryGroup.Value<>Parameters!ExpandedGroup.Value,True,False)
This statement means: If we haven't opened a dropdown, or if the dropdown isn't the one selected, set hidden to true. Otherwise, false.
Next click on your "X" column to the left of SalesTerritoryGroup or your supergroup. Right click to go to Textbox Properties. Click the action tab. From there select "Go to Report". When you specify a report, make the target itself (For instance, mine is Main). Then, add parameters to the report.
The most important here is ExpandedGroup. The name should be ExpandedGroup, but the value is not just [ExpandedGroup]. Instead, it's an expression:
=IIF(Fields!SalesTerritoryGroup.Value=Parameters!ExpandedGroup.Value,
"",
Fields!SalesTerritoryGroup.Value)
This expression says: If the Group is the same as the Expanded group, make ExpandedGroup an empty string when you load the report. Otherwise, send the TerritoryGroup value. Essentially, this will let us toggle on and off the drilldown (same as you would in the report if you had traditional drilldowns).
Note: Also be sure to pass other parameters! For instance, my query requires a date to exclude some transaction data. If you don't pass this parameter in the "Go to Report" action, then you'll have to enter it again when you DrillDown. This also means you can give yourself even more flexibility when you click a drilldown (changing a chart that's displayed etc.) which is what I'm doing for this project.
Hope it helps someone out! Of course, if there is a more elegant or simpler solution I'd absolutely love to hear it.