dolibarr/htdocs/core/tpl/objectlinked_lineimport.tpl.php

112 lines
3.6 KiB
PHP
Raw Permalink Normal View History

2018-02-22 14:19:20 +00:00
<?php
/* Copyright (C) 2011-2013 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
2018-02-22 14:19:20 +00: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
* 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
2019-09-23 19:55:30 +00:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-02-22 14:19:20 +00:00
*/
/**
* @var Conf $conf
* @var CommonObject $object
* @var Translate $langs
*/
2018-02-22 14:19:20 +00:00
// Protection to avoid direct call of template
2021-02-23 21:03:23 +00:00
if (empty($conf) || !is_object($conf)) {
2018-02-22 14:19:20 +00:00
print "Error, template page can't be called as URL";
exit(1);
2018-02-22 14:19:20 +00:00
}
$objectUrl = $object->getNomUrl(0, '', '0', 1);
2021-02-23 21:03:23 +00:00
if ($object->element == 'propal') {
$objectUrl = dolBuildUrl(DOL_URL_ROOT.'/comm/propal/card.php', ['id' => $object->id]);
}
2018-02-22 14:19:20 +00:00
?>
<!-- START TEMPLATE IMPORT OBJECT LINKED LINES -->
2020-08-16 20:03:11 +00:00
<script>
2018-02-22 14:19:20 +00:00
2025-11-18 17:01:07 +00:00
$(function() {
$(document).on('click', '.objectlinked_importbtn', function(e) {
2021-02-23 21:03:23 +00:00
e.preventDefault();
var page = $(this).attr("href");
2018-02-22 14:19:20 +00:00
2021-02-23 21:03:23 +00:00
var fromelement = $(this).attr("data-element");
var fromelementid = $(this).attr("data-id");
2019-09-23 19:55:30 +00:00
2018-02-22 14:19:20 +00:00
if( page != undefined && fromelement != undefined && fromelementid != undefined)
{
2021-02-23 21:03:23 +00:00
var windowWidth = $(window).width()*0.8; //retrieve current window width
var windowHeight = $(window).height()*0.8; //retrieve current window height
2018-02-22 14:19:20 +00:00
var htmlLines;
2018-02-22 16:21:12 +00:00
var formId = "ajaxloaded_tablelinesform_" + fromelement + "_" + fromelementid;
2021-02-23 21:03:23 +00:00
$.get(page, function (data) {
htmlLines = $(data).find('#tablelines') ;
});
var $dialog = $('<form id="' + formId + '" action="<?php print $objectUrl; ?>" method="post" ></form>')
.load( page + " #tablelines", function() {
$("#" + formId + " #tablelines").prop("id", "ajaxloaded_tablelines"); // change id attribute
$("#" + formId + " .linecheckbox,#" + formId + " .linecheckboxtoggle").prop("checked", true); // checked by default
// reload checkbox toggle function
$("#" + formId + " .linecheckboxtoggle").click(function(){
var checkBoxes = $("#" + formId + " .linecheckbox");
checkBoxes.prop("checked", this.checked);
});
})
.html(htmlLines)
.dialog({
autoOpen: false,
modal: true,
height: windowHeight,
width: windowWidth,
title: "<?php echo $langs->transnoentities('LinesToImport'); ?>",
buttons: {
"<?php echo $langs->trans('Import'); ?>": function() {
$( this ).dialog( "close" );
$("#" + formId).append('<input type="hidden" name="action" value="import_lines_from_object" />');
$("#" + formId).append('<input type="hidden" name="fromelement" value="' + fromelement + '" />');
2025-11-18 17:01:07 +00:00
$("#" + formId).append('<input type="hidden" name="token" value="<?php print dol_escape_htmltag(newToken()); ?>" />');
2021-02-23 21:03:23 +00:00
$("#" + formId).append('<input type="hidden" name="fromelementid" value="' + fromelementid + '" />');
2025-11-18 17:01:07 +00:00
$("#" + formId).trigger('submit');
2021-02-23 21:03:23 +00:00
},
"<?php echo $langs->trans("Cancel"); ?>": function() {
$( this ).dialog( "close" );
}
}
});
$dialog.dialog('open');
2018-02-22 14:19:20 +00:00
}
else
{
$.jnotify("<?php echo $langs->trans('ErrorNoUrl'); ?>", "error", true);
}
2021-02-23 21:03:23 +00:00
});
2018-02-22 14:19:20 +00:00
});
</script>
<style type="text/css">
.objectlinked_importbtn{
2021-02-23 21:03:23 +00:00
cursor:pointer;
2018-02-22 14:19:20 +00:00
}
</style>
2019-09-23 19:55:30 +00:00
<!-- END TEMPLATE IMPORT OBJECT LINKED LINES -->