feature: display pdf attachments inline

This commit is contained in:
Gary Sharp
2026-01-26 16:34:26 +11:00
parent f807d75162
commit 204d57a4a5
15 changed files with 6285 additions and 274 deletions
@@ -56,7 +56,19 @@
<script type="text/javascript">
Shadowbox.init({
skipSetup: true,
modal: true
modal: true,
onOpen: function (obj) {
if (obj.player === 'iframe' && obj.content.indexOf('inline=True') === -1) {
obj.content += (obj.content.indexOf('?') === -1 ? '?' : '&') + 'inline=True';
}
return true;
},
onChange: function (obj) {
if (obj.player === 'iframe' && obj.content.indexOf('inline=True') === -1) {
obj.content += (obj.content.indexOf('?') === -1 ? '?' : '&') + 'inline=True';
}
return true;
}
});
$(function () {
var $Attachments = $('#Attachments');
@@ -116,6 +128,8 @@
e.show('slow');
if (a.MimeType.toLowerCase().indexOf('image/') == 0)
e.shadowbox({ gallery: 'attachments', player: 'img', title: a.Description });
else if (a.MimeType.toLowerCase().indexOf('application/pdf') == 0 && navigator.pdfViewerEnabled)
e.shadowbox({ gallery: 'attachments', player: 'iframe', title: a.Description });
else
e.click(onDownload);
@@ -170,7 +184,7 @@
a.hide(300).delay(300).queue(function () {
var $this = $(this);
if ($this.attr('data-mimetype').toLowerCase().indexOf('image/') == 0)
if (this['shadowboxCacheKey'])
Shadowbox.removeCache(this);
$this.find('.timestamp').livestamp('destroy');
$this.remove();
@@ -338,6 +352,8 @@
$this = $(this);
if ($this.attr('data-mimetype').toLowerCase().indexOf('image/') == 0)
$this.shadowbox({ gallery: 'attachments', player: 'img', title: $this.find('.comments').text() });
else if ($this.attr('data-mimetype').toLowerCase().indexOf('application/pdf') == 0 && navigator.pdfViewerEnabled)
$this.shadowbox({ gallery: 'attachments', player: 'iframe', title: $this.find('.comments').text() });
else
$this.click(onDownload);
});
@@ -491,25 +491,29 @@ WriteLiteral(" </div>\r\n <script");
WriteLiteral(" type=\"text/javascript\"");
WriteLiteral(@">
Shadowbox.init({
skipSetup: true,
modal: true
});
$(function () {
var $Attachments = $('#Attachments');
var $attachmentOutput = $Attachments.find('.attachmentOutput');
var $dialogRemoveAttachment = null;
let $attachmentDownloadHost = null;
let attachmentUploader = null;
function onAttachmentAdded(id, quick) {
var data = { id: id };
$.ajax({
url: '");
WriteLiteral(">\r\n Shadowbox.init({\r\n skipSetu" +
"p: true,\r\n modal: true,\r\n " +
"onOpen: function (obj) {\r\n if (obj.player === \'if" +
"rame\' && obj.content.indexOf(\'inline=True\') === -1) {\r\n " +
" obj.content += (obj.content.indexOf(\'?\') === -1 ? \'?\' : \'&\') + \'inlin" +
"e=True\';\r\n }\r\n ret" +
"urn true;\r\n },\r\n onChange:" +
" function (obj) {\r\n if (obj.player === \'iframe\' &" +
"& obj.content.indexOf(\'inline=True\') === -1) {\r\n " +
" obj.content += (obj.content.indexOf(\'?\') === -1 ? \'?\' : \'&\') + \'inline=True\'" +
";\r\n }\r\n return tru" +
"e;\r\n }\r\n });\r\n " +
" $(function () {\r\n var $Attachments = $(\'#Atta" +
"chments\');\r\n var $attachmentOutput = $Attachments.fin" +
"d(\'.attachmentOutput\');\r\n var $dialogRemoveAttachment" +
" = null;\r\n let $attachmentDownloadHost = null;\r\n " +
" let attachmentUploader = null;\r\n\r\n " +
" function onAttachmentAdded(id, quick) {\r\n va" +
"r data = { id: id };\r\n $.ajax({\r\n " +
" url: \'");
#line 71 "..\..\Views\User\UserParts\_Resources.cshtml"
#line 83 "..\..\Views\User\UserParts\_Resources.cshtml"
Write(Url.Action(MVC.API.User.Attachment()));
@@ -546,39 +550,36 @@ WriteLiteral("\',\r\n dataType: \'json\',\r\n
"ef\', \'");
#line 105 "..\..\Views\User\UserParts\_Resources.cshtml"
#line 117 "..\..\Views\User\UserParts\_Resources.cshtml"
Write(Url.Action(MVC.API.User.AttachmentDownload()));
#line default
#line hidden
WriteLiteral(@"/' + a.Id);
e.find('.comments').text(a.Description);
e.find('.author').text(a.Author);
e.find('.timestamp').text(a.TimestampFull).attr('title', a.TimestampFull).livestamp(a.TimestampUnixEpoc);
if (canRemove)
e.find('.remove').click(removeAttachment);
if (!quick)
e.hide();
$attachmentOutput.prepend(e);
onUpdate();
if (!quick)
e.show('slow');
if (a.MimeType.toLowerCase().indexOf('image/') == 0)
e.shadowbox({ gallery: 'attachments', player: 'img', title: a.Description });
else
e.click(onDownload);
// Add Thumbnail
var buildThumbnail = function () {
var retryCount = 0;
var img = e.find('.icon img');
var setThumbnailUrl = function () {
img.attr('src', '");
WriteLiteral("/\' + a.Id);\r\n e.find(\'.comments\').text(a.Descripti" +
"on);\r\n e.find(\'.author\').text(a.Author);\r\n " +
" e.find(\'.timestamp\').text(a.TimestampFull).attr(\'title\'" +
", a.TimestampFull).livestamp(a.TimestampUnixEpoc);\r\n " +
" if (canRemove)\r\n e.find(\'.remove\').click(" +
"removeAttachment);\r\n if (!quick)\r\n " +
" e.hide();\r\n $attachmentOutpu" +
"t.prepend(e);\r\n onUpdate();\r\n " +
" if (!quick)\r\n e.show(\'slow\');\r\n " +
" if (a.MimeType.toLowerCase().indexOf(\'image/\') == " +
"0)\r\n e.shadowbox({ gallery: \'attachments\', pl" +
"ayer: \'img\', title: a.Description });\r\n else if (" +
"a.MimeType.toLowerCase().indexOf(\'application/pdf\') == 0 && navigator.pdfViewerE" +
"nabled)\r\n e.shadowbox({ gallery: \'attachments" +
"\', player: \'iframe\', title: a.Description });\r\n e" +
"lse\r\n e.click(onDownload);\r\n\r\n " +
" // Add Thumbnail\r\n var buildThum" +
"bnail = function () {\r\n var retryCount = 0;\r\n" +
" var img = e.find(\'.icon img\');\r\n\r\n " +
" var setThumbnailUrl = function () {\r\n " +
" img.attr(\'src\', \'");
#line 128 "..\..\Views\User\UserParts\_Resources.cshtml"
#line 142 "..\..\Views\User\UserParts\_Resources.cshtml"
Write(Url.Action(MVC.API.User.AttachmentThumbnail()));
@@ -617,61 +618,61 @@ WriteLiteral("/\' + a.Id + \'?v=\' + retryCount);\r\n
"unction onAttachmentRemoved(id) {\r\n var a = $atta" +
"chmentOutput.find(\'a[data-attachmentid=\' + id + \']\');\r\n\r\n " +
" a.hide(300).delay(300).queue(function () {\r\n " +
" var $this = $(this);\r\n if ($this.att" +
"r(\'data-mimetype\').toLowerCase().indexOf(\'image/\') == 0)\r\n " +
" Shadowbox.removeCache(this);\r\n " +
" $this.find(\'.timestamp\').livestamp(\'destroy\');\r\n " +
" $this.remove();\r\n onUpdate();\r\n " +
" });\r\n }\r\n\r\n " +
" function onUpdate() {\r\n var attachmen" +
"tCount = $attachmentOutput.children(\'a\').length;\r\n " +
" var tabHeading = \'Attachments [\' + attachmentCount + \']\';\r\n " +
" $(\'#UserDetailTab-ResourcesLink\').text(tabHeading);\r\n " +
" }\r\n\r\n $Attachments\r\n " +
" .find(\'.attachmentInput span.download-all\')\r\n " +
" .on(\'click\', function (event) {\r\n c" +
"onst downloadAllUrl = $Attachments.attr(\'data-downloadallurl\');\r\n " +
" const id = $Attachments.attr(\'data-id\');\r\n " +
" const $this = $(this);\r\n\r\n " +
" if ($this.hasClass(\'fa-spinner\'))\r\n retu" +
"rn;\r\n\r\n $this\r\n " +
" .removeClass(\'fa-download\')\r\n ." +
"addClass(\'fa-spinner fa-spin\');\r\n\r\n if (!$att" +
"achmentDownloadHost) {\r\n $attachmentDownl" +
"oadHost = $(\'<iframe>\')\r\n .attr({ \'id" +
"\': \'AttachmentsDownloadHost\', \'name\': \'AttachmentsDownloadHost\', \'title\': \'Attac" +
"hment Download Host\' })\r\n .addClass(\'" +
"hidden\')\r\n .appendTo(\'body\')\r\n " +
" .contents();\r\n " +
" }\r\n const $form = $(\'<form>\')\r\n " +
" .attr({\r\n " +
" method: \'POST\',\r\n action: downl" +
"oadAllUrl,\r\n target: \'AttachmentsDown" +
"loadHost\'\r\n })\r\n " +
" .append($(\'<input>\')\r\n " +
" .attr({ type: \'hidden\', name: \'__RequestVerificationToken\' })\r\n " +
" .val(document.body.dataset.antiforgery))\r\n " +
" .append($(\'<input>\')\r\n " +
" .attr({ type: \'hidden\', name: \'id\' })\r\n " +
" .val(id))\r\n .appendTo(" +
"document.body)\r\n .trigger(\'submit\');\r\n\r\n " +
" window.setTimeout(function () {\r\n " +
" $this\r\n ." +
"removeClass(\'fa-spinner fa-spin\')\r\n ." +
"addClass(\'fa-download\');\r\n $form.remove()" +
";\r\n }, 2000);\r\n " +
" });\r\n\r\n document.DiscoFunctions.onAttachmentAdded =" +
" onAttachmentAdded;\r\n document.DiscoFunctions.onAttac" +
"hmentRemoved = onAttachmentRemoved;\r\n\r\n");
" var $this = $(this);\r\n if (this[\'sha" +
"dowboxCacheKey\'])\r\n Shadowbox.removeCache" +
"(this);\r\n $this.find(\'.timestamp\').livestamp(" +
"\'destroy\');\r\n $this.remove();\r\n " +
" onUpdate();\r\n });\r\n " +
" }\r\n\r\n function onUpdate() {\r\n " +
" var attachmentCount = $attachmentOutput.children(\'a\'" +
").length;\r\n var tabHeading = \'Attachments [\' + at" +
"tachmentCount + \']\';\r\n $(\'#UserDetailTab-Resource" +
"sLink\').text(tabHeading);\r\n }\r\n\r\n " +
" $Attachments\r\n .find(\'.attachmentInput sp" +
"an.download-all\')\r\n .on(\'click\', function (event)" +
" {\r\n const downloadAllUrl = $Attachments.attr" +
"(\'data-downloadallurl\');\r\n const id = $Attach" +
"ments.attr(\'data-id\');\r\n const $this = $(this" +
");\r\n\r\n if ($this.hasClass(\'fa-spinner\'))\r\n " +
" return;\r\n\r\n " +
" $this\r\n .removeClass(\'fa-download\')\r\n" +
" .addClass(\'fa-spinner fa-spin\');\r\n\r\n " +
" if (!$attachmentDownloadHost) {\r\n " +
" $attachmentDownloadHost = $(\'<iframe>\')\r\n " +
" .attr({ \'id\': \'AttachmentsDownloadHost\', \'name\': \'" +
"AttachmentsDownloadHost\', \'title\': \'Attachment Download Host\' })\r\n " +
" .addClass(\'hidden\')\r\n " +
" .appendTo(\'body\')\r\n .c" +
"ontents();\r\n }\r\n " +
" const $form = $(\'<form>\')\r\n .attr(" +
"{\r\n method: \'POST\',\r\n " +
" action: downloadAllUrl,\r\n " +
" target: \'AttachmentsDownloadHost\'\r\n " +
" })\r\n .append($(\'<input>\')\r\n " +
" .attr({ type: \'hidden\', name: \'__Reque" +
"stVerificationToken\' })\r\n .val(docume" +
"nt.body.dataset.antiforgery))\r\n .append($" +
"(\'<input>\')\r\n .attr({ type: \'hidden\'," +
" name: \'id\' })\r\n .val(id))\r\n " +
" .appendTo(document.body)\r\n " +
" .trigger(\'submit\');\r\n\r\n wind" +
"ow.setTimeout(function () {\r\n $this\r\n " +
" .removeClass(\'fa-spinner fa-spin\')\r\n " +
" .addClass(\'fa-download\');\r\n " +
" $form.remove();\r\n " +
"}, 2000);\r\n });\r\n\r\n do" +
"cument.DiscoFunctions.onAttachmentAdded = onAttachmentAdded;\r\n " +
" document.DiscoFunctions.onAttachmentRemoved = onAttachmentRemoved;\r\n\r\n" +
"");
#line 234 "..\..\Views\User\UserParts\_Resources.cshtml"
#line 248 "..\..\Views\User\UserParts\_Resources.cshtml"
#line default
#line hidden
#line 234 "..\..\Views\User\UserParts\_Resources.cshtml"
#line 248 "..\..\Views\User\UserParts\_Resources.cshtml"
if (canAddAttachments)
{
@@ -718,7 +719,7 @@ WriteLiteral("\r\n //#region Add Attachments\r\n
" //#endregion\r\n ");
#line 281 "..\..\Views\User\UserParts\_Resources.cshtml"
#line 295 "..\..\Views\User\UserParts\_Resources.cshtml"
}
@@ -727,7 +728,7 @@ WriteLiteral("\r\n //#region Add Attachments\r\n
WriteLiteral(" ");
#line 282 "..\..\Views\User\UserParts\_Resources.cshtml"
#line 296 "..\..\Views\User\UserParts\_Resources.cshtml"
if (canRemoveAnyAttachments || canRemoveOwnAttachments)
{
@@ -771,7 +772,7 @@ WriteLiteral("\r\n //#region Remove Attachments\r\n\r
"");
#line 335 "..\..\Views\User\UserParts\_Resources.cshtml"
#line 349 "..\..\Views\User\UserParts\_Resources.cshtml"
}
@@ -782,6 +783,8 @@ WriteLiteral(@"
$this = $(this);
if ($this.attr('data-mimetype').toLowerCase().indexOf('image/') == 0)
$this.shadowbox({ gallery: 'attachments', player: 'img', title: $this.find('.comments').text() });
else if ($this.attr('data-mimetype').toLowerCase().indexOf('application/pdf') == 0 && navigator.pdfViewerEnabled)
$this.shadowbox({ gallery: 'attachments', player: 'iframe', title: $this.find('.comments').text() });
else
$this.click(onDownload);
});
@@ -795,7 +798,7 @@ WriteLiteral(@"
$('#UserDetailTabItems').append('<li><a href=""#UserDetailTab-Resources"" id=""UserDetailTab-ResourcesLink"">Attachments [");
#line 351 "..\..\Views\User\UserParts\_Resources.cshtml"
#line 367 "..\..\Views\User\UserParts\_Resources.cshtml"
Write(Model.User.UserAttachments == null ? 0 : Model.User.UserAttachments.Count);
@@ -804,7 +807,7 @@ WriteLiteral(@"
WriteLiteral("]</a></li>\');\r\n </script>\r\n</div>\r\n");
#line 354 "..\..\Views\User\UserParts\_Resources.cshtml"
#line 370 "..\..\Views\User\UserParts\_Resources.cshtml"
if (canRemoveAnyAttachments || canRemoveOwnAttachments)
{
@@ -826,7 +829,7 @@ WriteLiteral(" class=\"fa fa-exclamation-triangle fa-lg\"");
WriteLiteral("></i>&nbsp;Are you sure?\r\n </p>\r\n </div>\r\n");
#line 361 "..\..\Views\User\UserParts\_Resources.cshtml"
#line 377 "..\..\Views\User\UserParts\_Resources.cshtml"
}
#line default