/*
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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Mvc.Html;
using Everest.CmsServices.Models;
using Everest.Library.Mvc.Paging;
using Everest.Library.ExtensionMethod;
using InteSoft.Web.ExternalResourceLoader;
namespace Everest.CmsServices.MvcHelper{
#region CmsPager
public class CmsPager : Pager
{
private string pageIndexName = "pageIndex";
/// <summary>
/// Initializes a new instance of the <see cref="ContentPager"/> class.
/// </summary>
/// <param name="viewContext">The view context.</param>
/// <param name="pageSize">Size of the page.</param>
/// <param name="currentPage">The current page.</param>
/// <param name="totalItemCount">The total item count.</param>
/// <param name="valuesDictionary">The values dictionary.</param>
/// <param name="pageIndexName">Name of the page index.</param>
public CmsPager(ViewContext viewContext, int pageSize, int currentPage, int totalItemCount, RouteValueDictionary valuesDictionary
, string pageIndexName)
: base(viewContext, pageSize, currentPage, totalItemCount, valuesDictionary)
{
if (!StringExtensions.IsNullOrEmptyTrim(pageIndexName))
{
this.pageIndexName = pageIndexName;
}
}
/// <summary>
/// Generates the page link.
/// </summary>
/// <param name="linkText">The link text.</param>
/// <param name="pageNumber">The page number.</param>
/// <returns></returns>
protected override string GeneratePageLink(string linkText, int pageNumber)
{
var pageRouteValues = new RouteValueDictionary(this.routeValues);
pageRouteValues.Add(pageIndexName, pageNumber);
var cmsContext = viewContext.RequestContext.HttpContext.GetCmsContext();
Cms_Page cms_page = cmsContext.Cms_Page;
aspnet_Applications application = cmsContext.Cms_Application;
UrlHelper urlHelper = new UrlHelper(viewContext.RequestContext);
string url = urlHelper.GenerateContextPageUrl(cms_page, pageRouteValues);
if (url != null)
{
string linkFormat = "<a href=\"{0}\">{1}</a>";
return String.Format(linkFormat, url, linkText);
}
else
{
return null;
}
}
}
#endregion
public enum TinyMCETheme
{
simple,
advanced
}
public enum TinyMCESkin
{
@default,
o2k7
}
/// <summary>
///
/// </summary>
public static class HtmlHelperExtensions
{
#region PageLink
/// <summary>
/// Pages the link.
/// </summary>
/// <param name="htmlHeper">The HTML heper.</param>
/// <param name="linkText">The link text.</param>
/// <param name="pageName">Name of the page.</param>
/// <returns></returns>
public static string PageLink(this HtmlHelper htmlHeper, object linkText, string pageVirtualPath)
{
return htmlHeper.PageLink(linkText, pageVirtualPath, null);
}
/// <summary>
/// Pages the link.
/// </summary>
/// <param name="htmlHelper">The HTML helper.</param>
/// <param name="linkText">The link text.</param>
/// <param name="pageName">Name of the page.</param>
/// <param name="values">The values.</param>
/// <returns></returns>
public static string PageLink(this HtmlHelper htmlHelper, object linkText, string pageVirtualPath, object values)
{
return htmlHelper.PageLink(linkText, pageVirtualPath, values, null);
}
/// <summary>
/// Pages the link.
/// </summary>
/// <param name="htmlHelper">The HTML helper.</param>
/// <param name="linkText">The link text.</param>
/// <param name="pageName">Name of the page.</param>
/// <param name="useDefaultRouteValues">if set to <c>true</c> [use default route values].</param>
/// <returns></returns>
public static string PageLink(this HtmlHelper htmlHelper, object linkText, string pageVirtualPath, bool useDefaultRouteValues)
{
return htmlHelper.PageLink(linkText, pageVirtualPath, null, useDefaultRouteValues, null);
}
/// <summary>
/// Pages the link.
/// </summary>
/// <param name="htmlHelper">The HTML helper.</param>
/// <param name="linkText">The link text.</param>
/// <param name="pageName">Name of the page.</param>
/// <param name="defaultValues">if set to <c>true</c> [use the route default values].</param>
/// <param name="htmlAttributes">The HTML attributes.</param>
/// <returns></returns>
public static string PageLink(this HtmlHelper htmlHelper, object linkText, string pageVirtualPath, bool useDefaultRouteValues, object htmlAttributes)
{
return htmlHelper.PageLink(linkText, pageVirtualPath, null, useDefaultRouteValues, htmlAttributes);
}
/// <summary>
/// Pages the link.
/// </summary>
/// <param name="htmlHelper">The HTML helper.</param>
/// <param name="linkText">The link text.</param>
/// <param name="pageName">Name of the page.</param>
/// <param name="routeValues">The route values.</param>
/// <param name="htmlAttributes">The HTML attributes.</param>
/// <returns></returns>
public static string PageLink(this HtmlHelper htmlHelper, object linkText, string pageVirtualPath, object routeValues, object htmlAttributes)
{
return htmlHelper.PageLink(linkText, pageVirtualPath, routeValues, false, htmlAttributes);
}
/// <summary>
/// Pages the link.
/// </summary>
/// <param name="htmlHelper">The HTML helper.</param>
/// <param name="linkText">The link text.</param>
/// <param name="pageName">Name of the page.</param>
/// <param name="routeValues">The route values.</param>
/// <param name="useDefaultValues">if set to <c>true</c> [use default values].</param>
/// <param name="htmlAttributes">The HTML attributes.</param>
/// <returns></returns>
private static string PageLink(this HtmlHelper htmlHelper, object linkText, string pageVirtualPath, object routeValues, bool useDefaultRouteValues, object htmlAttributes)
{
string strLinkText = "";
if (linkText != null)
{
strLinkText = linkText.ToString();
}
var htmlAttributesDic = new RouteValueDictionary(htmlAttributes);
UrlHelper urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
string url = UrlHelperExtensions.PageUrl(urlHelper, pageVirtualPath, routeValues, useDefaultRouteValues);
TagBuilder builder = new TagBuilder("a")
{
InnerHtml = !StringExtensions.IsNullOrEmptyTrim(strLinkText) ? HttpUtility.HtmlEncode(strLinkText) : string.Empty
};
builder.MergeAttributes<string, object>(htmlAttributesDic);
builder.MergeAttribute("href", url);
return builder.ToString(TagRenderMode.Normal);
}
#endregion
#region Pager
/// <summary>
/// Pagers the specified HTML helper.
/// </summary>
/// <param name="htmlHelper">The HTML helper.</param>
/// <param name="pageSize">Size of the page.</param>
/// <param name="currentPage">The current page.</param>
/// <param name="totalItemCount">The total item count.</param>
/// <returns></returns>
public static string CmsPager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount)
{
return CmsPager(htmlHelper, pageSize, currentPage, totalItemCount, string.Empty, null);
}
/// <summary>
/// Pagers the specified HTML helper.
/// </summary>
/// <param name="htmlHelper">The HTML helper.</param>
/// <param name="pageSize">Size of the page.</param>
/// <param name="currentPage">The current page.</param>
/// <param name="totalItemCount">The total item count.</param>
/// <param name="pageIndexName">Name of the page index.</param>
/// <returns></returns>
public static string CmsPager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, string pageIndexName)
{
return CmsPager(htmlHelper, pageSize, currentPage, totalItemCount, null, pageIndexName);
}
/// <summary>
/// Pagers the specified HTML helper.
/// </summary>
/// <param name="htmlHelper">The HTML helper.</param>
/// <param name="pageSize">Size of the page.</param>
/// <param name="currentPage">The current page.</param>
/// <param name="totalItemCount">The total item count.</param>
/// <param name="routeValues">The route values on the paging link.</param>
/// <returns></returns>
public static string CmsPager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, object routeValues)
{
return CmsPager(htmlHelper, pageSize, currentPage, totalItemCount, string.Empty, routeValues);
}
/// <summary>
/// Pagers the specified HTML helper.
/// </summary>
/// <param name="htmlHelper">The HTML helper.</param>
/// <param name="pageSize">Size of the page.</param>
/// <param name="currentPage">The current page.</param>
/// <param name="totalItemCount">The total item count.</param>
/// <param name="pageIndexName">Name of the page index.</param>
/// <param name="routeValues">The route values on the paging link.</param>
/// <returns></returns>
public static string CmsPager(this HtmlHelper htmlHelper, int pageSize, int currentPage,
int totalItemCount, string pageIndexName, object routeValues)
{
var valuesDictionary = new RouteValueDictionary(routeValues);
var pager = new CmsPager(htmlHelper.ViewContext, pageSize, currentPage, totalItemCount, valuesDictionary, pageIndexName);
return pager.RenderHtml();
}
#endregion
#region EditField
/// <summary>
/// Edits the field.
/// </summary>
/// <param name="htmlHeper">The HTML heper.</param>
/// <param name="contentValues">The content values.</param>
/// <param name="fieldName">Name of the field.</param>
/// <param name="editor">The editor.</param>
/// <returns></returns>
public static string EditField(this HtmlHelper htmlHeper, IDictionary<string, object> contentValues, string fieldName, Editor editor)
{
return EditField(htmlHeper, contentValues, fieldName, editor, string.Empty);
}
/// <summary>
/// Edits the field.
/// </summary>
/// <param name="htmlHeper">The HTML heper.</param>
/// <param name="contentValues">The content values.</param>
/// <param name="fieldName">Name of the field.</param>
/// <param name="editor">The editor.</param>
/// <param name="editCssName">Name of the edit CSS.</param>
/// <returns></returns>
public static string EditField(this HtmlHelper htmlHeper, IDictionary<string, object> contentValues, string fieldName, Editor editor, string editCssName)
{
var field = new EditField(htmlHeper, contentValues, fieldName, editor)
{
EditCssName = editCssName
};
return field.RenderHtml();
}
/// <summary>
/// Edits the field.
/// </summary>
/// <param name="htmlHeper">The HTML heper.</param>
/// <param name="contentValues">The content values.</param>
/// <param name="fieldName">Name of the field.</param>
/// <param name="comboItems">The combo items.</param>
/// <returns></returns>
public static string EditField(this HtmlHelper htmlHeper, IDictionary<string, object> contentValues, string fieldName, string[] comboItems)
{
return EditField(htmlHeper, contentValues, fieldName, comboItems, string.Empty);
}
/// <summary>
/// Edits the field.
/// </summary>
/// <param name="htmlHeper">The HTML heper.</param>
/// <param name="contentValues">The content values.</param>
/// <param name="fieldName">Name of the field.</param>
/// <param name="comboItems">The combo items.</param>
/// <param name="editCssName">Name of the edit CSS.</param>
/// <returns></returns>
public static string EditField(this HtmlHelper htmlHeper, IDictionary<string, object> contentValues, string fieldName, string[] comboItems, string editCssName)
{
var field = new EditField(htmlHeper, contentValues, fieldName, Editor.ComboBox)
{
EditCssName = editCssName,
ComboItems = comboItems
};
return field.RenderHtml();
}
#endregion
#region TinyMCE
/// <summary>
/// Registers the tinymce scripts.
/// </summary>
/// <param name="htmlHelper">The HTML helper.</param>
/// <returns></returns>
public static MvcHtmlString RegisterTinymceScripts(this HtmlHelper htmlHelper)
{
return htmlHelper.RegisterTinymceScripts(TinyMCETheme.simple, TinyMCESkin.@default, "");
}
/// <summary>
/// Registers the tinymce scripts.
/// </summary>
/// <param name="htmlHelper">The HTML helper.</param>
/// <param name="theme">The theme.</param>
/// <param name="skin">The skin.</param>
/// <param name="optional">The optional. for example:
///
/// plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager",
/// // Theme options
/// theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
/// theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
/// theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
/// theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
/// theme_advanced_toolbar_location : "top",
/// theme_advanced_toolbar_align : "left",
///theme_advanced_statusbar_location : "bottom",
///theme_advanced_resizing : true,
/// <returns></returns>
public static MvcHtmlString RegisterTinymceScripts(this HtmlHelper htmlHelper, TinyMCETheme theme, TinyMCESkin skin, string optionalSettings)
{
if (!string.IsNullOrEmpty(optionalSettings))
{
optionalSettings = "," + optionalSettings;
}
string tinymcejs = string.Format(@"<script src=""{0}"" type=""text/javascript""></script>", Everest.Library.Web.UrlConvertor.ResolveUrl("~/Kooboojs/tiny_mce/tiny_mce.js"));
string script = tinymcejs + string.Format(@"
<script type=""text/javascript"">
tinyMCE.init({{
theme : ""{0}"",
mode: 'specific_textareas',
editor_selector: 'tinymce',
skin:""{1}""
{2}
}});
</script>
", theme.ToString().ToLower(), skin.ToString(), optionalSettings);
return MvcHtmlString.Create(script);
}
/// <summary>
/// Tinymces the specified HTML helper.
/// </summary>
/// <param name="htmlHelper">The HTML helper.</param>
/// <param name="name">The name.</param>
/// <returns></returns>
public static MvcHtmlString Tinymce(this HtmlHelper htmlHelper, string name)
{
return htmlHelper.Tinymce(name, "", null);
}
/// <summary>
/// Tinymces the specified HTML helper.
/// </summary>
/// <param name="htmlHelper">The HTML helper.</param>
/// <param name="name">The name.</param>
/// <param name="value">The value.</param>
/// <param name="htmlAttributes">The HTML attributes.</param>
/// <returns></returns>
public static MvcHtmlString Tinymce(this HtmlHelper htmlHelper, string name, string value, object htmlAttributes)
{
var htmlAttributesDic = new RouteValueDictionary(htmlAttributes);
htmlAttributesDic.Add("class", "tinymce");
MvcHtmlString textAreaHtml = htmlHelper.TextArea(name, value, htmlAttributesDic);
return textAreaHtml;
}
#endregion
#region FCKEditor
/// <summary>
/// Registers the FC keditor scripts.
/// </summary>
/// <param name="htmlHelper">The HTML helper.</param>
/// <returns></returns>
public static MvcHtmlString RegisterFCKeditorScripts(this HtmlHelper htmlHelper)
{
var fckEditorjs = string.Format(@"<script src=""{0}"" type=""text/javascript""></script>", Everest.Library.Web.UrlConvertor.ResolveUrl("~/Kooboojs/fckeditor/fckeditor.js"));
return MvcHtmlString.Create(fckEditorjs);
}
/// <summary>
/// create the fckeditor.
/// </summary>
/// <param name="htmlHelper">The HTML helper.</param>
/// <param name="name">The name.</param>
/// <returns></returns>
public static MvcHtmlString FCKeditor(this HtmlHelper htmlHelper, string name)
{
return htmlHelper.FCKeditor(name, "", null);
}
/// <summary>
/// create the fckeditor.
/// </summary>
/// <param name="htmlHelper">The HTML helper.</param>
/// <param name="name">The name.</param>
/// <param name="value">The value.</param>
/// <param name="htmlAttributes">The HTML attributes.</param>
/// <returns></returns>
public static MvcHtmlString FCKeditor(this HtmlHelper htmlHelper, string name, string value, object htmlAttributes)
{
MvcHtmlString textAreaHtml = htmlHelper.TextArea(name, value, htmlAttributes);
string toggleEditor = string.Format(@"<script type=""text/javascript"">var oFCKeditor = new FCKeditor('{0}') ;oFCKeditor.BasePath=""{1}""; oFCKeditor.ReplaceTextarea() ;</script>", name
, Everest.Library.Web.UrlConvertor.ResolveUrl("~/Kooboojs/FCKEditor/"));
return MvcHtmlString.Create(textAreaHtml + toggleEditor);
}
#endregion
#region CKEditor
/// <summary>
/// Registers the Ckeditor scripts.
/// </summary>
/// <param name="htmlHelper">The HTML helper.</param>
/// <returns></returns>
public static MvcHtmlString RegisterCKeditorScripts(this HtmlHelper htmlHelper)
{
//http://forum.kooboo.com/yaf_postsm1818_Problems-with-CKEditor.aspx#post1818
var ckEditorjs = string.Format(@"<script src=""{0}"" type=""text/javascript""></script>", Everest.Library.Web.UrlConvertor.ResolveUrl("~/Kooboojs/ckeditor/ckeditor.js"));
return MvcHtmlString.Create(ckEditorjs);
}
/// <summary>
/// CKs the editor.
/// </summary>
/// <param name="htmlHelper">The HTML helper.</param>
/// <param name="name">The name.</param>
/// <returns></returns>
public static MvcHtmlString CKEditor(this HtmlHelper htmlHelper, string name)
{
return htmlHelper.CKEditor(name, "", null);
}
/// <summary>
/// CKs the editor.
/// </summary>
/// <param name="htmlHelper">The HTML helper.</param>
/// <param name="name">The name.</param>
/// <param name="value">The value.</param>
/// <param name="htmlAttributes">The HTML attributes.</param>
/// <returns></returns>
public static MvcHtmlString CKEditor(this HtmlHelper htmlHelper, string name, string value, object htmlAttributes)
{
MvcHtmlString textAreaHtml = htmlHelper.TextArea(name, value, htmlAttributes);
string toggleEditor = string.Format(@"<script type=""text/javascript"">CKEDITOR.replace( '{0}' );</script>", name);
return MvcHtmlString.Create(textAreaHtml + toggleEditor);
}
#endregion
}
}
|