public ActionResult AddWidgetPOST(int layerId, string widgetType, string returnUrl)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel)))
            {
                return(new HttpUnauthorizedResult());
            }

            try {
                WidgetPart widgetPart = _widgetsService.CreateWidget(layerId, widgetType, "", "", "");
                if (widgetPart == null)
                {
                    return(HttpNotFound());
                }

                var model = Services.ContentManager.UpdateEditor(widgetPart, this);
                // override the CommonPart's persisting of the current container
                widgetPart.LayerPart = _widgetsService.GetLayer(layerId);
                if (!ModelState.IsValid)
                {
                    Services.TransactionManager.Cancel();
                    // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
                    return(View((object)model));
                }

                Services.Notifier.Information(T("Your {0} has been added.", widgetPart.TypeDefinition.DisplayName));
            } catch (Exception exception) {
                this.Error(exception, T("Creating widget failed: {0}", exception.Message), Logger, Services.Notifier);
            }

            return(this.RedirectLocal(returnUrl, () => RedirectToAction("Index")));
        }
Example #2
0
        public ActionResult AddWidgetPOST([Bind(Prefix = "WidgetPart.LayerId")] int layerId, string widgetType, string returnUrl)
        {
            if (!IsAuthorizedToManageWidgets())
            {
                return(new HttpUnauthorizedResult());
            }

            WidgetPart widgetPart = _widgetsService.CreateWidget(layerId, widgetType, "", "", "");

            if (widgetPart == null)
            {
                return(HttpNotFound());
            }

            var model = Services.ContentManager.UpdateEditor(widgetPart, this);

            try {
                // override the CommonPart's persisting of the current container
                widgetPart.LayerPart = _widgetsService.GetLayer(layerId);
            }
            catch (Exception exception) {
                Logger.Error(T("Creating widget failed: {0}", exception.Message).Text);
                Services.Notifier.Error(T("Creating widget failed: {0}", exception.Message));
                return(this.RedirectLocal(returnUrl, () => RedirectToAction("Index")));
            }
            if (!ModelState.IsValid)
            {
                Services.TransactionManager.Cancel();
                return(View(model));
            }

            Services.Notifier.Information(T("Your {0} has been added.", widgetPart.TypeDefinition.DisplayName));

            return(this.RedirectLocal(returnUrl, () => RedirectToAction("Index")));
        }
Example #3
0
        //[HttpPost, ActionName("AddWidget")]
        //[Orchard.Mvc.FormValueRequired("submit.Save")]
        public ActionResult AddWidgetPost(string widgetType, int hostId, Action <ContentItem> conditionallyPublish)
        {
            if (!IsAuthorizedToManageWidgets())
            {
                return(new HttpUnauthorizedResult());
            }

            // Check that the user has permission to create the widget before doing anything
            var dummyWidget = _services.ContentManager.New <WidgetPart>(widgetType);

            if (dummyWidget == null)
            {
                return(HttpNotFound());
            }
            if (!_services.Authorizer.Authorize(
                    Orchard.Core.Contents.Permissions.EditContent,
                    dummyWidget,
                    T("Cannot create widget")))
            {
                return(new HttpUnauthorizedResult());
            }

            var layer      = _widgetsService.GetLayers().First();
            var widgetPart = _widgetsService.CreateWidget(layer.Id, widgetType, "", "", "");

            if (widgetPart == null)
            {
                return(HttpNotFound());
            }
            else if (!widgetPart.ContentItem.TypeDefinition.Settings.GetModel <ContentTypeSettings>().Draftable &&
                     !widgetPart.ContentItem.Has <IPublishingControlAspect>())
            {
                _contentManager.Publish(widgetPart.ContentItem);
            }

            var contentItem = _services.ContentManager.Get(hostId, VersionOptions.Latest);

            var contentMetadata = _services.ContentManager.GetItemMetadata(contentItem);
            var returnUrl       = Url.RouteUrl(contentMetadata.EditorRouteValues);
            var model           = _services.ContentManager.UpdateEditor(widgetPart, this).HostId(hostId);

            var widgetExPart = widgetPart.As <WidgetExPart>();

            try {
                widgetPart.LayerPart = _widgetManager.GetContentLayer();
                widgetExPart.Host    = contentItem;
            } catch (Exception exception) {
                Logger.Error(T("Creating widget failed: {0}", exception.Message).Text);
                _services.Notifier.Error(T("Creating widget failed: {0}", exception.Message));
                return(Redirect(returnUrl));
            }
            if (!ModelState.IsValid)
            {
                _services.TransactionManager.Cancel();
                return(View((object)model));
            }
            conditionallyPublish(widgetPart.ContentItem);
            _services.Notifier.Information(T("Your {0} has been added.", widgetPart.TypeDefinition.DisplayName));
            return(Redirect(returnUrl));
        }
Example #4
0
        public ActionResult IndexPOST()
        {
            if (!_orchardServices.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to migrate the navigation.")))
            {
                return(new HttpUnauthorizedResult());
            }

            var menus = _menuService.GetMenus();

            if (menus.Any())
            {
                _orchardServices.Notifier.Error(T("This step is unnecessary as some menus already exist."));
                return(View());
            }

            // create a Main Menu
            var mainMenu = _menuService.Create("Main Menu");

            _orchardServices.Notifier.Success(T("Main menu created"));

            // assign the Main Menu to all current menu items
            foreach (var menuItem in _menuService.Get())
            {
                // if they don't have a position or a text, then they are not displayed
                if (string.IsNullOrWhiteSpace(menuItem.MenuPosition) || string.IsNullOrEmpty(menuItem.MenuText))
                {
                    continue;
                }
                menuItem.Menu = mainMenu.ContentItem;
            }
            _orchardServices.Notifier.Success(T("Menu items moved to Main menu"));

            // a widget should is created to display the navigation
            var layer = _widgetsService.GetLayers().FirstOrDefault(x => x.Name == "Default");

            if (layer == null)
            {
                _orchardServices.Notifier.Warning(T("Widget could not be created. Please create it manually."));
            }

            var widget = _widgetsService.CreateWidget(layer.Id, "MenuWidget", "Main Menu", "1.0", "Navigation");

            widget.RenderTitle = false;

            var menuWidget = widget.As <MenuWidgetPart>();

            menuWidget.MenuContentItemId = mainMenu.ContentItem.Id;

            menuWidget.StartLevel     = 1;
            menuWidget.Levels         = 1;
            menuWidget.Breadcrumb     = false;
            menuWidget.AddHomePage    = false;
            menuWidget.AddCurrentPage = false;

            _orchardServices.ContentManager.Publish(menuWidget.ContentItem);

            return(View("Index"));
        }
Example #5
0
        public void Create(string type)
        {
            var widgetTypeNames = _widgetsService.GetWidgetTypeNames();

            if (!widgetTypeNames.Contains(type))
            {
                Context.Output.WriteLine(T("Creating widget failed : type {0} was not found. Supported widget types are: {1}.",
                                           type,
                                           widgetTypeNames.Aggregate(String.Empty, (current, widgetType) => current + " " + widgetType)));
                return;
            }

            var layer = GetLayer(Layer);

            if (layer == null)
            {
                Context.Output.WriteLine(T("Creating widget failed : layer {0} was not found.", Layer));
                return;
            }

            var widget = _widgetsService.CreateWidget(layer.ContentItem.Id, type, T(Title).Text, Position, Zone);
            var text   = String.Empty;

            if (widget.Has <BodyPart>())
            {
                if (UseLoremIpsumText)
                {
                    text = T(LoremIpsum).Text;
                }
                else
                {
                    if (!String.IsNullOrEmpty(Text))
                    {
                        text = Text;
                    }
                }
                widget.As <BodyPart>().Text = text;
            }
            if (String.IsNullOrEmpty(Owner))
            {
                Owner = _siteService.GetSiteSettings().SuperUser;
            }
            var owner = _membershipService.GetUser(Owner);

            widget.As <ICommonPart>().Owner = owner;

            if (widget.Has <IdentityPart>() && !String.IsNullOrEmpty(Identity))
            {
                widget.As <IdentityPart>().Identifier = Identity;
            }

            Context.Output.WriteLine(T("Widget created successfully.").Text);
        }
Example #6
0
        private WidgetPart CreateWidget(string type)
        {
            var widgetTypeNames = _widgetsService.GetWidgetTypeNames().ToList();

            var layer = GetLayer(Layer);

            if (layer == null)
            {
                Context.Output.WriteLine(T("Creating widget failed : layer {0} was not found.", Layer));
                return(null);
            }

            var widget = _widgetsService.CreateWidget(layer.ContentItem.Id, type, T(Title).Text, WidgetPosition, Zone);

            if (!String.IsNullOrWhiteSpace(Name))
            {
                widget.Name = Name.Trim();
            }

            widget.RenderTitle = RenderTitle;

            if (widget.Has <MenuWidgetPart>() && !String.IsNullOrWhiteSpace(MenuName))
            {
                var menu = _menuService.GetMenu(MenuName);

                if (menu != null)
                {
                    widget.RenderTitle = false;
                    widget.As <MenuWidgetPart>().MenuContentItemId = menu.ContentItem.Id;
                }
            }

            if (String.IsNullOrEmpty(Owner))
            {
                Owner = _siteService.GetSiteSettings().SuperUser;
            }
            var owner = _membershipService.GetUser(Owner);

            widget.As <ICommonPart>().Owner = owner;

            if (widget.Has <IdentityPart>() && !String.IsNullOrEmpty(Identity))
            {
                widget.As <IdentityPart>().Identifier = Identity;
            }

            return(widget);
        }
        public ActionResult AddWidgetPost(string widgetType, int hostId)
        {
            if (!IsAuthorizedToManageWidgets())
            {
                return(new HttpUnauthorizedResult());
            }

            var layer      = _widgetsService.GetLayers().First();
            var widgetPart = _widgetsService.CreateWidget(layer.Id, widgetType, "", "", "");

            if (widgetPart == null)
            {
                return(HttpNotFound());
            }
            else
            {
                _contentManager.Publish(widgetPart.ContentItem);
            }

            var contentItem = _services.ContentManager.Get(hostId, VersionOptions.Latest);

            var contentMetadata = _services.ContentManager.GetItemMetadata(contentItem);
            var returnUrl       = Url.RouteUrl(contentMetadata.EditorRouteValues);
            var model           = _services.ContentManager.UpdateEditor(widgetPart, this).HostId(hostId);

            var widgetExPart = widgetPart.As <WidgetExPart>();

            try {
                widgetPart.LayerPart = _widgetManager.GetContentLayer();
                widgetExPart.Host    = contentItem;
            } catch (Exception exception) {
                Logger.Error(T("Creating widget failed: {0}", exception.Message).Text);
                _services.Notifier.Error(T("Creating widget failed: {0}", exception.Message));
                return(Redirect(returnUrl));
            }
            if (!ModelState.IsValid)
            {
                _services.TransactionManager.Cancel();
                return(View((object)model));
            }

            _services.Notifier.Information(T("Your {0} has been added.", widgetPart.TypeDefinition.DisplayName));
            return(Redirect(returnUrl));
        }
Example #8
0
        public void CreateWidget()
        {
            if (String.IsNullOrEmpty(Owner))
            {
                Owner = _siteService.GetSiteSettings().SuperUser;
            }

            var owner = _membershipService.GetUser(Owner);

            _authenticationService.SetAuthenticatedUserForRequest(owner);

            var layers    = this.widgetsService.GetLayers();
            var layer     = layers.First(c => c.Name == LayerName);
            var dashboard = widgetsService.CreateWidget(layer.Id, "TicketsDashboardWidget", Title, WidgetPosition, Zone);

            dashboard.Record.RenderTitle = RenderTitle;

            dashboard.As <ICommonPart>().Owner = owner;

            _contentManager.Publish(dashboard.ContentItem);
            Context.Output.WriteLine(T("Dashboard created successfully.").Text);
        }
        public void Create(string type)
        {
            var widgetTypeNames = _widgetsService.GetWidgetTypeNames().ToList();

            if (!widgetTypeNames.Contains(type))
            {
                Context.Output.WriteLine(T("Creating widget failed : type {0} was not found. Supported widget types are: {1}.",
                                           type,
                                           string.Join(" ", widgetTypeNames)));
                return;
            }

            var layer = GetLayer(Layer);

            if (layer == null)
            {
                Context.Output.WriteLine(T("Creating widget failed : layer {0} was not found.", Layer));
                return;
            }

            var widget = _widgetsService.CreateWidget(layer.ContentItem.Id, type, T(Title).Text, Position, Zone);

            if (!String.IsNullOrWhiteSpace(Name))
            {
                widget.Name = Name.Trim();
            }

            var text = String.Empty;

            if (widget.Has <BodyPart>())
            {
                if (UseLoremIpsumText)
                {
                    text = T(LoremIpsum).Text;
                }
                else
                {
                    if (!String.IsNullOrEmpty(Text))
                    {
                        text = Text;
                    }
                }
                widget.As <BodyPart>().Text = text;
            }

            widget.RenderTitle = RenderTitle;

            if (widget.Has <MenuWidgetPart>() && !String.IsNullOrWhiteSpace(MenuName))
            {
                var menu = _menuService.GetMenu(MenuName);

                if (menu != null)
                {
                    widget.RenderTitle = false;
                    widget.As <MenuWidgetPart>().MenuContentItemId = menu.ContentItem.Id;
                }
            }

            if (String.IsNullOrEmpty(Owner))
            {
                Owner = _siteService.GetSiteSettings().SuperUser;
            }
            var owner = _membershipService.GetUser(Owner);

            widget.As <ICommonPart>().Owner = owner;

            if (widget.Has <IdentityPart>() && !String.IsNullOrEmpty(Identity))
            {
                widget.As <IdentityPart>().Identifier = Identity;
            }

            _contentManager.Publish(widget.ContentItem);
            Context.Output.WriteLine(T("Widget created successfully.").Text);
        }
        public WidgetPart CreateBaseWidget(CommandContext context, string type, string title, string name, string zone, string position, string layer, string identity, bool renderTitle, string owner, string text, bool useLoremIpsumText, string menuName)
        {
            var widgetTypeNames = _widgetsService.GetWidgetTypeNames().ToList();

            if (!widgetTypeNames.Contains(type))
            {
                context.Output.WriteLine(T("Creating widget failed : type {0} was not found. Supported widget types are: {1}.",
                                           type,
                                           string.Join(" ", widgetTypeNames)));
                return(null);
            }

            var layerPart = GetLayer(layer);

            if (layerPart == null)
            {
                context.Output.WriteLine(T("Creating widget failed : layer {0} was not found.", layer));
                return(null);
            }

            var widget = _widgetsService.CreateWidget(layerPart.ContentItem.Id, type, T(title).Text, position, zone);

            if (!String.IsNullOrWhiteSpace(name))
            {
                widget.Name = name.Trim();
            }

            var widgetText = String.Empty;

            if (widget.Has <BodyPart>())
            {
                if (useLoremIpsumText)
                {
                    widgetText = T(LoremIpsum).Text;
                }
                else
                {
                    if (!String.IsNullOrEmpty(text))
                    {
                        widgetText = text;
                    }
                }
                widget.As <BodyPart>().Text = text;
            }

            widget.RenderTitle = renderTitle;

            if (widget.Has <MenuWidgetPart>() && !String.IsNullOrWhiteSpace(menuName))
            {
                var menu = _menuService.GetMenu(menuName);

                if (menu != null)
                {
                    widget.As <MenuWidgetPart>().MenuContentItemId = menu.ContentItem.Id;
                }
            }

            if (String.IsNullOrEmpty(owner))
            {
                owner = _siteService.GetSiteSettings().SuperUser;
            }
            var widgetOwner = _membershipService.GetUser(owner);

            widget.As <ICommonPart>().Owner = widgetOwner;

            if (widget.Has <IdentityPart>() && !String.IsNullOrEmpty(identity))
            {
                widget.As <IdentityPart>().Identifier = identity;
            }

            return(widget);
        }
Example #11
0
        public void Create(string type)
        {
            var widgetTypeNames = _widgetsService.GetWidgetTypeNames();

            if (!widgetTypeNames.Contains(type))
            {
                Context.Output.WriteLine(T("Creating widget failed : type {0} was not found. Supported widget types are: {1}.",
                                           type,
                                           widgetTypeNames.Aggregate(String.Empty, (current, widgetType) => current + " " + widgetType)));
                return;
            }

            var layer = GetLayer(Layer);

            if (layer == null)
            {
                Context.Output.WriteLine(T("Creating widget failed : layer {0} was not found.", Layer));
                return;
            }

            var widget = _widgetsService.CreateWidget(layer.ContentItem.Id, type, T(Title).Text, Position, Zone);
            var text   = String.Empty;

            if (widget.Has <BodyPart>())
            {
                if (UseLoremIpsumText)
                {
                    text = T(LoremIpsum).Text;
                }
                else
                {
                    if (!String.IsNullOrEmpty(Text))
                    {
                        text = Text;
                    }
                }
                widget.As <BodyPart>().Text = text;
            }

            widget.RenderTitle = RenderTitle;

            if (widget.Has <MenuWidgetPart>() && !String.IsNullOrWhiteSpace(MenuName))
            {
                // flushes before doing a query in case a previous command created the menu
                _contentManager.Flush();

                var menu = _menuService.GetMenu(MenuName);

                if (menu != null)
                {
                    widget.RenderTitle = false;
                    widget.As <MenuWidgetPart>().Menu = menu.ContentItem.Record;
                }
            }

            if (String.IsNullOrEmpty(Owner))
            {
                Owner = _siteService.GetSiteSettings().SuperUser;
            }
            var owner = _membershipService.GetUser(Owner);

            widget.As <ICommonPart>().Owner = owner;

            if (widget.Has <IdentityPart>() && !String.IsNullOrEmpty(Identity))
            {
                widget.As <IdentityPart>().Identifier = Identity;
            }

            Context.Output.WriteLine(T("Widget created successfully.").Text);
        }