You need to sign in to do that
Don't have an account?
visualforce timer module - based on case timer
I have been working on an application to create a claim timer... I remade it ok in s-control and now find I need to make it again in visual force...
where and how do I begin..?! please help.
here is my s-control
<html>
<head>
<link href="/dCSS/Theme2/default/common.css" type="text/css" media="handheld,print,projection,screen,tty,tv" rel="stylesheet" >
<link href="/dCSS/Theme2/default/custom.css" type="text/css" media="handheld,print,projection,screen,tty,tv" rel="stylesheet" >
<script src="/soap/ajax/10.0/connection.js"></script>
<style type=text/css>
table {font-size:12px}
.fTitle {font-size:11px; width:150px}
.fData {font-size:12px;}
</style>
<script>
var tO = null;
//var caseId = '{!Claim__c.Id}';
var caseId = 'a07300000045gt4';
var caseNumber = '{!SUBSTITUTE(SUBSTITUTE(Claim__c.Name,"<","<"),">",">")}';
var timerStart = '{!TEXT( Claim__c.FM_Timer_Timer_Start__c )}';
var timerRunning = '{!Claim__c.FM_Timer_Timer_Running__c}';
var timerSeconds = parseInt('{!TEXT(Claim__c.FM_Timer_Timer_Current_Seconds__c)}');
var timerPrevSeconds = parseInt('{!TEXT(Claim__c.FM_Timer_Timer_Previous_Seconds__c)}');
if (!(timerPrevSeconds))
{
timerPrevSeconds = 0;
}
if (!(timerSeconds))
{
timerSeconds = 0;
}
function UpdateTimer(s) {
Timer.innerHTML = FormatDate(s);
TimerTotal.innerHTML = FormatDate(s + timerPrevSeconds);
}
function RunTimer() {
timerSeconds += 1;
UpdateTimer(timerSeconds);
tO = setTimeout("RunTimer();",1000);
}
function Zero(n) {
if (n < 10)
return "0" + n;
else
return n;
}
function FormatDate(d) {
days = Math.floor(d / 86400);
hours = Math.floor((d % 86400) / 3600);
mins = Math.floor((d % 3600) / 60);
secs = (d % 60);
return days + "D " + Zero(hours) + ":" + Zero(mins) + ":" + Zero(secs);
}
function setupPage() {
if (timerRunning == '1')
{
ToggleButton(true);
RunTimer();
}
else
{
UpdateTimer(0);
}
}
function ToggleButton(b) {
if (b)
{
document.getElementById('startButton').style.display = 'none';
document.getElementById('stopButton').style.display = 'inline';
}
else
{
startButton.style.display = 'inline';
stopButton.style.display = 'none';
}
}
var wiprate = '100';
function getWIP(w,t) {
result = sforce.connection.query("Select Id,WIP__c from Claim__c where Id = '" + caseId + "'");
var records = result.getArray("records");
var oldWIP = records[0].getInt("WIP__c");
//var WIP = (w * t) + oldWIP;
var latestWIP = w * t;
var WIP = oldWIP + latestWIP;
return WIP;
}
function SetTimer()
{
result = sforce.connection.query("Select Id,FM_Timer_Timer_Running__c from Claim__c where Id = '" + caseId + "'");
var records = result.getArray("records");
if (records.length != 1)
{
alert("An error occurred when starting the timer: cannot find case");
}
else
{
if (records[0].getBoolean("FM_Timer_Timer_Running__c"))
{
alert('Timer already started');
}
else
{
serverTime = sforce.connection.getServerTimestamp().timestamp;
thisClaim__c = new sforce.SObject("Claim__c");
thisClaim__c.id = caseId;
thisClaim__c.FM_Timer_Timer_Start__c = serverTime;
thisClaim__c.FM_Timer_Timer_Running__c = 1;
result = sforce.connection.update([thisClaim__c]);
if (!(result[0].getBoolean("success")))
{
alert('An error occurred when starting the timer: update failed');
}
else
{
ToggleButton(true);
RunTimer();
}
}
}
}
function StopTimer() {
result = sforce.connection.query("Select Id,FM_Timer_Timer_Running__c,FM_Timer_Timer_Total_Seconds__c from Claim__c where Id = '" + caseId + "'");
var records = result.getArray("records");
if (records.length != 1)
{
alert("An error occurred when stopping the timer: cannot find case");
}
else
{
if (records[0].getBoolean("FM_Timer_Timer_Running__c"))
{
t = records[0].getInt("FM_Timer_Timer_Total_Seconds__c");
thisClaim__c = new sforce.SObject("Claim__c");
thisClaim__c.id = caseId;
thisClaim__c.FM_Timer_Timer_Start__c = null;
thisClaim__c.FM_Timer_Timer_Running__c = false;
thisClaim__c.WIP__c = getWIP(wiprate, t);
thisClaim__c.FM_Timer_Timer_Previous_Seconds__c = t;
result2 = sforce.connection.update([thisClaim__c]);
if (!(result2[0].getBoolean("success")))
{
alert('An error occurred when stopping the timer: update failed');
}
else
{
clearTimeout(tO);
timerPrevSeconds += timerSeconds;
timerSeconds = 0;
ToggleButton(false);
}
}
else
{
alert('Timer already stopped');
}
}
}
</script>
</head>
<body onload=setupPage() class="case" style="text-align:center; background-color:#f3f3ec">
<table border="0" cellpadding="0" cellspacing="0" style="text-align:center">
<tr>
<td class="fTitle" >Current Time</td>
<td class="fTitle">Total Time</td>
</tr>
<tr>
<td class="fData"><div id=Timer>0D 00:00:00</div></td>
<td class="fData"><div id=TimerTotal>0D 00:00:00</div></td>
</tr>
<tr>
<td colspan=2>
<input type=button class=btn id=startButton value=Start onclick=SetTimer() style="font-size:10px;">
<input type=button class=btn id=stopButton value=Stop onclick=StopTimer() style="font-size:10px; ">
</td>
</tr>
</tr>
</table>
</body>
</html>