objectlinked_lineimport.tpl.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /* Copyright (C) 2011-2013 Regis Houssin <regis.houssin@inodbox.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. // Protection to avoid direct call of template
  18. if (empty($conf) || !is_object($conf)) {
  19. print "Error, template page can't be called as URL";
  20. exit;
  21. }
  22. $objectUrl = $object->getNomUrl(0, '', 0, 1);
  23. if ($object->element == 'propal') {
  24. $objectUrl = DOL_URL_ROOT.'/comm/propal/card.php?id='.$object->id;
  25. }
  26. ?>
  27. <!-- START TEMPLATE IMPORT OBJECT LINKED LINES -->
  28. <script>
  29. $(document).ready(function(){
  30. $('.objectlinked_importbtn').click(function (e) {
  31. e.preventDefault();
  32. var page = $(this).attr("href");
  33. var fromelement = $(this).attr("data-element");
  34. var fromelementid = $(this).attr("data-id");
  35. if( page != undefined && fromelement != undefined && fromelementid != undefined)
  36. {
  37. var windowWidth = $(window).width()*0.8; //retrieve current window width
  38. var windowHeight = $(window).height()*0.8; //retrieve current window height
  39. var htmlLines;
  40. var formId = "ajaxloaded_tablelinesform_" + fromelement + "_" + fromelementid;
  41. $.get(page, function (data) {
  42. htmlLines = $(data).find('#tablelines') ;
  43. });
  44. var $dialog = $('<form id="' + formId + '" action="<?php print $objectUrl; ?>" method="post" ></form>')
  45. .load( page + " #tablelines", function() {
  46. $("#" + formId + " #tablelines").prop("id", "ajaxloaded_tablelines"); // change id attribute
  47. $("#" + formId + " .linecheckbox,#" + formId + " .linecheckboxtoggle").prop("checked", true); // checked by default
  48. // reload checkbox toggle function
  49. $("#" + formId + " .linecheckboxtoggle").click(function(){
  50. var checkBoxes = $("#" + formId + " .linecheckbox");
  51. checkBoxes.prop("checked", this.checked);
  52. });
  53. })
  54. .html(htmlLines)
  55. .dialog({
  56. autoOpen: false,
  57. modal: true,
  58. height: windowHeight,
  59. width: windowWidth,
  60. title: "<?php echo $langs->transnoentities('LinesToImport'); ?>",
  61. buttons: {
  62. "<?php echo $langs->trans('Import'); ?>": function() {
  63. $( this ).dialog( "close" );
  64. $("#" + formId).append('<input type="hidden" name="action" value="import_lines_from_object" />');
  65. $("#" + formId).append('<input type="hidden" name="fromelement" value="' + fromelement + '" />');
  66. $("#" + formId).append('<input type="hidden" name="fromelementid" value="' + fromelementid + '" />');
  67. $("#" + formId).submit();
  68. },
  69. "<?php echo $langs->trans("Cancel"); ?>": function() {
  70. $( this ).dialog( "close" );
  71. }
  72. }
  73. });
  74. $dialog.dialog('open');
  75. }
  76. else
  77. {
  78. $.jnotify("<?php echo $langs->trans('ErrorNoUrl'); ?>", "error", true);
  79. }
  80. });
  81. });
  82. </script>
  83. <style type="text/css">
  84. .objectlinked_importbtn{
  85. cursor:pointer;
  86. }
  87. </style>
  88. <!-- END TEMPLATE IMPORT OBJECT LINKED LINES -->