Ejemplo n.º 1
0
        public static HtmlString InputFor <T>(Expression <Func <T, DateTime?> > propertySelector,
                                              string format = null, DateTimePreservationOptions preserve = DateTimePreservationOptions.None, int?stepping = null)
        {
            var propertyModel = ReflectionRepository.PropertyBySelector(propertySelector);

            return(DateTime(propertyModel.JsVariableForBinding, format, preserve, stepping));
        }
Ejemplo n.º 2
0
        public static HtmlString DateTime(
            string dataBinding, string format = null, DateTimePreservationOptions preserve = DateTimePreservationOptions.None, int?stepping = null, bool delaySave = true)
        {
            string icon         = "fa-calendar";
            string steppingText = "";

            if (stepping.HasValue)
            {
                steppingText = ", stepping: " + stepping.ToString();
            }
            if (string.IsNullOrWhiteSpace(format))
            {
                switch (preserve)
                {
                case DateTimePreservationOptions.Date:
                    format = DefaultDateFormat;
                    break;

                case DateTimePreservationOptions.Time:
                    format = DefaultTimeFormat;
                    break;

                default:
                    format = DefaultDateTimeFormat;
                    break;
                }
            }
            if (!format.Contains("D"))
            {
                icon = "fa-clock-o";
            }
            string result = string.Format(@"
                    <div class=""input-group date"">
                        <input data-bind=""datePicker: {0}, format: '{1}', preserveTime: {2}, preserveDate: {3} {5}, {6}"" type=""text"" class=""form-control"" />
                        <span class=""input-group-addon"">
                            <span class=""fa {4}""></span>
                        </span>
                    </div>",
                                          dataBinding,
                                          format,
                                          (preserve == DateTimePreservationOptions.Time).ToString().ToLower(),
                                          (preserve == DateTimePreservationOptions.Date).ToString().ToLower(),
                                          icon,
                                          steppingText,
                                          delaySave ? "delaySave: true" : "");

            return(new HtmlString(result));
        }
Ejemplo n.º 3
0
        public static HtmlString DisplayFor <T>(Expression <Func <T, DateTimeOffset> > propertySelector,
                                                string format = null, DateTimePreservationOptions preserve = DateTimePreservationOptions.None)
        {
            var        propertyModel = ReflectionRepository.PropertyBySelector(propertySelector);
            HtmlString returnString;

            switch (preserve)
            {
            case (DateTimePreservationOptions.Date):
                returnString = DisplayDate(propertyModel.JsVariableForBinding, format);
                break;

            case (DateTimePreservationOptions.Time):
                returnString = DisplayTime(propertyModel.JsVariableForBinding, format);
                break;

            default:
                returnString = DisplayDateTime(propertyModel.JsVariableForBinding, format);
                break;
            }

            return(returnString);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dataBinding"></param>
        /// <param name="format"></param>
        /// <param name="preserve"></param>
        /// <param name="stepping"></param>
        /// <returns></returns>
        public static HtmlString DateTime(
            string dataBinding, string format = null, DateTimePreservationOptions preserve = DateTimePreservationOptions.None, int?stepping = null)
        {
            string icon = "fa-calendar";

            if (string.IsNullOrWhiteSpace(format))
            {
                switch (preserve)
                {
                case DateTimePreservationOptions.Date:
                    format = DefaultDateFormat;
                    break;

                case DateTimePreservationOptions.Time:
                    format = DefaultTimeFormat;
                    break;

                default:
                    format = DefaultDateTimeFormat;
                    break;
                }
            }
            if (!format.Contains("D"))
            {
                icon = "fa-clock-o";
            }
            string result = $@"
                    <div class=""input-group date"">
                        <input data-bind=""datePicker: {dataBinding}, format: '{format}', preserveTime: {(preserve == DateTimePreservationOptions.Time).ToString().ToLower()}, preserveDate: {(preserve == DateTimePreservationOptions.Date).ToString().ToLower()} {(stepping.HasValue ? $", stepping: {stepping}" : "")}"" type=""text"" class=""form-control"" />
                        <span class=""input-group-addon"">
                            <span class=""fa {icon}""></span>
                        </span>
                    </div>";

            return(new HtmlString(result));
        }
Ejemplo n.º 5
0
 public static HtmlString DateTimeWithLabel(
     string label, string dataBinding, string format = null, DateTimePreservationOptions preserve = DateTimePreservationOptions.None, int?stepping = null, int?labelCols = null, int?inputCols = null, bool delaySave = true)
 {
     return(DateTime(dataBinding, format, preserve, stepping, delaySave).AddLabel(label, labelCols, inputCols));
 }
Ejemplo n.º 6
0
        public static HtmlString InputWithLabelFor <T>(Expression <Func <T, DateTime> > propertySelector,
                                                       string format = "M/D/YYYY", int?labelCols = null, int?inputCols = null, string label = null, DateTimePreservationOptions preserve = DateTimePreservationOptions.None, int stepping = 1)
        {
            var propertyModel = ReflectionRepository.PropertyBySelector(propertySelector);

            return(DateTimeWithLabel(propertyModel.DisplayNameLabel(label), propertyModel.JsVariableForBinding, format, preserve, stepping, labelCols, inputCols));
        }
Ejemplo n.º 7
0
        public static HtmlString InputWithLabelFor <T>(Expression <Func <T, DateTimeOffset?> > propertySelector,
                                                       string format = null, int?labelCols = null, int?inputCols = null, string label = null, DateTimePreservationOptions preserve = DateTimePreservationOptions.None, int stepping = 1)
        {
            PropertyViewModel propertyModel = ReflectionRepository.Global.PropertyBySelector(propertySelector);

            return(DateTimeWithLabel(label ?? propertyModel.DisplayName, propertyModel.JsVariableForBinding(), format, preserve, stepping, labelCols, inputCols));
        }