private void InitLocalizationGrid()
        {
            var pgDiv = this.ById("PropertyGrid");

            if (pgDiv.Length <= 0)
            {
                return;
            }

            var pgOptions      = GetPropertyGridOptions();
            var anyLocalizable = false;

            foreach (var item in pgOptions.Items)
            {
                if (item.Localizable)
                {
                    anyLocalizable = true;
                }
            }

            if (!anyLocalizable)
            {
                return;
            }

            var localGridDiv = J("<div/>")
                               .Attribute("id", this.IdPrefix + "LocalizationGrid")
                               .Hide()
                               .InsertAfter(pgDiv);

            pgOptions.IdPrefix = this.idPrefix + "Localization_";
            var items = new List <PropertyItem>();

            foreach (var item in pgOptions.Items)
            {
                if (item.Localizable)
                {
                    var copy = jQuery.ExtendObject(new PropertyItem(), item);
                    copy.Insertable   = true;
                    copy.Updatable    = true;
                    copy.OneWay       = false;
                    copy.Required     = false;
                    copy.Localizable  = false;
                    copy.DefaultValue = null;
                    items.Add(copy);
                }
            }

            pgOptions.Items  = items;
            localizationGrid = new PropertyGrid(localGridDiv, pgOptions);

            localGridDiv.AddClass("s-LocalizationGrid");

            var self = this;

            localizationSelect = J("<select/>")
                                 .AddClass("s-LocalizationSelect")
                                 .AppendTo(toolbar.Element)
                                 .Change((e) => self.LocalizationSelectChange(e));

            foreach (var k in GetLanguages())
            {
                Q.AddOption(localizationSelect, k.Item1.ToString(), k.Item2);
            }
        }
Beispiel #2
0
        private void InitLocalizationGridCommon(PropertyGridOptions pgOptions)
        {
            var pgDiv          = this.ById("PropertyGrid");
            var anyLocalizable = false;

            foreach (var item in pgOptions.Items)
            {
                if (item.Localizable)
                {
                    anyLocalizable = true;
                }
            }

            if (!anyLocalizable)
            {
                return;
            }

            var localGridDiv = J("<div/>")
                               .Attribute("id", this.IdPrefix + "LocalizationGrid")
                               .Hide()
                               .InsertAfter(pgDiv);

            pgOptions.IdPrefix = this.idPrefix + "Localization_";
            var items = new List <PropertyItem>();

            foreach (var item in pgOptions.Items)
            {
                if (item.Localizable)
                {
                    var copy = jQuery.ExtendObject(new PropertyItem(), item);
                    copy.OneWay       = true;
                    copy.ReadOnly     = true;
                    copy.Required     = false;
                    copy.DefaultValue = null;
                    items.Add(copy);

                    foreach (var lang in GetLanguages())
                    {
                        copy              = jQuery.ExtendObject(new PropertyItem(), item);
                        copy.Name         = lang.Item1 + "$" + copy.Name;
                        copy.Title        = lang.Item2;
                        copy.CssClass     = string.Join(" ", copy.CssClass, "translation");
                        copy.Insertable   = true;
                        copy.Updatable    = true;
                        copy.OneWay       = false;
                        copy.Required     = false;
                        copy.Localizable  = false;
                        copy.DefaultValue = null;
                        items.Add(copy);
                    }
                }
            }

            pgOptions.Items  = items;
            localizationGrid = new PropertyGrid(localGridDiv, pgOptions).Init();

            localGridDiv.AddClass("s-LocalizationGrid");

            var self = this;
        }
        private void InitLocalizationGridCommon(PropertyGridOptions pgOptions)
        {
            var pgDiv          = this.ById("PropertyGrid");
            var anyLocalizable = false;

            foreach (var item in pgOptions.Items)
            {
                if (item.Localizable == true)
                {
                    anyLocalizable = true;
                }
            }

            if (!anyLocalizable)
            {
                return;
            }

            var localGridDiv = J("<div/>")
                               .Attribute("id", this.IdPrefix + "LocalizationGrid")
                               .Hide()
                               .InsertAfter(pgDiv);

            pgOptions.IdPrefix = this.idPrefix + "Localization_";
            var items = new List <PropertyItem>();

            foreach (var item in pgOptions.Items)
            {
                string[][] langs = null;

                if (item.Localizable == true)
                {
                    var copy = jQuery.ExtendObject(new PropertyItem(), item);
                    copy.OneWay       = true;
                    copy.ReadOnly     = true;
                    copy.Required     = false;
                    copy.DefaultValue = null;
                    items.Add(copy);

                    if (langs == null)
                    {
                        var langsTuple = GetLanguages();
                        langs = (langsTuple as object) as string[][];
                        if (langs == null || langs.Length == 0 || langs[0] == null || !Q.IsArray(langs[0]))
                        {
                            langs = langsTuple.Select(x => new string[] { x.Item1, x.Item2 }).ToArray();
                        }
                    }

                    foreach (var lang in langs)
                    {
                        copy              = jQuery.ExtendObject(new PropertyItem(), item);
                        copy.Name         = lang[0] + "$" + copy.Name;
                        copy.Title        = lang[1];
                        copy.CssClass     = string.Join(" ", copy.CssClass, "translation");
                        copy.Insertable   = true;
                        copy.Updatable    = true;
                        copy.OneWay       = false;
                        copy.Required     = false;
                        copy.Localizable  = false;
                        copy.DefaultValue = null;
                        items.Add(copy);
                    }
                }
            }

            pgOptions.Items  = items;
            localizationGrid = new PropertyGrid(localGridDiv, pgOptions).Init();

            localGridDiv.AddClass("s-LocalizationGrid");

            var self = this;
        }
Beispiel #4
0
        public TWidget AddEqualityFilter <TWidget>(string field, string title, object options = null, Action <QuickFilterArgs <TWidget> > handler = null,
                                                   Action <jQueryObject> element = null, Action <TWidget> init = null)
            where TWidget : Widget
        {
            if (quickFiltersDiv == null)
            {
                J("<div/>").AddClass("clear").AppendTo(toolbar.Element);
                quickFiltersDiv = J("<div/>").AddClass("quick-filters-bar").AppendTo(toolbar.Element);
            }

            var quickFilter = J("<div class='quick-filter-item'><span class='quick-filter-label'></span></div>")
                              .AppendTo(quickFiltersDiv)
                              .Children().Text(title ?? "")
                              .Parent();

            var widget = Widget.Create <TWidget>(
                element: e =>
            {
                if (!field.IsEmptyOrNull())
                {
                    e.Attribute("id", this.UniqueName + "_QuickFilter_" + field);
                }
                e.Attribute("placeholder", " ");
                e.AppendTo(quickFilter);
                if (element != null)
                {
                    element(e);
                }
            },
                options: options,
                init: init);

            submitHandlers += () =>
            {
                var request = (ListRequest)view.Params;
                request.EqualityFilter = request.EqualityFilter ?? new JsDictionary <string, object>();

                var obj = new JsDictionary <string, object>();
                PropertyGrid.SaveEditorValue(widget, new PropertyItem
                {
                    Name = "$$value$$",
                }, obj);
                var value = obj["$$value$$"];

                bool active = Script.IsValue(value) && !string.IsNullOrEmpty(value.ToString());

                if (handler != null)
                {
                    var args = new QuickFilterArgs <TWidget>
                    {
                        Field          = field,
                        Request        = request,
                        EqualityFilter = request.EqualityFilter,
                        Value          = value,
                        Active         = active,
                        Handled        = true
                    };

                    handler(args);

                    quickFilter.ToggleClass("quick-filter-active", args.Active);

                    if (!args.Handled)
                    {
                        request.EqualityFilter[field] = value;
                    }
                }
                else
                {
                    request.EqualityFilter[field] = value;
                    quickFilter.ToggleClass("quick-filter-active", active);
                }
            };

            widget.Change(e =>
            {
                this.QuickFilterChange(e);
            });

            return(widget);
        }