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:
Shannon
2013-08-12 18:09:16 +10:00
parent c3e773b598
commit 50aa9d7144
7 changed files with 58 additions and 4 deletions

View File

@@ -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);

View File

@@ -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>

View File

@@ -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);
}

View File

@@ -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);
}
}
}
}

View File

@@ -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
};
}
}
}

View 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; }
}
}
}

View File

@@ -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" />