441 lines
19 KiB
C#
441 lines
19 KiB
C#
#pragma warning disable 1591
|
|
//------------------------------------------------------------------------------
|
|
// <auto-generated>
|
|
// This code was generated by a tool.
|
|
// Runtime Version:4.0.30319.42000
|
|
//
|
|
// Changes to this file may cause incorrect behavior and will be lost if
|
|
// the code is regenerated.
|
|
// </auto-generated>
|
|
//------------------------------------------------------------------------------
|
|
|
|
namespace Disco.Web.Views.Device.DeviceParts
|
|
{
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Web;
|
|
using System.Web.Helpers;
|
|
using System.Web.Mvc;
|
|
using System.Web.Mvc.Ajax;
|
|
using System.Web.Mvc.Html;
|
|
using System.Web.Routing;
|
|
using System.Web.Security;
|
|
using System.Web.UI;
|
|
using System.Web.WebPages;
|
|
using Disco;
|
|
using Disco.Models.Repository;
|
|
using Disco.Services;
|
|
using Disco.Services.Authorization;
|
|
using Disco.Services.Web;
|
|
using Disco.Web;
|
|
using Disco.Web.Extensions;
|
|
|
|
[System.CodeDom.Compiler.GeneratedCodeAttribute("RazorGenerator", "2.0.0.0")]
|
|
[System.Web.WebPages.PageVirtualPathAttribute("~/Views/Device/DeviceParts/_Comments.cshtml")]
|
|
public partial class _Comments : Disco.Services.Web.WebViewPage<Disco.Web.Models.Device.ShowModel>
|
|
{
|
|
public _Comments()
|
|
{
|
|
}
|
|
public override void Execute()
|
|
{
|
|
|
|
#line 2 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
|
|
Authorization.Require(Claims.Device.ShowComments);
|
|
var canAddComments = Authorization.Has(Claims.Device.Actions.AddComments);
|
|
var canRemoveAnyComments = Authorization.Has(Claims.Device.Actions.RemoveAnyComments);
|
|
var canRemoveOwnComments = Authorization.Has(Claims.Device.Actions.RemoveOwnComments);
|
|
|
|
|
|
#line default
|
|
#line hidden
|
|
WriteLiteral("\r\n<div");
|
|
|
|
WriteLiteral(" id=\"Comments\"");
|
|
|
|
WriteAttribute("class", Tuple.Create(" class=\"", 387), Tuple.Create("\"", 607)
|
|
|
|
#line 8 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
, Tuple.Create(Tuple.Create("", 395), Tuple.Create<System.Object, System.Int32>(canAddComments ? "canAddComments" : "cannotAddComments"
|
|
|
|
#line default
|
|
#line hidden
|
|
, 395), false)
|
|
|
|
#line 8 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
, Tuple.Create(Tuple.Create(" ", 453), Tuple.Create<System.Object, System.Int32>(canRemoveAnyComments ? "canRemoveAnyComments" : "cannotRemoveAnyComments"
|
|
|
|
#line default
|
|
#line hidden
|
|
, 454), false)
|
|
|
|
#line 8 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
, Tuple.Create(Tuple.Create(" ", 530), Tuple.Create<System.Object, System.Int32>(canRemoveOwnComments ? "canRemoveOwnComments" : "cannotRemoveOwnComments"
|
|
|
|
#line default
|
|
#line hidden
|
|
, 531), false)
|
|
);
|
|
|
|
WriteLiteral(" data-id=\"");
|
|
|
|
|
|
#line 8 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
Write(Model.Device.SerialNumber);
|
|
|
|
|
|
#line default
|
|
#line hidden
|
|
WriteLiteral("\"");
|
|
|
|
WriteLiteral(" data-userid=\"");
|
|
|
|
|
|
#line 8 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
Write(CurrentUser.UserId);
|
|
|
|
|
|
#line default
|
|
#line hidden
|
|
WriteLiteral("\"");
|
|
|
|
WriteLiteral(" data-addurl=\"");
|
|
|
|
|
|
#line 8 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
Write(Url.Action(MVC.API.Device.CommentAdd(Model.Device.SerialNumber)));
|
|
|
|
|
|
#line default
|
|
#line hidden
|
|
WriteLiteral("\"");
|
|
|
|
WriteLiteral(" data-removeurl=\"");
|
|
|
|
|
|
#line 8 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
Write(Url.Action(MVC.API.Device.CommentRemove()));
|
|
|
|
|
|
#line default
|
|
#line hidden
|
|
WriteLiteral("\"");
|
|
|
|
WriteLiteral(" data-geturl=\"");
|
|
|
|
|
|
#line 8 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
Write(Url.Action(MVC.API.Device.Comment()));
|
|
|
|
|
|
#line default
|
|
#line hidden
|
|
WriteLiteral("\"");
|
|
|
|
WriteLiteral(">\r\n");
|
|
|
|
|
|
#line 9 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
|
|
|
|
#line default
|
|
#line hidden
|
|
|
|
#line 9 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
if (canAddComments)
|
|
{
|
|
|
|
|
|
#line default
|
|
#line hidden
|
|
WriteLiteral(" <div");
|
|
|
|
WriteLiteral(" class=\"commentInput\"");
|
|
|
|
WriteLiteral(">\r\n <textarea");
|
|
|
|
WriteLiteral(" class=\"commentInput\"");
|
|
|
|
WriteLiteral(" placeholder=\"add comment...\"");
|
|
|
|
WriteLiteral(" accesskey=\"l\"");
|
|
|
|
WriteLiteral("></textarea>\r\n <button");
|
|
|
|
WriteLiteral(" type=\"button\"");
|
|
|
|
WriteLiteral(" title=\"Add Comment\"");
|
|
|
|
WriteLiteral(" disabled><i");
|
|
|
|
WriteLiteral(" class=\"fa fa-comment\"");
|
|
|
|
WriteLiteral("></i></button>\r\n </div>\r\n");
|
|
|
|
|
|
#line 15 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
}
|
|
|
|
|
|
#line default
|
|
#line hidden
|
|
WriteLiteral(" <div");
|
|
|
|
WriteLiteral(" class=\"commentOutput\"");
|
|
|
|
WriteLiteral(">\r\n");
|
|
|
|
|
|
#line 17 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
|
|
|
|
#line default
|
|
#line hidden
|
|
|
|
#line 17 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
foreach (var c in Model.Device.DeviceComments.OrderBy(m => m.Timestamp))
|
|
{
|
|
|
|
|
|
#line default
|
|
#line hidden
|
|
WriteLiteral(" <div");
|
|
|
|
WriteLiteral(" class=\"comment\"");
|
|
|
|
WriteLiteral(" data-commentid=\"");
|
|
|
|
|
|
#line 19 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
Write(c.Id);
|
|
|
|
|
|
#line default
|
|
#line hidden
|
|
WriteLiteral("\"");
|
|
|
|
WriteLiteral(">\r\n <span");
|
|
|
|
WriteLiteral(" class=\"author\"");
|
|
|
|
WriteLiteral(">");
|
|
|
|
|
|
#line 20 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
Write(c.TechUser.ToStringFriendly());
|
|
|
|
|
|
#line default
|
|
#line hidden
|
|
WriteLiteral("</span>");
|
|
|
|
|
|
#line 20 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
if (canRemoveAnyComments || (canRemoveOwnComments && c.TechUserId.Equals(CurrentUser.UserId, StringComparison.OrdinalIgnoreCase)))
|
|
{
|
|
|
|
#line default
|
|
#line hidden
|
|
WriteLiteral("<span");
|
|
|
|
WriteLiteral(" class=\"remove fa fa-times-circle\"");
|
|
|
|
WriteLiteral("></span>");
|
|
|
|
|
|
#line 21 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
}
|
|
|
|
#line default
|
|
#line hidden
|
|
WriteLiteral("<span");
|
|
|
|
WriteLiteral(" class=\"timestamp\"");
|
|
|
|
WriteLiteral(" data-livestamp=\"");
|
|
|
|
|
|
#line 21 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
Write(c.Timestamp.ToUnixEpoc());
|
|
|
|
|
|
#line default
|
|
#line hidden
|
|
WriteLiteral("\"");
|
|
|
|
WriteAttribute("title", Tuple.Create(" title=\"", 1707), Tuple.Create("\"", 1744)
|
|
|
|
#line 21 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
, Tuple.Create(Tuple.Create("", 1715), Tuple.Create<System.Object, System.Int32>(c.Timestamp.ToFullDateTime()
|
|
|
|
#line default
|
|
#line hidden
|
|
, 1715), false)
|
|
);
|
|
|
|
WriteLiteral(">");
|
|
|
|
|
|
#line 21 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
Write(c.Timestamp.ToFullDateTime());
|
|
|
|
|
|
#line default
|
|
#line hidden
|
|
WriteLiteral("</span>\r\n <div");
|
|
|
|
WriteLiteral(" class=\"comment\"");
|
|
|
|
WriteLiteral(">");
|
|
|
|
|
|
#line 22 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
Write(c.Comments.ToHtmlComment());
|
|
|
|
|
|
#line default
|
|
#line hidden
|
|
WriteLiteral("</div>\r\n </div>\r\n");
|
|
|
|
|
|
#line 24 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
}
|
|
|
|
|
|
#line default
|
|
#line hidden
|
|
WriteLiteral(" </div>\r\n</div>\r\n<script>\r\n if (!document.DiscoFunctions) {\r\n docume" +
|
|
"nt.DiscoFunctions = {};\r\n }\r\n\r\n $(function () {\r\n const $comments =" +
|
|
" $(\'#Comments\');\r\n const $commentOutput = $comments.find(\'.commentOutput\'" +
|
|
");\r\n\r\n window.setTimeout(function () {\r\n $commentOutput[0].scr" +
|
|
"ollTop = $commentOutput[0].scrollHeight; // Scroll to Bottom\r\n }, 0);\r\n " +
|
|
" $(\'#DeviceDetailTabs\').on(\'tabsactivate\', function (event, ui) {\r\n " +
|
|
" if (ui.newPanel && ui.newPanel.is(\'#DeviceDetailTab-CommentsAndJobs\')) {\r\n " +
|
|
" $commentOutput[0].scrollTop = $commentOutput[0].scrollHeight; // S" +
|
|
"croll to Bottom\r\n }\r\n });\r\n\r\n function onCommentAdded(i" +
|
|
"d) {\r\n onCommentAddedAsync(id);\r\n }\r\n async function on" +
|
|
"CommentAddedAsync(id) {\r\n const formData = new FormData();\r\n " +
|
|
" formData.append(\'__RequestVerificationToken\', document.body.dataset.antiforge" +
|
|
"ry);\r\n formData.append(\'id\', id);\r\n\r\n const response = awa" +
|
|
"it fetch($comments.attr(\'data-geturl\'), {\r\n method: \'POST\',\r\n " +
|
|
" body: formData\r\n });\r\n\r\n if (!response.ok) {\r\n" +
|
|
" alert(\'Unable to load live comment \' + id + \': \' + response.stat" +
|
|
"usText);\r\n } else {\r\n const comment = await response.j" +
|
|
"son();\r\n\r\n if ($comments.hasClass(\'canRemoveAnyComments\'))\r\n " +
|
|
" renderComment(comment, false, true);\r\n else if ($c" +
|
|
"omments.hasClass(\'canRemoveOwnComments\'))\r\n renderComment(com" +
|
|
"ment, false, (comment.AuthorId === $comments.attr(\'data-userid\')));\r\n " +
|
|
" else\r\n renderComment(comment, false, false);\r\n " +
|
|
" }\r\n }\r\n function onCommentRemoved(id) {\r\n $commentOut" +
|
|
"put.children(\'div[data-commentid=\"\' + id + \'\"]\').slideUp(300).delay(300).queue(f" +
|
|
"unction () {\r\n const $this = $(this);\r\n $this.find" +
|
|
"(\'.timestamp\').livestamp(\'destroy\');\r\n $this.remove();\r\n " +
|
|
" });\r\n }\r\n function renderComment(c, quick, canRemove) {\r\n " +
|
|
" let t = \'<div><span class=\"author\" />\';\r\n if (canRemove)\r\n " +
|
|
" t += \'<span class=\"remove fa fa-times-circle\" />\';\r\n t += " +
|
|
"\'<span class=\"timestamp\" /><div class=\"comment\" /></div>\';\r\n\r\n const " +
|
|
"e = $(t);\r\n e.attr(\'data-commentid\', c.Id);\r\n e.find(\'.aut" +
|
|
"hor\').text(c.Author);\r\n e.find(\'.timestamp\').text(c.TimestampFull).at" +
|
|
"tr(\'title\', c.TimestampFull).livestamp(c.TimestampUnixEpoc);\r\n e.find" +
|
|
"(\'.comment\').html(c.HtmlComments);\r\n\r\n $commentOutput.append(e);\r\n\r\n " +
|
|
" if (!quick) {\r\n e.animate({ backgroundColor: \'#ffff99\'" +
|
|
" }, 500, function () {\r\n e.animate({ backgroundColor: \'#fafaf" +
|
|
"a\' }, 500, function () {\r\n e.css(\'background-color\', \'\');" +
|
|
"\r\n });\r\n });\r\n $commentOutput.a" +
|
|
"nimate({ scrollTop: $commentOutput[0].scrollHeight }, 250)\r\n }\r\n " +
|
|
" }\r\n\r\n document.DiscoFunctions.onCommentAdded = onCommentAdded;\r\n " +
|
|
" document.DiscoFunctions.onCommentRemoved = onCommentRemoved;\r\n });\r\n</scrip" +
|
|
"t>\r\n");
|
|
|
|
|
|
#line 106 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
if (canAddComments)
|
|
{
|
|
|
|
|
|
#line default
|
|
#line hidden
|
|
WriteLiteral(" <script>\r\n $(function () {\r\n const $comments = $(\'#Comments" +
|
|
"\');\r\n const $commentInput = $comments.find(\'textarea.commentInput\');\r" +
|
|
"\n const $commentInputButton = $comments.find(\'button\');\r\n " +
|
|
"$commentInputButton.on(\'click\', postComment);\r\n $commentInput.on(\'key" +
|
|
"press\', function (e) {\r\n if (e.which == 13 && !e.shiftKey) {\r\n " +
|
|
" postComment();\r\n return false;\r\n " +
|
|
" }\r\n });\r\n\r\n async function postComment() {\r\n " +
|
|
" if ($commentInputButton.prop(\'disabled\')) {\r\n alert(\'Di" +
|
|
"sconnected from the Disco ICT Server, please refresh this page and try again\');\r" +
|
|
"\n return;\r\n }\r\n\r\n const comment" +
|
|
" = $commentInput.val();\r\n\r\n if (comment == \'\') {\r\n " +
|
|
" alert(\'Enter a comment to post\');\r\n $commentInput.focus(" +
|
|
");\r\n return;\r\n }\r\n\r\n $commentIn" +
|
|
"put.prop(\'disabled\', true);\r\n\r\n const formData = new FormData();\r" +
|
|
"\n formData.append(\'__RequestVerificationToken\', document.body.dat" +
|
|
"aset.antiforgery);\r\n formData.append(\'comment\', comment);\r\n\r\n " +
|
|
" const response = await fetch($comments.attr(\'data-addurl\'), {\r\n " +
|
|
" method: \'POST\',\r\n body: formData\r\n " +
|
|
" });\r\n\r\n if (response.ok) {\r\n $commentInput" +
|
|
".val(\'\').prop(\'disabled\', false).focus();\r\n } else {\r\n " +
|
|
" alert(\'Unable to add comment: \' + response.statusText);\r\n " +
|
|
" $commentInput.prop(\'disabled\', false).focus();\r\n }\r\n " +
|
|
" }\r\n });\r\n </script>\r\n");
|
|
|
|
|
|
#line 155 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
}
|
|
|
|
|
|
#line default
|
|
#line hidden
|
|
|
|
#line 156 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
if (canRemoveAnyComments || canRemoveOwnComments)
|
|
{
|
|
|
|
|
|
#line default
|
|
#line hidden
|
|
WriteLiteral(" <script>\r\n $(function () {\r\n const $comments = $(\'#Comments" +
|
|
"\');\r\n const $commentOutput = $comments.find(\'.commentOutput\');\r\n " +
|
|
" let $dialogRemove = null;\r\n\r\n $commentOutput.on(\'click\', \'span" +
|
|
".remove\', removeComment);\r\n\r\n function removeComment(e) {\r\n " +
|
|
" e.preventDefault();\r\n\r\n const commentId = $(this).closest(\'" +
|
|
"div\').attr(\'data-commentid\');\r\n\r\n if (!$dialogRemove) {\r\n " +
|
|
" $dialogRemove = $(\'<div class=\"dialog\" title=\"Remove this Comment?\">" +
|
|
"<p><i class=\"fa fa-exclamation-triangle fa-lg\"></i> Are you sure?</p></div>" +
|
|
"\')\r\n .appendTo(document.body)\r\n .d" +
|
|
"ialog({\r\n resizable: false,\r\n " +
|
|
" height: 140,\r\n modal: true,\r\n " +
|
|
" autoOpen: false\r\n });\r\n }\r\n\r\n " +
|
|
" $dialogRemove.dialog(\"enable\").dialog(\'option\', \'buttons\', {\r\n " +
|
|
" \"Remove\": function () {\r\n $dialogRemove.dial" +
|
|
"og(\"disable\");\r\n $dialogRemove.dialog(\"option\", \"buttons\"" +
|
|
", null);\r\n\r\n removeCommentAsync(commentId);\r\n " +
|
|
" },\r\n \"Cancel\": function () {\r\n " +
|
|
" $dialogRemove.dialog(\"close\");\r\n }\r\n }).dialo" +
|
|
"g(\'open\');\r\n }\r\n async function removeCommentAsync(comment" +
|
|
"Id) {\r\n const formData = new FormData();\r\n formDat" +
|
|
"a.append(\'__RequestVerificationToken\', document.body.dataset.antiforgery);\r\n " +
|
|
" formData.append(\'id\', commentId);\r\n\r\n const response " +
|
|
"= await fetch($comments.attr(\'data-removeurl\'), {\r\n method: \'" +
|
|
"POST\',\r\n body: formData\r\n });\r\n\r\n " +
|
|
" if (!response.ok) {\r\n alert(\'Unable to remove comment: \' +" +
|
|
" response.statusText);\r\n }\r\n $dialogRemove.dialog(" +
|
|
"\"close\");\r\n }\r\n });\r\n </script>\r\n");
|
|
|
|
|
|
#line 211 "..\..\Views\Device\DeviceParts\_Comments.cshtml"
|
|
}
|
|
|
|
|
|
#line default
|
|
#line hidden
|
|
}
|
|
}
|
|
}
|
|
#pragma warning restore 1591
|