Example #1
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;
                }
            }
        }
Example #2
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."));
            }
        }
        private void RemoveWidgets(WidgetsContainerViewModel viewModel) {
            if (string.IsNullOrEmpty(viewModel.RemovedWidgets))
                return;

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

            foreach (var widgetId in widgetIds) {
                _widgetsService.DeleteWidget(widgetId);
            }
        }
        protected override DriverResult Editor(WidgetsContainerPart part, IUpdateModel updater, dynamic shapeHelper) {
            var viewModel = new WidgetsContainerViewModel();
            if (updater.TryUpdateModel(viewModel, null, null, null)) {
                UpdatePositions(viewModel);
                RemoveWidgets(viewModel);
                CloneWidgets(viewModel, part.ContentItem);

            }

            return Editor(part, shapeHelper);
        }
Example #5
0
 private void CloneWidgets(WidgetsContainerViewModel viewModel, ContentItem hostContentItem)
 {
     CloneWidgets(viewModel.CloneFrom, hostContentItem);
 }