Beispiel #1
0
        public override void Render(HtmlTextWriter output, Ribbon ribbon, Item button, CommandContext context)
        {
            var viewName    = context.Parameters["viewName"];
            var ruleContext = new RuleContext
            {
                Item = context.CustomData as Item
            };

            ruleContext.Parameters["ViewName"] = viewName;

            ShowListViewFeatures features;
            var showShared = Enum.TryParse(context.Parameters["features"] ?? "", out features) &&
                             features.HasFlag(ShowListViewFeatures.SharedExport);

            foreach (
                Item scriptItem in
                ModuleManager.GetFeatureRoots(IntegrationPoints.ReportExportFeature)
                .SelectMany(parent => parent.Children)
                .Where(scriptItem => RulesUtils.EvaluateRulesForView(scriptItem[FieldNames.ShowRule], ruleContext, !showShared)))
            {
                RenderSmallButton(output, ribbon, Control.GetUniqueID("export"),
                                  Translate.Text(scriptItem.DisplayName),
                                  scriptItem[Sitecore.FieldIDs.Icon], scriptItem.Appearance.ShortDescription,
                                  string.Format("export:results(scriptDb={0},scriptID={1})", scriptItem.Database.Name,
                                                scriptItem.ID),
                                  RulesUtils.EvaluateRules(scriptItem[FieldNames.EnableRule], context.CustomData as Item) &&
                                  context.Parameters["ScriptRunning"] == "0",
                                  false);
            }
        }
Beispiel #2
0
        public override void Render(HtmlTextWriter output, Ribbon ribbon, Item button, CommandContext context)
        {
            if (!ServiceAuthorizationManager.IsUserAuthorized(WebServiceSettings.ServiceExecution, Context.User.Name))
            {
                return;
            }
            var psButtons = button.GetChildren();

            foreach (Item psButton in psButtons)
            {
                var command  = (psButton.Fields["Click"] ?? psButton.Fields["Command"]).Value;
                var msg      = Message.Parse(this, command);
                var scriptDb = msg.Arguments["scriptDB"];
                var scriptId = msg.Arguments["script"];

                if (string.IsNullOrWhiteSpace(scriptDb) || string.IsNullOrWhiteSpace(scriptId))
                {
                    continue;
                }

                var scriptItem = Factory.GetDatabase(scriptDb).GetItem(scriptId);

                if (!scriptItem.IsPowerShellScript() ||
                    !RulesUtils.EvaluateRules(scriptItem[Templates.Script.Fields.ShowRule], context.Items[0]))
                {
                    continue;
                }

                RenderButton(output, psButton.TemplateID, ribbon, Control.GetUniqueID("script"),
                             Translate.Text(psButton.DisplayName), scriptItem["__Icon"], scriptItem[TemplateFieldIDs.ToolTip],
                             command, RulesUtils.EvaluateRules(scriptItem[Templates.Script.Fields.EnableRule], context.Items[0]), context,
                             psButton.Paths.Path);
            }
        }
        public override void Render(HtmlTextWriter output, Ribbon ribbon, Item button, CommandContext context)
        {
            var psButtons = button.GetChildren();

            foreach (Item psButton in psButtons)
            {
                var msg      = Message.Parse(this, psButton["Click"]);
                var scriptDb = msg.Arguments["scriptDB"];
                var scriptId = msg.Arguments["script"];

                if (string.IsNullOrWhiteSpace(scriptDb) || string.IsNullOrWhiteSpace(scriptId))
                {
                    continue;
                }

                var scriptItem = Factory.GetDatabase(scriptDb).GetItem(scriptId);
                if (scriptItem == null || !RulesUtils.EvaluateRules(scriptItem["ShowRule"], context.Items[0]))
                {
                    continue;
                }

                RenderLargeButton(output, ribbon, Control.GetUniqueID("script"),
                                  Translate.Text(scriptItem.DisplayName),
                                  scriptItem["__Icon"], string.Empty,
                                  psButton["Click"],
                                  RulesUtils.EvaluateRules(scriptItem["EnableRule"], context.Items[0]),
                                  false, context);

                return;
            }
        }
        public void RenderLargeButton(HtmlTextWriter output, Ribbon ribbon, string id, string header, string icon,
                                      string tooltip, string command, bool enabled, bool down, CommandContext context)
        {
            var buttonId    = Control.GetUniqueID("script");
            var largeButton = new LargeButton
            {
                ID      = buttonId,
                Header  = header,
                Icon    = icon,
                Down    = down,
                Enabled = enabled,
                ToolTip = tooltip,
                Command = GetClick(command, context, buttonId),
            };

            largeButton.RenderControl(output);
        }
Beispiel #5
0
        private void ResolveControlFromField()
        {
            var contentEditorPage = Page as ContentEditorPage;

            if (!(contentEditorPage?.CodeBeside is ContentEditorForm codeBeside))
            {
                return;
            }

            var itemUri = typeof(ContentEditorForm)
                          .GetProperty("CurrentItem", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
                          ?.GetValue(codeBeside) as ItemUri;

            if (!(codeBeside.FieldInfo[ID] is FieldInfo fieldInfo) || itemUri == null)
            {
                return;
            }

            var database = Factory.GetDatabase(itemUri.DatabaseName);
            var item     = database.GetItem(itemUri.ItemID);

            var feild          = item.Fields[fieldInfo.FieldID];
            var fieldType      = database.GetItem(feild.ID);
            var fieldTypeValue = fieldType["Type"];

            const string indexName = "sitecore_core_index";

            using (var index = ContentSearchManager.GetIndex(indexName).CreateSearchContext())
            {
                var query = index.GetQueryable <SearchResultItem>()
                            .Where(i => i.TemplateId == new ID())
                            .Where(i => i.Name == fieldTypeValue);


                var searchResults = query.GetResults();

                var typeValue = searchResults.Hits.SingleOrDefault()?.Document.Fields["Type"];

                var controlType = Type.GetType(typeValue.ToString());
                _control = ResolveControl(controlType);
            }
        }
Beispiel #6
0
        public override void Render(HtmlTextWriter output, Ribbon ribbon, Item button, CommandContext context)
        {
            var typeName    = context.Parameters["type"];
            var viewName    = context.Parameters["viewName"];
            var ruleContext = new RuleContext
            {
                Item = context.CustomData as Item
            };

            ruleContext.Parameters["ViewName"] = viewName;

            var showShared = Enum.TryParse(context.Parameters["features"] ?? "", out ShowListViewFeatures features) &&
                             features.HasFlag(ShowListViewFeatures.SharedActions);

            if (string.IsNullOrEmpty(typeName))
            {
                return;
            }

            foreach (
                var scriptItem in
                ModuleManager.GetFeatureRoots(IntegrationPoints.ReportActionFeature)
                .Select(parent => parent.Paths.GetSubItem(typeName))
                .Where(scriptLibrary => scriptLibrary != null)
                .SelectMany(scriptLibrary => scriptLibrary.Children)
                .Where(
                    scriptItem =>
                    RulesUtils.EvaluateRulesForView(scriptItem[FieldNames.ShowRule], ruleContext, !showShared)))
            {
                RenderSmallButton(output, ribbon, Control.GetUniqueID("export"),
                                  Translate.Text(scriptItem.DisplayName),
                                  scriptItem["__Icon"], scriptItem.Appearance.ShortDescription,
                                  $"listview:action(scriptDb={scriptItem.Database.Name},scriptID={scriptItem.ID})",
                                  RulesUtils.EvaluateRules(scriptItem[FieldNames.EnableRule], ruleContext) &&
                                  context.Parameters["ScriptRunning"] == "0",
                                  false);
            }
        }
Beispiel #7
0
        public override void Render(HtmlTextWriter output, Ribbon ribbon, Item button, CommandContext context)
        {
            var contextChunks = context.CustomData as List <Item>;

            if (contextChunks != null)
            {
                var chunk = contextChunks[0];
                contextChunks.RemoveAt(0);
                var psButtons   = chunk.Children;
                var contextItem = context.Items.Length > 0 ? context.Items[0] : null;

                var ruleContext = new RuleContext
                {
                    Item = contextItem
                };
                foreach (var parameter in context.Parameters.AllKeys)
                {
                    ruleContext.Parameters[parameter] = context.Parameters[parameter];
                }

                foreach (Item psButton in psButtons)
                {
                    if (!RulesUtils.EvaluateRules(psButton[FieldNames.ShowRule], ruleContext))
                    {
                        continue;
                    }

                    RenderLargeButton(output, ribbon, Control.GetUniqueID("script"),
                                      Translate.Text(psButton.DisplayName),
                                      psButton[Sitecore.FieldIDs.Icon], string.Empty,
                                      $"ise:runplugin(scriptDb={psButton.Database.Name},scriptId={psButton.ID})",
                                      context.Parameters["ScriptRunning"] == "0" && RulesUtils.EvaluateRules(psButton[FieldNames.EnableRule], ruleContext),
                                      false, context);
                }
            }
        }
Beispiel #8
0
        public void RenderButton(HtmlTextWriter output, ID buttonTemplateId, Ribbon ribbon, string id, string header, string icon,
                                 string tooltip, string command, bool enabled, CommandContext context, string menuPath)
        {
            var buttonId = Control.GetUniqueID("script");

            if (buttonTemplateId == Ribbon.LargeButton)
            {
                var button = new LargeButton
                {
                    ID      = buttonId,
                    Header  = header,
                    Icon    = icon,
                    Enabled = enabled,
                    ToolTip = tooltip,
                    Command = GetClick(command, context, buttonId),
                };
                button.RenderControl(output);
            }
            else if (buttonTemplateId == Ribbon.LargeMenuComboButton)
            {
                var button = new LargeMenuComboButton
                {
                    ID             = buttonId,
                    Header         = header,
                    Icon           = icon,
                    Enabled        = enabled,
                    ToolTip        = tooltip,
                    Command        = GetClick(command, context, buttonId),
                    CommandContext = context,
                    Menu           = menuPath
                };
                button.RenderControl(output);
            }
            else if (buttonTemplateId == Ribbon.SmallButton)
            {
                var button = new SmallButton
                {
                    ID      = buttonId,
                    Header  = header,
                    Icon    = icon,
                    Enabled = enabled,
                    ToolTip = tooltip,
                    Command = GetClick(command, context, buttonId),
                };
                ribbon.RenderSmallButton(output, button);
            }
            else if (buttonTemplateId == Ribbon.SmallMenuComboButton)
            {
                var button = new SmallMenuComboButton
                {
                    ID             = buttonId,
                    Header         = header,
                    Icon           = icon,
                    Enabled        = enabled,
                    ToolTip        = tooltip,
                    Command        = GetClick(command, context, buttonId),
                    CommandContext = context,
                    Menu           = menuPath
                };
                ribbon.RenderSmallButton(output, button);
            }
        }