You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

248 lines
7.7 KiB

  1. import {EtrackerUtils} from "./EtrackerUtils";
  2. export class UiUtils {
  3. static initUI() {
  4. UiUtils.initPrintDialog();
  5. UiUtils.initfileupload();
  6. UiUtils.initTrackEventElementAnalytics();
  7. UiUtils.disbaleInitialForNewsletterSubPage();
  8. UiUtils.initEtrackerOnCookiebotEvent();
  9. }
  10. static initEtrackerOnCookiebotEvent() {
  11. if (typeof ihk !== "undefined" && ihk.settings && ihk.settings.etrackerCookieless === false) {
  12. window.addEventListener('CookiebotOnConsentReady', EtrackerUtils.initEtrackerCookies, false);
  13. }
  14. }
  15. static initTrackEventElementAnalytics() {
  16. if (!window.isPbe) {
  17. $(".trackEventElement").each(
  18. function () {
  19. const category = $(this).data(
  20. 'analytics-category');
  21. const object = $(this).data('analytics-object');
  22. const action = $(this).data('analytics-action');
  23. const tags = $(this).data('analytics-tags');
  24. window.setTimeout(EtrackerUtils.fireETrackerEvent, 250,
  25. category, object, action, tags);
  26. });
  27. }
  28. }
  29. static disbaleInitialForNewsletterSubPage() {
  30. const inxForm = $(".inxform");
  31. const inxHolderText = $(inxForm).closest(".detail-text");
  32. if (inxHolderText.length > 0) {
  33. inxHolderText.find(".text").first().addClass("no-initial");
  34. }
  35. }
  36. static initfileupload() {
  37. //todo: make great again
  38. if (typeof jQuery.fn.fileupload == 'function') {
  39. var filelist = [], uploadUrl = $('#fileupload')
  40. .data("url");
  41. $('#fileupload')
  42. .fileupload(
  43. {
  44. url: uploadUrl,
  45. previewMaxWidth: "90",
  46. previewMaxHeight: "90",
  47. previewCrop: true,
  48. singleFileUploads: false,
  49. filesContainer: $('#uploaded-files'),
  50. uploadTemplateId: null,
  51. downloadTemplateId: null,
  52. uploadTemplate: function (o) {
  53. var rows = $();
  54. $
  55. .each(
  56. o.files,
  57. function (
  58. index,
  59. file) {
  60. var row = $('<div class="mwf-upload-row thumbnail template-upload">'
  61. + ' <div class="mwf-upload-fileinfo">'
  62. + ' <div class="mwf-upload-preview"><div class="preview"><span></span></div></div>'
  63. + ' <div class="mwf-upload-metadata">'
  64. + ' <ul>'
  65. + ' <li>Name: <span class="name"></span></li>'
  66. + ' <li>Größe: <span class="size"></span></li>'
  67. + (file.error ? '<li>Fehler: <span class="error"></span></li>'
  68. : '')
  69. + ' </ul>'
  70. + ' </div>'
  71. + ' </div>'
  72. + ' <div class="mwf-upload-actions">'
  73. + ' <div class="cancel"><button>Löschen</button></div>'
  74. + ' </div>'
  75. + '</div>');
  76. row
  77. .find(
  78. '.name')
  79. .text(
  80. file.name);
  81. row
  82. .find(
  83. '.size')
  84. .text(
  85. o
  86. .formatFileSize(file.size));
  87. row
  88. .find(
  89. 'button')
  90. .click(
  91. function () {
  92. for (var i in filelist) {
  93. var fileEntry = filelist[i];
  94. if (fileEntry.name == file.name) {
  95. filelist
  96. .splice(
  97. i,
  98. 1);
  99. $(
  100. '.mwf-upload-error')
  101. .text(
  102. '');
  103. break;
  104. }
  105. }
  106. });
  107. rows = rows
  108. .add(row);
  109. });
  110. return rows;
  111. },
  112. dataType: 'json',
  113. progressall: function (e, data) {
  114. var progress = parseInt(
  115. data.loaded
  116. / data.total
  117. * 100, 10);
  118. $('#progress .bar').css(
  119. 'width',
  120. progress + '%');
  121. },
  122. dropZone: $('#dropzone')
  123. })
  124. .on(
  125. "fileuploadadd",
  126. function (e, data) {
  127. var maxFiles = $('#fileupload')
  128. .data('maxfiles'), maxFilesize = $(
  129. '#fileupload').data(
  130. 'maxfilesize');
  131. // letzt Meldung entfernen:
  132. $('.mwf-upload-error').text('');
  133. if (filelist.length > (maxFiles - 1)) {
  134. $('.mwf-upload-error')
  135. .text(
  136. 'Hinweis: Es dürfen maximal '
  137. + maxFiles
  138. + ' Dateien hochgeladen werden.');
  139. return false;
  140. } else {
  141. for (var i = 0; i < data.files.length; i++) {
  142. filelist
  143. .push(data.files[i])
  144. }
  145. var totalSize = 0;
  146. for (var pos in filelist) {
  147. totalSize += filelist[pos].size;
  148. }
  149. if (totalSize > (maxFilesize * 1024 * 1024)) {
  150. filelist.pop();
  151. $('.mwf-upload-error')
  152. .text(
  153. 'Hinweis: Die Größe der Dateien überschreitet die maximale Gesamtgröße von '
  154. + maxFilesize
  155. + 'MB.');
  156. return false;
  157. }
  158. }
  159. });
  160. $('#uploadbutton')
  161. .click(
  162. function () {
  163. $('#fileupload')
  164. .fileupload('send', {
  165. files: filelist
  166. }).done(
  167. function (
  168. result,
  169. textStatus,
  170. jqXHR) {
  171. if (result.success === true) {
  172. $(
  173. '.mwf-upload')
  174. .html(
  175. '<p><strong>Ihre Daten wurden erfolgreich hochgeladen.</strong></p>');
  176. } else {
  177. $(
  178. '.mwf-upload')
  179. .html(
  180. '<p><strong>Es ist ein Fehler aufgetreten: '
  181. + result.errors
  182. + '</strong></p>');
  183. }
  184. }).fail(
  185. function (
  186. jqXHR,
  187. textStatus,
  188. errorThrown) {
  189. $(
  190. '.mwf-upload')
  191. .html(
  192. '<p><strong>Es ist ein Fehler aufgetreten: '
  193. + errorThrown
  194. + '</strong></p>');
  195. })
  196. .always(
  197. function (
  198. result,
  199. textStatus,
  200. jqXHR) {
  201. filelist = [];
  202. })
  203. });
  204. }
  205. }
  206. static initPrintDialog() {
  207. if ((window.location.href.indexOf('print=true') !== -1)
  208. && (window.location.href.indexOf('printsrc=button') !== -1)
  209. && (window.print !== undefined)) {
  210. console.log("print load")
  211. global.$('body').trigger("lazyload-gallery-image");
  212. // todo: Workaround mit timeout, hier musste auf jedes Bild ein http response event gesetzt werden und async print aufrufen
  213. setTimeout(() => {
  214. // wartet auf letztes frame der sich gerade rendert
  215. requestAnimationFrame(() => {
  216. window.print()
  217. });
  218. }, 1000)
  219. }
  220. }
  221. }