|
|
@@ -31,6 +31,8 @@ public class DynamicVariableGrid : DynamicDataGrid<DigitalFormVariable>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public DynamicFormLayoutGrid? LayoutGrid { get; set; }
|
|
|
+
|
|
|
protected override void Init()
|
|
|
{
|
|
|
base.Init();
|
|
|
@@ -109,9 +111,18 @@ public class DynamicVariableGrid : DynamicDataGrid<DigitalFormVariable>
|
|
|
}
|
|
|
}
|
|
|
converter.ConvertProperties(oldProperties, newProperties);
|
|
|
+ newProperties.SetDefaultValue(converter.Convert(oldProperties, oldProperties.GetDefaultValue(), newProperties));
|
|
|
|
|
|
if (DynamicVariableUtils.EditProperties(Form, Variables, newProperties.GetType(), newProperties, false))
|
|
|
{
|
|
|
+ if(!MessageWindow.ShowYesNo(
|
|
|
+ $"This will convert field '{variable.Code}' from {oldFieldType.GetCaption()} to {fieldType.GetCaption()}. Note that this will " +
|
|
|
+ $"update all instances of this form '{Form.Code}' that have been filled in, converting the field data. Do you wish to proceed?",
|
|
|
+ "Proceed?"))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
variable.SaveProperties(fieldType, newProperties);
|
|
|
|
|
|
if (DFUtils.GetFormInstanceType(Form.AppliesTo) is not Type instanceType)
|
|
|
@@ -145,6 +156,38 @@ public class DynamicVariableGrid : DynamicDataGrid<DigitalFormVariable>
|
|
|
|
|
|
Client.Create(instanceType).Save(forms, $"Changed {variable.Code} from {oldFieldType.GetCaption()} to {fieldType.GetCaption()}");
|
|
|
|
|
|
+ if(LayoutGrid is not null)
|
|
|
+ {
|
|
|
+ foreach(var layout in LayoutGrid.Layouts)
|
|
|
+ {
|
|
|
+ var dfLayout = DFLayout.FromLayoutString(layout.Layout);
|
|
|
+
|
|
|
+ void UpdateList(List<DFLayoutControl> elements)
|
|
|
+ {
|
|
|
+ var updates = new List<(int, DFLayoutField)>();
|
|
|
+ foreach(var (i, element) in elements.WithIndex())
|
|
|
+ {
|
|
|
+ if (element is not DFLayoutField field
|
|
|
+ || field.Name != variable.Code) continue;
|
|
|
+ updates.Add((i, field));
|
|
|
+ }
|
|
|
+ foreach(var (i, field) in updates)
|
|
|
+ {
|
|
|
+ var newField = (Activator.CreateInstance(fieldType) as DFLayoutField)!;
|
|
|
+ newField.LoadFromString(field.SaveToString());
|
|
|
+ elements[i] = newField;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ UpdateList(dfLayout.Elements);
|
|
|
+ UpdateList(dfLayout.HiddenElements);
|
|
|
+
|
|
|
+ layout.Layout = dfLayout.SaveLayout();
|
|
|
+ }
|
|
|
+ LayoutGrid.SaveItems(LayoutGrid.Layouts);
|
|
|
+ LayoutGrid.Refresh(false, true);
|
|
|
+ }
|
|
|
+
|
|
|
SaveItem(variable);
|
|
|
Refresh(false, true);
|
|
|
}
|