public void CancelEdit() { if (!IsInEdit) { return; } SecurityToken = BackupSecurityToken; Attributes.Run(a => a.RestoreEditBackup()); IsDirty = false; if (!StateBehavior.HasFlag(StateBehavior.StayInEdit)) { IsInEdit = false; } Notification = null; }
public async Task Save() { try { var result = await Client.ExecuteActionAsync("PersistentObject.Save", this).ConfigureAwait(false); if (result == null) { return; } await RefreshFromResult(result).ConfigureAwait(false); if (string.IsNullOrWhiteSpace(Notification) || NotificationType != NotificationType.Error) { IsDirty = false; IsInEdit = StateBehavior.HasFlag(StateBehavior.StayInEdit); if (OwnerAttributeWithReference != null) { if (OwnerAttributeWithReference.ObjectId != ObjectId) { OwnerAttributeWithReference.Parent.Edit(); var fakeSelectedItem = new JObject(new JProperty("id", ObjectId), new JProperty("values", new JArray())); await OwnerAttributeWithReference.ChangeReference(new QueryResultItem(fakeSelectedItem, OwnerAttributeWithReference.Lookup)).ConfigureAwait(false); } } else if (OwnerQuery != null) { await OwnerQuery.RefreshQueryAsync().ConfigureAwait(false); if (OwnerQuery.SemanticZoomOwner != null) { await OwnerQuery.SemanticZoomOwner.RefreshQueryAsync().ConfigureAwait(false); } } } } catch (Exception ex) { SetNotification(ex.Message); } }
internal PersistentObject(Client client, JObject model) : base(client, model) { if (model.TryGetValue("attributes", out var attributesToken)) { var attributes = (JArray)attributesToken; Attributes = attributes.Select(jAttr => { if (jAttr["lookup"] != null) { return(new PersistentObjectAttributeWithReference(client, (JObject)jAttr, this)); } if (jAttr["details"] != null) { return(new PersistentObjectAttributeAsDetail(client, (JObject)jAttr, this)); } return(new PersistentObjectAttribute(client, (JObject)jAttr, this)); }).ToArray(); } else { Attributes = new PersistentObjectAttribute[0]; } if (model.TryGetValue("queries", out var queriesToken)) { var queries = (JArray)queriesToken; Queries = new KeyValueList <string, Query>(queries.Select(jQuery /* :-) */ => client.Hooks.OnConstruct(client, (JObject)jQuery, this, false)).ToDictionary(q => q.Name, q => q)); } else { Queries = new KeyValueList <string, Query>(new Dictionary <string, Query>()); } var parent = (JObject)model["parent"]; if (parent != null) { Parent = client.Hooks.OnConstruct(client, parent); } // Initialize Tabs and Groups var tabIndex = 0; var attributeTabs = !IsHidden?Attributes.OrderBy(attr => attr.Offset).GroupBy(attr => attr.Tab).Select(tab => { var groups = tab.OrderBy(attr => attr.Offset).GroupBy(attr => attr.GroupName).Select(group => new PersistentObjectAttributeGroup(client, group.Key, group.ToArray())).ToArray(); if (groups.Length == 1) { groups[0].IsNameVisible = false; } var t = (PersistentObjectTab)CreateAttributesTab(groups.SelectMany(g => g.Attributes).ToArray(), string.IsNullOrEmpty(tab.Key) ? Label : tab.Key, this); t.Index = tabIndex++; return(t); }) : new PersistentObjectTabAttributes[0]; Tabs = attributeTabs.Concat(Queries.OrderBy(q => q.Value.Offset).Select(q => CreateQueryTab(q.Value))).ToList(); if (!IsHidden) { // Initialize Action if (model.TryGetValue("actions", out var actionsToken)) { var actions = ActionBase.GetActions(client, actionsToken, this); Actions = actions.Where(a => !a.IsPinned).ToArray(); PinnedActions = actions.Where(a => a.IsPinned).ToArray(); Actions.Run(a => a.Initialize()); PinnedActions.Run(a => a.Initialize()); } else { Actions = PinnedActions = new ActionBase[0]; } } else { Actions = PinnedActions = new ActionBase[0]; } // Also check IsInEdit (Object could have been reconstructed after suspend/resume) IsInEdit = IsInEdit || IsNew || StateBehavior.HasFlag(StateBehavior.OpenInEdit) || StateBehavior.HasFlag(StateBehavior.StayInEdit); IsDirty = IsDirty; // Also triggers reconstructed changes // Specials HasNotification = !string.IsNullOrWhiteSpace(Notification); client.Hooks.OnConstruct(this); Tabs.Select((tab, n) => tab.Index = n).Run(); }