Add popin dialog

This commit is contained in:
John 2018-02-22 15:19:20 +01:00
parent f313fb925b
commit a7a6630fad
4 changed files with 139 additions and 7 deletions

View File

@ -47,8 +47,10 @@ foreach($linkedObjectBlock as $key => $objectlink)
$trclass=($var?'pair':'impair');
if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) $trclass.=' liste_sub_total';
?>
<tr class="<?php echo $trclass; ?>" data-element="<?php echo $objectlink->element; ?>" data-id="<?php echo $objectlink->id; ?>" >
<td class="linkedcol-element" ><?php echo $langs->trans("CustomerOrder"); ?></td>
<tr class="<?php echo $trclass; ?>" >
<td class="linkedcol-element" ><?php echo $langs->trans("CustomerOrder"); ?>
<?php if(!empty($showImportButton)) print '<a class="objectlinked_importbtn" href="'.$objectlink->getNomUrl(0,'',0,1).'&amp;action=selectlines" data-element="'.$objectlink->element.'" data-id="'.$objectlink->id.'" > <i class="fa fa-indent"></i> </a'; ?>
</td>
<td class="linkedcol-name" ><?php echo $objectlink->getNomUrl(1); ?></td>
<td class="linkedcol-ref" align="center"><?php echo $objectlink->ref_client; ?></td>
<td class="linkedcol-date" align="center"><?php echo dol_print_date($objectlink->date,'day'); ?></td>

View File

@ -2087,6 +2087,13 @@ if (empty($reshook))
header('Location: ' . $_SERVER["PHP_SELF"] . '?facid=' . $id); // Pour reaffichage de la fiche en cours d'edition
exit();
}
// add lines from objectlinked
elseif ($action == 'import_lines_from_object' && $user->rights->facture->creer)
{
}
// Actions when printing a doc from card
include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
@ -4516,8 +4523,16 @@ else if ($id > 0 || ! empty($ref))
// Show links to link elements
$linktoelem = $form->showLinkToObjectBlock($object, null, array('invoice'));
$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
$compatibleImportElementsList = false;
if($user->rights->facture->creer
&& $object->statut == Facture::STATUS_DRAFT
&& ($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA || $object->type == Facture::TYPE_SITUATION) )
{
$compatibleImportElementsList = array('commande'); // import from linked elements
}
$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem,$compatibleImportElementsList);
// Show online payment link
$useonlinepayment = (! empty($conf->paypal->enabled) || ! empty($conf->stripe->enabled) || ! empty($conf->paybox->enabled));

View File

@ -5833,9 +5833,10 @@ class Form
*
* @param CommonObject $object Object we want to show links to
* @param string $morehtmlright More html to show on right of title
* @param array $compatibleImportElementsList Array of compatibles elements object for "import from" action
* @return int <0 if KO, >=0 if OK
*/
function showLinkedObjectBlock($object, $morehtmlright='')
function showLinkedObjectBlock($object, $morehtmlright='',$compatibleImportElementsList=false)
{
global $conf,$langs,$hookmanager;
global $bc;
@ -5844,7 +5845,9 @@ class Form
// Bypass the default method
$hookmanager->initHooks(array('commonobject'));
$parameters=array();
$parameters=array(
'compatibleImportElementsList' =>& $compatibleImportElementsList,
);
$reshook=$hookmanager->executeHooks('showLinkedObjectBlock',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook))
@ -5873,7 +5876,13 @@ class Form
foreach($object->linkedObjects as $objecttype => $objects)
{
$tplpath = $element = $subelement = $objecttype;
// to display inport button on tpl
$showImportButton=false;
if(!empty($compatibleImportElementsList) && in_array($element,$compatibleImportElementsList)){
$showImportButton=true;
}
if ($objecttype != 'supplier_proposal' && preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs))
{
$element = $regs[1];
@ -5949,6 +5958,13 @@ class Form
}
print '</table>';
if(!empty($compatibleImportElementsList))
{
$res=@include dol_buildpath('core/tpl/ajax/objectlinked_lineimport.tpl.php');
}
print '</div>';
return $nbofdifferenttypes;

View File

@ -0,0 +1,99 @@
<?php
/* Copyright (C) 2011-2013 Regis Houssin <regis.houssin@capnetworks.com>
*
* 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/>.
*/
// Protection to avoid direct call of template
if (empty($conf) || ! is_object($conf))
{
print "Error, template page can't be called as URL";
exit;
}
?>
<!-- START TEMPLATE IMPORT OBJECT LINKED LINES -->
<script type="text/javascript">
$(document).ready(function(){
$('.objectlinked_importbtn').click(function (e) {
e.preventDefault();
var page = $(this).attr("href");
var fromelement = $(this).attr("data-element");
var fromelementid = $(this).attr("data-id");
if( page != undefined && fromelement != undefined && fromelementid != undefined)
{
var windowWidth = $(window).width()*0.8; //retrieve current window width
var windowHeight = $(window).height()*0.8; //retrieve current window height
var htmlLines;
$.get(page, function (data) {
htmlLines = $(data).find('#tablelines') ;
});
var $dialog = $('<form id="ajaxloaded_tablelinesform" action="<?php print $object->getNomUrl(0,'',0,1); ?>" method="post" ></form>')
.load( page + " #tablelines", function() {
$("#ajaxloaded_tablelinesform #tablelines").prop("id", "ajaxloaded_tablelines"); // change id attribute
$("#ajaxloaded_tablelines .linecheckbox").prop("checked", true); // checked by default
// reload checkbox toggle function
$("#ajaxloaded_tablelines .linecheckboxtoggle").click(function(){
var checkBoxes = $(".ajaxloadedtablelines .linecheckbox");
checkBoxes.prop("checked", this.checked);
});
var inputs = '<div class="tabsAction" ><button class="butAction" type="submit" name="import" ><?php echo $langs->trans('Import'); ?></button></div>'
$('#ajaxloaded_tablelinesform').append( inputs );
$('#ajaxloaded_tablelinesform').append('<input type="hidden" name="action" value="import_lines_from_object" />');
$('#ajaxloaded_tablelinesform').append('<input type="hidden" name="fromelement" value="' + fromelement + '" />');
$('#ajaxloaded_tablelinesform').append('<input type="hidden" name="fromelementid" value="' + fromelementid + '" />');
})
.html(htmlLines)
.dialog({
autoOpen: false,
modal: true,
height: windowHeight,
width: windowWidth,
title: "<?php echo $langs->trans('LinesToImport'); ?>"
});
$dialog.dialog('open');
}
else
{
$.jnotify("<?php echo $langs->trans('ErrorNoUrl'); ?>", "error", true);
}
});
});
</script>
<style type="text/css">
.objectlinked_importbtn{
cursor:pointer;
}
</style>
cursor: pointer;
<!-- END TEMPLATE IMPORT OBJECT LINKED LINES -->