New: Possibilité de choisir le gestionnaire de popup date

This commit is contained in:
Laurent Destailleur 2006-03-11 23:51:59 +00:00
parent 1d52199fa6
commit 731b50e703
3 changed files with 91 additions and 87 deletions

View File

@ -1629,14 +1629,18 @@ class Form
//print "e".$conf->format_date_short; //print "e".$conf->format_date_short;
$timearray=getDate($set_time); $timearray=getDate($set_time);
$formated_date=dolibarr_print_date($set_time,$conf->format_date_short); $formated_date=dolibarr_print_date($set_time,$conf->format_date_short);
// Zone de saisie manuelle de la date
print '<input id="'.$prefix.'" name="'.$prefix.'" type="text" size="11" maxlength="11" value="'.$formated_date.'"> '; print '<input id="'.$prefix.'" name="'.$prefix.'" type="text" size="11" maxlength="11" value="'.$formated_date.'"> ';
// Icone calendrier
print '<button id="'.$prefix.'Button" type="button" class="dpInvisibleButtons"'; print '<button id="'.$prefix.'Button" type="button" class="dpInvisibleButtons"';
//$base=DOL_URL_ROOT.'/theme/'.$conf->theme.'/';
$base=DOL_URL_ROOT.'/lib/'; $base=DOL_URL_ROOT.'/lib/';
print ' onClick="showDP(\''.$base.'\',\''.$prefix.'\',\''.$conf->format_date_short_java.'\');">'.img_object($langs->trans("SelectDate"),'calendar').'</button>'; print ' onClick="showDP(\''.$base.'\',\''.$prefix.'\',\''.$conf->format_date_short_java.'\');">'.img_object($langs->trans("SelectDate"),'calendar').'</button>';
print '<input type="hidden" name="'.$prefix.'day" value="'.$sday.'">'."\n";
print '<input type="hidden" name="'.$prefix.'month" value="'.$month.'">'."\n"; print '<input type="hidden" id="'.$prefix.'day" name="'.$prefix.'day" value="'.$sday.'">'."\n";
print '<input type="hidden" name="'.$prefix.'year" value="'.$syear.'">'."\n"; print '<input type="hidden" id="'.$prefix.'month" name="'.$prefix.'month" value="'.$smonth.'">'."\n";
print '<input type="hidden" id="'.$prefix.'year" name="'.$prefix.'year" value="'.$syear.'">'."\n";
} }
else else
{ {
@ -1651,9 +1655,9 @@ class Form
$formated_date=dolibarr_print_date($set_time,$conf->format_date_short); $formated_date=dolibarr_print_date($set_time,$conf->format_date_short);
if($formated_date=="?") $formated_date=""; if($formated_date=="?") $formated_date="";
print '<input id="'.$prefix.'" type="text" name="'.$prefix.'" size="10" value="'.$formated_date.'"> '; print '<input id="'.$prefix.'" type="text" name="'.$prefix.'" size="10" value="'.$formated_date.'"> ';
print '<input type="hidden" name="'.$prefix.'day" value="'. $sday.'">'."\n"; print '<input type="hidden" id="'.$prefix.'day" name="'.$prefix.'day" value="'.$sday.'">'."\n";
print '<input type="hidden" name="'.$prefix.'month" value="'.$smonth.'">'."\n"; print '<input type="hidden" id="'.$prefix.'month" name="'.$prefix.'month" value="'.$smonth.'">'."\n";
print '<input type="hidden" name="'.$prefix.'year" value="'. $syear.'">'."\n"; print '<input type="hidden" id="'.$prefix.'year" name="'.$prefix.'year" value="'.$syear.'">'."\n";
if($form_name =="") if($form_name =="")
print '<A HREF="javascript:showCalendar(document.forms[3].'.$prefix.')">'.img_cal().'</a>'; print '<A HREF="javascript:showCalendar(document.forms[3].'.$prefix.')">'.img_cal().'</a>';
else else

View File

@ -52,7 +52,7 @@ function xyzToUnixTimestamp($mysqldate){
} }
function displayBox($selectedDate,$month,$year){ function displayBox($selectedDate,$month,$year){
global $dolibarr_main_url_root,$langs; global $dolibarr_main_url_root,$langs,$conf;
$langs->load("main"); $langs->load("main");
//print "$selectedDate,$month,$year"; //print "$selectedDate,$month,$year";
@ -109,7 +109,10 @@ function displayBox($selectedDate,$month,$year){
elseif($thedate==$today) $dayclass="dpToday"; elseif($thedate==$today) $dayclass="dpToday";
// Sur click dans calendrier, appelle fonction dpClickDay // Sur click dans calendrier, appelle fonction dpClickDay
echo "<TD class=\"".$dayclass."\" onMouseOver=\"dpHighlightDay(".$mydate["year"].",".date("n",$thedate).",".$mydate["mday"].")\" onClick=\"dpClickDay(".$mydate["year"].",".date("n",$thedate).",".$mydate["mday"].")\">".sprintf("%02s",$mydate["mday"])."</TD>"; echo "<TD class=\"".$dayclass."\"";
echo " onMouseOver=\"dpHighlightDay(".$mydate["year"].",".date("n",$thedate).",".$mydate["mday"].")\"";
echo " onClick=\"dpClickDay(".$mydate["year"].",".date("n",$thedate).",".$mydate["mday"].",'".$conf->format_date_short_java."')\"";
echo ">".sprintf("%02s",$mydate["mday"])."</TD>";
if($mydate["wday"]==6) echo "</tr>"; if($mydate["wday"]==6) echo "</tr>";
$thedate=strtotime("tomorrow",$thedate); $thedate=strtotime("tomorrow",$thedate);

View File

@ -3,10 +3,12 @@
// Script javascript mis en en-tete de pages (dans section head) // Script javascript mis en en-tete de pages (dans section head)
// //
// \file htdocs/lib/lib_head.js // \file htdocs/lib/lib_head.js
// \brief Fichier qui inclue les fonctions javascript d'en-tete si option use_javascript active // \brief Fichier qui inclue les fonctions javascript d'en-tete (inclue si option use_javascript active)
// \version $Revision$ // \version $Revision$
// *****************************************
// Pour la fonction de saisi auto des villes // Pour la fonction de saisi auto des villes
// ***************************************** // *****************************************
@ -32,15 +34,19 @@ function autofilltownfromzip_save_refresh_create()
// *****************************************
// Pour la saisie des dates par calendrier // Pour la saisie des dates par calendrier
// *************************************** // *****************************************
// base "/theme/eldy" // base "/theme/eldy"
// dateFieldID "dateo" Nom du champ // dateFieldID "dateo" Nom du champ
// format "dd/MM/yyyy" Format issu de Dolibarr de SimpleDateFormat à utiliser pour retour // format "dd/MM/yyyy" Format issu de Dolibarr de SimpleDateFormat à utiliser pour retour
function showDP(base,dateFieldID,format) function showDP(base,dateFieldID,format)
{ {
var dateField= getObjectFromID(dateFieldID); showDP.datefieldID=dateFieldID;
var dateField=getObjectFromID(dateFieldID);
//check to see if another box is already showing //check to see if another box is already showing
var alreadybox=getObjectFromID("DPCancel"); var alreadybox=getObjectFromID("DPCancel");
@ -59,8 +65,6 @@ function showDP(base,dateFieldID,format)
showDP.box.style.top=thetop + "px"; showDP.box.style.top=thetop + "px";
showDP.box.style.left=theleft + "px"; showDP.box.style.left=theleft + "px";
showDP.datefieldID=dateFieldID;
if(dateField.value) // Si il y avait valeur initiale dans champ if(dateField.value) // Si il y avait valeur initiale dans champ
{ {
selDate=getDateFromFormat(dateField.value,format); selDate=getDateFromFormat(dateField.value,format);
@ -110,12 +114,27 @@ function closeDPBox(){
showDP.datefieldID=null; showDP.datefieldID=null;
} }
function dpClickDay(year,month,day){ function dpClickDay(year,month,day,format){
var thefield=getObjectFromID(showDP.datefieldID); var thefield=getObjectFromID(showDP.datefieldID);
if (day < 10) day="0"+day; var thefieldday=getObjectFromID(showDP.datefieldID+"day");
if (month < 10) month="0"+month; var thefieldmonth=getObjectFromID(showDP.datefieldID+"month");
thefield.value=day+"/"+month+"/"+year; var thefieldyear=getObjectFromID(showDP.datefieldID+"year");
var dt = new Date();
dt.setMonth(month-1);
dt.setYear(year);
dt.setDate(day);
thefield.value=formatDate(dt,format);
if(thefield.onchange) thefield.onchange.call(thefield); if(thefield.onchange) thefield.onchange.call(thefield);
thefieldday.value=day;
if(thefieldday.onchange) thefieldday.onchange.call(thefieldday);
thefieldmonth.value=month;
if(thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth);
thefieldyear.value=year;
if(thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear);
closeDPBox(); closeDPBox();
} }
@ -182,34 +201,6 @@ function loadXMLDoc(url,readyStateFunction,async)
} }
} }
/*
function addEvent(obj, evType, fn){
if (obj.addEventListener){
obj.addEventListener(evType, fn, true);
return true;
} else if (obj.attachEvent){
var r = obj.attachEvent("on"+evType, fn);
return r;
} else {
return false;
}
}
*/
/*
function removeEvent(obj, evType, fn, useCapture){
if (obj.removeEventListener){
obj.removeEventListener(evType, fn, useCapture);
return true;
} else if (obj.detachEvent){
var r = obj.detachEvent("on"+evType, fn);
return r;
} else {
window.status=("Handler could not be removed");
}
}
*/
function hideSelectBoxes() { function hideSelectBoxes() {
var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10); var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);
if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1) { if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1) {
@ -248,45 +239,50 @@ var enabletip=false
if (ie||ns6) if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : "" var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""
function ietruebody(){ function ietruebody()
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body {
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
} }
function showtip(thetext){ function showtip(thetext)
if (ns6||ie){ {
tipobj.innerHTML=thetext if (ns6||ie)
enabletip=true {
return false tipobj.innerHTML=thetext
} enabletip=true
return false
}
} }
function positiontip(e){ function positiontip(e)
if (enabletip){ {
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft; if (enabletip)
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop; {
//Find out how close the mouse is to the corner of the window var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20 var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20 //Find out how close the mouse is to the corner of the window
var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000 var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20
//if the horizontal distance isn't enough to accomodate the width of the context menu var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000
if (rightedge<tipobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width //if the horizontal distance isn't enough to accomodate the width of the context menu
tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px" if (rightedge<tipobj.offsetWidth)
else if (curX<leftedge) //move the horizontal position of the menu to the left by it's width
tipobj.style.left="5px" tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
else else if (curX<leftedge)
//position the horizontal position of the menu where the mouse is positioned tipobj.style.left="5px"
tipobj.style.left=curX+offsetxpoint+"px" else
//position the horizontal position of the menu where the mouse is positioned
//same concept with the vertical position tipobj.style.left=curX+offsetxpoint+"px"
if (bottomedge<tipobj.offsetHeight)
tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px" //same concept with the vertical position
else if (bottomedge<tipobj.offsetHeight)
tipobj.style.top=curY+offsetypoint+"px" tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
tipobj.style.visibility="visible" else
} tipobj.style.top=curY+offsetypoint+"px"
tipobj.style.visibility="visible"
}
} }
function hidetip(){ function hidetip(){
@ -400,7 +396,7 @@ function compareDates(date1,dateformat1,date2,dateformat2) {
return 1; return 1;
} }
return 0; return 0;
} }
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// formatDate (date_object, format) // formatDate (date_object, format)
@ -463,7 +459,7 @@ function formatDate(date,format) {
} }
//alert(format+' -> '+result); //alert(format+' -> '+result);
return result; return result;
} }
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// Utility functions for parsing in getDateFromFormat() // Utility functions for parsing in getDateFromFormat()
@ -474,7 +470,8 @@ function _isInteger(val) {
if (digits.indexOf(val.charAt(i))==-1) { return false; } if (digits.indexOf(val.charAt(i))==-1) { return false; }
} }
return true; return true;
} }
function _getInt(str,i,minlength,maxlength) { function _getInt(str,i,minlength,maxlength) {
for (var x=maxlength; x>=minlength; x--) { for (var x=maxlength; x>=minlength; x--) {
var token=str.substring(i,i+x); var token=str.substring(i,i+x);
@ -482,7 +479,7 @@ function _getInt(str,i,minlength,maxlength) {
if (_isInteger(token)) { return token; } if (_isInteger(token)) { return token; }
} }
return null; return null;
} }
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// getDateFromFormat( date_string , format_string ) // getDateFromFormat( date_string , format_string )
@ -619,7 +616,7 @@ function getDateFromFormat(val,format) {
// return newdate.getTime(); // return newdate.getTime();
return newdate; return newdate;
} }
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// parseDate( date_string [, prefer_euro_format] ) // parseDate( date_string [, prefer_euro_format] )
@ -650,6 +647,6 @@ function parseDate(val) {
} }
} }
return null; return null;
} }