Ejemplo n.º 1
0
        public static void AddActions(HTMLElement dst, IEnumerable <HTMLElement> src)
        {
            var leftAndRight = src.ToList().Partition(x => !x.HasAttribute(Magics.AttrAlignToRight));

            dst.ReplaceChildren(
                leftAndRight.Item1
                .ConcatElementIfTrue(
                    leftAndRight.Item2.Any(),
                    DocumentUtil.CreateElementHavingClassName("span", Magics.CssClassFlexSpacer))
                .Concat(leftAndRight.Item2));
        }
Ejemplo n.º 2
0
        public LabellessReadOnlyView(string elementType = "div", TextType inputType = TextType.TreatAsText, string defaultValue = null)
        {
            _inputType = inputType;

            _elem = DocumentUtil.CreateElementHavingClassName(elementType, GetType().FullName);
            if (_inputType == TextType.TreatAsPreformatted)
            {
                _elem.Style.WhiteSpace = WhiteSpace.Pre;
            }

            if (defaultValue != null)
            {
                Value = defaultValue;
            }
        }
Ejemplo n.º 3
0
        public LabeledReadOnlyView(TextType type, string label, string containerType = "div", string elementType = "div", string defaultValue = null)
        {
            _type = type;
            if (_type == TextType.TreatAsPreformatted)
            {
                _elem.Style.WhiteSpace = WhiteSpace.Pre;
            }

            _container = DocumentUtil.CreateElementHavingClassName(containerType, GetType().FullName);
            _label     = new HTMLLabelElement()
            {
                TextContent = label
            };
            _elem = new HTMLElement(elementType);
            if (defaultValue != null)
            {
                Value = defaultValue;
            }

            _container.AppendChild(_label);
            _container.AppendChild(_elem);
        }
        public ActionButtonsMenuBarView(
            Func <MenuItemModel, InputTypeButtonActionView> customButtonBuilder = null)
        {
            _buttonBuilder = customButtonBuilder ?? (x => {
                var res = new InputTypeButtonActionView(x.Label.Value);
                x.Label.Changed += (_, __, newValue, ___, ____) =>
                                   res.ProperLabelElem.TextContent = newValue;

                res.Widget.SetAttribute(Magics.AttrDataMenuItemId, x.Id.ToString());

                if (x.DescriptonOrNull != null)
                {
                    res.Widget.Title = x.DescriptonOrNull;
                }

                return(res);
            });

            _nav    = DocumentUtil.CreateElementHavingClassName("nav", GetType().FullName);
            _nav.Id = UniqueIdGenerator.GenerateAsString();

            _actionsCntnr = new HTMLDivElement();
            _nav.AppendChild(_actionsCntnr);
        }
Ejemplo n.º 5
0
        public HorizontalMenuBarView(
            Func <MenuItemModel, Tuple <HTMLElement, Action <string> > > customItemBuilder = null)
        {
            _itemBuilder = customItemBuilder ?? (x => {
                var el = new HTMLAnchorElement {
                    Href = "#"
                };
                return(Tuple.Create <HTMLElement, Action <string> >(el, y => el.TextContent = y));
            });

            _nav    = DocumentUtil.CreateElementHavingClassName("nav", GetType().FullNameWithoutGenerics());
            _nav.Id = UniqueIdGenerator.GenerateAsString();

            _root = new HTMLElement("ul")
            {
                Id = UniqueIdGenerator.GenerateAsString()
            };
            _nav.AppendChild(_root);

            _onItemClicked = ev => {
                if (!ev.HasHtmlTarget())
                {
                    return;
                }

                ev.PreventDefault();

                var htmlTarget = ev.HtmlTarget();
                var menuItemId = htmlTarget.GetAttribute(Magics.AttrDataMenuItemId);
                Logger.Debug(GetType(), "user activated menuItemId {0} in view", menuItemId);
                ActivateAllBut(_root, new List <HTMLElement>());
                ItemActivated?.Invoke(Convert.ToInt32(menuItemId));
            };
            _onMouseOver = ev => {
                if (!ev.HasHtmlCurrentTarget())
                {
                    return;
                }

                var hoverOn = ev.HtmlCurrentTarget();
                var active  = new List <HTMLElement> {
                    hoverOn
                };

                var parent = hoverOn.ParentElement;
                while (parent != _root)
                {
                    active.Add(parent);
                    parent = parent.ParentElement;
                }

                ActivateAllBut(_root, active);
                hoverOn.Focus();
            };

            Document.Body.AddEventListener("click", ev => {
                //find out if clicked item is a descendant of menu - if not fold whole menu

                if (!ev.HasHtmlTarget())
                {
                    return;
                }

                if (ev.HtmlTarget().IsDescendantOf(_nav))
                {
                    return;
                }

                ActivateAllBut(_root, new List <HTMLElement>());
            });
        }