2015-12-07 15:10:23 +01:00
< ? php
/* Copyright ( C ) 2005 - 2014 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2005 - 2014 Regis Houssin < regis . houssin @ capnetworks . com >
* Copyright ( C ) 2015 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http :// www . gnu . org / licenses />.
* or see http :// www . gnu . org /
*/
/**
2017-12-14 21:28:51 +01:00
* \file htdocs / core / js / lib_head . js . php
* \brief File that include javascript functions ( included if option use_javascript activated )
* JQuery ( providing object $ ) and JQuery - UI ( providing $datepicker ) libraries must be loaded before this file .
2015-12-07 15:10:23 +01:00
*/
if ( ! defined ( 'NOREQUIRESOC' )) define ( 'NOREQUIRESOC' , '1' );
if ( ! defined ( 'NOCSRFCHECK' )) define ( 'NOCSRFCHECK' , 1 );
if ( ! defined ( 'NOTOKENRENEWAL' )) define ( 'NOTOKENRENEWAL' , 1 );
if ( ! defined ( 'NOLOGIN' )) define ( 'NOLOGIN' , 1 );
if ( ! defined ( 'NOREQUIREMENU' )) define ( 'NOREQUIREMENU' , 1 );
if ( ! defined ( 'NOREQUIREHTML' )) define ( 'NOREQUIREHTML' , 1 );
if ( ! defined ( 'NOREQUIREAJAX' )) define ( 'NOREQUIREAJAX' , '1' );
2018-04-16 13:51:16 +02:00
session_cache_limiter ( false );
2015-12-07 15:10:23 +01:00
require_once '../../main.inc.php' ;
2006-06-05 20:26:46 +02:00
2015-12-07 15:10:23 +01:00
// Define javascript type
2017-05-09 21:01:37 +02:00
top_httphead ( 'text/javascript; charset=UTF-8' );
2015-12-07 15:10:23 +01:00
// Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
if ( empty ( $dolibarr_nocache )) header ( 'Cache-Control: max-age=3600, public, must-revalidate' );
else header ( 'Cache-Control: no-cache' );
2017-10-13 22:01:56 +02:00
// Define tradMonths javascript array (we define this in datepicker AND in parent page to avoid errors with IE8)
$tradMonths = array (
dol_escape_js ( $langs -> transnoentitiesnoconv ( " January " )),
dol_escape_js ( $langs -> transnoentitiesnoconv ( " February " )),
dol_escape_js ( $langs -> transnoentitiesnoconv ( " March " )),
dol_escape_js ( $langs -> transnoentitiesnoconv ( " April " )),
dol_escape_js ( $langs -> transnoentitiesnoconv ( " May " )),
dol_escape_js ( $langs -> transnoentitiesnoconv ( " June " )),
dol_escape_js ( $langs -> transnoentitiesnoconv ( " July " )),
dol_escape_js ( $langs -> transnoentitiesnoconv ( " August " )),
dol_escape_js ( $langs -> transnoentitiesnoconv ( " September " )),
dol_escape_js ( $langs -> transnoentitiesnoconv ( " October " )),
dol_escape_js ( $langs -> transnoentitiesnoconv ( " November " )),
dol_escape_js ( $langs -> transnoentitiesnoconv ( " December " ))
);
$tradMonthsShort = array (
$langs -> trans ( " JanuaryMin " ),
$langs -> trans ( " FebruaryMin " ),
$langs -> trans ( " MarchMin " ),
$langs -> trans ( " AprilMin " ),
$langs -> trans ( " MayMin " ),
$langs -> trans ( " JuneMin " ),
$langs -> trans ( " JulyMin " ),
$langs -> trans ( " AugustMin " ),
$langs -> trans ( " SeptemberMin " ),
$langs -> trans ( " OctoberMin " ),
$langs -> trans ( " NovemberMin " ),
$langs -> trans ( " DecemberMin " )
);
$tradDays = array (
$langs -> trans ( " Sunday " ),
$langs -> trans ( " Monday " ),
$langs -> trans ( " Tuesday " ),
$langs -> trans ( " Wednesday " ),
$langs -> trans ( " Thursday " ),
$langs -> trans ( " Friday " ),
$langs -> trans ( " Saturday " )
);
$tradDaysShort = array (
$langs -> trans ( " ShortSunday " ),
$langs -> trans ( " ShortMonday " ),
$langs -> trans ( " ShortTuesday " ),
$langs -> trans ( " ShortWednesday " ),
$langs -> trans ( " ShortThursday " ),
$langs -> trans ( " ShortFriday " ),
$langs -> trans ( " ShortSaturday " )
);
$tradDaysMin = array (
$langs -> trans ( " SundayMin " ),
$langs -> trans ( " MondayMin " ),
$langs -> trans ( " TuesdayMin " ),
$langs -> trans ( " WednesdayMin " ),
$langs -> trans ( " ThursdayMin " ),
$langs -> trans ( " FridayMin " ),
$langs -> trans ( " SaturdayMin " )
);
2015-12-07 15:10:23 +01:00
?>
2017-09-24 21:02:20 +02:00
// Javascript libraries for Dolibarr ERP CRM (https://www.dolibarr.org)
2017-09-24 20:36:27 +02:00
2017-10-13 22:01:56 +02:00
// For jQuery date picker
var tradMonths = < ? php echo json_encode ( $tradMonths ) ?> ;
var tradMonthsShort = < ? php echo json_encode ( $tradMonthsShort ) ?> ;
var tradDays = < ? php echo json_encode ( $tradDays ) ?> ;
var tradDaysShort = < ? php echo json_encode ( $tradDaysShort ) ?> ;
var tradDaysMin = < ? php echo json_encode ( $tradDaysMin ) ?> ;
2017-10-13 22:37:30 +02:00
// For JQuery date picker
$ ( document ) . ready ( function () {
$ . datepicker . setDefaults ({
autoSize : true ,
changeMonth : true ,
changeYear : true ,
altField : '#timestamp' ,
altFormat : '@' // Gives a timestamp dateformat
});
});
jQuery ( function ( $ ){
$ . datepicker . regional [ '<?php echo $langs->defaultlang ?>' ] = {
closeText : '<?php echo $langs->trans("Close2") ?>' ,
prevText : '<?php echo $langs->trans("Previous") ?>' ,
nextText : '<?php echo $langs->trans("Next") ?>' ,
currentText : '<?php echo $langs->trans("Now") ?>' ,
monthNames : tradMonths ,
monthNamesShort : tradMonthsShort ,
dayNames : tradDays ,
dayNamesShort : tradDaysShort ,
dayNamesMin : tradDaysMin ,
weekHeader : '<?php echo $langs->trans("Week"); ?>' ,
2017-10-13 22:40:33 +02:00
dateFormat : '<?php echo $langs->trans("FormatDateShortJQuery"); ?>' , /* Note dd/mm/yy means year on 4 digit in jquery format */
2017-10-13 22:37:30 +02:00
firstDay : < ? php echo ( isset ( $conf -> global -> MAIN_START_WEEK ) ? $conf -> global -> MAIN_START_WEEK : '1' ); ?> ,
isRTL : < ? php echo ( $langs -> trans ( " DIRECTION " ) == 'rtl' ? 'true' : 'false' ); ?> ,
showMonthAfterYear : false , /* TODO add specific to country */
yearSuffix : '' /* TODO add specific to country */
};
$ . datepicker . setDefaults ( $ . datepicker . regional [ '<?php echo $langs->defaultlang ?>' ]);
});
2017-09-24 20:36:27 +02:00
/**
2017-10-21 19:05:24 +02:00
* Set array used for select2 translations
2017-09-24 20:36:27 +02:00
*/
2017-10-21 19:05:24 +02:00
var select2arrayoflanguage = {
matches : function ( matches ) { return matches + " <?php echo dol_escape_js( $langs->transnoentitiesnoconv ( " Select2ResultFoundUseArrows " )); ?> " ; },
noResults : function () { return " <?php echo dol_escape_js( $langs->transnoentitiesnoconv ( " Select2NotFound " )); ?> " ; },
inputTooShort : function ( input ) {
var n = input . minimum ;
2017-10-28 17:34:46 +02:00
/* console . log ( input );
console . log ( input . minimum ); */
2017-10-21 19:05:24 +02:00
if ( n > 1 ) return " <?php echo dol_escape_js( $langs->transnoentitiesnoconv ( " Select2Enter " )); ?> " + n + " <?php echo dol_escape_js( $langs->transnoentitiesnoconv ( " Select2MoreCharacters " )); ?> " ;
else return " <?php echo dol_escape_js( $langs->transnoentitiesnoconv ( " Select2Enter " )); ?> " + n + " <?php echo dol_escape_js( $langs->transnoentitiesnoconv ( " Select2MoreCharacter " )); ?> "
},
loadMore : function ( pageNumber ) { return " <?php echo dol_escape_js( $langs->transnoentitiesnoconv ( " Select2LoadingMoreResults " )); ?> " ; },
searching : function () { return " <?php echo dol_escape_js( $langs->transnoentitiesnoconv ( " Select2SearchInProgress " )); ?> " ; }
};
2017-09-24 20:36:27 +02:00
2017-10-21 19:05:24 +02:00
/**
* For calendar input
2010-08-29 19:52:06 +02:00
*/
2017-09-24 20:55:48 +02:00
// Returns an object given an id
function getObjectFromID ( id ){
var theObject ;
if ( document . getElementById )
theObject = document . getElementById ( id );
else
theObject = document . all [ id ];
return theObject ;
}
// Called after selection of a date to save details into detailed fields
function dpChangeDay ( dateFieldID , format )
{
//showDP.datefieldID=dateFieldID;
console . log ( " Call dpChangeDay, we save date into detailed fields. " );
var thefield = getObjectFromID ( dateFieldID );
var thefieldday = getObjectFromID ( dateFieldID + " day " );
var thefieldmonth = getObjectFromID ( dateFieldID + " month " );
var thefieldyear = getObjectFromID ( dateFieldID + " year " );
var date = getDateFromFormat ( thefield . value , format );
if ( date )
{
thefieldday . value = date . getDate ();
if ( thefieldday . onchange ) thefieldday . onchange . call ( thefieldday );
thefieldmonth . value = date . getMonth () + 1 ;
if ( thefieldmonth . onchange ) thefieldmonth . onchange . call ( thefieldmonth );
thefieldyear . value = date . getFullYear ();
if ( thefieldyear . onchange ) thefieldyear . onchange . call ( thefieldyear );
}
else
{
thefieldday . value = '' ;
if ( thefieldday . onchange ) thefieldday . onchange . call ( thefieldday );
thefieldmonth . value = '' ;
if ( thefieldmonth . onchange ) thefieldmonth . onchange . call ( thefieldmonth );
thefieldyear . value = '' ;
if ( thefieldyear . onchange ) thefieldyear . onchange . call ( thefieldyear );
}
}
2010-08-29 19:52:06 +02:00
/*
2017-08-22 09:23:35 +02:00
* =================================================================
2010-08-29 19:52:06 +02:00
* Function :
* formatDate ( javascript object Date (), format ) Purpose : Returns a date in the
* output format specified . The format string can use the following tags : Field |
* Tags -------------+------------------------------- Year | yyyy ( 4 digits ), yy
* ( 2 digits ) Month | MM ( 2 digits ) Day of Month | dd ( 2 digits ) Hour ( 1 - 12 ) |
* hh ( 2 digits ) Hour ( 0 - 23 ) | HH ( 2 digits ) Minute | mm ( 2 digits ) Second | ss
* ( 2 digits ) Author : Laurent Destailleur Author : Matelli ( see
* http :// matelli . fr / showcases / patchs - dolibarr / update - date - input - in - action - form . html )
* Licence : GPL
* ==================================================================
*/
2007-01-21 22:43:04 +01:00
function formatDate ( date , format )
2007-02-11 20:02:09 +01:00
{
2010-08-29 19:52:06 +02:00
// alert('formatDate date='+date+' format='+format);
2017-08-22 09:23:35 +02:00
2007-01-21 22:43:04 +01:00
// Force parametres en chaine
2007-02-11 20:02:09 +01:00
format = format + " " ;
2017-08-22 09:23:35 +02:00
2007-01-21 22:43:04 +01:00
var result = " " ;
2007-02-11 20:02:09 +01:00
var year = date . getYear () + " " ; if ( year . length < 4 ) { year = " " + ( year - 0 + 1900 ); }
var month = date . getMonth () + 1 ;
var day = date . getDate ();
var hour = date . getHours ();
2008-12-03 22:41:07 +01:00
var minute = date . getMinutes ();
2007-02-11 20:02:09 +01:00
var seconde = date . getSeconds ();
2007-01-21 22:43:04 +01:00
var i = 0 ;
while ( i < format . length )
2007-02-11 20:02:09 +01:00
{
c = format . charAt ( i ); // Recupere char du format
substr = " " ;
2007-01-21 22:43:04 +01:00
j = i ;
2013-11-16 18:12:13 +01:00
while (( format . charAt ( j ) == c ) && ( j < format . length )) // Recupere char successif identiques
2007-02-11 20:02:09 +01:00
{
substr += format . charAt ( j ++ );
}
2007-01-21 22:43:04 +01:00
2010-08-29 19:52:06 +02:00
// alert('substr='+substr);
2007-02-11 20:02:09 +01:00
if ( substr == 'yyyy' ) { result = result + year ; }
else if ( substr == 'yy' ) { result = result + year . substring ( 2 , 4 ); }
2009-08-09 21:25:17 +02:00
else if ( substr == 'M' ) { result = result + month ; }
2007-02-11 20:02:09 +01:00
else if ( substr == 'MM' ) { result = result + ( month < 1 || month > 9 ? " " : " 0 " ) + month ; }
else if ( substr == 'd' ) { result = result + day ; }
else if ( substr == 'dd' ) { result = result + ( day < 1 || day > 9 ? " " : " 0 " ) + day ; }
2008-12-03 22:41:07 +01:00
else if ( substr == 'hh' ) { if ( hour > 12 ) hour -= 12 ; result = result + ( hour < 0 || hour > 9 ? " " : " 0 " ) + hour ; }
else if ( substr == 'HH' ) { result = result + ( hour < 0 || hour > 9 ? " " : " 0 " ) + hour ; }
else if ( substr == 'mm' ) { result = result + ( minute < 0 || minute > 9 ? " " : " 0 " ) + minute ; }
else if ( substr == 'ss' ) { result = result + ( seconde < 0 || seconde > 9 ? " " : " 0 " ) + seconde ; }
2007-01-21 22:43:04 +01:00
else { result = result + substr ; }
2017-08-22 09:23:35 +02:00
2007-02-11 20:02:09 +01:00
i += substr . length ;
2007-01-21 22:43:04 +01:00
}
2010-08-29 19:52:06 +02:00
// alert(result);
2007-01-21 22:43:04 +01:00
return result ;
}
2010-08-29 19:52:06 +02:00
/*
2017-08-22 09:23:35 +02:00
* =================================================================
2017-10-21 19:05:24 +02:00
* Function : getDateFromFormat ( date_string , format_string )
* Purpose : This function takes a date string and a format string .
* It parses the date string with format and it
2010-08-29 19:52:06 +02:00
* returns the date as a javascript Date () object . If date does not match
2017-08-22 09:23:35 +02:00
* format , it returns 0. The format string can use the following tags :
2010-11-19 22:24:48 +01:00
* Field | Tags
* -------------+-----------------------------------
2017-08-22 09:23:35 +02:00
* Year | yyyy ( 4 digits ), yy ( 2 digits )
* Month | MM ( 2 digits )
* Day of Month | dd ( 2 digits )
* Hour ( 1 - 12 ) | hh ( 2 digits )
* Hour ( 0 - 23 ) | HH ( 2 digits )
* Minute | mm ( 2 digits )
2010-11-19 22:24:48 +01:00
* Second | ss ( 2 digits )
2017-08-22 09:23:35 +02:00
* Author : Laurent Destailleur
2010-11-19 22:24:48 +01:00
* Licence : GPL
2010-08-29 19:52:06 +02:00
* ==================================================================
*/
2007-01-21 22:43:04 +01:00
function getDateFromFormat ( val , format )
2007-02-11 20:02:09 +01:00
{
2010-08-29 19:52:06 +02:00
// alert('getDateFromFormat val='+val+' format='+format);
2007-01-21 22:43:04 +01:00
// Force parametres en chaine
2007-02-11 20:02:09 +01:00
val = val + " " ;
2007-01-21 22:43:04 +01:00
format = format + " " ;
2010-11-19 22:24:48 +01:00
if ( val == '' ) return 0 ;
2017-08-22 09:23:35 +02:00
2007-02-11 20:02:09 +01:00
var now = new Date ();
2007-01-21 22:43:04 +01:00
var year = now . getYear (); if ( year . length < 4 ) { year = " " + ( year - 0 + 1900 ); }
2007-02-11 20:02:09 +01:00
var month = now . getMonth () + 1 ;
var day = now . getDate ();
var hour = now . getHours ();
var minute = now . getMinutes ();
var seconde = now . getSeconds ();
2007-01-21 22:43:04 +01:00
var i = 0 ;
2010-08-29 19:52:06 +02:00
var d = 0 ; // -d- follows the date string while -i- follows the format
// string
2009-05-05 02:18:23 +02:00
2007-01-21 22:43:04 +01:00
while ( i < format . length )
2007-02-11 20:02:09 +01:00
{
c = format . charAt ( i ); // Recupere char du format
2007-01-21 22:43:04 +01:00
substr = " " ;
2007-02-11 20:02:09 +01:00
j = i ;
2010-08-29 19:52:06 +02:00
while (( format . charAt ( j ) == c ) && ( j < format . length )) // Recupere char
// successif
// identiques
2007-02-11 20:02:09 +01:00
{
substr += format . charAt ( j ++ );
}
2007-01-21 22:43:04 +01:00
2010-08-29 19:52:06 +02:00
// alert('substr='+substr);
2017-08-22 09:23:35 +02:00
if ( substr == " yyyy " ) year = getIntegerInString ( val , d , 4 , 4 );
if ( substr == " yy " ) year = " " + ( getIntegerInString ( val , d , 2 , 2 ) - 0 + 1900 );
if ( substr == " MM " || substr == " M " )
{
month = getIntegerInString ( val , d , 1 , 2 );
2017-09-30 18:52:33 +02:00
if ( month ) d -= 2 - month . length ;
2017-08-22 09:23:35 +02:00
}
if ( substr == " dd " )
{
day = getIntegerInString ( val , d , 1 , 2 );
2017-09-30 18:52:33 +02:00
if ( day ) d -= 2 - day . length ;
2017-08-22 09:23:35 +02:00
}
if ( substr == " HH " || substr == " hh " )
{
hour = getIntegerInString ( val , d , 1 , 2 );
2017-09-30 18:52:33 +02:00
if ( dhouray ) d -= 2 - hour . length ;
2017-08-22 09:23:35 +02:00
}
if ( substr == " mm " ){
minute = getIntegerInString ( val , d , 1 , 2 );
2017-09-30 18:52:33 +02:00
if ( minute ) d -= 2 - minute . length ;
2017-08-22 09:23:35 +02:00
}
if ( substr == " ss " )
{
seconde = getIntegerInString ( val , d , 1 , 2 );
2017-09-30 18:52:33 +02:00
if ( seconde ) d -= 2 - seconde . length ;
2017-08-22 09:23:35 +02:00
}
2007-01-21 22:43:04 +01:00
i += substr . length ;
2009-05-05 02:18:23 +02:00
d += substr . length ;
2007-01-21 22:43:04 +01:00
}
2017-08-22 09:23:35 +02:00
2007-01-21 22:43:04 +01:00
// Check if format param are ok
2007-02-11 20:02:09 +01:00
if ( year == null || year < 1 ) { return 0 ; }
if ( month == null || ( month < 1 ) || ( month > 12 )) { return 0 ; }
if ( day == null || ( day < 1 ) || ( day > 31 )) { return 0 ; }
if ( hour == null || ( hour < 0 ) || ( hour > 24 )) { return 0 ; }
if ( minute == null || ( minute < 0 ) || ( minute > 60 )) { return 0 ; }
if ( seconde == null || ( seconde < 0 ) || ( seconde > 60 )) { return 0 ; }
2017-08-22 09:23:35 +02:00
2010-08-29 19:52:06 +02:00
// alert(year+' '+month+' '+day+' '+hour+' '+minute+' '+seconde);
2013-09-05 16:37:23 +02:00
return new Date ( year , month - 1 , day , hour , minute , seconde );
2007-01-21 22:43:04 +01:00
}
2010-08-29 19:52:06 +02:00
/*
2017-08-22 09:23:35 +02:00
* =================================================================
2017-10-21 19:05:24 +02:00
* Function : stringIsInteger ( string )
* Purpose : Return true if string is an integer
2010-08-29 19:52:06 +02:00
* ==================================================================
*/
2007-01-21 22:43:04 +01:00
function stringIsInteger ( str )
2007-02-11 20:02:09 +01:00
{
var digits = " 1234567890 " ;
2007-01-21 22:43:04 +01:00
for ( var i = 0 ; i < str . length ; i ++ )
2007-02-11 20:02:09 +01:00
{
2007-01-21 22:43:04 +01:00
if ( digits . indexOf ( str . charAt ( i )) ==- 1 )
{
return false ;
2007-02-11 20:02:09 +01:00
}
}
return true ;
}
2007-01-21 22:43:04 +01:00
2010-08-29 19:52:06 +02:00
/*
2017-08-22 09:23:35 +02:00
* =================================================================
2017-10-21 19:05:24 +02:00
* Function : getIntegerInString ( string , pos , minlength , maxlength )
* Purpose : Return part of string from position i that is integer
2010-08-29 19:52:06 +02:00
* ==================================================================
*/
2007-01-21 22:43:04 +01:00
function getIntegerInString ( str , i , minlength , maxlength )
2007-02-11 20:02:09 +01:00
{
2007-01-21 22:43:04 +01:00
for ( var x = maxlength ; x >= minlength ; x -- )
2007-02-11 20:02:09 +01:00
{
var substr = str . substring ( i , i + x );
if ( substr . length < minlength ) { return null ; }
if ( stringIsInteger ( substr )) { return substr ; }
}
return null ;
2007-01-21 22:43:04 +01:00
}
2006-06-05 20:26:46 +02:00
2007-01-18 23:05:49 +01:00
2010-08-29 19:52:06 +02:00
/*
2017-08-22 09:23:35 +02:00
* =================================================================
2017-10-21 19:05:24 +02:00
* Purpose : Clean string to have it url encoded
* Input : s
* Author : Laurent Destailleur
2010-08-29 19:52:06 +02:00
* Licence : GPL
* ==================================================================
*/
2010-08-21 17:30:17 +02:00
function urlencode ( s ) {
2011-06-08 17:26:54 +02:00
news = s ;
news = news . replace ( / \ +/ gi , '%2B' );
news = news . replace ( /&/ gi , '%26' );
return news ;
2010-08-21 17:30:17 +02:00
}
2017-10-26 20:06:23 +02:00
/*
* =================================================================
* Purpose : Clean string to have it url encoded
* Input : s
* Author : Laurent Destailleur
* Licence : GPL
* ==================================================================
*/
function htmlEntityDecodeJs ( inp ){
var replacements = { '<' : '<' , '>' : '>' , '/' : '/' , '"' : '"' , ''' : '\'' , '&' : '&' , ' ' : ' ' };
if ( inp )
{
for ( var r in replacements ){
inp = inp . replace ( new RegExp ( r , 'g' ), replacements [ r ]);
}
return inp . replace ( /& #(\d+);/g, function(match, dec) {
return String . fromCharCode ( dec );
});
}
else { return '' ; }
}
2010-08-21 17:30:17 +02:00
2010-08-29 19:52:06 +02:00
/*
2017-08-22 09:23:35 +02:00
* =================================================================
2017-10-21 19:05:24 +02:00
* Purpose : Applique un delai avant execution . Used for autocompletion of companies .
2017-08-22 09:23:35 +02:00
* Input : funct , delay
* Author : Regis Houssin
2010-09-06 13:34:53 +02:00
* Licence : GPL
2010-08-29 19:52:06 +02:00
* ==================================================================
*/
2009-08-28 03:14:35 +02:00
function ac_delay ( funct , delay ) {
// delay before start of action
2009-08-28 01:31:50 +02:00
setTimeout ( funct , delay );
2007-08-01 09:41:53 +02:00
}
2010-08-29 19:52:06 +02:00
/*
2017-08-22 09:23:35 +02:00
* =================================================================
2010-08-29 19:52:06 +02:00
* Purpose :
2010-09-06 13:34:53 +02:00
* Clean values of a " Sortable.serialize " . Used by drag and drop .
2017-08-22 09:23:35 +02:00
* Input : expr
* Author : Regis Houssin
2010-09-06 13:34:53 +02:00
* Licence : GPL
2010-08-29 19:52:06 +02:00
* ==================================================================
*/
2007-08-01 09:41:53 +02:00
function cleanSerialize ( expr ) {
2012-03-19 14:06:21 +01:00
if ( typeof ( expr ) != 'string' ) return '' ;
2007-08-01 09:41:53 +02:00
var reg = new RegExp ( " (&) " , " g " );
2007-08-03 00:02:58 +02:00
var reg2 = new RegExp ( " [^A-Z0-9,] " , " g " );
2007-08-01 09:41:53 +02:00
var liste1 = expr . replace ( reg , " , " );
2013-09-06 10:22:13 +02:00
return liste1 . replace ( reg2 , " " );
2007-08-04 12:10:45 +02:00
}
2010-08-18 10:11:42 +02:00
2010-08-29 19:52:06 +02:00
/*
2017-08-22 09:23:35 +02:00
* =================================================================
2010-09-06 13:34:53 +02:00
* Purpose : Display a temporary message in input text fields ( For showing help message on
* input field ) .
* Input : fieldId
* Input : message
2017-08-22 09:23:35 +02:00
* Author : Regis Houssin
2010-09-06 13:34:53 +02:00
* Licence : GPL
* ==================================================================
2010-08-29 19:52:06 +02:00
*/
2010-08-18 10:11:42 +02:00
function displayMessage ( fieldId , message ) {
2009-11-14 11:37:30 +01:00
var textbox = document . getElementById ( fieldId );
2010-08-18 10:11:42 +02:00
if ( textbox . value == '' ) {
textbox . style . color = 'grey' ;
textbox . value = message ;
}
2009-11-14 11:37:30 +01:00
}
2010-08-29 19:52:06 +02:00
/*
2017-08-22 09:23:35 +02:00
* =================================================================
2010-09-06 13:34:53 +02:00
* Purpose : Hide a temporary message in input text fields ( For showing help message on
2017-08-22 09:23:35 +02:00
* input field ) .
* Input : fiedId
* Input : message
2010-09-06 13:34:53 +02:00
* Author : Regis Houssin
* Licence : GPL
2010-08-29 19:52:06 +02:00
* ==================================================================
*/
2010-08-18 10:11:42 +02:00
function hideMessage ( fieldId , message ) {
2009-11-14 11:37:30 +01:00
var textbox = document . getElementById ( fieldId );
2010-08-18 10:11:42 +02:00
textbox . style . color = 'black' ;
if ( textbox . value == message ) textbox . value = '' ;
2009-12-18 15:34:25 +01:00
}
2011-02-05 04:28:56 +01:00
2013-11-16 18:12:13 +01:00
2012-08-13 20:53:48 +02:00
/*
2017-02-04 11:02:10 +01:00
* Used by button to set on / off
*
* @ param string url Url
* @ param string code Code
* @ param string intput Input
* @ param int entity Entity
* @ param int strict Strict
2012-08-13 20:53:48 +02:00
*/
2014-08-17 15:12:20 +02:00
function setConstant ( url , code , input , entity , strict ) {
2012-08-13 20:53:48 +02:00
$ . get ( url , {
action : " set " ,
name : code ,
entity : entity
},
function () {
$ ( " #set_ " + code ) . hide ();
$ ( " #del_ " + code ) . show ();
$ . each ( input , function ( type , data ) {
// Enable another element
2014-08-17 15:12:20 +02:00
if ( type == " disabled " && strict != 1 ) {
2012-08-13 20:53:48 +02:00
$ . each ( data , function ( key , value ) {
2013-03-13 23:05:34 +01:00
var newvalue = (( value . search ( " ^# " ) < 0 && value . search ( " ^ \ . " ) < 0 ) ? " # " : " " ) + value ;
$ ( newvalue ) . removeAttr ( " disabled " );
if ( $ ( newvalue ) . hasClass ( " butActionRefused " ) == true ) {
$ ( newvalue ) . removeClass ( " butActionRefused " );
$ ( newvalue ) . addClass ( " butAction " );
2012-08-13 20:53:48 +02:00
}
});
2013-03-13 23:05:34 +01:00
} else if ( type == " enabled " ) {
$ . each ( data , function ( key , value ) {
var newvalue = (( value . search ( " ^# " ) < 0 && value . search ( " ^ \ . " ) < 0 ) ? " # " : " " ) + value ;
2014-08-17 15:12:20 +02:00
if ( strict == 1 )
$ ( newvalue ) . removeAttr ( " disabled " );
else
$ ( newvalue ) . attr ( " disabled " , true );
2013-03-13 23:05:34 +01:00
if ( $ ( newvalue ) . hasClass ( " butAction " ) == true ) {
$ ( newvalue ) . removeClass ( " butAction " );
$ ( newvalue ) . addClass ( " butActionRefused " );
}
2017-08-22 09:23:35 +02:00
});
2012-08-13 20:53:48 +02:00
// Show another element
} else if ( type == " showhide " || type == " show " ) {
$ . each ( data , function ( key , value ) {
2013-03-13 23:05:34 +01:00
var newvalue = (( value . search ( " ^# " ) < 0 && value . search ( " ^ \ . " ) < 0 ) ? " # " : " " ) + value ;
$ ( newvalue ) . show ();
2012-08-13 20:53:48 +02:00
});
// Set another constant
} else if ( type == " set " ) {
$ . each ( data , function ( key , value ) {
$ ( " #set_ " + key ) . hide ();
$ ( " #del_ " + key ) . show ();
$ . get ( url , {
action : " set " ,
name : key ,
value : value ,
entity : entity
});
});
}
});
});
}
2011-02-05 04:28:56 +01:00
2012-08-13 20:53:48 +02:00
/*
2017-02-04 11:02:10 +01:00
* Used by button to set on / off
*
* @ param string url Url
* @ param string code Code
* @ param string intput Input
* @ param int entity Entity
* @ param int strict Strict
2012-08-13 20:53:48 +02:00
*/
2014-08-17 15:12:20 +02:00
function delConstant ( url , code , input , entity , strict ) {
2012-08-13 20:53:48 +02:00
$ . get ( url , {
action : " del " ,
name : code ,
entity : entity
},
function () {
$ ( " #del_ " + code ) . hide ();
$ ( " #set_ " + code ) . show ();
$ . each ( input , function ( type , data ) {
// Disable another element
if ( type == " disabled " ) {
$ . each ( data , function ( key , value ) {
2013-03-13 23:05:34 +01:00
var newvalue = (( value . search ( " ^# " ) < 0 && value . search ( " ^ \ . " ) < 0 ) ? " # " : " " ) + value ;
$ ( newvalue ) . attr ( " disabled " , true );
if ( $ ( newvalue ) . hasClass ( " butAction " ) == true ) {
$ ( newvalue ) . removeClass ( " butAction " );
$ ( newvalue ) . addClass ( " butActionRefused " );
2012-08-13 20:53:48 +02:00
}
});
2014-08-17 15:12:20 +02:00
} else if ( type == " enabled " && strict != 1 ) {
2013-03-13 23:05:34 +01:00
$ . each ( data , function ( key , value ) {
var newvalue = (( value . search ( " ^# " ) < 0 && value . search ( " ^ \ . " ) < 0 ) ? " # " : " " ) + value ;
$ ( newvalue ) . removeAttr ( " disabled " );
if ( $ ( newvalue ) . hasClass ( " butActionRefused " ) == true ) {
$ ( newvalue ) . removeClass ( " butActionRefused " );
$ ( newvalue ) . addClass ( " butAction " );
}
2017-08-22 09:23:35 +02:00
});
2012-08-13 20:53:48 +02:00
// Hide another element
} else if ( type == " showhide " || type == " hide " ) {
$ . each ( data , function ( key , value ) {
2013-03-13 23:05:34 +01:00
var newvalue = (( value . search ( " ^# " ) < 0 && value . search ( " ^ \ . " ) < 0 ) ? " # " : " " ) + value ;
$ ( newvalue ) . hide ();
2012-08-13 20:53:48 +02:00
});
// Delete another constant
} else if ( type == " del " ) {
$ . each ( data , function ( key , value ) {
$ ( " #del_ " + value ) . hide ();
$ ( " #set_ " + value ) . show ();
$ . get ( url , {
action : " del " ,
name : value ,
entity : entity
});
});
}
});
});
}
2011-02-05 04:28:56 +01:00
2012-08-13 20:53:48 +02:00
/*
2017-02-04 11:02:10 +01:00
* Used by button to set on / off
*
* @ param string action Action
* @ param string url Url
* @ param string code Code
* @ param string intput Input
* @ param string box Box
* @ param int entity Entity
* @ param int yesButton yesButton
* @ param int noButton noButton
* @ param int strict Strict
2012-08-13 20:53:48 +02:00
*/
2014-08-17 15:12:20 +02:00
function confirmConstantAction ( action , url , code , input , box , entity , yesButton , noButton , strict ) {
2012-10-25 14:57:56 +02:00
var boxConfirm = box ;
2012-08-13 20:53:48 +02:00
$ ( " #confirm_ " + code )
2012-10-25 14:57:56 +02:00
. attr ( " title " , boxConfirm . title )
. html ( boxConfirm . content )
2012-08-13 20:53:48 +02:00
. dialog ({
resizable : false ,
height : 170 ,
width : 500 ,
modal : true ,
buttons : [
{
2012-12-01 15:45:05 +01:00
id : 'yesButton_' + code ,
2012-08-13 20:53:48 +02:00
text : yesButton ,
click : function () {
if ( action == " set " ) {
2014-08-17 15:12:20 +02:00
setConstant ( url , code , input , entity , strict );
2012-08-13 20:53:48 +02:00
} else if ( action == " del " ) {
2014-08-17 15:12:20 +02:00
delConstant ( url , code , input , entity , strict );
2012-08-13 20:53:48 +02:00
}
// Close dialog
$ ( this ) . dialog ( " close " );
2012-10-25 14:57:56 +02:00
// Execute another method
if ( boxConfirm . method ) {
var fnName = boxConfirm . method ;
2012-08-13 20:53:48 +02:00
if ( window . hasOwnProperty ( fnName )) {
window [ fnName ]();
}
}
}
},
{
2012-12-01 15:45:05 +01:00
id : 'noButton_' + code ,
2012-08-13 20:53:48 +02:00
text : noButton ,
click : function () {
$ ( this ) . dialog ( " close " );
}
}
]
});
2012-12-01 15:45:05 +01:00
// For information dialog box only, hide the noButton
if ( boxConfirm . info ) {
$ ( " #noButton_ " + code ) . button () . hide ();
}
2012-08-13 20:53:48 +02:00
}
2011-02-05 04:28:56 +01:00
2017-10-21 19:05:24 +02:00
2017-08-22 09:23:35 +02:00
/*
* =================================================================
2012-10-27 00:23:16 +02:00
* This is to allow to transform all select box into ajax autocomplete box
2017-08-22 09:23:35 +02:00
* with just one line :
2013-11-16 18:12:13 +01:00
* $ ( function () { $ ( " #idofmylist " ) . combobox (); });
2017-08-22 09:23:35 +02:00
* Do not use it on large combo boxes
* =================================================================
2011-02-05 04:28:56 +01:00
*/
2012-03-15 10:14:54 +01:00
( function ( $ ) {
$ . widget ( " ui.combobox " , {
2013-01-29 15:22:07 +01:00
options : {
2013-09-05 20:28:24 +02:00
minLengthToAutocomplete : 0
2013-01-29 15:22:07 +01:00
},
2011-02-05 04:28:56 +01:00
_create : function () {
2013-01-29 15:22:07 +01:00
var savMinLengthToAutocomplete = this . options . minLengthToAutocomplete ;
2011-02-05 04:28:56 +01:00
var self = this ,
select = this . element . hide (),
selected = select . children ( " :selected " ),
value = selected . val () ? selected . text () : " " ;
2012-03-15 10:14:54 +01:00
var input = this . input = $ ( " <input> " )
2011-02-05 04:28:56 +01:00
. insertAfter ( select )
. val ( value )
2014-06-17 11:18:30 +02:00
. attr ( 'id' , 'inputautocomplete' + select . attr ( 'id' ))
2011-02-05 04:28:56 +01:00
. autocomplete ({
delay : 0 ,
2013-01-29 15:22:07 +01:00
minLength : this . options . minLengthToAutocomplete ,
2011-02-05 04:28:56 +01:00
source : function ( request , response ) {
2012-03-15 10:14:54 +01:00
var matcher = new RegExp ( $ . ui . autocomplete . escapeRegex ( request . term ), " i " );
2013-07-08 12:51:17 +02:00
response ( select . children ( " option:enabled " ) . map ( function () {
2012-03-15 10:14:54 +01:00
var text = $ ( this ) . text ();
2011-02-05 04:28:56 +01:00
if ( this . value && ( ! request . term || matcher . test ( text ) ) )
return {
label : text . replace (
new RegExp (
" (?![^&;]+;)(?!<[^<>]*)( " +
2012-03-15 10:14:54 +01:00
$ . ui . autocomplete . escapeRegex ( request . term ) +
2011-02-05 04:28:56 +01:00
" )(?![^<>]*>)(?![^&;]+;) " , " gi "
), " <strong> $ 1</strong> " ),
value : text ,
option : this
};
}) );
},
select : function ( event , ui ) {
ui . item . option . selected = true ;
self . _trigger ( " selected " , event , {
item : ui . item . option
});
},
change : function ( event , ui ) {
if ( ! ui . item ) {
2012-03-15 10:14:54 +01:00
var matcher = new RegExp ( " ^ " + $ . ui . autocomplete . escapeRegex ( $ ( this ) . val () ) + " $ " , " i " ),
2011-02-05 04:28:56 +01:00
valid = false ;
select . children ( " option " ) . each ( function () {
2012-03-15 10:14:54 +01:00
if ( $ ( this ) . text () . match ( matcher ) ) {
2011-02-05 04:28:56 +01:00
this . selected = valid = true ;
return false ;
}
});
if ( ! valid ) {
// remove invalid value, as it didnt match anything
2012-03-15 10:14:54 +01:00
$ ( this ) . val ( " " );
2011-02-05 04:28:56 +01:00
select . val ( " " );
2015-06-21 00:06:37 +02:00
input . data ( " ui-autocomplete " ) . term = " " ;
2011-02-05 04:28:56 +01:00
return false ;
}
}
}
})
2011-04-06 21:36:56 +02:00
. addClass ( " ui-widget ui-widget-content ui-corner-left dolibarrcombobox " );
2011-02-05 04:28:56 +01:00
2015-06-21 00:06:37 +02:00
input . data ( " ui-autocomplete " ) . _renderItem = function ( ul , item ) {
2015-11-30 20:31:42 +01:00
return $ ( " <li> " )
. data ( " ui-autocomplete-item " , item ) // jQuery UI > 1.10.0
2011-02-05 04:28:56 +01:00
. append ( " <a> " + item . label + " </a> " )
. appendTo ( ul );
};
2012-03-15 10:14:54 +01:00
this . button = $ ( " <button type= \ 'button \ '> </button> " )
2011-02-05 04:28:56 +01:00
. attr ( " tabIndex " , - 1 )
. attr ( " title " , " Show All Items " )
. insertAfter ( input )
. button ({
icons : {
primary : " ui-icon-triangle-1-s "
},
text : false
})
. removeClass ( " ui-corner-all " )
. addClass ( " ui-corner-right ui-button-icon " )
. click ( function () {
// close if already visible
if ( input . autocomplete ( " widget " ) . is ( " :visible " ) ) {
input . autocomplete ( " close " );
return ;
}
// pass empty string as value to search for, displaying all results
2013-01-29 15:22:07 +01:00
input . autocomplete ({ minLength : 0 });
2011-02-05 04:28:56 +01:00
input . autocomplete ( " search " , " " );
2013-01-29 15:22:07 +01:00
input . autocomplete ({ minLength : savMinLengthToAutocomplete });
2011-02-05 04:28:56 +01:00
input . focus ();
});
},
destroy : function () {
this . input . remove ();
this . button . remove ();
this . element . show ();
2012-03-15 10:14:54 +01:00
$ . Widget . prototype . destroy . call ( this );
2011-02-05 04:28:56 +01:00
}
});
})( jQuery );
2012-08-22 17:42:40 +02:00
2014-02-19 11:08:43 +01:00
2017-10-21 19:05:24 +02:00
2017-02-04 11:02:10 +01:00
/**
2014-02-19 11:08:43 +01:00
* Function to output a dialog bog for copy / paste
2017-08-22 09:23:35 +02:00
*
2014-02-19 11:08:43 +01:00
* @ param string text Text to put into copy / paste area
* @ param string text2 Text to put under the copy / paste area
*/
2017-08-22 09:23:35 +02:00
function copyToClipboard ( text , text2 )
2014-02-19 11:08:43 +01:00
{
text = text . replace ( /< br >/ g , " \n " );
2016-01-02 00:27:14 +01:00
var newElem = '<textarea id="coordsforpopup" style="border: none; width: 90%; height: 120px;">' + text + '</textarea><br><br>' + text2 ;
/* alert(newElem); */
$ ( " #dialogforpopup " ) . html ( newElem );
$ ( " #dialogforpopup " ) . dialog ();
$ ( " #coordsforpopup " ) . select ();
2014-02-19 11:08:43 +01:00
return false ;
}
2016-08-05 15:30:28 +02:00
2017-02-04 11:02:10 +01:00
/**
* Show a popup HTML page . Use the " window.open " function .
2017-08-22 09:23:35 +02:00
*
2017-02-04 11:02:10 +01:00
* @ param string url Url
* @ param string title Title of popup
* @ return boolean False
* @ see document_preview
*/
function newpopup ( url , title ) {
var argv = newpopup . arguments ;
var argc = newpopup . arguments . length ;
tmp = url ;
var l = ( argc > 2 ) ? argv [ 2 ] : 600 ;
var h = ( argc > 3 ) ? argv [ 3 ] : 400 ;
var left = ( screen . width - l ) / 2 ;
var top = ( screen . height - h ) / 2 ;
var wfeatures = " directories=0,menubar=0,status=0,resizable=0,scrollbars=1,toolbar=0,width= " + l + " ,height= " + h + " ,left= " + left + " ,top= " + top ;
fen = window . open ( tmp , title , wfeatures );
return false ;
}
/**
* Function show document preview . Use the " dialog " function .
2016-08-05 12:18:51 +02:00
*
2017-02-04 14:16:17 +01:00
* @ param string file Url
* @ param string type Mime file type ( " image/jpeg " , " application/pdf " , " text/html " )
2017-02-04 11:02:10 +01:00
* @ param string title Title of popup
* @ return void
* @ see newpopup
2016-08-02 03:35:22 +02:00
*/
2016-08-05 12:18:51 +02:00
function document_preview ( file , type , title )
{
2016-08-02 03:35:22 +02:00
var ValidImageTypes = [ " image/gif " , " image/jpeg " , " image/png " ];
2017-08-22 13:14:10 +02:00
var showOriginalSizeButton = false ;
2017-05-18 13:01:48 +02:00
console . log ( " document_preview A click was done. file= " + file + " , type= " + type + " , title= " + title );
2017-08-22 09:23:35 +02:00
2016-08-02 03:35:22 +02:00
if ( $ . inArray ( type , ValidImageTypes ) < 0 ) {
var width = '85%' ;
var object_width = '100%' ;
2017-11-09 01:00:43 +01:00
var height = ( $ ( window ) . height () - 60 ) * 0.90 ;
2016-08-02 03:35:22 +02:00
var object_height = '98%' ;
2017-08-22 13:14:10 +02:00
show_preview ( 'notimage' );
2016-08-02 03:35:22 +02:00
} else {
var object_width = 0 ;
var object_height = 0 ;
var img = new Image ();
img . onload = function () {
object_width = this . width ;
object_height = this . height ;
width = $ ( window ) . width () * 0.90 ;
if ( object_width < width ){
2017-08-22 13:14:10 +02:00
console . log ( " Object width is small, we set width of popup according to image width. " );
2016-08-02 03:35:22 +02:00
width = object_width + 30
}
height = $ ( window ) . height () * 0.85 ;
if ( object_height < height ){
2017-08-22 13:14:10 +02:00
console . log ( " Object height is small, we set height of popup according to image height. " );
2016-08-02 03:35:22 +02:00
height = object_height + 80
}
2017-08-22 13:14:10 +02:00
else
{
showOriginalSizeButton = true ;
}
2016-08-02 03:35:22 +02:00
2017-08-22 13:14:10 +02:00
show_preview ( 'image' );
2016-08-02 03:35:22 +02:00
};
img . src = file ;
}
2017-08-22 13:14:10 +02:00
function show_preview ( mode ) {
2017-08-22 13:15:56 +02:00
/* console.log("mode="+mode+" file="+file+" type="+type+" width="+width+" height="+height); */
2017-05-18 13:01:48 +02:00
var newElem = '<object name="objectpreview" data="' + file + '" type="' + type + '" width="' + object_width + '" height="' + object_height + '" param="noparam"></object>' ;
2016-08-02 03:35:22 +02:00
2017-08-22 13:14:10 +02:00
optionsbuttons = {}
if ( mode == 'image' && showOriginalSizeButton )
{
optionsbuttons = {
2017-11-18 12:35:25 +01:00
" <?php echo dol_escape_js( $langs->transnoentitiesnoconv ( " OriginalSize " )); ?> " : function () { console . log ( " Click on original size " ); jQuery ( " .ui-dialog-content.ui-widget-content > object " ) . css ({ " max-height " : " none " }); },
" <?php echo dol_escape_js( $langs->transnoentitiesnoconv ( " Close " )); ?> " : function () { $ ( this ) . dialog ( " close " ); }
2017-08-22 13:14:10 +02:00
};
}
2016-08-02 03:35:22 +02:00
$ ( " #dialogforpopup " ) . html ( newElem );
$ ( " #dialogforpopup " ) . dialog ({
closeOnEscape : true ,
resizable : true ,
width : width ,
height : height ,
modal : true ,
2017-08-22 13:14:10 +02:00
title : title ,
buttons : optionsbuttons
2016-08-02 03:35:22 +02:00
});
2017-08-22 13:14:10 +02:00
if ( showOriginalSizeButton )
{
jQuery ( " .ui-dialog-content.ui-widget-content > object " ) . css ({ " max-height " : " 100% " , " width " : " auto " , " margin-left " : " auto " , " margin-right " : " auto " , " display " : " block " });
}
2016-08-02 03:35:22 +02:00
}
}
2015-11-13 03:35:55 +01:00
/*
2017-08-22 09:23:35 +02:00
* Provide a function to get an URL GET parameter in javascript
*
2015-11-13 03:35:55 +01:00
* @ param string name Name of parameter
* @ param mixed valueifnotfound Value if not found
* @ return string Value
2012-08-22 17:42:40 +02:00
*/
2017-08-22 09:23:35 +02:00
function getParameterByName ( name , valueifnotfound )
2015-11-13 03:35:55 +01:00
{
name = name . replace ( / [ \ [] / , " \\ [ " ) . replace ( / [ \ ]] / , " \\ ] " );
var regex = new RegExp ( " [ \\ ?&] " + name + " =([^&#]*) " ),
results = regex . exec ( location . search );
return results === null ? valueifnotfound : decodeURIComponent ( results [ 1 ] . replace ( / \ +/ g , " " ));
}
2015-12-07 15:10:23 +01:00
2017-02-04 11:02:10 +01:00
2015-12-07 15:10:23 +01:00
// Code in the public domain from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round
( function () {
/**
* Decimal adjustment of a number .
*
* @ param { String } type The type of adjustment .
* @ param { Number } value The number .
* @ param { Integer } exp The exponent ( the 10 logarithm of the adjustment base ) .
* @ returns { Number } The adjusted value .
*/
function decimalAdjust ( type , value , exp ) {
// If the exp is undefined or zero...
if ( typeof exp === 'undefined' || + exp === 0 ) {
return Math [ type ]( value );
}
value = + value ;
exp = + exp ;
// If the value is not a number or the exp is not an integer...
if ( isNaN ( value ) || ! ( typeof exp === 'number' && exp % 1 === 0 )) {
return NaN ;
}
// Shift
value = value . toString () . split ( 'e' );
value = Math [ type ]( + ( value [ 0 ] + 'e' + ( value [ 1 ] ? ( + value [ 1 ] - exp ) : - exp )));
// Shift back
value = value . toString () . split ( 'e' );
return + ( value [ 0 ] + 'e' + ( value [ 1 ] ? ( + value [ 1 ] + exp ) : exp ));
}
// Decimal round
if ( ! Math . round10 ) {
Math . round10 = function ( value , exp ) {
return decimalAdjust ( 'round' , value , exp );
};
}
// Decimal floor
if ( ! Math . floor10 ) {
Math . floor10 = function ( value , exp ) {
return decimalAdjust ( 'floor' , value , exp );
};
}
// Decimal ceil
if ( ! Math . ceil10 ) {
Math . ceil10 = function ( value , exp ) {
return decimalAdjust ( 'ceil' , value , exp );
};
}
})();
2017-08-22 09:23:35 +02:00
// Another solution, easier, to build a javascript rounding function
2016-07-27 18:49:34 +02:00
function dolroundjs ( number , decimals ) { return + ( Math . round ( number + " e+ " + decimals ) + " e- " + decimals ); }
2015-12-07 15:10:23 +01:00
/**
* Function similar to PHP price2num ()
*
2017-02-04 11:02:10 +01:00
* @ param { number | string } amount The amount to convert / clean
* @ return { string } The amount in universal numeric format ( Example : '99.99999' )
2015-12-07 15:10:23 +01:00
* @ todo Implement rounding parameter
*/
function price2numjs ( amount ) {
if ( amount == '' ) return '' ;
< ? php
2016-07-27 18:49:34 +02:00
$dec = ',' ;
2015-12-07 15:10:23 +01:00
$thousand = ' ' ;
if ( $langs -> transnoentitiesnoconv ( " SeparatorDecimal " ) != " SeparatorDecimal " ) {
$dec = $langs -> transnoentitiesnoconv ( " SeparatorDecimal " );
}
if ( $langs -> transnoentitiesnoconv ( " SeparatorThousand " ) != " SeparatorThousand " ) {
$thousand = $langs -> transnoentitiesnoconv ( " SeparatorThousand " );
}
2016-07-27 18:49:34 +02:00
if ( $thousand == 'Space' ) $thousand = ' ' ;
2016-06-17 10:35:18 +02:00
print " var dec=' " . dol_escape_js ( $dec ) . " '; var thousand=' " . dol_escape_js ( $thousand ) . " '; \n " ; // Set var in javascript
2015-12-07 15:10:23 +01:00
?>
2016-06-17 10:40:11 +02:00
var main_max_dec_shown = < ? php echo ( int ) str_replace ( '.' , '' , $conf -> global -> MAIN_MAX_DECIMALS_SHOWN ); ?> ;
var main_rounding_unit = < ? php echo ( int ) $conf -> global -> MAIN_MAX_DECIMALS_UNIT ; ?> ;
var main_rounding_tot = < ? php echo ( int ) $conf -> global -> MAIN_MAX_DECIMALS_TOT ; ?> ;
2015-12-07 15:10:23 +01:00
var amount = amount . toString ();
// rounding for unit price
var rounding = main_rounding_unit ;
var pos = amount . indexOf ( dec );
var decpart = '' ;
if ( pos >= 0 ) decpart = amount . substr ( pos + 1 ) . replace ( '/0+$/i' , '' ); // Remove 0 for decimal part
var nbdec = decpart . length ;
if ( nbdec > rounding ) rounding = nbdec ;
// If rounding higher than max shown
if ( rounding > main_max_dec_shown ) rounding = main_max_dec_shown ;
if ( thousand != ',' && thousand != '.' ) amount = amount . replace ( ',' , '.' );
2017-10-21 19:05:24 +02:00
amount = amount . replace ( ' ' , '' ); // To avoid spaces
2015-12-07 15:10:23 +01:00
amount = amount . replace ( thousand , '' ); // Replace of thousand before replace of dec to avoid pb if thousand is .
amount = amount . replace ( dec , '.' );
2016-07-27 18:49:34 +02:00
//console.log("amount before="+amount+" rouding="+rounding)
var res = Math . round10 ( amount , - rounding );
2017-08-22 09:23:35 +02:00
// Other solution is
2016-07-27 18:49:34 +02:00
// var res = dolroundjs(amount, rounding)
console . log ( " res= " + res )
return res ;
2015-12-07 15:10:23 +01:00
}
2017-08-22 09:23:35 +02:00
2016-08-05 15:30:28 +02:00
2017-11-19 12:22:01 +01:00
< ? php
if ( empty ( $conf -> global -> MAIN_DISABLE_JQUERY_JNOTIFY ) && ! defined ( 'DISABLE_JQUERY_JNOTIFY' )) {
?>
// Defined properties for JNotify
$ ( document ) . ready ( function () {
2017-11-24 14:23:25 +01:00
if ( typeof $ . jnotify == 'function' )
{
$ . jnotify . setup ({
delay : 3000 // the default time to show each notification (in milliseconds)
, sticky : false // determines if the message should be considered "sticky" (user must manually close notification)
, closeLabel : " × " // the HTML to use for the "Close" link
, showClose : true // determines if the "Close" link should be shown if notification is also sticky
, fadeSpeed : 1000 // the speed to fade messages out (in milliseconds)
, slideSpeed : 250 // the speed used to slide messages out (in milliseconds)
, classContainer : " jnotify-container "
, classNotification : " jnotify-notification "
, classBackground : " jnotify-background "
, classClose : " jnotify-close "
, classMessage : " jnotify-message "
, init : null // callback that occurs when the main jnotify container is created
, create : null // callback that occurs when when the note is created (occurs just before appearing in DOM)
, beforeRemove : null // callback that occurs when before the notification starts to fade away
});
}
2017-11-19 12:22:01 +01:00
});
< ? php } ?>
2017-11-19 16:30:05 +01:00
// End of lib_head.js.php