2007-12-29 18:06:53 +01:00
< ? php
2010-10-03 23:43:03 +02:00
/* Copyright ( C ) 2007 - 2010 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2007 - 2015 Regis Houssin < regis . houssin @ inodbox . com >
2012-07-18 15:17:04 +02:00
* Copyright ( C ) 2012 Christophe Battarel < christophe . battarel @ altairis . fr >
2007-12-29 18:06:53 +01:00
*
* 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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2007-12-29 18:06:53 +01:00
* ( 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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
* or see https :// www . gnu . org /
2009-03-28 20:11:38 +01:00
*/
/**
2011-10-24 09:49:50 +02:00
* \file htdocs / core / lib / ajax . lib . php
2020-05-14 16:52:21 +02:00
* \brief Page called to enhance interface with Javascript and Ajax features .
2007-12-29 18:06:53 +01:00
*/
/**
2021-04-01 11:27:39 +02:00
* Generic function that return javascript to add to a page to transform a common input field into an autocomplete field by calling an Ajax page ( ex : / societe / ajax / ajaxcompanies . php ) .
2020-08-07 14:56:30 +02:00
* The HTML field must be an input text with id = search_ $htmlname .
* This use the jQuery " autocomplete " function . If we want to use the select2 , we must also convert the input into select on funcntions that call this method .
2011-11-09 22:10:58 +01:00
*
2020-08-07 14:56:30 +02:00
* @ param string $selected Preselected value
* @ param string $htmlname HTML name of input field
* @ param string $url Ajax Url to call for request : / path / page . php . Must return a json array ( 'key' => id , 'value' => String shown into input field once selected , 'label' => String shown into combo list )
* @ param string $urloption More parameters on URL request
* @ param int $minLength Minimum number of chars to trigger that Ajax search
2021-09-07 14:10:26 +02:00
* @ param int $autoselect Automatic selection if just one value ( trigger ( " change " ) on field is done if search return only 1 result )
2020-08-07 14:56:30 +02:00
* @ param array $ajaxoptions Multiple options array
2018-08-09 11:50:07 +02:00
* - Ex : array ( 'update' => array ( 'field1' , 'field2' ... )) will reset field1 and field2 once select done
* - Ex : array ( 'disabled' => )
* - Ex : array ( 'show' => )
* - Ex : array ( 'update_textarea' => )
* - Ex : array ( 'option_disabled' => id to disable and warning to show if we select a disabled value ( this is possible when using autocomplete ajax )
2020-08-04 14:13:52 +02:00
* @ param string $moreparams More params provided to ajax call
2020-08-07 14:56:30 +02:00
* @ return string Script
2009-03-28 20:11:38 +01:00
*/
2020-08-04 14:13:52 +02:00
function ajax_autocompleter ( $selected , $htmlname , $url , $urloption = '' , $minLength = 2 , $autoselect = 0 , $ajaxoptions = array (), $moreparams = '' )
2007-12-29 18:06:53 +01:00
{
2021-10-21 17:10:39 +02:00
global $conf ;
2021-02-23 22:03:23 +01:00
if ( empty ( $minLength )) {
$minLength = 1 ;
}
2011-05-31 22:36:06 +02:00
2020-09-07 10:18:17 +02:00
$dataforrenderITem = 'ui-autocomplete' ;
$dataforitem = 'ui-autocomplete-item' ;
// Allow two constant to use other values for backward compatibility
2021-02-23 22:03:23 +01:00
if ( defined ( 'JS_QUERY_AUTOCOMPLETE_RENDERITEM' )) {
$dataforrenderITem = constant ( 'JS_QUERY_AUTOCOMPLETE_RENDERITEM' );
}
if ( defined ( 'JS_QUERY_AUTOCOMPLETE_ITEM' )) {
$dataforitem = constant ( 'JS_QUERY_AUTOCOMPLETE_ITEM' );
}
2017-07-28 18:09:38 +02:00
2022-05-17 00:50:59 +02:00
$htmlnamejquery = str_replace ( '.' , '\\\\.' , $htmlname );
2020-09-07 10:18:17 +02:00
// Input search_htmlname is original field
// Input htmlname is a second input field used when using ajax autocomplete.
2020-08-04 14:13:52 +02:00
$script = '<input type="hidden" name="' . $htmlname . '" id="' . $htmlname . '" value="' . $selected . '" ' . ( $moreparams ? $moreparams : '' ) . ' />' ;
2009-08-28 00:20:01 +02:00
2020-02-21 17:53:37 +01:00
$script .= '<!-- Javascript code for autocomplete of field ' . $htmlname . ' -->' . " \n " ;
$script .= '<script>' . " \n " ;
$script .= ' $ ( document ) . ready ( function () {
2021-09-07 14:10:26 +02:00
var autoselect = '.((int) $autoselect).' ;
2020-07-06 15:34:26 +02:00
var options = '.json_encode($ajaxoptions).' ; /* Option of actions to do after keyup, or after select */
2012-08-22 17:42:40 +02:00
2017-10-06 10:46:45 +02:00
/* Remove selected id as soon as we type or delete a char (it means old selection is wrong). Use keyup/down instead of change to avoid loosing the product id. This is needed only for select of predefined product */
2022-05-17 00:50:59 +02:00
$ ( " input#search_'. $htmlnamejquery .' " ) . keydown ( function ( e ) {
2017-10-06 10:46:45 +02:00
if ( e . keyCode != 9 ) /* If not "Tab" key */
{
2020-12-08 20:53:42 +01:00
if ( e . keyCode == 13 ) { return false ; } /* disable "ENTER" key useful for barcode readers */
2017-10-06 10:46:45 +02:00
console . log ( " Clear id previously selected for field '. $htmlname .' " );
2022-05-17 00:50:59 +02:00
$ ( " #'. $htmlnamejquery .' " ) . val ( " " );
2017-10-06 10:46:45 +02:00
}
2012-11-26 13:33:18 +01:00
});
2016-10-12 15:33:33 +02:00
2016-02-14 23:53:42 +01:00
// Check options for secondary actions when keyup
2022-05-17 00:50:59 +02:00
$ ( " input#search_'. $htmlnamejquery .' " ) . keyup ( function () {
2012-08-22 17:42:40 +02:00
if ( $ ( this ) . val () . length == 0 )
{
2022-05-17 00:50:59 +02:00
$ ( " #search_'. $htmlnamejquery .' " ) . val ( " " );
$ ( " #'. $htmlnamejquery .' " ) . val ( " " ) . trigger ( " change " );
2012-08-22 17:42:40 +02:00
if ( options . option_disabled ) {
$ ( " # " + options . option_disabled ) . removeAttr ( " disabled " );
}
if ( options . disabled ) {
$ . each ( options . disabled , function ( key , value ) {
$ ( " # " + value ) . removeAttr ( " disabled " );
});
}
if ( options . update ) {
$ . each ( options . update , function ( key , value ) {
$ ( " # " + key ) . val ( " " ) . trigger ( " change " );
});
}
if ( options . show ) {
$ . each ( options . show , function ( key , value ) {
$ ( " # " + value ) . hide () . trigger ( " hide " );
});
}
2012-08-29 17:40:13 +02:00
if ( options . update_textarea ) {
$ . each ( options . update_textarea , function ( key , value ) {
if ( typeof CKEDITOR == " object " && typeof CKEDITOR . instances != " undefined " && CKEDITOR . instances [ key ] != " undefined " ) {
CKEDITOR . instances [ key ] . setData ( " " );
} else {
$ ( " # " + key ) . html ( " " );
}
});
}
2012-08-22 17:42:40 +02:00
}
2010-10-11 23:32:53 +02:00
});
2020-02-19 03:07:12 +01:00
2022-05-17 00:50:59 +02:00
$ ( " input#search_'. $htmlnamejquery .' " ) . autocomplete ({
2010-10-08 17:28:18 +02:00
source : function ( request , response ) {
2022-05-17 00:50:59 +02:00
$ . get ( " '. $url .( $urloption ? '?'. $urloption : '').' " , { " '.str_replace('.', '_', $htmlname ).' " : request . term }, function ( data ){
2014-08-31 15:09:10 +02:00
if ( data != null )
{
response ( $ . map ( data , function ( item ) {
if ( autoselect == 1 && data . length == 1 ) {
2022-05-17 00:50:59 +02:00
$ ( " #search_'. $htmlnamejquery .' " ) . val ( item . value );
$ ( " #'. $htmlnamejquery .' " ) . val ( item . key ) . trigger ( " change " );
2014-08-31 15:09:10 +02:00
}
var label = item . label . toString ();
var update = {};
if ( options . update ) {
$ . each ( options . update , function ( key , value ) {
update [ key ] = item [ value ];
});
}
var textarea = {};
if ( options . update_textarea ) {
$ . each ( options . update_textarea , function ( key , value ) {
textarea [ key ] = item [ value ];
});
}
2022-10-13 14:31:08 +02:00
2022-09-25 12:36:57 +02:00
console . log ( " Return value from GET to the rest of code " );
2022-10-13 14:31:08 +02:00
return { label : label ,
value : item . value ,
id : item . key ,
disabled : item . disabled ,
2022-09-25 12:36:57 +02:00
update : update ,
textarea : textarea ,
2020-10-26 16:31:07 +01:00
pbq : item . pbq ,
2022-09-25 12:36:57 +02:00
type : item . type ,
qty : item . qty ,
discount : item . discount ,
2021-02-15 13:12:27 +01:00
pricebasetype : item . pricebasetype ,
price_ht : item . price_ht ,
2020-10-26 16:31:07 +01:00
price_ttc : item . price_ttc ,
2022-10-13 14:31:08 +02:00
price_unit_ht : item . price_unit_ht ,
price_unit_ht_locale : item . price_unit_ht_locale ,
2021-02-15 13:12:27 +01:00
description : item . description ,
2022-09-25 12:36:57 +02:00
ref_customer : item . ref_customer ,
tva_tx : item . tva_tx }
2014-08-31 15:09:10 +02:00
}));
2022-05-17 00:50:59 +02:00
} else {
console . error ( " Error: Ajax url '. $url .( $urloption ? '?'. $urloption : '').' has returned an empty page. Should be an empty json array. " );
2014-08-31 15:09:10 +02:00
}
2010-10-09 18:44:49 +02:00
}, " json " );
},
2010-10-11 23:32:53 +02:00
dataType : " json " ,
2022-05-17 00:50:59 +02:00
minLength : '.((int) $minLength).' ,
2016-02-14 23:53:42 +01:00
select : function ( event , ui ) { // Function ran once new value has been selected into javascript combo
2021-02-02 13:04:41 +01:00
console . log ( " We will trigger change on input '. $htmlname .' because of the select definition of autocomplete code for input#search_'. $htmlname .' " );
2016-04-28 20:04:48 +02:00
console . log ( " Selected id = " + ui . item . id + " - If this value is null, it means you select a record with key that is null so selection is not effective " );
2020-07-06 15:34:26 +02:00
2021-02-15 13:12:27 +01:00
console . log ( " Propagate before some properties retrieved by ajax into data-xxx properties " );
2020-07-06 15:34:26 +02:00
2021-02-15 13:12:27 +01:00
// For supplier price and customer when price by quantity is off
2022-05-17 00:50:59 +02:00
$ ( " #'. $htmlnamejquery .' " ) . attr ( " data-up " , ui . item . price_ht );
2022-10-13 14:31:08 +02:00
$ ( " #'. $htmlnamejquery .' " ) . attr ( " data-up-locale " , ui . item . price_unit_ht_locale );
2022-05-17 00:50:59 +02:00
$ ( " #'. $htmlnamejquery .' " ) . attr ( " data-base " , ui . item . pricebasetype );
$ ( " #'. $htmlnamejquery .' " ) . attr ( " data-qty " , ui . item . qty );
$ ( " #'. $htmlnamejquery .' " ) . attr ( " data-discount " , ui . item . discount );
$ ( " #'. $htmlnamejquery .' " ) . attr ( " data-description " , ui . item . description );
$ ( " #'. $htmlnamejquery .' " ) . attr ( " data-ref-customer " , ui . item . ref_customer );
2022-09-25 12:36:57 +02:00
$ ( " #'. $htmlnamejquery .' " ) . attr ( " data-tvatx " , ui . item . tva_tx );
2021-02-15 13:12:27 +01:00
' ;
2022-12-31 13:36:31 +01:00
if ( ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY ) || ! empty ( $conf -> global -> PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES )) {
2020-10-26 16:31:07 +01:00
$script .= '
2021-02-15 13:12:27 +01:00
// For customer price when PRODUIT_CUSTOMER_PRICES_BY_QTY is on
2022-05-17 00:50:59 +02:00
$ ( " #'. $htmlnamejquery .' " ) . attr ( " data-pbq " , ui . item . pbq );
$ ( " #'. $htmlnamejquery .' " ) . attr ( " data-pbqup " , ui . item . price_ht );
$ ( " #'. $htmlnamejquery .' " ) . attr ( " data-pbqbase " , ui . item . pricebasetype );
$ ( " #'. $htmlnamejquery .' " ) . attr ( " data-pbqqty " , ui . item . qty );
$ ( " #'. $htmlnamejquery .' " ) . attr ( " data-pbqpercent " , ui . item . discount );
2020-10-26 16:31:07 +01:00
' ;
}
$script .= '
2022-10-13 14:31:08 +02:00
// A new value has been selected, we trigger the handlers on #htmlnamejquery
console . log ( " Trigger changes on #'. $htmlnamejquery .' " );
2022-05-17 00:50:59 +02:00
$ ( " #'. $htmlnamejquery .' " ) . val ( ui . item . id ) . trigger ( " change " ); // Select new value
2021-02-02 13:04:41 +01:00
2012-08-17 18:17:15 +02:00
// Disable an element
2012-08-22 17:42:40 +02:00
if ( options . option_disabled ) {
2017-08-23 15:02:38 +02:00
console . log ( " Make action option_disabled on # " + options . option_disabled + " with disabled= " + ui . item . disabled )
2012-08-17 16:58:57 +02:00
if ( ui . item . disabled ) {
2015-05-12 14:47:33 +02:00
$ ( " # " + options . option_disabled ) . prop ( " disabled " , true );
2012-08-17 16:58:57 +02:00
if ( options . error ) {
2014-05-05 17:59:43 +02:00
$ . jnotify ( options . error , " error " , true ); // Output with jnotify the error message
2012-08-17 16:58:57 +02:00
}
2014-05-05 17:59:43 +02:00
if ( options . warning ) {
$ . jnotify ( options . warning , " warning " , false ); // Output with jnotify the warning message
}
2017-08-23 15:02:38 +02:00
} else {
2012-08-22 17:42:40 +02:00
$ ( " # " + options . option_disabled ) . removeAttr ( " disabled " );
2012-08-17 16:58:57 +02:00
}
}
2021-02-02 13:04:41 +01:00
2012-08-22 17:42:40 +02:00
if ( options . disabled ) {
2017-08-23 15:02:38 +02:00
console . log ( " Make action disabled on each " + options . option_disabled )
2012-08-22 17:42:40 +02:00
$ . each ( options . disabled , function ( key , value ) {
2015-05-12 14:47:33 +02:00
$ ( " # " + value ) . prop ( " disabled " , true );
2012-08-22 17:42:40 +02:00
});
}
if ( options . show ) {
2017-08-23 15:02:38 +02:00
console . log ( " Make action show on each " + options . show )
2012-08-22 17:42:40 +02:00
$ . each ( options . show , function ( key , value ) {
$ ( " # " + value ) . show () . trigger ( " show " );
});
}
2021-02-02 13:04:41 +01:00
2012-08-22 17:42:40 +02:00
// Update an input
2012-08-17 18:17:15 +02:00
if ( ui . item . update ) {
2017-08-23 15:02:38 +02:00
console . log ( " Make action update on each ui.item.update " )
2013-11-28 15:54:12 +01:00
// loop on each "update" fields
2012-08-17 18:17:15 +02:00
$ . each ( ui . item . update , function ( key , value ) {
2021-02-10 02:17:01 +01:00
console . log ( " Set value " + value + " into # " + key );
2012-08-22 17:42:40 +02:00
$ ( " # " + key ) . val ( value ) . trigger ( " change " );
});
}
if ( ui . item . textarea ) {
2017-08-23 15:02:38 +02:00
console . log ( " Make action textarea on each ui.item.textarea " )
2012-08-22 17:42:40 +02:00
$ . each ( ui . item . textarea , function ( key , value ) {
2012-08-28 12:36:35 +02:00
if ( typeof CKEDITOR == " object " && typeof CKEDITOR . instances != " undefined " && CKEDITOR . instances [ key ] != " undefined " ) {
2012-08-22 17:42:40 +02:00
CKEDITOR . instances [ key ] . setData ( value );
CKEDITOR . instances [ key ] . focus ();
} else {
$ ( " # " + key ) . html ( value );
$ ( " # " + key ) . focus ();
}
2012-08-17 18:17:15 +02:00
});
}
2021-02-02 13:04:41 +01:00
console . log ( " ajax_autocompleter new value selected, we trigger change also on original component so on field #search_'. $htmlname .' " );
2017-06-21 11:37:34 +02:00
2022-05-17 00:50:59 +02:00
$ ( " #search_'. $htmlnamejquery .' " ) . trigger ( " change " ); // We have changed value of the combo select, we must be sure to trigger all js hook binded on this event. This is required to trigger other javascript change method binded on original field by other code.
2010-10-08 10:20:57 +02:00
}
2014-10-30 18:45:47 +01:00
, delay : 500
2017-07-28 18:09:38 +02:00
}) . data ( " '. $dataforrenderITem .' " ) . _renderItem = function ( ul , item ) {
2015-11-30 20:28:36 +01:00
return $ ( " <li> " )
2017-07-28 18:09:38 +02:00
. data ( " '. $dataforitem .' " , item ) // jQuery UI > 1.10.0
2012-11-20 12:09:52 +01:00
. append ( \ ' < a >< span class = " tag " > \ ' + item . label + " </span></a> " )
2011-09-20 11:40:27 +02:00
. appendTo ( ul );
2010-10-11 10:43:33 +02:00
};
2014-02-04 20:49:07 +01:00
2010-10-08 10:20:57 +02:00
}); ' ;
2020-02-21 17:53:37 +01:00
$script .= '</script>' ;
2010-03-04 09:28:30 +01:00
return $script ;
}
2010-10-12 19:14:53 +02:00
/**
2014-08-30 20:05:16 +02:00
* Generic function that return javascript to add to a page to transform a common input field into an autocomplete field by calling an Ajax page ( ex : core / ajax / ziptown . php ) .
* The Ajax page can also returns several values ( json format ) to fill several input fields .
* The HTML field must be an input text with id = $htmlname .
* This use the jQuery " autocomplete " function .
2011-12-28 21:30:33 +01:00
*
2014-08-30 20:05:16 +02:00
* @ param string $htmlname HTML name of input field
2021-01-13 12:45:23 +01:00
* @ param array $fields Array of key of fields to autocomplete
2014-08-30 20:05:16 +02:00
* @ param string $url URL for ajax request : / chemin / fichier . php
2012-02-04 14:39:47 +01:00
* @ param string $option More parameters on URL request
* @ param int $minLength Minimum number of chars to trigger that Ajax search
* @ param int $autoselect Automatic selection if just one value
* @ return string Script
2010-10-12 19:14:53 +02:00
*/
2019-01-27 15:20:16 +01:00
function ajax_multiautocompleter ( $htmlname , $fields , $url , $option = '' , $minLength = 2 , $autoselect = 0 )
2010-10-12 19:14:53 +02:00
{
2011-11-05 12:45:13 +01:00
$script = '<!-- Autocomplete -->' . " \n " ;
2020-02-21 17:53:37 +01:00
$script .= '<script>' ;
$script .= ' jQuery ( document ) . ready ( function () {
2011-11-05 12:45:13 +01:00
var fields = '.json_encode($fields).' ;
2014-08-30 20:05:16 +02:00
var nboffields = fields . length ;
2011-02-07 15:15:56 +01:00
var autoselect = '.$autoselect.' ;
2014-08-30 20:05:16 +02:00
//alert(fields + " " + nboffields);
2010-10-22 10:11:51 +02:00
2010-10-13 09:38:48 +02:00
jQuery ( " input#'. $htmlname .' " ) . autocomplete ({
2010-10-13 11:32:53 +02:00
dataType : " json " ,
2011-02-07 15:15:56 +01:00
minLength : '.$minLength.' ,
2010-10-12 19:14:53 +02:00
source : function ( request , response ) {
2020-02-21 17:53:37 +01:00
jQuery . getJSON ( " '. $url .( $option ? '?'. $option : '').' " , { '.$htmlname.' : request . term }, function ( data ){
2010-10-13 11:32:53 +02:00
response ( jQuery . map ( data , function ( item ) {
2011-02-07 15:15:56 +01:00
if ( autoselect == 1 && data . length == 1 ) {
2010-10-13 11:32:53 +02:00
jQuery ( " #'. $htmlname .' " ) . val ( item . value );
2010-10-13 19:03:28 +02:00
// TODO move this to specific request
2010-10-13 18:49:43 +02:00
if ( item . states ) {
2013-09-20 14:34:14 +02:00
jQuery ( " #state_id " ) . html ( item . states );
2010-10-13 18:47:49 +02:00
}
2014-08-30 20:05:16 +02:00
for ( i = 0 ; i < nboffields ; i ++ ) {
2010-10-31 21:09:50 +01:00
if ( item [ fields [ i ]]) { // If defined
2015-06-20 17:23:28 +02:00
//alert(item[fields[i]]);
jQuery ( " # " + fields [ i ]) . val ( item [ fields [ i ]]);
2010-10-13 11:32:53 +02:00
}
}
}
return item
}));
});
2010-10-13 10:34:49 +02:00
},
2010-10-12 19:14:53 +02:00
select : function ( event , ui ) {
2015-06-20 17:23:28 +02:00
needtotrigger = " " ;
2014-08-30 20:05:16 +02:00
for ( i = 0 ; i < nboffields ; i ++ ) {
2010-10-13 09:38:48 +02:00
//alert(fields[i] + " = " + ui.item[fields[i]]);
2011-12-29 18:34:56 +01:00
if ( fields [ i ] == " selectcountry_id " )
2010-10-31 21:09:50 +01:00
{
if ( ui . item [ fields [ i ]] > 0 ) // Do not erase country if unknown
{
2015-06-20 17:23:28 +02:00
oldvalue = jQuery ( " # " + fields [ i ]) . val ();
newvalue = ui . item [ fields [ i ]];
//alert(oldvalue+" "+newvalue);
2010-10-31 21:09:50 +01:00
jQuery ( " # " + fields [ i ]) . val ( ui . item [ fields [ i ]]);
2015-06-20 17:23:28 +02:00
if ( oldvalue != newvalue ) // To force select2 to refresh visible content
{
needtotrigger = " # " + fields [ i ];
}
2010-10-31 21:09:50 +01:00
// If we set new country and new state, we need to set a new list of state to allow change
2013-09-20 14:34:14 +02:00
if ( ui . item . states && ui . item [ " state_id " ] != jQuery ( " #state_id " ) . value ) {
jQuery ( " #state_id " ) . html ( ui . item . states );
2010-10-31 21:09:50 +01:00
}
}
}
2013-09-20 14:34:14 +02:00
else if ( fields [ i ] == " state_id " || fields [ i ] == " state_id " )
2010-10-31 21:09:50 +01:00
{
if ( ui . item [ fields [ i ]] > 0 ) // Do not erase state if unknown
{
2015-06-20 17:23:28 +02:00
oldvalue = jQuery ( " # " + fields [ i ]) . val ();
newvalue = ui . item [ fields [ i ]];
//alert(oldvalue+" "+newvalue);
2010-10-31 21:09:50 +01:00
jQuery ( " # " + fields [ i ]) . val ( ui . item [ fields [ i ]]); // This may fails if not correct country
2015-06-20 17:23:28 +02:00
if ( oldvalue != newvalue ) // To force select2 to refresh visible content
{
needtotrigger = " # " + fields [ i ];
}
2010-10-31 21:09:50 +01:00
}
}
else if ( ui . item [ fields [ i ]]) { // If defined
2015-06-20 17:23:28 +02:00
oldvalue = jQuery ( " # " + fields [ i ]) . val ();
newvalue = ui . item [ fields [ i ]];
//alert(oldvalue+" "+newvalue);
2010-10-31 21:09:50 +01:00
jQuery ( " # " + fields [ i ]) . val ( ui . item [ fields [ i ]]);
2015-06-20 17:23:28 +02:00
if ( oldvalue != newvalue ) // To force select2 to refresh visible content
{
needtotrigger = " # " + fields [ i ];
}
2010-10-13 09:38:48 +02:00
}
2016-10-12 15:33:33 +02:00
2016-04-23 16:49:43 +02:00
if ( needtotrigger != " " ) // To force select2 to refresh visible content
{
// We introduce a delay so hand is back to js and all other js change can be done before the trigger that may execute a submit is done
// This is required for example when changing zip with autocomplete that change the country
jQuery ( needtotrigger ) . delay ( 500 ) . queue ( function () {
jQuery ( this ) . trigger ( " change " );
});
}
2015-06-20 17:23:28 +02:00
}
2010-10-12 19:14:53 +02:00
}
});
}); ' ;
2020-02-21 17:53:37 +01:00
$script .= '</script>' ;
2010-10-12 19:14:53 +02:00
return $script ;
}
2010-10-03 23:43:03 +02:00
/**
2010-10-04 11:56:24 +02:00
* Show an ajax dialog
2012-02-04 14:39:47 +01:00
*
* @ param string $title Title of dialog box
* @ param string $message Message of dialog box
* @ param int $w Width of dialog box
* @ param int $h height of dialog box
2019-11-26 00:28:26 +01:00
* @ return string
2010-10-03 23:43:03 +02:00
*/
2019-01-27 15:20:16 +01:00
function ajax_dialog ( $title , $message , $w = 350 , $h = 150 )
2010-10-03 23:43:03 +02:00
{
global $langs ;
2010-10-11 23:32:53 +02:00
2020-02-21 17:53:37 +01:00
$newtitle = dol_textishtml ( $title ) ? dol_string_nohtmltag ( $title , 1 ) : $title ;
$msg = '<div id="dialog-info" title="' . dol_escape_htmltag ( $newtitle ) . '">' ;
$msg .= $message ;
$msg .= '</div>' . " \n " ;
2020-09-07 10:18:17 +02:00
$msg .= ' < script >
2010-10-03 23:43:03 +02:00
jQuery ( function () {
jQuery ( " #dialog-info " ) . dialog ({
resizable : false ,
height : '.$h.' ,
width : '.$w.' ,
modal : true ,
buttons : {
Ok : function () {
2012-08-13 20:53:48 +02:00
jQuery ( this ) . dialog ( \ ' close\ ' );
2010-10-03 23:43:03 +02:00
}
}
});
});
</ script > ' ;
2010-10-11 23:32:53 +02:00
2020-09-07 10:18:17 +02:00
$msg .= " \n " ;
2010-10-11 23:32:53 +02:00
2020-09-07 10:18:17 +02:00
return $msg ;
2010-10-03 23:43:03 +02:00
}
2017-03-23 11:16:30 +01:00
2011-04-25 16:24:43 +02:00
/**
2014-02-04 20:49:07 +01:00
* Convert a html select field into an ajax combobox .
* Use ajax_combobox () only for small combo list ! If not , use instead ajax_autocompleter () .
* TODO : It is used when COMPANY_USE_SEARCH_TO_SELECT and CONTACT_USE_SEARCH_TO_SELECT are set by html . formcompany . class . php . Should use ajax_autocompleter instead like done by html . form . class . php for select_produits .
2011-07-28 20:57:23 +02:00
*
2015-06-29 16:57:32 +02:00
* @ param string $htmlname Name of html select field ( 'myid' or '.myclass' )
2014-09-15 16:18:19 +02:00
* @ param array $events More events option . Example : array ( array ( 'method' => 'getContacts' , 'url' => dol_buildpath ( '/core/ajax/contacts.php' , 1 ), 'htmlname' => 'contactid' , 'params' => array ( 'add-customer-contact' => 'disabled' )))
2014-02-04 20:49:07 +01:00
* @ param int $minLengthToAutocomplete Minimum length of input string to start autocomplete
2015-01-30 19:57:38 +01:00
* @ param int $forcefocus Force focus on field
2016-11-11 15:06:31 +01:00
* @ param string $widthTypeOfAutocomplete 'resolve' or 'off'
2021-05-25 22:51:37 +02:00
* @ param string $idforemptyvalue '-1'
2015-04-15 18:14:26 +02:00
* @ return string Return html string to convert a select field into a combo , or '' if feature has been disabled for some reason .
2019-03-11 01:01:15 +01:00
* @ see selectArrayAjax () of html . form . class
2011-04-25 16:24:43 +02:00
*/
2021-05-25 22:51:37 +02:00
function ajax_combobox ( $htmlname , $events = array (), $minLengthToAutocomplete = 0 , $forcefocus = 0 , $widthTypeOfAutocomplete = 'resolve' , $idforemptyvalue = '-1' )
2011-04-25 16:24:43 +02:00
{
2013-04-03 00:36:31 +02:00
global $conf ;
2017-06-21 11:37:34 +02:00
2019-03-15 01:28:54 +01:00
// select2 can be disabled for smartphones
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> browser -> layout ) && $conf -> browser -> layout == 'phone' && ! empty ( $conf -> global -> MAIN_DISALLOW_SELECT2_WITH_SMARTPHONE )) {
return '' ;
}
2017-11-11 14:20:08 +01:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> MAIN_DISABLE_AJAX_COMBOX )) {
return '' ;
}
if ( empty ( $conf -> use_javascript_ajax )) {
return '' ;
}
if ( empty ( $conf -> global -> MAIN_USE_JQUERY_MULTISELECT ) && ! defined ( 'REQUIRE_JQUERY_MULTISELECT' )) {
return '' ;
}
if ( ! empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER )) {
return '' ;
}
2015-01-30 19:57:38 +01:00
2021-02-23 22:03:23 +01:00
if ( empty ( $minLengthToAutocomplete )) {
$minLengthToAutocomplete = 0 ;
}
2015-01-30 19:57:38 +01:00
2020-09-07 10:18:17 +02:00
$tmpplugin = 'select2' ;
$msg = " \n " . '<!-- JS CODE TO ENABLE ' . $tmpplugin . ' for id = ' . $htmlname . ' -->
2019-01-20 23:36:39 +01:00
< script >
2015-05-31 12:25:33 +02:00
$ ( document ) . ready ( function () {
2020-02-21 17:53:37 +01:00
$ ( \ '' . ( preg_match ( '/^\./' , $htmlname ) ? $htmlname : '#' . $htmlname ) . '\').' . $tmpplugin . ' ({
2015-05-31 12:25:33 +02:00
dir : \ ' ltr\ ' ,
2016-10-12 15:33:33 +02:00
width : \ '' . $widthTypeOfAutocomplete . ' \ ' , /* off or resolve */
2017-10-21 19:05:24 +02:00
minimumInputLength : '.$minLengthToAutocomplete.' ,
language : select2arrayoflanguage ,
2017-11-11 14:20:08 +01:00
containerCssClass : \ ' : all : \ ' , /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag */
2021-01-28 16:31:32 +01:00
selectionCssClass : \ ' : all : \ ' , /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag */
2017-10-21 19:05:24 +02:00
templateResult : function ( data , container ) { /* Format visible output into combo list */
2017-10-26 14:06:23 +02:00
/* Code to add class of origin OPTION propagated to the new select2 <li> tag */
2017-11-11 14:20:08 +01:00
if ( data . element ) { $ ( container ) . addClass ( $ ( data . element ) . attr ( " class " )); }
2021-05-19 13:56:13 +02:00
//console.log($(data.element).attr("data-html"));
2021-05-25 22:51:37 +02:00
if ( data . id == '.((int) $idforemptyvalue).' && $ ( data . element ) . attr ( " data-html " ) == undefined ) {
2021-04-25 15:09:56 +02:00
return \ ' & nbsp ; \ ' ;
}
2017-12-10 15:46:35 +01:00
if ( $ ( data . element ) . attr ( " data-html " ) != undefined ) return htmlEntityDecodeJs ( $ ( data . element ) . attr ( " data-html " )); // If property html set, we decode html entities and use this
2021-01-28 16:31:32 +01:00
return data . text ;
2017-10-21 19:05:24 +02:00
},
templateSelection : function ( selection ) { /* Format visible output of selected value */
2021-05-25 22:51:37 +02:00
if ( selection . id == '.((int) $idforemptyvalue).' ) return \ ' < span class = " placeholder " > \ ' + selection . text + \ ' </ span > \ ' ;
2017-10-21 19:05:24 +02:00
return selection . text ;
},
2017-10-26 20:06:23 +02:00
escapeMarkup : function ( markup ) {
return markup ;
2018-04-13 17:10:07 +02:00
},
2018-04-13 19:30:11 +02:00
dropdownCssClass : \ ' ui - dialog\ '
2015-05-31 12:25:33 +02:00
}) ' ;
2021-02-23 22:03:23 +01:00
if ( $forcefocus ) {
$msg .= '.select2(\'focus\')' ;
}
2020-02-21 17:53:37 +01:00
$msg .= ';' . " \n " ;
2014-12-05 13:26:47 +01:00
2021-02-23 22:03:23 +01:00
if ( is_array ( $events ) && count ( $events )) { // If an array of js events to do were provided.
2020-02-21 17:53:37 +01:00
$msg .= '
2017-02-02 20:47:45 +01:00
jQuery ( " #'. $htmlname .' " ) . change ( function () {
2014-12-05 13:26:47 +01:00
var obj = '.json_encode($events).' ;
2014-12-20 13:06:08 +01:00
$ . each ( obj , function ( key , values ) {
if ( values . method . length ) {
2017-02-02 20:47:45 +01:00
runJsCodeForEvent '.$htmlname.' ( values );
2014-12-20 13:06:08 +01:00
}
2012-03-15 16:52:18 +01:00
});
2014-12-20 13:06:08 +01:00
});
2015-01-30 19:57:38 +01:00
2017-02-02 20:47:45 +01:00
function runJsCodeForEvent '.$htmlname.' ( obj ) {
var id = $ ( " #'. $htmlname .' " ) . val ();
2014-12-20 13:06:08 +01:00
var method = obj . method ;
var url = obj . url ;
var htmlname = obj . htmlname ;
var showempty = obj . showempty ;
2017-11-12 13:40:05 +01:00
console . log ( " Run runJsCodeForEvent-'. $htmlname .' from ajax_combobox id= " + id + " method= " + method + " showempty= " + showempty + " url= " + url + " htmlname= " + htmlname );
$ . getJSON ( url ,
2014-12-20 13:06:08 +01:00
{
action : method ,
id : id ,
htmlname : htmlname ,
showempty : showempty
},
function ( response ) {
$ . each ( obj . params , function ( key , action ) {
if ( key . length ) {
var num = response . num ;
if ( num > 0 ) {
$ ( " # " + key ) . removeAttr ( action );
} else {
$ ( " # " + key ) . attr ( action , action );
}
2012-03-18 14:06:55 +01:00
}
2014-12-20 13:06:08 +01:00
});
$ ( " select# " + htmlname ) . html ( response . value );
if ( response . num ) {
var selecthtml_str = response . value ;
var selecthtml_dom = $ . parseHTML ( selecthtml_str );
2021-02-14 21:32:19 +01:00
if ( typeof ( selecthtml_dom [ 0 ][ 0 ]) !== \ ' undefined\ ' ) {
$ ( " #inputautocomplete " + htmlname ) . val ( selecthtml_dom [ 0 ][ 0 ] . innerHTML );
}
2014-12-20 13:06:08 +01:00
} else {
$ ( " #inputautocomplete " + htmlname ) . val ( " " );
2012-03-18 14:06:55 +01:00
}
2014-12-20 13:06:08 +01:00
$ ( " select# " + htmlname ) . change (); /* Trigger event change */
2014-06-17 11:18:30 +02:00
}
2014-12-20 13:06:08 +01:00
);
} ' ;
}
2015-01-30 19:57:38 +01:00
2020-02-21 17:53:37 +01:00
$msg .= '});' . " \n " ;
2020-09-07 10:18:17 +02:00
$msg .= " </script> \n " ;
2011-05-25 15:27:07 +02:00
2020-09-07 10:18:17 +02:00
return $msg ;
2011-04-25 16:24:43 +02:00
}
2011-05-15 22:21:34 +02:00
/**
* On / off button for constant
2011-07-28 20:57:23 +02:00
*
2020-02-18 09:37:59 +01:00
* @ param string $code Name of constant
2021-02-23 11:03:34 +01:00
* @ param array $input Array of complementary actions to do if success ( " disabled " | " enabled'|'set'|'del') => CSS element to switch, 'alert' => message to show, ... Example: array('disabled'=>array(0=>'cssid'))
* @ param int $entity Entity . Current entity is used if null .
2021-08-05 14:42:28 +02:00
* @ param int $revertonoff 1 = Revert on / off
2020-02-25 12:37:44 +01:00
* @ param int $strict Use only " disabled " with delConstant and " enabled " with setConstant
2020-02-18 09:37:59 +01:00
* @ param int $forcereload Force to reload page if we click / change value ( this is supported only when there is no 'alert' option in input )
2021-09-10 09:21:37 +02:00
* @ param string $marginleftonlyshort 1 = Add a short left margin on picto , 2 = Add a larger left margin on picto , 0 = No left margin .
2021-02-23 11:03:34 +01:00
* @ param int $forcenoajax 1 = Force to use a ahref link instead of ajax code .
2021-08-05 14:42:28 +02:00
* @ param int $setzeroinsteadofdel 1 = Set constantto '0' instead of deleting it
2021-09-10 09:21:37 +02:00
* @ param string $suffix Suffix to use on the name of the switch_on picto . Example : '' , '_red'
2021-09-10 10:18:46 +02:00
* @ param string $mode Add parameter & mode = to the href link ( Used for href link )
2015-02-10 10:52:48 +01:00
* @ return string
2011-05-15 22:21:34 +02:00
*/
2021-09-10 10:18:46 +02:00
function ajax_constantonoff ( $code , $input = array (), $entity = null , $revertonoff = 0 , $strict = 0 , $forcereload = 0 , $marginleftonlyshort = 2 , $forcenoajax = 0 , $setzeroinsteadofdel = 0 , $suffix = '' , $mode = '' )
2011-05-15 22:21:34 +02:00
{
2020-03-25 16:00:42 +01:00
global $conf , $langs , $user ;
2012-01-11 21:12:15 +01:00
2012-02-13 09:44:24 +01:00
$entity = (( isset ( $entity ) && is_numeric ( $entity ) && $entity >= 0 ) ? $entity : $conf -> entity );
2021-02-23 22:03:23 +01:00
if ( ! isset ( $input )) {
$input = array ();
}
2011-05-25 15:27:07 +02:00
2021-02-23 22:03:23 +01:00
if ( empty ( $conf -> use_javascript_ajax ) || $forcenoajax ) {
if ( empty ( $conf -> global -> $code )) {
2022-02-06 22:11:44 +01:00
print '<a href="' . $_SERVER [ 'PHP_SELF' ] . '?action=set_' . $code . '&token=' . newToken () . '&entity=' . $entity . ( $mode ? '&mode=' . $mode : '' ) . ( $forcereload ? '&dol_resetcache=1' : '' ) . '">' . img_picto ( $langs -> trans ( " Disabled " ), 'off' ) . '</a>' ;
2021-02-23 22:03:23 +01:00
} else {
2022-02-06 22:11:44 +01:00
print '<a href="' . $_SERVER [ 'PHP_SELF' ] . '?action=del_' . $code . '&token=' . newToken () . '&entity=' . $entity . ( $mode ? '&mode=' . $mode : '' ) . ( $forcereload ? '&dol_resetcache=1' : '' ) . '">' . img_picto ( $langs -> trans ( " Enabled " ), 'on' ) . '</a>' ;
2021-02-23 22:03:23 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2020-02-21 17:53:37 +01:00
$out = " \n <!-- Ajax code to switch constant " . $code . " --> " . '
2019-01-20 23:36:39 +01:00
< script >
2014-06-29 23:35:00 +02:00
$ ( document ) . ready ( function () {
var input = '.json_encode($input).' ;
var url = \ '' . DOL_URL_ROOT . ' / core / ajax / constantonoff . php\ ' ;
2022-02-06 22:11:44 +01:00
var code = \ '' . dol_escape_js ( $code ) . ' \ ' ;
var entity = \ '' . dol_escape_js ( $entity ) . ' \ ' ;
var strict = \ '' . dol_escape_js ( $strict ) . ' \ ' ;
var userid = \ '' . dol_escape_js ( $user -> id ) . ' \ ' ;
2020-09-19 01:53:22 +02:00
var yesButton = \ '' . dol_escape_js ( $langs -> transnoentities ( " Yes " )) . ' \ ' ;
var noButton = \ '' . dol_escape_js ( $langs -> transnoentities ( " No " )) . ' \ ' ;
2020-09-19 12:50:47 +02:00
var token = \ '' . currentToken () . ' \ ' ;
2011-07-28 20:57:23 +02:00
2014-06-29 23:35:00 +02:00
// Set constant
$ ( " #set_ " + code ) . click ( function () {
if ( input . alert && input . alert . set ) {
if ( input . alert . set . yesButton ) yesButton = input . alert . set . yesButton ;
if ( input . alert . set . noButton ) noButton = input . alert . set . noButton ;
2020-09-19 01:53:22 +02:00
confirmConstantAction ( " set " , url , code , input , input . alert . set , entity , yesButton , noButton , strict , userid , token );
2014-06-29 23:35:00 +02:00
} else {
2022-02-06 22:11:44 +01:00
setConstant ( url , code , input , entity , 0 , '.((int) $forcereload).' , userid , token );
2014-06-29 23:35:00 +02:00
}
});
2011-07-28 20:57:23 +02:00
2014-06-29 23:35:00 +02:00
// Del constant
$ ( " #del_ " + code ) . click ( function () {
if ( input . alert && input . alert . del ) {
if ( input . alert . del . yesButton ) yesButton = input . alert . del . yesButton ;
if ( input . alert . del . noButton ) noButton = input . alert . del . noButton ;
2020-09-19 01:53:22 +02:00
confirmConstantAction ( " del " , url , code , input , input . alert . del , entity , yesButton , noButton , strict , userid , token );
2021-08-05 14:42:28 +02:00
} else { ' ;
if ( empty ( $setzeroinsteadofdel )) {
2022-02-06 22:11:44 +01:00
$out .= ' delConstant(url, code, input, entity, 0, ' . (( int ) $forcereload ) . ', userid, token);' ;
2021-08-05 14:42:28 +02:00
} else {
2022-02-06 22:11:44 +01:00
$out .= ' setConstant(url, code, input, entity, 0, ' . (( int ) $forcereload ) . ', userid, token, 0);' ;
2021-08-05 14:42:28 +02:00
}
$out .= ' }
2014-06-29 23:35:00 +02:00
});
2011-05-15 22:21:34 +02:00
});
2014-06-29 23:35:00 +02:00
</ script > ' . " \n " ;
2011-05-25 15:27:07 +02:00
2020-02-21 17:53:37 +01:00
$out .= '<div id="confirm_' . $code . '" title="" style="display: none;"></div>' ;
2020-04-25 17:18:57 +02:00
$out .= '<span id="set_' . $code . '" class="valignmiddle linkobject ' . ( ! empty ( $conf -> global -> $code ) ? 'hideobject' : '' ) . '">' . ( $revertonoff ? img_picto ( $langs -> trans ( " Enabled " ), 'switch_on' , '' , false , 0 , 0 , '' , '' , $marginleftonlyshort ) : img_picto ( $langs -> trans ( " Disabled " ), 'switch_off' , '' , false , 0 , 0 , '' , '' , $marginleftonlyshort )) . '</span>' ;
2021-09-10 09:21:37 +02:00
$out .= '<span id="del_' . $code . '" class="valignmiddle linkobject ' . ( ! empty ( $conf -> global -> $code ) ? '' : 'hideobject' ) . '">' . ( $revertonoff ? img_picto ( $langs -> trans ( " Disabled " ), 'switch_off' . $suffix , '' , false , 0 , 0 , '' , '' , $marginleftonlyshort ) : img_picto ( $langs -> trans ( " Enabled " ), 'switch_on' . $suffix , '' , false , 0 , 0 , '' , '' , $marginleftonlyshort )) . '</span>' ;
2020-02-21 17:53:37 +01:00
$out .= " \n " ;
2014-06-29 23:35:00 +02:00
}
2011-05-25 15:27:07 +02:00
2011-05-15 22:21:34 +02:00
return $out ;
}
2014-10-12 14:20:49 +02:00
/**
2019-08-02 17:12:03 +02:00
* On / off button to change status of an object
* This is called when MAIN_DIRECT_STATUS_UPDATE is set and it use tha ajax service objectonoff . php
2014-10-12 14:20:49 +02:00
*
2019-02-23 18:15:56 +01:00
* @ param Object $object Object to set
2014-10-18 15:48:59 +02:00
* @ param string $code Name of constant : status or status_buy for product by example
2019-08-02 17:12:03 +02:00
* @ param string $field Name of database field : 'tosell' or 'tobuy' for product by example
2014-10-18 18:48:13 +02:00
* @ param string $text_on Text if on
* @ param string $text_off Text if off
2014-10-12 14:20:49 +02:00
* @ param array $input Array of type -> list of CSS element to switch . Example : array ( 'disabled' => array ( 0 => 'cssid' ))
2021-09-07 17:26:31 +02:00
* @ param string $morecss More CSS
2018-10-19 22:52:18 +02:00
* @ return string html for button on / off
2014-10-12 14:20:49 +02:00
*/
2021-09-07 17:26:31 +02:00
function ajax_object_onoff ( $object , $code , $field , $text_on , $text_off , $input = array (), $morecss = '' )
2014-10-12 14:20:49 +02:00
{
2020-09-07 10:18:17 +02:00
global $langs ;
2014-10-12 14:20:49 +02:00
2020-09-07 10:18:17 +02:00
$out = ' < script >
2014-10-12 14:20:49 +02:00
$ ( function () {
var input = '.json_encode($input).' ;
// Set constant
2014-10-18 16:32:32 +02:00
$ ( " #set_'. $code .'_'. $object->id .' " ) . click ( function () {
2014-10-18 17:11:02 +02:00
$ . get ( " '.DOL_URL_ROOT.'/core/ajax/objectonoff.php " , {
2014-10-18 22:46:13 +02:00
action : \ ' set\ ' ,
field : \ '' . $field . ' \ ' ,
2014-10-12 15:55:18 +02:00
value : \ ' 1 \ ' ,
2014-10-18 22:46:13 +02:00
element : \ '' . $object -> element . ' \ ' ,
2020-09-19 01:53:22 +02:00
id : \ '' . $object -> id . ' \ ' ,
token : \ '' . newToken () . ' \ '
2014-10-12 14:20:49 +02:00
},
function () {
2014-10-18 16:32:32 +02:00
$ ( " #set_'. $code .'_'. $object->id .' " ) . hide ();
$ ( " #del_'. $code .'_'. $object->id .' " ) . show ();
2014-10-12 14:20:49 +02:00
// Enable another element
if ( input . disabled && input . disabled . length > 0 ) {
$ . each ( input . disabled , function ( key , value ) {
$ ( " # " + value ) . removeAttr ( " disabled " );
if ( $ ( " # " + value ) . hasClass ( " butActionRefused " ) == true ) {
$ ( " # " + value ) . removeClass ( " butActionRefused " );
$ ( " # " + value ) . addClass ( " butAction " );
}
});
// Show another element
} else if ( input . showhide && input . showhide . length > 0 ) {
$ . each ( input . showhide , function ( key , value ) {
$ ( " # " + value ) . show ();
});
}
});
});
// Del constant
2014-10-18 16:32:32 +02:00
$ ( " #del_'. $code .'_'. $object->id .' " ) . click ( function () {
2014-10-18 17:11:02 +02:00
$ . get ( " '.DOL_URL_ROOT.'/core/ajax/objectonoff.php " , {
2014-10-18 22:46:13 +02:00
action : \ ' set\ ' ,
field : \ '' . $field . ' \ ' ,
2014-10-12 15:55:18 +02:00
value : \ ' 0 \ ' ,
2014-10-18 22:46:13 +02:00
element : \ '' . $object -> element . ' \ ' ,
2020-09-19 01:53:22 +02:00
id : \ '' . $object -> id . ' \ ' ,
token : \ '' . newToken () . ' \ '
2014-10-12 14:20:49 +02:00
},
function () {
2014-10-18 16:32:32 +02:00
$ ( " #del_'. $code .'_'. $object->id .' " ) . hide ();
$ ( " #set_'. $code .'_'. $object->id .' " ) . show ();
2014-10-12 14:20:49 +02:00
// Disable another element
if ( input . disabled && input . disabled . length > 0 ) {
$ . each ( input . disabled , function ( key , value ) {
2015-05-12 14:47:33 +02:00
$ ( " # " + value ) . prop ( " disabled " , true );
2014-10-12 14:20:49 +02:00
if ( $ ( " # " + value ) . hasClass ( " butAction " ) == true ) {
$ ( " # " + value ) . removeClass ( " butAction " );
$ ( " # " + value ) . addClass ( " butActionRefused " );
}
});
// Hide another element
} else if ( input . showhide && input . showhide . length > 0 ) {
$ . each ( input . showhide , function ( key , value ) {
$ ( " # " + value ) . hide ();
});
}
});
});
});
</ script > ' ;
2021-09-07 17:26:31 +02:00
$out .= '<span id="set_' . $code . '_' . $object -> id . '" class="linkobject ' . ( $object -> $code == 1 ? 'hideobject' : '' ) . ( $morecss ? ' ' . $morecss : '' ) . '">' . img_picto ( $langs -> trans ( $text_off ), 'switch_off' ) . '</span>' ;
$out .= '<span id="del_' . $code . '_' . $object -> id . '" class="linkobject ' . ( $object -> $code == 1 ? '' : 'hideobject' ) . ( $morecss ? ' ' . $morecss : '' ) . '">' . img_picto ( $langs -> trans ( $text_on ), 'switch_on' ) . '</span>' ;
2014-10-18 18:48:13 +02:00
2020-09-07 10:18:17 +02:00
return $out ;
2014-10-12 14:20:49 +02:00
}