Built files from Bizgaze WebServer
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.

w_documentfiles.js 10.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. var Unibase;
  2. (function (Unibase) {
  3. let Platform;
  4. (function (Platform) {
  5. let Forms;
  6. (function (Forms) {
  7. let Components;
  8. (function (Components) {
  9. class DocumentFiles extends Platform.Core.BaseComponent {
  10. previewDocument(documentFileId, previewicon) {
  11. if (previewicon == "disabled") {
  12. return false;
  13. }
  14. else {
  15. var instance = this;
  16. instance.fileCacheHelper.loadJsFiles(["platform/files/managers/filemanager.js", "platform/core/helpers/mobile/mobilehelper.js", "platform/core/helpers/mobile/interfaces/imobilehelper.js", "platform/core/helpers/mobile/android/androidhelper.js"], function () {
  17. if (isMobileApp()) {
  18. Unibase.Platform.Files.Managers.FileManager.Instance().getDocumentFile(documentFileId).then(function (response) {
  19. var filePath = response.result.DocumentFilePath;
  20. if (filePath != null && filePath != undefined && filePath != "") {
  21. filePath = filePath.replace("file://" + '/', '');
  22. filePath = filePath.replace(window.location.origin + '/', '');
  23. Unibase.Platform.Helpers.MobileHelper.Instance().getMobileFilePath(response, filePath, Unibase.Platform.Forms.Components.DocumentFiles.Instance().MobileFilePathPreviewCallBack);
  24. }
  25. });
  26. }
  27. else {
  28. Unibase.Platform.Files.Managers.FileManager.Instance().getDocumentBase64File(documentFileId).then(function (response) {
  29. var result = response.result;
  30. var byteCharacters = atob(result.FileData);
  31. var byteNumbers = new Array(byteCharacters.length);
  32. for (var i = 0; i < byteCharacters.length; i++) {
  33. byteNumbers[i] = byteCharacters.charCodeAt(i);
  34. }
  35. var byteArray = new Uint8Array(byteNumbers);
  36. var file = new Blob([byteArray], { type: result.DocumentGroup + '/' + result.FileType + ';base64' });
  37. var fileURL = URL.createObjectURL(file);
  38. var fileName = result.DocumentFileName + "." + result.FileType;
  39. window.open(fileURL, fileName, "width=600,height=600,scrollbars=yes");
  40. });
  41. }
  42. });
  43. }
  44. }
  45. downloadDocument(documentFileId) {
  46. var instance = this;
  47. instance.fileCacheHelper.loadJsFiles(["platform/files/managers/filemanager.js", "platform/core/helpers/mobile/mobilehelper.js", "platform/core/helpers/mobile/interfaces/imobilehelper.js", "platform/core/helpers/mobile/android/androidhelper.js"], function () {
  48. if (isMobileApp()) {
  49. Unibase.Platform.Files.Managers.FileManager.Instance().getDocumentFile(documentFileId).then(function (response) {
  50. var filePath = response.result.DocumentFilePath;
  51. if (filePath != null && filePath != undefined && filePath != "") {
  52. filePath = filePath.replace("file://" + '/', '');
  53. filePath = filePath.replace(window.location.origin + '/', '');
  54. Unibase.Platform.Helpers.MobileHelper.Instance().getMobileFilePath(response, filePath, Unibase.Platform.Forms.Components.DocumentFiles.Instance().MobileFilePathDownloadCallBack);
  55. }
  56. });
  57. }
  58. else {
  59. Unibase.Platform.Files.Managers.FileManager.Instance().getDocumentBase64File(documentFileId).then(function (response) {
  60. var a = document.createElement("a");
  61. a.href = "data:" + response.result.FileType + ";base64," + response.result.FileData;
  62. a.download = response.result.DocumentFileName + "." + response.result.FileType;
  63. a.click();
  64. });
  65. }
  66. });
  67. }
  68. MobileFilePathDownloadCallBack(response, filePath, mobileFilePath) {
  69. mobileFilePath.replace(/^\//, '');
  70. filePath = filePath.replace(mobileFilePath + '/', '');
  71. var tempPath = filePath.split("~/");
  72. var checkPath = tempPath[tempPath.length - 1];
  73. filePath = checkPath;
  74. var server_url = _appsettings.server_url();
  75. if (!filePath.includes(server_url)) {
  76. filePath = server_url + "/" + filePath;
  77. }
  78. var a = document.createElement("a");
  79. a.href = filePath;
  80. a.download = response.result.DocumentFileName + "." + response.result.FileType;
  81. a.click();
  82. }
  83. MobileFilePathPreviewCallBack(response, filePath, mobileFilePath) {
  84. mobileFilePath.replace(/^\//, '');
  85. filePath = filePath.replace(mobileFilePath + '/', '');
  86. var tempPath = filePath.split("~/");
  87. var checkPath = tempPath[tempPath.length - 1];
  88. filePath = checkPath;
  89. var server_url = _appsettings.server_url();
  90. if (!filePath.includes(server_url)) {
  91. filePath = server_url + "/" + filePath;
  92. }
  93. Unibase.Platform.Helpers.MobileHelper.Instance().openNewWindow(filePath);
  94. }
  95. deleteDocumentFile(DocumentFileId) {
  96. var instance = this;
  97. bootbox.confirm("Do you want to Delete this File ?", function (result) {
  98. if (result == true) {
  99. instance.fileCacheHelper.loadJsFile("platform/files/managers/filemanager.js", function () {
  100. Unibase.Platform.Files.Managers.FileManager.Instance().deleteDocumentFile(DocumentFileId).then(function (response) {
  101. MessageHelper.Instance().showSuccess("Document File Deleted Successfully.", "");
  102. var ContainerId = Unibase.Platform.Helpers.NavigationHelper.Instance().getLastContainerId();
  103. if (ContainerId != null && ContainerId != undefined && ContainerId != '') {
  104. var viewall = ContainerId.toString().includes("_viewall");
  105. if (viewall) {
  106. var refreshButton = $("#" + ContainerId).find(".report-refresh-btn");
  107. if (refreshButton.length > 0) {
  108. refreshButton.click();
  109. }
  110. }
  111. else {
  112. instance.reloadPortlet();
  113. }
  114. }
  115. else {
  116. instance.reloadPortlet();
  117. }
  118. });
  119. });
  120. }
  121. });
  122. }
  123. reloadPortlet() {
  124. var installedAppId = Unibase.Themes.Providers.DetailHelper.installedAppId;
  125. var containerId = "#" + Unibase.Platform.Helpers.NavigationHelper.Instance().getLastContainerId();
  126. var portletId = 0;
  127. var activePortletIndex = Unibase.Themes.Providers.Detail_Settings.Instance().ActivePortlets.findIndex(x => x.InstalledAppId == installedAppId);
  128. if (activePortletIndex > -1) {
  129. portletId = Unibase.Themes.Providers.Detail_Settings.Instance().ActivePortlets[activePortletIndex].ActivePortletId;
  130. }
  131. if (portletId == 0) {
  132. portletId = Number($("#hf_PortletId").val());
  133. }
  134. Unibase.Themes.Compact.Components.Details.Instance().loadWidgets(installedAppId, portletId, containerId);
  135. }
  136. static Instance() {
  137. if (this.instance === undefined) {
  138. this.instance = new DocumentFiles();
  139. }
  140. return this.instance;
  141. }
  142. }
  143. Components.DocumentFiles = DocumentFiles;
  144. })(Components = Forms.Components || (Forms.Components = {}));
  145. })(Forms = Platform.Forms || (Platform.Forms = {}));
  146. })(Platform = Unibase.Platform || (Unibase.Platform = {}));
  147. })(Unibase || (Unibase = {}));