diff --git a/Disco.Services/Documents/DocumentTemplateExtensions.cs b/Disco.Services/Documents/DocumentTemplateExtensions.cs index 8d776540..a7fc1f39 100644 --- a/Disco.Services/Documents/DocumentTemplateExtensions.cs +++ b/Disco.Services/Documents/DocumentTemplateExtensions.cs @@ -99,19 +99,19 @@ namespace Disco.Services switch (scope) { case AttachmentTypes.Device: - var device = database.Devices.Find(targetId); + var device = database.Devices.Include(d => d.AssignedUser).First(d => d.SerialNumber == targetId); targetUser = device?.AssignedUser; return device; case AttachmentTypes.Job: if (!int.TryParse(targetId, out var targetIdInt)) throw new ArgumentOutOfRangeException(nameof(targetId)); - var job = database.Jobs.Find(targetIdInt); + var job = database.Jobs.Include(j => j.User).First(j => j.Id == targetIdInt); targetUser = job?.User; return job; case AttachmentTypes.User: // special usecase in resolving users (they may not exist in the database yet) targetId = ActiveDirectory.ParseDomainAccountId(targetId); - var user = database.Users.Find(targetId); + var user = database.Users.First(u => u.UserId == targetId); if (user == null) { // try importing user diff --git a/Disco.Services/Plugins/PluginManifest.cs b/Disco.Services/Plugins/PluginManifest.cs index 4e4136c7..8353fca9 100644 --- a/Disco.Services/Plugins/PluginManifest.cs +++ b/Disco.Services/Plugins/PluginManifest.cs @@ -156,6 +156,7 @@ namespace Disco.Services.Plugins "Microsoft.Owin.Security", "Microsoft.Web.Infrastructure", "Newtonsoft.Json", + "Newtonsoft.Json.Bson", "Owin", "PdfiumViewer", "PdfSharp", diff --git a/Disco.Web/ClientSource/Scripts/Modules/Disco-PropertyChangeHelpers.js b/Disco.Web/ClientSource/Scripts/Modules/Disco-PropertyChangeHelpers.js index 3fc62809..f8990087 100644 --- a/Disco.Web/ClientSource/Scripts/Modules/Disco-PropertyChangeHelpers.js +++ b/Disco.Web/ClientSource/Scripts/Modules/Disco-PropertyChangeHelpers.js @@ -8,7 +8,7 @@ if (!document.DiscoFunctions.PropertyChangeHelper) { } return propertyField.val(); }; - document.DiscoFunctions.PropertyChangeHelper = function (propertyField, fieldWatermark, updateUrl, updatePropertyName, data) { + document.DiscoFunctions.PropertyChangeHelper = function (propertyField, fieldWatermark, updateUrl, updatePropertyName, data, validator) { var fieldValue = document.DiscoFunctions.PropertyValue(propertyField); var fieldChangeToken = null; var $ajaxSave = propertyField.nextAll('.ajaxSave').first(); @@ -17,6 +17,10 @@ if (!document.DiscoFunctions.PropertyChangeHelper) { $ajaxSave.hide(); var changedValue = document.DiscoFunctions.PropertyValue(propertyField); if (fieldValue != changedValue) { + if (validator && !validator(changedValue)) { + return; + } + fieldValue = changedValue; if (fieldChangeToken) window.clearTimeout(fieldChangeToken); diff --git a/Disco.Web/ClientSource/Scripts/Modules/Disco-PropertyChangeHelpers.min.js b/Disco.Web/ClientSource/Scripts/Modules/Disco-PropertyChangeHelpers.min.js index 37f1c4b5..f035e1c5 100644 --- a/Disco.Web/ClientSource/Scripts/Modules/Disco-PropertyChangeHelpers.min.js +++ b/Disco.Web/ClientSource/Scripts/Modules/Disco-PropertyChangeHelpers.min.js @@ -1 +1 @@ -if(document.DiscoFunctions||(document.DiscoFunctions={}),document.DiscoFunctions.PropertyChangeHelper||(document.DiscoFunctions.PropertyValue=function(n){return n[0].nodeName.toLowerCase()=="input"&&n.attr("type")=="checkbox"?n.is(":checked"):n.val()},document.DiscoFunctions.PropertyChangeHelper=function(n,t,i,r,u){var s=document.DiscoFunctions.PropertyValue(n),e=null,f=n.nextAll(".ajaxSave").first(),o=n.nextAll(".ajaxLoading").first(),h=function(){f.hide();var t=document.DiscoFunctions.PropertyValue(n);s!=t&&(s=t,e&&window.clearTimeout(e),e=window.setTimeout(function(){o.show();u||(u={});u[r]=s;$.getJSON(i,u,function(n,t){t!="success"||n!="OK"?(alert('Unable to change property "'+r+'":\n'+n),o.hide()):o.hide().next(".ajaxOk").show().delay("fast").fadeOut("slow")}).fail(function(n,t,i){alert('Unable to change property "'+r+'":\n'+i);o.hide()});e=null},500))};n[0].nodeName.toLowerCase()=="input"&&n.attr("type")=="checkbox"?n.click(h):n.change(h);n[0].nodeName.toLowerCase()=="input"&&n.attr("type")=="text"&&(n.keydown(function(n){f.show();n.which==13&&$(this).blur()}).blur(function(){f.hide()}).focus(function(){$(this).select()}),t&&n.watermark(t));n[0].nodeName.toLowerCase()=="textarea"&&n.keydown(function(){f.show()}).blur(function(){f.hide()})}),document.DiscoFunctions.DateChangeUserHelper||(document.DiscoFunctions.DateChangeUserHelper=function(n,t,i,r,u,f,e){var s=n.val(),o=null,h=t.next(".ajaxLoading");n.watermark(i).change(function(){var i=n.val();s.toLowerCase()!=i.toLowerCase()&&(s=i,o&&window.clearTimeout(o),o=window.setTimeout(function(){h.show();var n={};n[u]=s;$.getJSON(r,n,function(n,i){i!="success"||n.Result!="OK"?(alert("Unable to change Date:\n"+n),h.hide()):(t.text("by "+n.UserDescription),h.hide().next(".ajaxOk").show().delay("fast").fadeOut("slow"))});o=null},500))}).focus(function(){$(this).select()});e?n.datepicker({defaultDate:new Date,minDate:moment(f).toDate(),changeYear:!0,changeMonth:!0,dateFormat:"yy/mm/dd",beforeShow:function(n){$input=$(n);$input.val()||$input.datepicker("setDate",new Date)}}):n.datetimepicker({defaultDate:new Date,ampm:!0,minDate:moment(f).toDate(),changeYear:!0,changeMonth:!0,dateFormat:"yy/mm/dd",beforeShow:function(n){$input=$(n);$input.val()||$input.datetimepicker("setDate",new Date)}})}),document.DiscoFunctions.DateChangeHelper||(document.DiscoFunctions.DateChangeHelper=function(n,t,i,r,u,f){var o=n.val(),e=null,s=n.next(".ajaxLoading");n.watermark(t).change(function(){var t=n.val();o.toLowerCase()!=t.toLowerCase()&&(o=t,e&&window.clearTimeout(e),e=window.setTimeout(function(){s.show();var n={};n[r]=o;$.getJSON(i,n,function(n,t){t!="success"||n!="OK"?(alert("Unable to change Date:\n"+n),s.hide()):s.hide().next(".ajaxOk").show().delay("fast").fadeOut("slow")});e=null},500))}).focus(function(){$(this).select()});f?n.datepicker({defaultDate:new Date,minDate:moment(u).toDate(),changeYear:!0,changeMonth:!0,dateFormat:"yy/mm/dd",beforeShow:function(n){$input=$(n);$input.val()||$input.datepicker("setDate",new Date)}}):n.datetimepicker({defaultDate:new Date,ampm:!0,minDate:moment(u).toDate(),changeYear:!0,changeMonth:!0,dateFormat:"yy/mm/dd",beforeShow:function(n){$input=$(n);$input.val()||$input.datetimepicker("setDate",new Date)}})}),!document.DiscoFunctions.DateDialogCreateUpdater){var dialog,dialogForm,dialogHeader,dialogDateBox,dialogDatePropertyNameBox,updateUrl,friendlyName,dateField,userField,updatePropertyName,notSetDisplay,minDate,useAjax;function dateDialogGet(){if(!dialog){dialog=$("