Exemple #1
0
        protected override void Serialize(IDictionary <string, object> json)
        {
            if (!string.IsNullOrEmpty(DataSource.Transport.Read.Url))
            {
                json["dataSource"] = DataSource.ToJson();
            }
            else if (DataSource.Data != null)
            {
                json["dataSource"] = DataSource.Data;
            }

            if (!string.IsNullOrEmpty(Title))
            {
                json["title"] = Title;
            }

            json["field"] = Field;

            if (Multiple != false)
            {
                json["multiple"] = Multiple;
            }

            if (!string.IsNullOrEmpty(DataTextField))
            {
                json["dataTextField"] = DataTextField;
            }

            if (!string.IsNullOrEmpty(DataValueField))
            {
                json["dataValueField"] = DataValueField;
            }

            if (!string.IsNullOrEmpty(DataColorField))
            {
                json["dataColorField"] = DataColorField;
            }

            if (ValuePrimitive != true)
            {
                json["valuePrimitive"] = ValuePrimitive;
            }

            if (Name.HasValue())
            {
                json["name"] = Name;
            }
        }
Exemple #2
0
        protected virtual IDictionary <string, object> SeriailzeBaseOptions()
        {
            var options = new Dictionary <string, object>(Events);

            if (!string.IsNullOrEmpty(DataSource.Transport.Read.Url))
            {
                options["dataSource"] = DataSource.ToJson();
            }
            else if (DataSource.Data != null)
            {
                options["dataSource"] = DataSource.Data;
            }

            var animation = Animation.ToJson();

            if (animation.Keys.Any())
            {
                options["animation"] = animation["animation"];
            }

            if (!string.IsNullOrEmpty(DataTextField))
            {
                options["dataTextField"] = DataTextField;
            }

            if (Delay != null)
            {
                options["delay"] = Delay;
            }

            if (IgnoreCase != null)
            {
                options["ignoreCase"] = IgnoreCase;
            }

            if (Height != null)
            {
                options["height"] = Height;
            }

            return(options);
        }
Exemple #3
0
        protected virtual void SerializeDataSource(IDictionary <string, object> options)
        {
            if (!string.IsNullOrEmpty(DataSource.Transport.Read.Url))
            {
                if (!DataSource.Transport.Read.Type.HasValue())
                {
                    DataSource.Transport.Read.Type = "POST";
                }

                DataSource.Type = DataSourceType.Ajax;
                options.Add("dataSource", DataSource.ToJson());
            }
            else if (Data != null)
            {
                IDictionary <string, object> result = DataSource.ToJson();
                result["data"] = Data;
                result.Remove("transport");
                options.Add("dataSource", result);
            }
        }
Exemple #4
0
        public override void WriteInitializationScript(TextWriter writer)
        {
            var options = new Dictionary <string, object>(Events);

            var autoBind = DataSource.Type != DataSourceType.Server && AutoBind.GetValueOrDefault(true);

            var columns = VisibleColumns.Select(c => c.ToJson());

            var idPrefix = "#";

            if (IsInClientTemplate)
            {
                idPrefix = "\\" + idPrefix;
            }

            if (columns.Any())
            {
                options["columns"] = columns;
            }

            if (Grouping.Enabled)
            {
                options["groupable"] = Grouping.ToJson();
            }

            if (Pageable.Enabled)
            {
                Pageable.AutoBind = autoBind;

                options["pageable"] = Pageable.ToJson();
            }

            if (Sortable.Enabled)
            {
                var sorting = Sortable.ToJson();
                options["sortable"] = sorting.Any() ? (object)sorting : true;
            }

            if (Selectable.Enabled)
            {
                options["selectable"] = String.Format("{0}, {1}", Selectable.Mode, Selectable.Type);
            }

            if (Filterable.Enabled)
            {
                var filtering = Filterable.ToJson();
                options["filterable"] = filtering.Any() ? (object)filtering : true;
            }

            if (ColumnMenu.Enabled)
            {
                var menu = ColumnMenu.ToJson();
                options["columnMenu"] = menu.Any() ? (object)menu : true;
            }

            if (Resizable.Enabled)
            {
                options["resizable"] = true;
            }

            if (Reorderable.Enabled)
            {
                options["reorderable"] = true;
            }

            if (!Scrollable.Enabled)
            {
                options["scrollable"] = false;
            }
            else
            {
                var scrolling = Scrollable.ToJson();
                if (scrolling.Any())
                {
                    options["scrollable"] = scrolling;
                }
            }

            if (Editable.Enabled)
            {
                options["editable"] = Editable.ToJson();
            }

            if (ToolBar.Enabled)
            {
                options["toolbar"] = ToolBar.ToJson();
            }

            if (autoBind == false)
            {
                options["autoBind"] = autoBind;
            }

            options["dataSource"] = DataSource.ToJson();

            if (!String.IsNullOrEmpty(ClientDetailTemplateId))
            {
                options["detailTemplate"] = new ClientHandlerDescriptor {
                    HandlerName = String.Format("kendo.template($('{0}{1}').html())", idPrefix, ClientDetailTemplateId)
                };
            }

            if (!String.IsNullOrEmpty(ClientRowTemplate))
            {
                options["rowTemplate"] = ClientRowTemplate;
            }

            if (Navigatable.Enabled)
            {
                options["navigatable"] = true;
            }

            writer.Write(Initializer.Initialize(Selector, "Grid", options));

            base.WriteInitializationScript(writer);
        }
Exemple #5
0
        public override void WriteInitializationScript(TextWriter writer)
        {
            var options = new Dictionary <string, object>(Events);

            // use client-side rendering if templates are set
            if (Items.Any() && this.UsesTemplates())
            {
                this.DataSource.Data = SerializeItems(Items);
                this.LoadOnDemand    = false;
            }

            if (!string.IsNullOrEmpty(DataSource.Transport.Read.Url))
            {
                options["dataSource"] = DataSource.ToJson();
            }
            else if (DataSource.Data != null)
            {
                options["dataSource"] = DataSource.Data;
            }

            if (DragAndDrop)
            {
                options["dragAndDrop"] = true;
            }

            if (!AutoBind)
            {
                options["autoBind"] = false;
            }

            if (!LoadOnDemand)
            {
                options["loadOnDemand"] = false;
            }

            if (!string.IsNullOrEmpty(DataTextField))
            {
                options["dataTextField"] = DataTextField;
            }

            if (!string.IsNullOrEmpty(DataUrlField))
            {
                options["dataUrlField"] = DataUrlField;
            }

            if (!string.IsNullOrEmpty(DataSpriteCssClassField))
            {
                options["dataSpriteCssClassField"] = DataSpriteCssClassField;
            }

            if (!string.IsNullOrEmpty(DataImageUrlField))
            {
                options["dataImageUrlField"] = DataImageUrlField;
            }

            var idPrefix = "#";

            if (IsInClientTemplate)
            {
                idPrefix = "\\" + idPrefix;
            }

            if (!string.IsNullOrEmpty(TemplateId))
            {
                options["template"] = new ClientHandlerDescriptor {
                    HandlerName = string.Format("$('{0}{1}').html()", idPrefix, TemplateId)
                };
            }
            else if (!string.IsNullOrEmpty(Template))
            {
                options["template"] = Template;
            }

            var checkboxes = Checkboxes.ToJson();

            if (checkboxes.Keys.Any())
            {
                options["checkboxes"] = checkboxes["checkboxes"];
            }

            var animation = Animation.ToJson();

            if (animation.Keys.Any())
            {
                options["animation"] = animation["animation"];
            }

            writer.Write(Initializer.Initialize(Selector, "TreeView", options));

            base.WriteInitializationScript(writer);
        }
Exemple #6
0
        protected virtual IDictionary <string, object> SeriailzeBaseOptions()
        {
            var options = new Dictionary <string, object>(Events);

            var idPrefix = "#";

            if (Date != null)
            {
                options["date"] = Date;
            }

            if (StartTime != null)
            {
                options["startTime"] = StartTime;
            }

            if (EndTime != null)
            {
                options["endTime"] = EndTime;
            }

            if (Height != null)
            {
                options["height"] = Height;
            }

            if (Editable != null)
            {
                if (Editable.Enable == false)
                {
                    options["editable"] = false;
                }
                else
                {
                    IDictionary <string, object> editable = Editable.ToJson();
                    if (editable.Count > 0)
                    {
                        options["editable"] = editable;
                    }
                }
            }

            if (!string.IsNullOrEmpty(EventTemplate))
            {
                options["eventTemplate"] = EventTemplate;
            }

            if (!string.IsNullOrEmpty(EventTemplateId))
            {
                options["eventTemplate"] = new ClientHandlerDescriptor {
                    HandlerName = String.Format("kendo.template($('{0}{1}').html())", idPrefix, EventTemplateId)
                };
            }

            if (!string.IsNullOrEmpty(AllDayEventTemplate))
            {
                options["allDayEventTemplate"] = AllDayEventTemplate;
            }

            if (!string.IsNullOrEmpty(AllDayEventTemplateId))
            {
                options["allDayEventTemplate"] = new ClientHandlerDescriptor {
                    HandlerName = String.Format("kendo.template($('{0}{1}').html())", idPrefix, AllDayEventTemplateId)
                };
            }

            if (!AllDaySlot)
            {
                options["allDaySlot"] = AllDaySlot;
            }

            if (Selectable)
            {
                options["selectable"] = Selectable;
            }

            if (!string.IsNullOrEmpty(DateHeaderTemplate))
            {
                options["dateHeaderTemplate"] = DateHeaderTemplate;
            }

            if (!string.IsNullOrEmpty(DateHeaderTemplateId))
            {
                options["dateHeaderTemplate"] = new ClientHandlerDescriptor {
                    HandlerName = String.Format("kendo.template($('{0}{1}').html())", idPrefix, DateHeaderTemplateId)
                };
            }

            if (MajorTick != null)
            {
                options["majorTick"] = MajorTick;
            }

            if (!string.IsNullOrEmpty(MajorTimeHeaderTemplate))
            {
                options["majorTimeHeaderTemplate"] = MajorTimeHeaderTemplate;
            }

            if (!string.IsNullOrEmpty(MajorTimeHeaderTemplateId))
            {
                options["majorTimeHeaderTemplate"] = new ClientHandlerDescriptor {
                    HandlerName = String.Format("kendo.template($('{0}{1}').html())", idPrefix, MajorTimeHeaderTemplateId)
                };
            }

            if (!string.IsNullOrEmpty(MinorTimeHeaderTemplate))
            {
                options["minorTimeHeaderTemplate"] = MinorTimeHeaderTemplate;
            }

            if (!string.IsNullOrEmpty(MinorTimeHeaderTemplateId))
            {
                options["minorTimeHeaderTemplate"] = new ClientHandlerDescriptor {
                    HandlerName = String.Format("kendo.template($('{0}{1}').html())", idPrefix, MinorTimeHeaderTemplateId)
                };
            }

            if (MinorTickCount != null)
            {
                options["minorTickCount"] = MinorTickCount;
            }

            if (!string.IsNullOrEmpty(Timezone))
            {
                options["timezone"] = Timezone;
            }

            if (Width != null)
            {
                options["width"] = Width;
            }

            if (Resources.Count > 0)
            {
                options["resources"] = Resources.ToJson();
            }

            if (Views.Count > 0)
            {
                options["views"] = Views.ToJson();
            }

            var messages = Messages.ToJson();

            if (messages.Count > 0)
            {
                options["messages"] = messages;
            }

            var group = Group.ToJson();

            if (group.Count > 0)
            {
                options["group"] = group;
            }

            Dictionary <string, object> dataSource = (Dictionary <string, object>)DataSource.ToJson();

            //TODO: update logic
            if (DataSource.Data != null)
            {
                dataSource["data"] = new { Data = DataSource.Data };
            }

            options["dataSource"] = dataSource;

            return(options);
        }