maintenance: plugin refactoring

This commit is contained in:
Gary Sharp
2022-12-04 13:40:16 +11:00
parent 05593a1466
commit 4f9f0fd0a8
12 changed files with 402 additions and 129 deletions
@@ -23,7 +23,7 @@ namespace Disco.Web.Areas.Config.Controllers
}
#region Plugin Configuration
[DiscoAuthorize(Claims.Config.Plugin.Configure), HttpPost]
[DiscoAuthorize(Claims.Config.Plugin.Configure), HttpPost, ValidateInput(false)]
public virtual ActionResult Configure(string PluginId, FormCollection form)
{
if (string.IsNullOrEmpty(PluginId))
@@ -1,4 +1,4 @@
/// <reference path="../Core/jquery-2.1.1.js" />
/// <reference path="../../Core/jquery-2.1.1.js" />
function DiscoExpressionEditor(host, validateUrl, expression) {
this.host = host;
this.hostDocument = null;
@@ -2,63 +2,71 @@ if (!document.DiscoFunctions) {
document.DiscoFunctions = {};
}
if (!document.DiscoFunctions.PropertyChangeHelper) {
document.DiscoFunctions.PropertyValue = function (PropertyField) {
if (PropertyField[0].nodeName.toLowerCase() == 'input' && PropertyField.attr('type') == 'checkbox') {
return PropertyField.is(':checked');
document.DiscoFunctions.PropertyValue = function (propertyField) {
if (propertyField[0].nodeName.toLowerCase() == 'input' && propertyField.attr('type') == 'checkbox') {
return propertyField.is(':checked');
}
return PropertyField.val();
return propertyField.val();
};
document.DiscoFunctions.PropertyChangeHelper = function (PropertyField, FieldWatermark, UpdateUrl, UpdatePropertyName) {
var fieldValue = document.DiscoFunctions.PropertyValue(PropertyField);
document.DiscoFunctions.PropertyChangeHelper = function (propertyField, fieldWatermark, updateUrl, updatePropertyName, data) {
var fieldValue = document.DiscoFunctions.PropertyValue(propertyField);
var fieldChangeToken = null;
var $ajaxSave = PropertyField.nextAll('.ajaxSave').first();
var $ajaxLoading = PropertyField.nextAll('.ajaxLoading').first();
var $ajaxSave = propertyField.nextAll('.ajaxSave').first();
var $ajaxLoading = propertyField.nextAll('.ajaxLoading').first();
var fieldChangeFunction = function () {
$ajaxSave.hide();
var changedValue = document.DiscoFunctions.PropertyValue(PropertyField);
var changedValue = document.DiscoFunctions.PropertyValue(propertyField);
if (fieldValue != changedValue) {
fieldValue = changedValue;
if (fieldChangeToken)
window.clearTimeout(fieldChangeToken);
fieldChangeToken = window.setTimeout(function () {
$ajaxLoading.show();
var data = {};
data[UpdatePropertyName] = fieldValue;
$.getJSON(UpdateUrl, data, function (response, result) {
if (!data) {
data = {};
}
data[updatePropertyName] = fieldValue;
$.getJSON(updateUrl, data, function (response, result) {
if (result != 'success' || response != 'OK') {
alert('Unable to change property "' + UpdatePropertyName + '":\n' + response);
alert('Unable to change property "' + updatePropertyName + '":\n' + response);
$ajaxLoading.hide();
} else {
$ajaxLoading.hide().next('.ajaxOk').show().delay('fast').fadeOut('slow');
}
}).fail(function (jqXHR, textStatus, errorThrown) {
alert('Unable to change property "' + updatePropertyName + '":\n' + errorThrown);
$ajaxLoading.hide();
})
fieldChangeToken = null;
}, 500);
};
}
if (PropertyField[0].nodeName.toLowerCase() == 'input' && PropertyField.attr('type') == 'checkbox') {
PropertyField.click(fieldChangeFunction);
if (propertyField[0].nodeName.toLowerCase() == 'input' && propertyField.attr('type') == 'checkbox') {
propertyField.click(fieldChangeFunction);
} else {
PropertyField.change(fieldChangeFunction);
propertyField.change(fieldChangeFunction);
}
// For Input Text Boxes
if (PropertyField[0].nodeName.toLowerCase() == 'input' && PropertyField.attr('type') == 'text') {
PropertyField.keydown(function (e) {
if (propertyField[0].nodeName.toLowerCase() == 'input' && propertyField.attr('type') == 'text') {
propertyField.keydown(function (e) {
$ajaxSave.show();
if (e.which == 13) {
$(this).blur();
}
})
.watermark(FieldWatermark)
.blur(function () {
$ajaxSave.hide();
}).focus(function () {
$(this).select();
});
if (fieldWatermark) {
propertyField.watermark(fieldWatermark);
}
}
// For TextAreas
if (PropertyField[0].nodeName.toLowerCase() == 'textarea') {
PropertyField.keydown(function () {
if (propertyField[0].nodeName.toLowerCase() == 'textarea') {
propertyField.keydown(function () {
$ajaxSave.show();
}).blur(function () {
$ajaxSave.hide();
File diff suppressed because one or more lines are too long
@@ -2,63 +2,71 @@
document.DiscoFunctions = {};
}
if (!document.DiscoFunctions.PropertyChangeHelper) {
document.DiscoFunctions.PropertyValue = function (PropertyField) {
if (PropertyField[0].nodeName.toLowerCase() == 'input' && PropertyField.attr('type') == 'checkbox') {
return PropertyField.is(':checked');
document.DiscoFunctions.PropertyValue = function (propertyField) {
if (propertyField[0].nodeName.toLowerCase() == 'input' && propertyField.attr('type') == 'checkbox') {
return propertyField.is(':checked');
}
return PropertyField.val();
return propertyField.val();
};
document.DiscoFunctions.PropertyChangeHelper = function (PropertyField, FieldWatermark, UpdateUrl, UpdatePropertyName) {
var fieldValue = document.DiscoFunctions.PropertyValue(PropertyField);
document.DiscoFunctions.PropertyChangeHelper = function (propertyField, fieldWatermark, updateUrl, updatePropertyName, data) {
var fieldValue = document.DiscoFunctions.PropertyValue(propertyField);
var fieldChangeToken = null;
var $ajaxSave = PropertyField.nextAll('.ajaxSave').first();
var $ajaxLoading = PropertyField.nextAll('.ajaxLoading').first();
var $ajaxSave = propertyField.nextAll('.ajaxSave').first();
var $ajaxLoading = propertyField.nextAll('.ajaxLoading').first();
var fieldChangeFunction = function () {
$ajaxSave.hide();
var changedValue = document.DiscoFunctions.PropertyValue(PropertyField);
var changedValue = document.DiscoFunctions.PropertyValue(propertyField);
if (fieldValue != changedValue) {
fieldValue = changedValue;
if (fieldChangeToken)
window.clearTimeout(fieldChangeToken);
fieldChangeToken = window.setTimeout(function () {
$ajaxLoading.show();
var data = {};
data[UpdatePropertyName] = fieldValue;
$.getJSON(UpdateUrl, data, function (response, result) {
if (!data) {
data = {};
}
data[updatePropertyName] = fieldValue;
$.getJSON(updateUrl, data, function (response, result) {
if (result != 'success' || response != 'OK') {
alert('Unable to change property "' + UpdatePropertyName + '":\n' + response);
alert('Unable to change property "' + updatePropertyName + '":\n' + response);
$ajaxLoading.hide();
} else {
$ajaxLoading.hide().next('.ajaxOk').show().delay('fast').fadeOut('slow');
}
}).fail(function (jqXHR, textStatus, errorThrown) {
alert('Unable to change property "' + updatePropertyName + '":\n' + errorThrown);
$ajaxLoading.hide();
})
fieldChangeToken = null;
}, 500);
};
}
if (PropertyField[0].nodeName.toLowerCase() == 'input' && PropertyField.attr('type') == 'checkbox') {
PropertyField.click(fieldChangeFunction);
if (propertyField[0].nodeName.toLowerCase() == 'input' && propertyField.attr('type') == 'checkbox') {
propertyField.click(fieldChangeFunction);
} else {
PropertyField.change(fieldChangeFunction);
propertyField.change(fieldChangeFunction);
}
// For Input Text Boxes
if (PropertyField[0].nodeName.toLowerCase() == 'input' && PropertyField.attr('type') == 'text') {
PropertyField.keydown(function (e) {
if (propertyField[0].nodeName.toLowerCase() == 'input' && propertyField.attr('type') == 'text') {
propertyField.keydown(function (e) {
$ajaxSave.show();
if (e.which == 13) {
$(this).blur();
}
})
.watermark(FieldWatermark)
.blur(function () {
$ajaxSave.hide();
}).focus(function () {
$(this).select();
});
if (fieldWatermark) {
propertyField.watermark(fieldWatermark);
}
}
// For TextAreas
if (PropertyField[0].nodeName.toLowerCase() == 'textarea') {
PropertyField.keydown(function () {
if (propertyField[0].nodeName.toLowerCase() == 'textarea') {
propertyField.keydown(function () {
$ajaxSave.show();
}).blur(function () {
$ajaxSave.hide();
@@ -1,4 +1,4 @@
/// <reference path="../Core/jquery-2.1.1.js" />
/// <reference path="../../Core/jquery-2.1.1.js" />
(function ($) {
var checkboxBulkSelectMethods = {
@@ -13,6 +13,11 @@ namespace Disco.Web.Controllers
{
public partial class PluginWebHandlerController : Controller
{
protected override void OnAuthorization(AuthorizationContext filterContext)
{
base.OnAuthorization(filterContext);
}
[OutputCache(Duration = 0, Location = System.Web.UI.OutputCacheLocation.None)]
public virtual ActionResult Index(string PluginId, string PluginAction)
{
@@ -24,7 +29,6 @@ namespace Disco.Web.Controllers
{
using (var pluginWebHandler = manifest.CreateWebHandler(this))
{
pluginWebHandler.OnActionExecuting();
return pluginWebHandler.ExecuteAction(PluginAction);
}
}
+22 -3
View File
@@ -1,11 +1,12 @@
using System.Web.Mvc;
using RazorGenerator.Mvc;
using System;
using System.Web.Mvc;
using System.Web.Routing;
namespace Disco.Web.Extensions
namespace Disco.Web
{
public static class ControllerExtensions
{
public static ActionResult RedirectToAction(this Controller controller, ActionResult result, string urlFragment)
{
var callInfo = result.GetT4MVCResult();
@@ -24,5 +25,23 @@ namespace Disco.Web.Extensions
}
}
private static string[] _viewFileNames = new string[] { "cshtml" };
public static ActionResult PrecompiledPartialView<ViewType>(this Controller controller, object model) where ViewType : WebViewPage
{
return PrecompiledPartialView(controller, typeof(ViewType), model);
}
public static ActionResult PrecompiledPartialView(this Controller controller, Type viewType, object model)
{
if (!typeof(WebViewPage).IsAssignableFrom(viewType))
throw new ArgumentException("ViewType must be assignable from WebViewPage", "viewType");
IView v = new PrecompiledMvcView(controller.Request.Path, viewType, false, _viewFileNames);
if (model != null)
controller.ViewData.Model = model;
return new PartialViewResult { View = v, ViewData = controller.ViewData, TempData = controller.TempData };
}
}
}