private static List LookupList(ListItemModelHost listItemModelHost, XsltListViewWebPartDefinition wpModel) { return(LookupList(listItemModelHost.HostWeb, wpModel.ListUrl, wpModel.ListTitle, wpModel.ListId)); }
private List LookupList(ListItemModelHost listItemModelHost, XsltListViewWebPartDefinition wpModel) { var web = listItemModelHost.HostWeb; var context = listItemModelHost.HostWeb.Context; List list = null; if (!string.IsNullOrEmpty(wpModel.ListUrl)) { list = web.QueryAndGetListByUrl(wpModel.ListUrl); } else if (!string.IsNullOrEmpty(wpModel.ListTitle)) { list = web.Lists.GetByTitle(wpModel.ListTitle); } else if (wpModel.ListId != default(Guid)) { list = web.Lists.GetById(wpModel.ListId.Value); } else { throw new SPMeta2Exception("ListUrl, ListTitle or ListId should be defined."); } return(list); }
internal static ListBindContext LookupBindContext(ListItemModelHost listItemModelHost, XsltListViewWebPartDefinition wpModel) { return(LookupBindContext(listItemModelHost, wpModel.WebUrl, wpModel.WebId, wpModel.ListUrl, wpModel.ListTitle, wpModel.ListId, wpModel.ViewName, wpModel.ViewId, wpModel.TitleUrl)); }
//[SampleMetadataTag(Name = BuiltInTagNames.SampleHidden)] public void CanBindXsltListViewWebPartByListViewTitle() { var booksLibrary = new ListDefinition { Title = "Books library", Description = "A document library.", TemplateType = BuiltInListTemplateTypeId.DocumentLibrary, Url = "BooksLibrary" }; var booksView = new ListViewDefinition { Title = "Popular Books", Fields = new Collection <string> { BuiltInInternalFieldNames.Edit, BuiltInInternalFieldNames.ID, BuiltInInternalFieldNames.FileLeafRef }, RowLimit = 10 }; var xsltListView = new XsltListViewWebPartDefinition { Title = "Popular Books binding by List View Title", Id = "m2PopularBooksView", ZoneIndex = 10, ZoneId = "Main", ListUrl = booksLibrary.GetListUrl(), ViewName = booksView.Title }; var webPartPage = new WebPartPageDefinition { Title = "M2 Xslt List View provision", FileName = "xslt-listview-webpart-provision.aspx", PageLayoutTemplate = BuiltInWebPartPageTemplates.spstd1 }; var model = SPMeta2Model.NewWebModel(web => { web .AddList(booksLibrary, list => { list.AddListView(booksView); }) .AddHostList(BuiltInListDefinitions.SitePages, list => { list.AddWebPartPage(webPartPage, page => { page.AddXsltListViewWebPart(xsltListView); }); }); }); DeployModel(model); }
public void XsltListViewWebPartSetup(XsltListViewWebPartDefinition typedModel, string listName, string listId, string titleUrl, string jsLink) { var wpXml = WebpartXmlExtensions .LoadWebpartXmlDocument(BuiltInWebPartTemplates.XsltListViewWebPart) .SetListName(listName) .SetListId(listId) .SetTitleUrl(titleUrl) .SetOrUpdateProperty("JSLink", jsLink) .ToString(); }
private List LookupList(ListItemModelHost listItemModelHost, XsltListViewWebPartDefinition wpModel , out Guid webId) { var web = listItemModelHost.HostWeb; var context = web.Context; if (wpModel.WebId.HasGuidValue() || !string.IsNullOrEmpty(wpModel.WebUrl)) { web = new LookupFieldModelHandler() .GetTargetWeb(listItemModelHost.HostClientContext.Site, wpModel.WebUrl, wpModel.WebId, listItemModelHost); webId = web.Id; } else { context.Load(web); context.Load(web, w => w.Id); context.ExecuteQueryWithTrace(); webId = web.Id; } List list = null; if (!string.IsNullOrEmpty(wpModel.ListUrl)) { list = web.QueryAndGetListByUrl(wpModel.ListUrl); } else if (!string.IsNullOrEmpty(wpModel.ListTitle)) { list = web.Lists.GetByTitle(wpModel.ListTitle); } else if (wpModel.ListId != default(Guid)) { list = web.Lists.GetById(wpModel.ListId.Value); } else { throw new SPMeta2Exception("ListUrl, ListTitle or ListId should be defined."); } return(list); }
//[SampleMetadataTag(Name = BuiltInTagNames.SampleHidden)] public void CanBindXsltListViewWebPartByListUrl() { var booksLibrary = new ListDefinition { Title = "Books library", Description = "A document library.", TemplateType = BuiltInListTemplateTypeId.DocumentLibrary, Url = "BooksLibrary" }; var xsltListView = new XsltListViewWebPartDefinition { Title = "Books Default View by List Url", Id = "m2BooksView", ZoneIndex = 10, ZoneId = "Main", ListUrl = booksLibrary.GetListUrl() }; var webPartPage = new WebPartPageDefinition { Title = "M2 Xslt List View provision", FileName = "xslt-listview-webpart-provision.aspx", PageLayoutTemplate = BuiltInWebPartPageTemplates.spstd1 }; var model = SPMeta2Model.NewWebModel(web => { web .AddList(booksLibrary) .AddHostList(BuiltInListDefinitions.SitePages, list => { list.AddWebPartPage(webPartPage, page => { page.AddXsltListViewWebPart(xsltListView); }); }); }); DeployModel(model); }
private ListBindContext LookupBindContext(ListItemModelHost listItemModelHost, XsltListViewWebPartDefinition wpModel) { var result = new ListBindContext { }; var web = listItemModelHost.HostWeb; var context = listItemModelHost.HostWeb.Context; List list = null; if (!string.IsNullOrEmpty(wpModel.ListUrl)) { list = web.QueryAndGetListByUrl(wpModel.ListUrl); } else if (!string.IsNullOrEmpty(wpModel.ListTitle)) { list = web.Lists.GetByTitle(wpModel.ListTitle); } else if (wpModel.ListId != default(Guid)) { list = web.Lists.GetById(wpModel.ListId.Value); } else { throw new ArgumentException("ListUrl, ListTitle or ListId should be defined."); } context.Load(list, l => l.Id); context.Load(list, l => l.DefaultViewUrl); context.Load(list, l => l.Title); context.Load(list, l => l.DefaultView); context.ExecuteQueryWithTrace(); result.ListId = list.Id; result.TitleUrl = list.DefaultViewUrl; result.ViewId = list.DefaultView.Id; return(result); }
private ListBindContext LookupBindContext(ListItemModelHost listItemModelHost, XsltListViewWebPartDefinition wpModel) { var result = new ListBindContext { }; var web = listItemModelHost.HostWeb; var context = listItemModelHost.HostWeb.Context; var list = LookupList(listItemModelHost, wpModel); View view = null; if (wpModel.ViewId.HasValue && wpModel.ViewId != default(Guid)) { view = list.Views.GetById(wpModel.ViewId.Value); } else if (!string.IsNullOrEmpty(wpModel.ViewName)) { view = list.Views.GetByTitle(wpModel.ViewName); } context.Load(list, l => l.Id); context.Load(list, l => l.DefaultViewUrl); context.Load(list, l => l.Title); context.Load(list, l => l.DefaultView); if (view != null) { context.Load(view); context.ExecuteQueryWithTrace(); result.OriginalView = list.DefaultView; result.OriginalViewId = list.DefaultView.Id; result.TargetView = view; result.TargetViewId = view.Id; result.TitleUrl = view.ServerRelativeUrl; } else { context.ExecuteQueryWithTrace(); } result.ListId = list.Id; if (wpModel.TitleUrl == null) { if (string.IsNullOrEmpty(result.TitleUrl)) { result.TitleUrl = list.DefaultViewUrl; } } return(result); }
public static ModelNode AddXsltListViewWebPart(this ModelNode model, XsltListViewWebPartDefinition definition, Action <ModelNode> action) { return(model.AddDefinitionNode(definition, action)); }
public static ModelNode AddXsltListViewWebPart(this ModelNode model, XsltListViewWebPartDefinition definition) { return(AddXsltListViewWebPart(model, definition, null)); }
private List LookupList(ListItemModelHost listItemModelHost, XsltListViewWebPartDefinition wpModel) { var webId = default(Guid); return(LookupList(listItemModelHost, wpModel, out webId)); }
public static TModelNode AddXsltListViewWebPart <TModelNode>(this TModelNode model, XsltListViewWebPartDefinition definition, Action <XsltListViewWebPartModelNode> action) where TModelNode : ModelNode, IWebpartHostModelNode, new() { return(model.AddTypedDefinitionNode(definition, action)); }
public static TModelNode AddXsltListViewWebPart <TModelNode>(this TModelNode model, XsltListViewWebPartDefinition definition) where TModelNode : ModelNode, IWebpartHostModelNode, new() { return(AddXsltListViewWebPart(model, definition, null)); }