View previous topic :: View next topic |
Author |
Message |
jackb
Joined: 11 Sep 2006 Posts: 27
|
Posted: Sat Feb 03, 2007 8:57 am Post subject: Hold multiple dates in form using cookies |
|
|
Hello!
I have the calendar in a form, after I submit the form, I would like to return to it and still have the dates that I previously selected be still there. I tried using the cookie function you listed at http://www.calendarxp.net/forum/viewtopic.php?t=98 , but it did not work (no cookies were created). I am using the multi-select plugin. Any pointers would be appreciated.
Cheers,
Joe
|
|
Back to top |
|
|
calendarxp Site Admin
Joined: 30 Jan 2005 Posts: 409
|
Posted: Sat Feb 03, 2007 9:44 pm Post subject: |
|
|
Joe,
It's because multi-select plugin disabled the fSetDate() in order to override the function to select multiple dates instead of just one. Since the fOnchange() is triggered by fSetDate(), it won't get called at all in that plugin.
Also, the code in FAQ only shows you for storing just 1 date in cookie, it won't work if you have multiple dates selected.
So in order to make it work with multi-select plugin, you will have to append the following code to the end (must be placed after the multi-select code) of plugins.js:
Code: | var _cookieName="selectedDate";
var _cookieStr=fReadCookie(_cookieName);
if (_cookieStr&&_cookieStr.length>0)
_pds=eval(_cookieStr);
function fCreateCookie(name,value)
{
var valueStr="[";
for (var i=0;i<value.length;i++)
valueStr+="["+value[i][0]+","+value[i][1]+"],";
valueStr+="]";
document.cookie = name+"="+valueStr+"; path=/";
}
function fReadCookie(name)
{
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++)
{
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
} | Then append the following line to the bottom (last line in function) of fAddRange() and fRemoveRange():
Code: | fCreateCookie(_cookieName,_pds); |
_________________ Copyright 2003-2011 Idemfactor Solutions, Inc. All rights reserved. |
|
Back to top |
|
|
jackb
Joined: 11 Sep 2006 Posts: 27
|
Posted: Sat Feb 03, 2007 11:27 pm Post subject: No Luck |
|
|
calendarxp,
I inserted the code above but it is not working. Any ideas?
I put the cookie stuff at the very bottom and then put the fCreateCookie(_cookieName,_pds); at the bottom of both fRemoveRange and fAddRange functions - exaple below:
function fRemoveRange(y,m,d,bBatch) {
var dt=Date.UTC(y,m-1,d);
for (var i=0; i<_pds.length; i++)
if (_pds[i][0]<=dt&&_pds[i][1]>=dt) break;
if (i==_pds.length) return;
if (bBatch||_pds[i][0]==_pds[i][1]) {
for (var k=_pds[i][0];k<=_pds[i][1];k+=MILLIDAY) {
var dk=new Date(k);
fRemoveDate(dk.getUTCFullYear(),dk.getUTCMonth()+1,dk.getUTCDate());
}
fSplice(_pds,i);
} else {
fRemoveDate(y,m,d);
if (dt<_pds[i][1]) _pds.push([dt+MILLIDAY,_pds[i][1]]);
if (_pds[i][0]<dt) _pds[i][1]=dt-MILLIDAY;
else fSplice(_pds,i);
}
_ls=null;
fCreateCookie(_cookieName,_pds);
}
Cheers,
Joe
|
|
Back to top |
|
|
calendarxp Site Admin
Joined: 30 Jan 2005 Posts: 409
|
Posted: Sat Feb 03, 2007 11:36 pm Post subject: |
|
|
Could you please attach the plugins.js file you are using so that we can take a look?
_________________ Copyright 2003-2011 Idemfactor Solutions, Inc. All rights reserved. |
|
Back to top |
|
|
jackb
Joined: 11 Sep 2006 Posts: 27
|
Posted: Sun Feb 04, 2007 12:09 am Post subject: O.K. Now it is attached |
|
|
attached file
|
|
Back to top |
|
|
calendarxp Site Admin
Joined: 30 Jan 2005 Posts: 409
|
Posted: Sun Feb 04, 2007 12:24 am Post subject: |
|
|
Well, it seems working fine - I used it to replace the plugins1.js in the MultiPickerDemo.
Did you try to empty your browser cache after the change? Also, bring up your page with Firefox and see if there is any error in the javascript console?
_________________ Copyright 2003-2011 Idemfactor Solutions, Inc. All rights reserved. |
|
Back to top |
|
|
jackb
Joined: 11 Sep 2006 Posts: 27
|
Posted: Sun Feb 04, 2007 12:37 am Post subject: Thanks!!!! |
|
|
Works like a CHARM!!! I am sorry, my mistake, I had the source pointing to a different calendar folder.
Thank you so much!!!
Cheers,
Joe
|
|
Back to top |
|
|
jackb
Joined: 11 Sep 2006 Posts: 27
|
Posted: Sun Feb 04, 2007 12:47 am Post subject: Ops problem in explorer |
|
|
OPS - having problem in explorer
It seems to be working fine in firefox but I am getting an error in explorer and only to top piece of the calendar is dispaying. The error is as follows:
Char: 3
Error: '_pds[...]0' is null or not an object
Code: 0
URL: ..../iflateng.htm
Cheers,
Joe
|
|
Back to top |
|
|
calendarxp Site Admin
Joined: 30 Jan 2005 Posts: 409
|
Posted: Sun Feb 04, 2007 2:48 am Post subject: |
|
|
Found the culprit - please replace the fCreateCookie() with the following code:
Code: | function fCreateCookie(name,value)
{
var valueStr="[";
for (var i=0;i<value.length;i++)
valueStr+=(i>0?",":"")+"["+value[i][0]+","+value[i][1]+"]";
valueStr+="]";
document.cookie = name+"="+valueStr+"; path=/";
} |
_________________ Copyright 2003-2011 Idemfactor Solutions, Inc. All rights reserved. |
|
Back to top |
|
|
jackb
Joined: 11 Sep 2006 Posts: 27
|
Posted: Sun Feb 04, 2007 3:38 am Post subject: One more thing |
|
|
Thanks! its now fine in explorer
Just one more thing and we'll have it. The previously selected dates now hold there color, but they are not selected. So nothing is in the hidden fields. I would guess i will need to add an onload function to the frame, but from looking at the values in the cookies, I am not sure how to go about retrieving the dates and loading them into the hidden list.
Cheers,
Joe
|
|
Back to top |
|
|
calendarxp Site Admin
Joined: 30 Jan 2005 Posts: 409
|
Posted: Sun Feb 04, 2007 4:20 pm Post subject: |
|
|
The values in _pds are the time representation of a date (in milliseconds since 1970 Jan 1st), and they come in pairs to represent the selected date ranges.
To convert them into hidden field, you can simply use javascript to do that:
Code: | var hiddenStr = "";
for (var i=0; i<_pds.length; i++) {
var _dt0=new Date(_pds[i][0]), _dt1=new Date(_pds[i][1]);
hiddenStr+="["+_dt0.getFullYear()+"-"+(_dt0.getMonth()+1)+"-"+_dt0.getDate()+","+_dt1.getFullYear()+"-"+(_dt1.getMonth()+1)+"-"+_dt1.getDate()+"]";
}
alert(hiddenStr); |
_________________ Copyright 2003-2011 Idemfactor Solutions, Inc. All rights reserved. |
|
Back to top |
|
|
jackb
Joined: 11 Sep 2006 Posts: 27
|
Posted: Sun Feb 04, 2007 9:44 pm Post subject: where to add code |
|
|
I'm sorry guys, but I can't seem to figure out where to put the above code
Basically what I have now is something like the following in the containing form page:
function fAddListItem(strDate) {
var dl=document.formName.dateList;
dl.options[dl.options.length]=new Option(strDate,strDate);
}
function fRemoveListItem(strDate) {
var dl=document.formName.dateList;
for (var i=0;i<dl.options.length;i++)
if (strDate==dl.options[i].value) break;
dl.options[i]=null;
}
function submitByDates(fm) {
fm.allSelected.value="";
for (var i=0; i<fm.dateList.length; i++) {
if (i>0) fm.allSelected.value+=",";
fm.allSelected.value+=fm.dateList.options[i].value;
}
}
////////////
<body>
<form name="formName" action="xxx" onSubmit="return submitByDates();">
<iframe width=174 height=189 name="gToday:normal:agenda.js:gfFlat:plugins1.js" id="gToday:normal:agenda.js:gfFlat:plugins1.js" src="/folder/iflateng.htm" scrolling="no" frameborder="0">
</iframe>
<div style="display: none">
<select name="dateList" size="9">
<option value="-">-----------------</option>
</select></div><BR>
<script language="JavaScript">
document.formName.dateList.options[0]=null;
</script>
<input type="submit">
</form>
I don't seem to be able to figure out how to get these cookie dates into the dateList.
Cheers,
Joe
|
|
Back to top |
|
|
calendarxp Site Admin
Joined: 30 Jan 2005 Posts: 409
|
Posted: Sun Feb 04, 2007 11:18 pm Post subject: |
|
|
OK, here is the fully revised code that should work - just delete the previous code and append the following to the very bottom of your plugins.js:
Code: | var _cookieName="selectedDate";
var _cookieStr=fReadCookie(_cookieName);
var _cds=(_cookieStr&&_cookieStr.length>0)?eval(_cookieStr):[];
function fCreateCookie(name,value)
{
var valueStr="[";
for (var i=0;i<value.length;i++)
valueStr+=(i>0?",":"")+"["+value[i][0]+","+value[i][1]+"]";
valueStr+="]";
document.cookie = name+"="+valueStr+"; path=/";
}
function fReadCookie(name)
{
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++)
{
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
|
Then, prepend some code to the fOnload() plugin as following:
Code: | function fOnload() {
for (var i=0; i<_cds.length; i++) {
var _dt0=new Date(_cds[i][0]), _dt1=new Date(_cds[i][1]);
fAddRange(_dt0.getUTCFullYear(),_dt0.getUTCMonth()+1,_dt0.getUTCDate(),false);
fAddRange(_dt1.getUTCFullYear(),_dt1.getUTCMonth()+1,_dt1.getUTCDate(),true);
}
if (gContainer.fInitAgenda) gContainer.fInitAgenda();
} |
Finally, don't forget to append the
Code: | fCreateCookie(_cookieName,_pds); |
to fAddRange() and fRemoveRange() - if you removed them accidentally.
_________________ Copyright 2003-2011 Idemfactor Solutions, Inc. All rights reserved. |
|
Back to top |
|
|
jackb
Joined: 11 Sep 2006 Posts: 27
|
Posted: Sun Feb 04, 2007 11:55 pm Post subject: selected dates not showing |
|
|
Dear calendarxp,
The dates are now holding in the hidden field, but now the preselected dates on the calendar are not holding (not marked as selected).
Cheers,
Joe
|
|
Back to top |
|
|
calendarxp Site Admin
Joined: 30 Jan 2005 Posts: 409
|
Posted: Mon Feb 05, 2007 6:09 am Post subject: |
|
|
Attached please find the plugins1.js we are using - we tested it against MultiPickerDemo1 and everything is working fine (preselect dates are holding well). Please make sure to empty your browser cache before trying.
_________________ Copyright 2003-2011 Idemfactor Solutions, Inc. All rights reserved. |
|
Back to top |
|
|
|