Esempio n. 1
0
        public static MvcHtmlString RPDateTimeFor <TModel, TProperty>(
            this HtmlHelper <TModel> htmlHelper,
            Expression <Func <TModel, TProperty> > expression,
            DataTypeUI dataType             = DataTypeUI.Undefined,
            DateTimeFormatUI dateTimeFormat = DateTimeFormatUI.Date,
            string labelMessage             = null,
            string placeholderMessage       = null)
        {
            var metadata       = htmlHelper.GetModelMetadata(expression, labelMessage, placeholderMessage);
            var viewModel      = new DateTimeViewModel(metadata, dataType, dateTimeFormat);
            var htmlAttributes = new Dictionary <string, object>();

            if (!string.IsNullOrEmpty(viewModel.PlaceholderMessage))
            {
                htmlAttributes.Add("placeholder", viewModel.PlaceholderMessage);
            }

            htmlAttributes.Add("type", viewModel.DataType.GetMetadata().Value);
            switch (dateTimeFormat)
            {
            case DateTimeFormatUI.Date:
                htmlAttributes.Add("class", "form-control datepicker");
                break;

            case DateTimeFormatUI.DateTime:
                htmlAttributes.Add("class", "form-control datetimepicker");
                break;
            }
            viewModel.Input = htmlHelper.TextBoxFor(expression, ((DateTime?)viewModel.Model).ToShortDateString(CultureManager.DateTimeFormat), htmlAttributes);

            return(htmlHelper.Partial(Mvc.View.UI.DateTime, viewModel));
        }
Esempio n. 2
0
        public DateTimeViewModel(ModelMetadata metadata, DataTypeUI dataType, DateTimeFormatUI dateTimeFormat)
            : base(metadata)
        {
            if (string.IsNullOrEmpty(PlaceholderMessage))
            {
                switch (dateTimeFormat)
                {
                case DateTimeFormatUI.Date:
                    PlaceholderMessage = StyleContext.GetTranslation(Dom.Translation.Common.DateFormat);
                    break;

                case DateTimeFormatUI.DateTime:
                    PlaceholderMessage = StyleContext.GetTranslation(Dom.Translation.Common.DateTimeFormat);
                    break;
                }
            }

            DataType       = dataType;
            DateTimeFormat = dateTimeFormat;
        }