Exemplo n.º 1
0
        public ActionResult EditWidget(int id)
        {
            if (!IsAuthorizedToManageWidgets())
            {
                return(new HttpUnauthorizedResult());
            }

            WidgetPart widgetPart = null;

            widgetPart = _widgetsService.GetWidget(id);
            if (widgetPart == null)
            {
                Services.Notifier.Error(T("Widget not found: {0}", id));
                return(RedirectToAction("Index"));
            }
            try {
                var model = Services.ContentManager.BuildEditor(widgetPart);
                return(View(model));
            }
            catch (Exception exception) {
                Logger.Error(T("Editing widget failed: {0}", exception.Message).Text);
                Services.Notifier.Error(T("Editing widget failed: {0}", exception.Message));

                if (widgetPart != null && widgetPart.LayerPart != null)
                {
                    return(RedirectToAction("Index", "Admin", new { layerId = widgetPart.LayerPart.Id }));
                }

                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 2
0
        public ActionResult EditWidget(int hostId, int id)
        {
            if (!IsAuthorizedToManageWidgets())
            {
                return(new HttpUnauthorizedResult());
            }

            var contentItem     = _services.ContentManager.Get(hostId, VersionOptions.Latest);
            var contentMetadata = _services.ContentManager.GetItemMetadata(contentItem);
            var returnUrl       = Url.RouteUrl(contentMetadata.EditorRouteValues);
            var widgetPart      = _widgetsService.GetWidget(id);

            if (widgetPart == null)
            {
                _services.Notifier.Error(T("Widget not found: {0}", id));
                return(Redirect(returnUrl));
            }
            try {
                var model = _services.ContentManager.BuildEditor(widgetPart).HostId(hostId);
                return(View(model));
            }
            catch (Exception exception) {
                Logger.Error(T("Editing widget failed: {0}", exception.Message).Text);
                _services.Notifier.Error(T("Editing widget failed: {0}", exception.Message));

                return(Redirect(returnUrl));
            }
        }
Exemplo n.º 3
0
        private void RemoveWidgets(WidgetsContainerViewModel viewModel)
        {
            if (string.IsNullOrEmpty(viewModel.RemovedWidgets))
            {
                return;
            }

            var widgetIds = JsonConvert.DeserializeObject <int[]>(viewModel.RemovedWidgets);

            var unableToDeleteSome = false;

            foreach (var widgetId in widgetIds)
            {
                // make sure that the user is allowed to delete the widget.
                // Doing this check here handles cases where the UI is not aligned with the
                // configuration, because the latter changed but the former hasn't updated
                // yet.
                var currentWidget = _widgetsService.GetWidget(widgetId);
                if (_authorizer.Authorize(
                        Orchard.Core.Contents.Permissions.DeleteContent, currentWidget))
                {
                    _widgetsService.DeleteWidget(widgetId);
                }
                else
                {
                    unableToDeleteSome = true;
                }
            }
            if (unableToDeleteSome)
            {
                _notifier.Warning(T("You don't have the permissions to remove some of the widgets you attempted to delete."));
            }
        }
Exemplo n.º 4
0
        public ActionResult EditWidget(int id)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel)))
            {
                return(new HttpUnauthorizedResult());
            }

            WidgetPart widgetPart = null;

            try {
                widgetPart = _widgetsService.GetWidget(id);
                if (widgetPart == null)
                {
                    Services.Notifier.Error(T("Widget not found: {0}", id));
                    return(RedirectToAction("Index"));
                }

                dynamic model = Services.ContentManager.BuildEditor(widgetPart);
                // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
                return(View((object)model));
            }
            catch (Exception exception) {
                this.Error(exception, T("Editing widget failed: {0}", exception.Message), Logger, Services.Notifier);

                if (widgetPart != null && widgetPart.LayerPart != null)
                {
                    return(RedirectToAction("Index", "Admin", new { layerId = widgetPart.LayerPart.Id }));
                }

                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 5
0
        private void UpdatePositions(WidgetsContainerViewModel viewModel)
        {
            if (string.IsNullOrEmpty(viewModel.WidgetPlacement))
            {
                return;
            }

            var data      = JsonConvert.DeserializeXNode(viewModel.WidgetPlacement);
            var zonesNode = data.Root;

            foreach (var zoneNode in zonesNode.Elements())
            {
                var zoneName       = zoneNode.Name.ToString();
                var widgetElements = zoneNode.Elements("widgets");
                var position       = 0;

                foreach (var widget in widgetElements
                         .Select(widgetNode => XmlConvert.ToInt32(widgetNode.Value))
                         .Select(widgetId => _widgetsService.GetWidget(widgetId))
                         .Where(widget => widget != null))
                {
                    widget.Position = (position++).ToString();
                    widget.Zone     = zoneName;
                }
            }
        }