2010-09-18 09:52:17 +02:00
< ? php
2018-10-27 14:43:12 +02:00
/* Copyright ( C ) 2010 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
2016-11-27 20:55:59 +01:00
* Copyright ( C ) 2010 - 2016 Laurent Destailleur < eldy @ users . sourceforge . net >
2010-09-18 09:52:17 +02: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
2010-09-18 09:52:17 +02: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 />.
2010-09-18 09:52:17 +02:00
*
2012-09-15 13:53:19 +02:00
* Javascript code to activate drag and drop on lines
2018-11-15 19:58:06 +01:00
* You can use this if you want to be able to drag and drop rows of a table .
* You must add id = " tablelines " on table level tag
* and $object and $object -> id is defined
* and $object -> fk_element or $fk_element is defined
* and have ( $nboflines or count ( $object -> lines ) or count ( $taskarray ) > 0 )
* and have $table_element_line = 'tablename' or $object -> table_element_line with line to move
*
2010-09-18 09:52:17 +02:00
*/
2017-12-21 13:32:16 +01:00
// Protection to avoid direct call of template
2020-04-10 10:59:32 +02:00
if ( empty ( $object ) || ! is_object ( $object ))
2017-12-21 13:32:16 +01:00
{
print " Error, template page can't be called as URL " ;
exit ;
}
2010-09-18 09:52:17 +02:00
?>
2010-09-18 17:34:06 +02:00
2018-04-17 09:44:57 +02:00
<!-- BEGIN PHP TEMPLATE AJAXROW . TPL . PHP - Script to enable drag and drop on lines of a table -->
2012-09-15 13:53:19 +02:00
< ? php
2020-04-10 10:59:32 +02:00
$id = $object -> id ;
$fk_element = empty ( $object -> fk_element ) ? $fk_element : $object -> fk_element ;
$table_element_line = ( empty ( $table_element_line ) ? $object -> table_element_line : $table_element_line );
$nboflines = ( isset ( $object -> lines ) ? count ( $object -> lines ) : ( isset ( $tasksarray ) ? count ( $tasksarray ) : ( empty ( $nboflines ) ? 0 : $nboflines )));
$forcereloadpage = empty ( $conf -> global -> MAIN_FORCE_RELOAD_PAGE ) ? 0 : 1 ;
$tagidfortablednd = ( empty ( $tagidfortablednd ) ? 'tablelines' : $tagidfortablednd );
$filepath = ( empty ( $filepath ) ? '' : $filepath );
2012-09-15 15:33:00 +02:00
2019-01-27 11:55:16 +01:00
if ( GETPOST ( 'action' , 'aZ09' ) != 'editline' && $nboflines > 1 ) { ?>
2019-01-20 23:36:39 +01:00
< script >
2012-01-23 22:23:00 +01:00
$ ( document ) . ready ( function (){
2015-03-22 21:18:25 +01:00
$ ( " .imgupforline " ) . hide ();
$ ( " .imgdownforline " ) . hide ();
2012-01-23 22:23:00 +01:00
$ ( " .lineupdown " ) . removeAttr ( 'href' );
$ ( " .tdlineupdown " ) . css ( " background-image " , 'url(<?php echo DOL_URL_ROOT.' / theme / '.$conf->theme.' / img / grip . png '; ?>)' );
$ ( " .tdlineupdown " ) . css ( " background-repeat " , " no-repeat " );
$ ( " .tdlineupdown " ) . css ( " background-position " , " center center " );
2010-10-02 22:47:55 +02:00
2017-03-25 01:29:19 +01:00
console . log ( " Prepare tableDnd for #<?php echo $tagidfortablednd ; ?> " );
2013-10-21 13:43:31 +02:00
$ ( " #<?php echo $tagidfortablednd ; ?> " ) . tableDnD ({
2010-09-18 09:52:17 +02:00
onDrop : function ( table , row ) {
2012-09-15 13:53:19 +02:00
var reloadpage = " <?php echo $forcereloadpage ; ?> " ;
2017-03-24 23:52:06 +01:00
console . log ( " tableDND onDrop " );
2017-11-07 16:25:57 +01:00
console . log ( decodeURI ( $ ( " #<?php echo $tagidfortablednd ; ?> " ) . tableDnDSerialize ()));
2018-05-07 16:30:22 +02:00
$ ( '#<?php echo $tagidfortablednd; ?> tr[data-element=extrafield]' ) . attr ( 'id' , '' ); // Set extrafields id to empty value in order to ignore them in tableDnDSerialize function
2017-11-07 16:25:57 +01:00
var roworder = cleanSerialize ( decodeURI ( $ ( " #<?php echo $tagidfortablednd ; ?> " ) . tableDnDSerialize ()));
2012-09-15 13:53:19 +02:00
var table_element_line = " <?php echo $table_element_line ; ?> " ;
var fk_element = " <?php echo $fk_element ; ?> " ;
var element_id = " <?php echo $id ; ?> " ;
2016-12-20 22:14:27 +01:00
var filepath = " <?php echo urlencode( $filepath ); ?> " ;
2019-07-21 16:15:13 +02:00
var token = " <?php echo $_SESSION["token"] ; ?> " ; // We use old 'token' and not 'newtoken' for Ajax call because the ajax page has the NOTOKENRENEWAL constant set.
2012-02-13 12:40:43 +01:00
$ . post ( " <?php echo DOL_URL_ROOT; ?>/core/ajax/row.php " ,
2011-04-12 10:15:45 +02:00
{
roworder : roworder ,
table_element_line : table_element_line ,
fk_element : fk_element ,
2016-12-20 22:14:27 +01:00
element_id : element_id ,
2019-07-21 16:00:32 +02:00
filepath : filepath ,
token : token
2011-04-12 10:15:45 +02:00
},
function () {
2017-03-24 23:52:06 +01:00
console . log ( " tableDND end of ajax call " );
2011-04-12 10:15:45 +02:00
if ( reloadpage == 1 ) {
2019-04-09 13:23:30 +02:00
//console.log('<?php echo $urltorefreshaftermove.' - '.$_SERVER['PHP_SELF'].' - '.dol_escape_js($_SERVER['QUERY_STRING']); ?>');
location . href = '<?php echo dol_escape_js(empty($urltorefreshaftermove) ? ($_SERVER[' PHP_SELF '].' ? '.dol_escape_js($_SERVER[' QUERY_STRING '])) : $urltorefreshaftermove); ?>' ;
2011-04-12 10:15:45 +02:00
} else {
2013-10-21 13:43:31 +02:00
$ ( " #<?php echo $tagidfortablednd ; ?> .drag " ) . each (
2011-04-12 10:15:45 +02:00
function ( intIndex ) {
2017-03-24 23:52:06 +01:00
// $(this).removeClass("pair impair");
//if (intIndex % 2 == 0) $(this).addClass('impair');
//if (intIndex % 2 == 1) $(this).addClass('pair');
2011-04-12 10:15:45 +02:00
});
}
2011-04-12 09:48:07 +02:00
});
},
2010-10-02 22:47:55 +02:00
onDragClass : " dragClass " ,
2017-11-07 16:25:57 +01:00
dragHandle : " td.tdlineupdown "
2010-09-18 09:52:17 +02:00
});
2012-01-23 22:23:00 +01:00
$ ( " .tdlineupdown " ) . hover ( function () { $ ( this ) . addClass ( 'showDragHandle' ); },
function () { $ ( this ) . removeClass ( 'showDragHandle' ); }
2010-10-02 22:47:55 +02:00
);
2010-09-18 09:52:17 +02:00
});
</ script >
2010-10-01 18:19:53 +02:00
< ? php } else { ?>
< script >
2012-01-23 22:23:00 +01:00
$ ( document ) . ready ( function (){
2015-03-22 21:18:25 +01:00
$ ( " .imgupforline " ) . hide ();
$ ( " .imgdownforline " ) . hide ();
2012-01-23 22:23:00 +01:00
$ ( " .lineupdown " ) . removeAttr ( 'href' );
2010-10-01 18:19:53 +02:00
});
</ script >
< ? php } ?>
2019-09-23 21:55:30 +02:00
<!-- END PHP TEMPLATE AJAXROW . TPL . PHP -->