/*
Kooboo is a content management system based on ASP.NET MVC framework. Copyright 2009 Yardi Technology Limited.
This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License version 3 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.kooboo.com/gpl3/.
*/
using System.Web.Mvc;
using Everest.Library.ExtensionMethod;
using Everest.CmsServices.MvcHelper;
namespace Everest.CmsServices.Extension.Module{
/// <summary>
///
/// </summary>
public class ModuleViewUserControl : ViewUserControl
{
public ModuleViewUserControl()
{
this.EnableViewState = false;
}
#region Property
public ModuleRequestContext ModuleRequestContext
{
get
{
return (ModuleRequestContext)ViewContext.RequestContext;
}
}
/// <summary>
/// Gets the parent page context.
/// </summary>
/// <value>The parent page context.</value>
public ParentPageContext ParentPageContext
{
get
{
return ModuleRequestContext.ParentPageContext;
}
}
/// <summary>
/// Gets the module info.
/// </summary>
/// <value>The module info.</value>
public ModuleInfo ModuleInfo
{
get
{
return ModuleRequestContext.ModuleInfo;
}
}
/// <summary>
/// Gets the module controller.
/// </summary>
/// <value>The module controller.</value>
public ModuleController ModuleController
{
get
{
return (ModuleController)this.ViewContext.Controller;
}
}
#endregion
#region MVC Helper
private AjaxHelper _ajaxHelper;
private HtmlHelper _htmlHelper;
private UrlHelper _urlHelper;
// Properties
public new AjaxHelper Ajax
{
get
{
if (this._ajaxHelper == null)
{
this._ajaxHelper = new AjaxHelper(this.ViewContext, this, ModuleRequestContext.RouteTable);
}
return this._ajaxHelper;
}
}
public new HtmlHelper Html
{
get
{
if (this._htmlHelper == null)
{
this._htmlHelper = new HtmlHelper(this.ViewContext, this, ModuleRequestContext.RouteTable);
}
return this._htmlHelper;
}
}
public new UrlHelper Url
{
get
{
if (this._urlHelper == null)
{
this._urlHelper = new UrlHelper(ModuleRequestContext, ModuleRequestContext.RouteTable);
}
return this._urlHelper;
}
}
#endregion
/// <summary>
/// Resolves the page URL.
/// </summary>
/// <param name="moduleUrl">The module URL.e.g: blog/index</param>
/// <returns></returns>
public string ResolvePageUrl(string moduleUrl)
{
ModuleRequestContext requestContext = this.ModuleRequestContext;
return requestContext.ModuleUrlConvertor.ToPageUrl(ParentPageContext.UrlHelper
, requestContext.PageRouteData, requestContext.ModuleInfo.ModuleName, moduleUrl);
}
/// <summary>
/// Resolves the theme file URL.
/// </summary>
/// <param name="filePath">The file path.e.g: images/logo.gif </param>
/// <returns></returns>
public string ResolveThemeFileUrl(string filePath)
{
return Url.ResolveUrl(ModuleInfo.ResolveThemeFileUrl(filePath));
}
#region GetTextResource
/// <summary>
/// Gets the text resource.
/// </summary>
/// <param name="key">The key.</param>
/// <returns></returns>
protected string GetTextResource(string key)
{
return ParentPageContext.ViewPage.GetResource(key);
}
/// <summary>
/// Gets the text resource.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="defaultValue">The default value.</param>
/// <returns></returns>
protected string GetTextResource(string key, string defaultValue)
{
return ParentPageContext.ViewPage.GetResource(key, defaultValue);
}
/// <summary>
/// Gets the text resource.
/// </summary>
/// <param name="strNamespace">The STR namespace.</param>
/// <param name="key">The key.</param>
/// <param name="defaultValue">The default value.</param>
/// <returns></returns>
protected string GetTextResource(string strNamespace, string key, string defaultValue)
{
return ParentPageContext.ViewPage.GetResource(strNamespace, key, defaultValue);
}
#endregion
}
public class ModuleViewUserControl<TModel> : ViewUserControl<TModel>
where TModel : class
{
public ModuleViewUserControl()
{
this.EnableViewState = false;
}
#region Property
public ModuleRequestContext ModuleRequestContext
{
get
{
return (ModuleRequestContext)ViewContext.RequestContext;
}
}
/// <summary>
/// Gets the parent page context.
/// </summary>
/// <value>The parent page context.</value>
public ParentPageContext ParentPageContext
{
get
{
return ModuleRequestContext.ParentPageContext;
}
}
/// <summary>
/// Gets the module info.
/// </summary>
/// <value>The module info.</value>
public ModuleInfo ModuleInfo
{
get
{
return ModuleRequestContext.ModuleInfo;
}
}
/// <summary>
/// Gets the module controller.
/// </summary>
/// <value>The module controller.</value>
public ModuleController ModuleController
{
get
{
return (ModuleController)this.ViewContext.Controller;
}
}
#endregion
#region Helper
private AjaxHelper<TModel> _ajaxHelper;
private HtmlHelper<TModel> _htmlHelper;
private UrlHelper _urlHelper;
// Properties
public new AjaxHelper<TModel> Ajax
{
get
{
if (this._ajaxHelper == null)
{
this._ajaxHelper = new AjaxHelper<TModel>(this.ViewContext, this, ModuleRequestContext.RouteTable);
}
return this._ajaxHelper;
}
}
public new HtmlHelper<TModel> Html
{
get
{
if (this._htmlHelper == null)
{
this._htmlHelper = new HtmlHelper<TModel>(this.ViewContext, this, ModuleRequestContext.RouteTable);
}
return this._htmlHelper;
}
}
public new UrlHelper Url
{
get
{
if (this._urlHelper == null)
{
this._urlHelper = new UrlHelper(ModuleRequestContext, ModuleRequestContext.RouteTable);
}
return this._urlHelper;
}
}
#endregion
/// <summary>
/// Resolves the theme file URL.
/// </summary>
/// <param name="moduleUrl">The module URL.e.g: blog/index</param>
/// <returns></returns>
public string ResolvePageUrl(string moduleUrl)
{
ModuleRequestContext requestContext = this.ModuleRequestContext;
return requestContext.ModuleUrlConvertor.ToPageUrl(ParentPageContext.UrlHelper
, requestContext.PageRouteData, requestContext.ModuleInfo.ModuleName, moduleUrl);
}
/// <summary>
/// Resolves the theme file URL.
/// </summary>
/// <param name="filePath">The file path. e.g: images/logo.gif </param>
/// <returns></returns>
public string ResolveThemeFileUrl(string filePath)
{
return Url.ResolveUrl(ModuleInfo.ResolveThemeFileUrl(filePath));
}
#region GetTextResource
/// <summary>
/// Gets the text resource.
/// </summary>
/// <param name="key">The key.</param>
/// <returns></returns>
protected string GetTextResource(string key)
{
return ParentPageContext.ViewPage.GetResource(key);
}
/// <summary>
/// Gets the text resource.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="defaultValue">The default value.</param>
/// <returns></returns>
protected string GetTextResource(string key, string defaultValue)
{
return ParentPageContext.ViewPage.GetResource(key, defaultValue);
}
/// <summary>
/// Gets the text resource.
/// </summary>
/// <param name="strNamespace">The STR namespace.</param>
/// <param name="key">The key.</param>
/// <param name="defaultValue">The default value.</param>
/// <returns></returns>
protected string GetTextResource(string strNamespace, string key, string defaultValue)
{
return ParentPageContext.ViewPage.GetResource(strNamespace, key, defaultValue);
}
#endregion
}
}
|