-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFieldTypeConverterBase.cs
47 lines (45 loc) · 2 KB
/
FieldTypeConverterBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using Litium.FieldFramework;
using Litium.Web.Administration.FieldFramework;
using Newtonsoft.Json.Linq;
namespace Litium.Accelerator.FieldTypes
{
internal abstract class FieldTypeConverterBase : IEditFieldTypeConverter
{
private readonly IFieldTypeMetadata _fieldTypeMetadata;
public FieldTypeConverterBase(FieldTypeMetadataService fieldTypeMetadataService, string fieldTypeMetadataServiceName)
{
_fieldTypeMetadata = fieldTypeMetadataService.Get(fieldTypeMetadataServiceName);
}
public object CreateOptionsModel() => null;
public virtual object ConvertFromEditValue(EditFieldTypeConverterArgs args, JToken item)
{
var fieldTypeInstance = _fieldTypeMetadata.CreateInstance(args.FieldDefinition);
return fieldTypeInstance.ConvertFromJsonValue(item.ToObject(_fieldTypeMetadata.JsonType));
}
public virtual JToken ConvertToEditValue(EditFieldTypeConverterArgs args, object item)
{
var fieldTypeInstance = _fieldTypeMetadata.CreateInstance(args.FieldDefinition);
var value = fieldTypeInstance.ConvertToJsonValue(item);
if (value == null)
{
return JValue.CreateNull();
}
return JToken.FromObject(value);
}
/// <summary>
/// The AngularJS controller name to edit the CustomText field.
/// </summary>
public string EditControllerName => null;
/// <summary>
/// The AngularJS template to edit the CustomText field.
/// </summary>
public string EditControllerTemplate => null;
/**
* Since we don't have the setting UI for this CustomText field, we can skip the setting controllers and components.
* */
public string SettingsControllerName => null;
public string SettingsControllerTemplate => null;
public abstract string EditComponentName { get; }
public abstract string SettingsComponentName { get; }
}
}