internal PersistentObjectAttributeGroup(string name, PersistentObjectAttribute[] attributes)
 {
     _Name = name;
     Attributes = attributes;
     Attributes.Run(attr => attr.Group = this);
     IsNameVisible = true;
 }
 private void Target_Loaded(object sender, RoutedEventArgs e)
 {
     attribute = target.DataContext as PersistentObjectAttribute;
     if (attribute != null)
     {
         SetValidationErrorStyle(attribute.HasValidationError);
         attribute.PropertyChanged += Attribute_PropertyChanged;
     }
 }
        private void Render(PersistentObjectAttribute poa)
        {
            if (poa == null)
                return;

            var name = new StringBuilder("PersistentObjectAttributeTemplate");
            if (poa.Parent.IsInEdit && !poa.IsReadOnly)
            {
                name.Append(".Edit");

                if (poa.IsReadOnly)
                    name.Append(".ReadOnly");
            }

            ContentTemplate = GetAttributeTemplate(name + ".{0}.{1}", poa.Parent.Type, poa.Name) ?? GetAttributeTemplate(name + ".{0}", poa.Type) ?? GetAttributeTemplate(name + ".Default");
        }
Пример #4
0
        public async Task RefreshAttributesAsync(PersistentObjectAttribute attribute = null)
        {
            var parameters = attribute != null ? new Dictionary <string, string> {
                { "RefreshedPersistentObjectAttributeId", Client.ToServiceString(attribute.Id) }
            } : null;

            try
            {
                var result = await Client.ExecuteActionAsync("PersistentObject.Refresh", this, null, null, parameters).ConfigureAwait(false);

                SetNotification(result.Notification, result.NotificationType);

                if (!HasNotification || NotificationType != NotificationType.Error)
                {
                    await RefreshFromResult(result).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                SetNotification(ex.Message);
            }
        }
Пример #5
0
        public async Task RefreshAttributesAsync(PersistentObjectAttribute attribute = null)
        {
            var parameters = attribute != null ? new Dictionary<string, string> { { "RefreshedPersistentObjectAttributeId", Service.ToServiceString(attribute.Id) } } : null;
            try
            {
                var result = await Service.Current.ExecuteActionAsync("PersistentObject.Refresh", this, null, null, parameters);

                SetNotification(result.Notification, result.NotificationType);

                if (!HasNotification || NotificationType != NotificationType.Error)
                    await RefreshFromResult(result);
            }
            catch (Exception ex)
            {
                SetNotification(ex.Message);
            }
        }
Пример #6
0
 protected virtual PersistentObjectTabAttributes CreateAttributesTab(PersistentObjectAttribute[] attributes, string title, PersistentObject parent)
 {
     return new PersistentObjectTabAttributes(attributes, title, parent);
 }
Пример #7
0
        internal PersistentObject(JObject model)
            : base(model)
        {
            JToken attributesToken;
            if (model.TryGetValue("attributes", out attributesToken))
            {
                var attributes = (JArray)attributesToken;
                Attributes = attributes.Select(jAttr => jAttr["lookup"] != null ? new PersistentObjectAttributeWithReference((JObject)jAttr, this) : new PersistentObjectAttribute((JObject)jAttr, this)).ToArray();
            }
            else
                Attributes = new PersistentObjectAttribute[0];

            JToken queriesToken;
            if (model.TryGetValue("queries", out queriesToken))
            {
                var queries = (JArray)queriesToken;
                Queries = new KeyValueList<string, Query>(queries.Select(jQuery /* :-) */ => Service.Current.Hooks.OnConstruct((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 = Service.Current.Hooks.OnConstruct(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(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
                JToken actionsToken;
                if (model.TryGetValue("actions", out actionsToken))
                {
                    var actions = ActionBase.GetActions(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);

            Service.Current.Hooks.OnConstruct(this);

            Tabs.Select((tab, n) => tab.Index = n).Run();
        }
 internal AttributeContextMenuArgs(PersistentObjectAttribute attribute)
 {
     Attribute = attribute;
     Commands = new List<UICommand>();
 }
 public PhonePersistentObjectTabAttributes(PhonePersistentObject phoneParent, PersistentObjectAttribute[] attributes, string title, PersistentObject parent)
     : base(attributes, title, parent)
 {
     this.phoneParent = phoneParent;
 }
 protected override PersistentObjectTabAttributes CreateAttributesTab(PersistentObjectAttribute[] attributes, string title, PersistentObject parent)
 {
     return new PhonePersistentObjectTabAttributes(this, attributes, title, parent);
 }
Пример #11
0
        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();
        }
 public void Dispose()
 {
     if (attribute != null)
     {
         attribute.PropertyChanged -= Attribute_PropertyChanged;
         attribute = null;
     }
 }
 public StorePersistentObjectTabAttributes(PersistentObjectAttribute[] attributes, string title, PersistentObject parent)
     :
         base(attributes, title, parent)
 {
     Navigate = new Navigate();
 }
 internal PersistentObjectTabAttributes(PersistentObjectAttribute[] attributes, string title, PersistentObject parent)
     : base(title, parent)
 {
     Attributes = attributes;
     Groups = Attributes.Where(a => a.IsVisible).GroupBy(a => a.Group).Select(g => g.Key).ToArray();
 }