public PartialViewResult AddTarget(AdminWidgetsModel model, string error)
    {
      var m = new AdminWidgetSelectModel();
      m.SelectionTitle = "Select New Page or Widget";

      // get list of pages from container            
      var container = (IContainer)HttpContext.Application["container"];
      //SupportedScopes scope = SupportedScopes.EntireSite; //TODO: get correct scope

      m.WidgetSelections = container.GetAllInstances<IPage>()//.Where(w => (w.SupportedScopes & scope) == scope)
          .Select(p => new WidgetSelect()
          {
            Name = p.Name,
            Description = string.Format("{0} with {1} area{2}",
              p.Parent == null ? "<em>Master</em> page" : "Page", p.Areas.Count(), p.Areas.Count() == 1 ? string.Empty : "s"),
            ScopeFlags = (int)p.SupportedScopes,
            Icon = "page",
            PostHref = Url.Action("AddTarget", new
            {
              workspace = Scope.Workspace,
              collection = Scope.Collection,
              targetType = "page",
              targetName = p.Name
            })
          }).Concat(container.GetAllInstances<IWidget>().Where(w => w.Areas.Count() > 0) //.Where(w => (w.SupportedScopes & scope) == scope)
          .Select(w => new WidgetSelect()
          {
            Name = w.Name,
            Description = w.Description,
            ScopeFlags = (int)w.SupportedScopes,
            Icon = "widget",
            PostHref = Url.Action("AddTarget", new
            {
              workspace = Scope.Workspace,
              collection = Scope.Collection,
              targetType = "widget",
              targetName = w.Name
            })
          }));

      m.Error = error;
      m.CancelHref = Url.Action("AdminTargets", new
      {
        workspace = Scope.Workspace,
        collection = Scope.Collection,
        targetType = model.TargetType,
        targetName = model.TargetName,
        pageName = model.PageName
      });
      return PartialView("AdminWidgetSelect", m);
    }
    public PartialViewResult AddInclude(AdminWidgetsModel model, string error)
    {
      AdminWidgetSelectModel m = new AdminWidgetSelectModel();
      m.SelectionTitle = "Select a Widget Include";

      var container = (IContainer)HttpContext.Application["container"];
      //SupportedScopes scope = SupportedScopes.EntireSite; //TODO: get correct scope

      m.WidgetSelections = container.GetAllInstances<IWidget>()//.Where(w => (w.SupportedScopes & scope) == scope)
          .Select(w => new WidgetSelect()
          {
            Name = w.Name,
            Description = w.Description ?? "This widget has no description.",
            ScopeFlags = (int)w.SupportedScopes,
            Icon = "widget",
            IsHint = w.AreaHints.Contains(model.AreaName),
            ScopeMatch = IsScopeMatch(container, w.SupportedScopes, model.TargetType, model.TargetName),
            PostHref = Url.Action("AddInclude", new
            {
              workspace = Scope.Workspace,
              collection = Scope.Collection,
              targetType = model.TargetType,
              targetName = model.TargetName,
              areaName = model.AreaName,
              includeName = w.Name
            })
          }).OrderByDescending(w => w.IsHint).ThenByDescending(w => w.ScopeMatch);
      m.Error = error;
      m.CancelHref = Url.Action("AdminIncludes", new
      {
        workspace = Scope.Workspace,
        collection = Scope.Collection,
        targetType = model.TargetType,
        targetName = model.TargetName,
        pageName = model.PageName
      });
      return PartialView("AdminWidgetSelect", m);
    }
    public PartialViewResult AddArea(AdminWidgetsModel model, string error)
    {
      var m = new AdminWidgetSelectModel();
      m.SelectionTitle = "Select an Area";

      IEnumerable<string> areas = null;
      var container = (IContainer)HttpContext.Application["container"];
      if (model.TargetType == "page")
      {
        var pages = container.GetAllInstances<IPage>();
        IPage page = pages.Where(p => p.Name == model.TargetName).Single();
        IPage parent = pages.Where(p => p.Name == page.Parent).SingleOrDefault();
        if (parent != null) areas = page.Areas.Concat(parent.Areas);
        else areas = page.Areas;
      }
      else
      {
        var widgets = container.GetAllInstances<IWidget>();
        IWidget widget = widgets.Where(w => w.Name == model.TargetName).Single();
        areas = widget.Areas;
      }

      m.WidgetSelections = areas.Select(a => new WidgetSelect()
      {
        Name = a,
        //Icon = a,
        PostHref = Url.Action("AddArea", new
        {
          workspace = Scope.Workspace,
          collection = Scope.Collection,
          targetType = model.TargetType,
          targetName = model.TargetName,
          areaName = a
        })
      });

      m.Error = error;
      m.CancelHref = Url.Action("AdminAreas", new
      {
        workspace = Scope.Workspace,
        collection = Scope.Collection,
        targetType = model.TargetType,
        targetName = model.TargetName,
        pageName = model.PageName
      });
      return PartialView("AdminWidgetSelect", m);
    }