kreta/KretaWeb/Helpers/ProgressBarExtensions.cs
2024-03-13 00:33:46 +01:00

50 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Web.Mvc;
using Kendo.Mvc.UI;
using Kendo.Mvc.UI.Fluent;
namespace Kreta.Web.Helpers
{
public static class ProgressBarExtensions
{
public static ProgressBarBuilder KretaProgressBar(this HtmlHelper helper, string name, IDictionary<string, object> htmlAttributes = null)
{
if (htmlAttributes == null)
{
htmlAttributes = new Dictionary<string, object>();
}
var progressBar = helper.Kendo().ProgressBar()
.Name(name)
.HtmlAttributes(htmlAttributes)
.Type(ProgressBarType.Percent)
.Animation(true)
.Animation(a => a.Duration(600));
return progressBar;
}
public static ProgressBarBuilder KretaProgressBarFor<TModel, TValue>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TValue>> expression, IDictionary<string, object> htmlAttributes = null)
{
var fieldName = ExpressionHelper.GetExpressionText(expression);
var fullBindingName = helper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(fieldName);
var metadata = ModelMetadata.FromLambdaExpression(expression, helper.ViewData);
var value = (int)metadata.Model;
if (htmlAttributes == null)
{
htmlAttributes = new Dictionary<string, object>();
}
var progressBar = helper.Kendo().ProgressBar()
.Name(fieldName)
.HtmlAttributes(htmlAttributes)
.Type(ProgressBarType.Percent)
.Value(value)
.Animation(a => a.Duration(600));
return progressBar;
}
}
}