コード例 #1
0
 protected new void Add()
 {
     if (!this.Disabled)
     {
         string     viewStateString = base.GetViewStateString("ID");
         TreeviewEx treeviewEx      = this.FindControl(viewStateString + "_all") as TreeviewEx;
         Assert.IsNotNull(treeviewEx, typeof(DataTreeview));
         Listbox listbox = this.FindControl(viewStateString + "_selected") as Listbox;
         Assert.IsNotNull(listbox, typeof(Listbox));
         Item selectionItem = treeviewEx.GetSelectionItem();
         if (selectionItem == null)
         {
             SheerResponse.Alert("Select an item in the Content Tree.", new string[0]);
         }
         else if (!this.HasExcludeTemplateForSelection(selectionItem))
         {
             if (this.IsDeniedMultipleSelection(selectionItem, listbox))
             {
                 SheerResponse.Alert("You cannot select the same item twice.", new string[0]);
             }
             else if (this.HasIncludeTemplateForSelection(selectionItem))
             {
                 SheerResponse.Eval("scForm.browser.getControl('" + viewStateString + "_selected').selectedIndex=-1");
                 ListItem control = new ListItem();
                 control.ID = GetUniqueID("L");
                 Sitecore.Context.ClientPage.AddControl(listbox, control);
                 control.Header = selectionItem.DisplayName;
                 control.Value  = control.ID + "|" + selectionItem.ID;
                 SheerResponse.Refresh(listbox);
                 SetModified();
             }
         }
     }
 }
コード例 #2
0
        protected override void OnLoad(EventArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            base.OnLoad(args);

            if (!Sitecore.Context.ClientPage.IsEvent)
            {
                // find the existing TreeviewEx that the base OnLoad added, get a ref to its parent, and remove it from controls
                TreeviewEx existingTreeView = (TreeviewEx)WebUtil.FindControlOfType(this, typeof(TreeviewEx));
                Control    treeviewParent   = existingTreeView.Parent;

                existingTreeView.Parent.Controls.Clear(); // remove stock treeviewex, we replace with multiroot

                // find the existing DataContext that the base OnLoad added, get a ref to its parent, and remove it from controls
                DataContext dataContext       = (DataContext)WebUtil.FindControlOfType(this, typeof(DataContext));
                Control     dataContextParent = dataContext.Parent;

                dataContextParent.Controls.Remove(dataContext); // remove stock datacontext, we parse our own

                // create our MultiRootTreeview to replace the TreeviewEx
                MultiRootTreeview impostor = new Sitecore.Web.UI.WebControls.MultiRootTreeview();
                impostor.ID               = existingTreeView.ID;
                impostor.DblClick         = existingTreeView.DblClick;
                impostor.Enabled          = existingTreeView.Enabled;
                impostor.DisplayFieldName = existingTreeView.DisplayFieldName;

                // parse the data source and create appropriate data contexts out of it
                DataContext[] dataContexts = ParseDataContexts(dataContext);

                impostor.DataContext = string.Join("|", dataContexts.Select(x => x.ID));
                foreach (var context in dataContexts)
                {
                    dataContextParent.Controls.Add(context);
                }

                // inject our replaced control where the TreeviewEx originally was
                treeviewParent.Controls.Add(impostor);
            }
        }
コード例 #3
0
        /// <summary>
        /// Raises the load event.
        ///
        /// </summary>
        /// <param name="args">The arguments.</param><contract><requires name="args" condition="not null"/></contract>
        protected override void OnLoad(EventArgs args)
        {
            var loggingService = ObjectFactory.Instance.Resolve <ILoggingService>();
            var stopwatch      = new Stopwatch();

            loggingService.Log <CategoriesTreelist>("Starting CategoriesTreelist.OnLoad() ...");

            stopwatch.Start();

            Assert.ArgumentNotNull(args, "args");
            if (!ScContext.ClientPage.IsEvent)
            {
                SetProperties();
                var border1 = new Border();
                Controls.Add(border1);
                GetControlAttributes();
                foreach (string key in Attributes.Keys)
                {
                    border1.Attributes.Add(key, Attributes[key]);
                }
                border1.Attributes["id"] = ID;
                var border2 = new Border {
                    Class = "scTreeListHalfPart"
                };
                var border3 = border2;
                border1.Controls.Add(border3);
                var border4 = new Border();
                border3.Controls.Add(border4);
                SetViewStateString("ID", ID);
                var controls1 = border4.Controls;
                var literal1  = new Literal("All")
                {
                    Class = "scContentControlMultilistCaption"
                };
                var literal2 = literal1;
                controls1.Add(literal2);
                var scrollbox1 = new Scrollbox
                {
                    ID    = GetUniqueID("S"),
                    Class = "scScrollbox scContentControlTree"
                };
                var scrollbox2 = scrollbox1;
                border4.Controls.Add(scrollbox2);
                var treeviewEx = new TreeviewEx {
                    ID = ID + "_all", DblClick = ID + ".Add", AllowDragging = false
                };
                scrollbox2.Controls.Add(treeviewEx);
                var border5 = new Border {
                    Class = "scContentControlNavigation"
                };
                var border6 = border5;
                border3.Controls.Add(border6);
                var literalControl1 = new LiteralControl(new ImageBuilder
                {
                    Src     = "Applications/16x16/nav_right_blue.png",
                    ID      = (ID + "_right"),
                    OnClick = ScContext.ClientPage.GetClientEvent(ID + ".Add")
                }.ToString() + new ImageBuilder
                {
                    Src     = "Applications/16x16/nav_left_blue.png",
                    ID      = (ID + "_left"),
                    OnClick = ScContext.ClientPage.GetClientEvent(ID + ".Remove")
                });
                border6.Controls.Add(literalControl1);
                var border7 = new Border {
                    Class = "scTreeListHalfPart"
                };
                var border8 = border7;
                border1.Controls.Add(border8);
                var border9 = new Border {
                    Class = "scFlexColumnContainerWithoutFlexie"
                };
                var border10 = border9;
                border8.Controls.Add(border10);
                var controls2 = border10.Controls;
                var literal3  = new Literal("Selected")
                {
                    Class = "scContentControlMultilistCaption"
                };
                var literal4 = literal3;
                controls2.Add(literal4);
                var border11 = new Border {
                    Class = "scContentControlSelectedList"
                };
                var border12 = border11;
                border10.Controls.Add(border12);
                var listbox = new Listbox();
                border12.Controls.Add(listbox);
                _listBox                       = listbox;
                listbox.ID                     = ID + "_selected";
                listbox.DblClick               = ID + ".Remove";
                listbox.Style["width"]         = "100%";
                listbox.Size                   = "10";
                listbox.Attributes["onchange"] = "javascript:document.getElementById('" + ID +
                                                 "_help').innerHTML=this.selectedIndex>=0?this.options[this.selectedIndex].innerHTML:''";
                listbox.Attributes["class"] = "scContentControlMultilistBox scFlexContentWithoutFlexie";
                _listBox.TrackModified      = false;
                treeviewEx.Enabled          = !ReadOnly;
                listbox.Disabled            = ReadOnly;
                border10.Controls.Add(
                    new LiteralControl("<div class='scContentControlTreeListHelp' id=\"" + ID + "_help\"></div>"));
                var border13 = new Border {
                    Class = "scContentControlNavigation"
                };
                var border14 = border13;
                border8.Controls.Add(border14);
                var literalControl2 = new LiteralControl(new ImageBuilder
                {
                    Src     = "Applications/16x16/nav_up_blue.png",
                    ID      = (ID + "_up"),
                    OnClick = ScContext.ClientPage.GetClientEvent(ID + ".Up")
                }.ToString() + new ImageBuilder
                {
                    Src     = "Applications/16x16/nav_down_blue.png",
                    ID      = (ID + "_down"),
                    OnClick = ScContext.ClientPage.GetClientEvent(ID + ".Down")
                });
                border14.Controls.Add(literalControl2);
                var dataContext = new DataContext();
                border1.Controls.Add(dataContext);
                dataContext.ID              = GetUniqueID("D");
                dataContext.Filter          = FormTemplateFilterForDisplay();
                treeviewEx.DataContext      = dataContext.ID;
                treeviewEx.DisplayFieldName = DisplayFieldName;
                dataContext.DataViewName    = "Master";
                if (!string.IsNullOrEmpty(DatabaseName))
                {
                    dataContext.Parameters = "databasename=" + DatabaseName;
                }
                dataContext.Root     = DataSource;
                dataContext.Language = Language.Parse(ItemLanguage);
                treeviewEx.ShowRoot  = true;
                RestoreState();
            }
            base.OnLoad(args);

            stopwatch.Stop();
            loggingService.Log <CategoriesTreelist>(string.Format("CategoriesTreelist.OnLoad() took {0} ms", stopwatch.ElapsedMilliseconds));
        }