2014-05-13 12:36:38 +02:00
using System ;
using System.Web.Mvc ;
2019-10-07 22:10:21 +02:00
using System.Web.Mvc.Html ;
2016-06-10 16:37:28 +02:00
using Umbraco.Core.Models.PublishedContent ;
2014-05-13 12:36:38 +02:00
namespace Umbraco.Web
{
2014-10-07 13:39:18 +02:00
public static class GridTemplateExtensions
2014-05-13 12:36:38 +02:00
{
2015-01-30 15:48:55 +11:00
public static MvcHtmlString GetGridHtml ( this HtmlHelper html , IPublishedProperty property , string framework = "bootstrap3" )
{
2017-12-06 11:51:35 +01:00
var asString = property . GetValue ( ) as string ;
2015-06-16 15:04:31 +02:00
if ( asString ! = null & & string . IsNullOrEmpty ( asString ) ) return new MvcHtmlString ( string . Empty ) ;
2015-01-30 15:48:55 +11:00
var view = "Grid/" + framework ;
2017-12-06 11:51:35 +01:00
return html . Partial ( view , property . GetValue ( ) ) ;
2015-01-30 15:48:55 +11:00
}
public static MvcHtmlString GetGridHtml ( this HtmlHelper html , IPublishedContent contentItem )
{
return html . GetGridHtml ( contentItem , "bodyText" , "bootstrap3" ) ;
}
public static MvcHtmlString GetGridHtml ( this HtmlHelper html , IPublishedContent contentItem , string propertyAlias )
{
2019-10-07 22:10:21 +02:00
if ( propertyAlias = = null ) throw new ArgumentNullException ( nameof ( propertyAlias ) ) ;
if ( string . IsNullOrWhiteSpace ( propertyAlias ) ) throw new ArgumentException ( "Value can't be empty or consist only of white-space characters." , nameof ( propertyAlias ) ) ;
2015-01-30 15:48:55 +11:00
return html . GetGridHtml ( contentItem , propertyAlias , "bootstrap3" ) ;
}
public static MvcHtmlString GetGridHtml ( this HtmlHelper html , IPublishedContent contentItem , string propertyAlias , string framework )
{
2019-10-07 22:10:21 +02:00
if ( propertyAlias = = null ) throw new ArgumentNullException ( nameof ( propertyAlias ) ) ;
if ( string . IsNullOrWhiteSpace ( propertyAlias ) ) throw new ArgumentException ( "Value can't be empty or consist only of white-space characters." , nameof ( propertyAlias ) ) ;
2015-01-30 15:48:55 +11:00
var view = "Grid/" + framework ;
var prop = contentItem . GetProperty ( propertyAlias ) ;
2019-11-13 23:57:26 +01:00
if ( prop = = null ) throw new InvalidOperationException ( "No property type found with alias " + propertyAlias ) ;
2017-12-06 11:51:35 +01:00
var model = prop . GetValue ( ) ;
2015-01-30 15:48:55 +11:00
var asString = model as string ;
2015-01-30 19:04:39 +11:00
if ( asString ! = null & & string . IsNullOrEmpty ( asString ) ) return new MvcHtmlString ( string . Empty ) ;
return html . Partial ( view , model ) ;
}
public static MvcHtmlString GetGridHtml ( this IPublishedProperty property , HtmlHelper html , string framework = "bootstrap3" )
{
2017-12-06 11:51:35 +01:00
var asString = property . GetValue ( ) as string ;
2015-06-16 15:04:31 +02:00
if ( asString ! = null & & string . IsNullOrEmpty ( asString ) ) return new MvcHtmlString ( string . Empty ) ;
2015-01-30 15:48:55 +11:00
2015-01-30 19:04:39 +11:00
var view = "Grid/" + framework ;
2017-12-06 11:51:35 +01:00
return html . Partial ( view , property . GetValue ( ) ) ;
2015-01-30 19:04:39 +11:00
}
2019-11-13 23:57:26 +01:00
2015-01-30 19:04:39 +11:00
public static MvcHtmlString GetGridHtml ( this IPublishedContent contentItem , HtmlHelper html )
{
return GetGridHtml ( contentItem , html , "bodyText" , "bootstrap3" ) ;
}
2019-11-13 23:57:26 +01:00
2015-01-30 19:04:39 +11:00
public static MvcHtmlString GetGridHtml ( this IPublishedContent contentItem , HtmlHelper html , string propertyAlias )
{
2019-10-07 22:10:21 +02:00
if ( propertyAlias = = null ) throw new ArgumentNullException ( nameof ( propertyAlias ) ) ;
if ( string . IsNullOrWhiteSpace ( propertyAlias ) ) throw new ArgumentException ( "Value can't be empty or consist only of white-space characters." , nameof ( propertyAlias ) ) ;
2015-01-30 19:04:39 +11:00
return GetGridHtml ( contentItem , html , propertyAlias , "bootstrap3" ) ;
}
2019-11-13 23:57:26 +01:00
2015-01-30 19:04:39 +11:00
public static MvcHtmlString GetGridHtml ( this IPublishedContent contentItem , HtmlHelper html , string propertyAlias , string framework )
{
2019-10-07 22:10:21 +02:00
if ( propertyAlias = = null ) throw new ArgumentNullException ( nameof ( propertyAlias ) ) ;
if ( string . IsNullOrWhiteSpace ( propertyAlias ) ) throw new ArgumentException ( "Value can't be empty or consist only of white-space characters." , nameof ( propertyAlias ) ) ;
2015-01-30 19:04:39 +11:00
var view = "Grid/" + framework ;
var prop = contentItem . GetProperty ( propertyAlias ) ;
2019-11-13 23:57:26 +01:00
if ( prop = = null ) throw new InvalidOperationException ( "No property type found with alias " + propertyAlias ) ;
2017-12-06 11:51:35 +01:00
var model = prop . GetValue ( ) ;
2015-01-30 19:04:39 +11:00
var asString = model as string ;
if ( asString ! = null & & string . IsNullOrEmpty ( asString ) ) return new MvcHtmlString ( string . Empty ) ;
2015-01-30 15:48:55 +11:00
return html . Partial ( view , model ) ;
}
2014-05-13 12:36:38 +02:00
}
}