Adds more functionality to prop editors to be able to flag the value editor as readonly so no bound values will be persisted (ie. for the label property editor)
This commit is contained in:
@@ -367,7 +367,7 @@ namespace Umbraco.Core
|
||||
/// <returns></returns>
|
||||
internal static string ToXmlString(this object value, Type type)
|
||||
{
|
||||
if (type == typeof(string)) return ((string)value).IsNullOrWhiteSpace() ? "" : (string)value;
|
||||
if (type == typeof(string)) return (value.ToString().IsNullOrWhiteSpace() ? "" : value.ToString());
|
||||
if (type == typeof(bool)) return XmlConvert.ToString((bool)value);
|
||||
if (type == typeof(byte)) return XmlConvert.ToString((byte)value);
|
||||
if (type == typeof(char)) return XmlConvert.ToString((char)value);
|
||||
|
||||
@@ -102,6 +102,14 @@ namespace Umbraco.Core.PropertyEditors
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set this to true if the property editor is for display purposes only
|
||||
/// </summary>
|
||||
public virtual bool IsReadOnly
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to try to convert the string value to the correct CLR type based on the DatabaseDataType specified for this value editor
|
||||
/// </summary>
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
angular.module('umbraco').controller("Umbraco.Editors.ReadOnlyValueController",
|
||||
function($rootScope, $scope, $filter){
|
||||
|
||||
if ($scope.model.config && $scope.model.config.filter) {
|
||||
if ($scope.model.config &&
|
||||
angular.isArray($scope.model.config) &&
|
||||
$scope.model.config.length > 0 &&
|
||||
$scope.model.config[0] &&
|
||||
$scope.model.config.filter)
|
||||
{
|
||||
|
||||
if ($scope.model.config.format) {
|
||||
$scope.displayvalue = $filter($scope.model.config.filter)($scope.model.value, $scope.model.config.format);
|
||||
}
|
||||
|
||||
@@ -4,10 +4,12 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http;
|
||||
using System.Web.Mvc;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Editors;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.WebApi.Filters;
|
||||
|
||||
@@ -101,7 +103,13 @@ namespace Umbraco.Web.Editors
|
||||
}
|
||||
else
|
||||
{
|
||||
dboProperty.Value = p.PropertyEditor.ValueEditor.DeserializeValue(data, dboProperty.Value);
|
||||
var valueEditor = p.PropertyEditor.ValueEditor;
|
||||
//don't persist any bound value if the editor is readonly
|
||||
if (valueEditor.IsReadOnly == false)
|
||||
{
|
||||
dboProperty.Value = p.PropertyEditor.ValueEditor.DeserializeValue(data, dboProperty.Value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Umbraco.Core;
|
||||
using System.ComponentModel;
|
||||
using System.Web.Mvc;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
|
||||
namespace Umbraco.Web.PropertyEditors
|
||||
@@ -6,5 +8,16 @@ namespace Umbraco.Web.PropertyEditors
|
||||
[PropertyEditor(Constants.PropertyEditors.NoEdit, "Label", "readonlyvalue")]
|
||||
public class LabelPropertyEditor : PropertyEditor
|
||||
{
|
||||
|
||||
protected override ValueEditor CreateValueEditor()
|
||||
{
|
||||
var baseEditor = base.CreateValueEditor();
|
||||
|
||||
return new LabelValueEditor
|
||||
{
|
||||
View = baseEditor.View
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
18
src/Umbraco.Web/PropertyEditors/LabelValueEditor.cs
Normal file
18
src/Umbraco.Web/PropertyEditors/LabelValueEditor.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
|
||||
namespace Umbraco.Web.PropertyEditors
|
||||
{
|
||||
/// <summary>
|
||||
/// Custom value editor to mark it as readonly
|
||||
/// </summary>
|
||||
internal class LabelValueEditor : ValueEditor
|
||||
{
|
||||
/// <summary>
|
||||
/// This editor is for display purposes only, any values bound to it will not be saved back to the database
|
||||
/// </summary>
|
||||
public override bool IsReadOnly
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -301,6 +301,7 @@
|
||||
<Compile Include="Editors\EntityController.cs" />
|
||||
<Compile Include="Models\PagedResult.cs" />
|
||||
<Compile Include="PropertyEditors\LabelPropertyEditor.cs" />
|
||||
<Compile Include="PropertyEditors\LabelValueEditor.cs" />
|
||||
<Compile Include="Routing\UrlProviderExtensions.cs" />
|
||||
<Compile Include="WebApi\ControllerContextExtensions.cs" />
|
||||
<Compile Include="WebApi\CustomDateTimeConvertor.cs" />
|
||||
|
||||
Reference in New Issue
Block a user