Inheritance: RockTextBox
Esempio n. 1
0
        /// <summary>
        /// Gets the javascript for year picker.
        /// </summary>
        /// <param name="ypGraduationYear">The yp graduation year.</param>
        /// <returns></returns>
        public string GetJavascriptForYearPicker(YearPicker ypGraduationYear)
        {
            DateTime gradeTransitionDate = GlobalAttributesCache.Read().GetValue("GradeTransitionDate").AsDateTime() ?? new DateTime(RockDateTime.Now.Year, 6, 1);

            // add a year if the next graduation mm/dd won't happen until next year
            int gradeOffsetRefactor = (RockDateTime.Now < gradeTransitionDate) ? 0 : 1;

            string gradeSelectionScriptFormat = @"
    $('#{0}').change(function(){{
        var selectedGradeOffsetValue = $(this).val();
        if ( selectedGradeOffsetValue == '') {{
            $('#{1}').val('');
        }} else {{
            $('#{1}').val( {2} + ( {3} + parseInt( selectedGradeOffsetValue ) ) );
        }} 
    }});

    $('#{1}').change(function(){{
        var selectedYearValue = $(this).val();
        if (selectedYearValue == '') {{
            $('#{0}').val('');
        }} else {{
            var gradeOffset = ( parseInt( selectedYearValue ) - {4} ) - {3};
            if (gradeOffset >= 0 ) {{
                $('#{0}').val(gradeOffset.toString());

                // if there is a gap in gradeOffsets (grade is combined), keep trying if we haven't hit an actual offset yet
                while (!$('#{0}').val() && gradeOffset <= {5}) {{
                    $('#{0}').val(gradeOffset++);
                }}
            }} else {{
                $('#{0}').val('');
            }}
        }}
    }});";
            string script = string.Format(
                gradeSelectionScriptFormat,
                this.ClientID,             // {0}
                ypGraduationYear.ClientID, // {1}
                gradeTransitionDate.Year,  // {2}
                gradeOffsetRefactor,       // {3}
                RockDateTime.Now.Year,     // {4}
                this.MaxGradeOffset        // {5}
                );

            return(script);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the javascript for year picker.
        /// </summary>
        /// <param name="ypGraduationYear">The yp graduation year.</param>
        /// <returns></returns>
        public string GetJavascriptForYearPicker(YearPicker ypGraduationYear)
        {
            DateTime currentGraduationDate = RockDateTime.CurrentGraduationDate;
            DateTime gradeTransitionDate   = new DateTime(RockDateTime.Now.Year, currentGraduationDate.Month, currentGraduationDate.Day);

            // add a year if the next graduation mm/dd won't happen until next year
            int gradeOffsetRefactor = (RockDateTime.Now < gradeTransitionDate) ? 0 : 1;

            string gradeSelectionScript = $@"
    $('#{this.ClientID}').change(function(){{
        var selectedGradeOffsetValue = $(this).val();
        if ( selectedGradeOffsetValue == '') {{
            $('#{ypGraduationYear.ClientID}').val('');
        }} else {{
            $('#{ypGraduationYear.ClientID}').val( {gradeTransitionDate.Year} + ( {gradeOffsetRefactor} + parseInt( selectedGradeOffsetValue ) ) );
        }} 
    }});

    $('#{1}').change(function(){{
        var selectedYearValue = $(this).val();
        if (selectedYearValue == '') {{
            $('#{this.ClientID}').val('');
        }} else {{
            var gradeOffset = ( parseInt( selectedYearValue ) - {RockDateTime.Now.Year} ) - {gradeOffsetRefactor};
            if (gradeOffset >= 0 ) {{
                $('#{this.ClientID}').val(gradeOffset.toString());

                // if there is a gap in gradeOffsets (grade is combined), keep trying if we haven't hit an actual offset yet
                while (!$('#{this.ClientID}').val() && gradeOffset <= {this.MaxGradeOffset}) {{
                    $('#{this.ClientID}').val(gradeOffset++);
                }}
            }} else {{
                $('#{this.ClientID}').val('');
            }}
        }}
    }});";

            return(gradeSelectionScript);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the javascript for year picker.
        /// </summary>
        /// <param name="ypGraduationYear">The yp graduation year.</param>
        /// <returns></returns>
        public string GetJavascriptForYearPicker( YearPicker ypGraduationYear)
        {
            DateTime gradeTransitionDate = GlobalAttributesCache.Read().GetValue( "GradeTransitionDate" ).AsDateTime() ?? new DateTime( RockDateTime.Now.Year, 6, 1 );

            // add a year if the next graduation mm/dd won't happen until next year
            int gradeOffsetRefactor = ( RockDateTime.Now < gradeTransitionDate ) ? 0 : 1;

            string gradeSelectionScriptFormat = @"
            $('#{0}').change(function(){{
            var selectedGradeOffsetValue = $(this).val();
            if ( selectedGradeOffsetValue == '') {{
            $('#{1}').val('');
            }} else {{
            $('#{1}').val( {2} + ( {3} + parseInt( selectedGradeOffsetValue ) ) );
            }}
            }});

            $('#{1}').change(function(){{
            var selectedYearValue = $(this).val();
            if (selectedYearValue == '') {{
            $('#{0}').val('');
            }} else {{
            var gradeOffset = ( parseInt( selectedYearValue ) - {4} ) - {3};
            if (gradeOffset >= 0 ) {{
                $('#{0}').val(gradeOffset.toString());

                // if there is a gap in gradeOffsets (grade is combined), keep trying if we haven't hit an actual offset yet
                while (!$('#{0}').val() && gradeOffset <= {5}) {{
                    $('#{0}').val(gradeOffset++);
                }}
            }} else {{
                $('#{0}').val('');
            }}
            }}
            }});";
            string script = string.Format(
                gradeSelectionScriptFormat,
                this.ClientID,     // {0}
                ypGraduationYear.ClientID,       // {1}
                gradeTransitionDate.Year,   // {2}
                gradeOffsetRefactor,   // {3}
                RockDateTime.Now.Year, // {4}
                this.MaxGradeOffset // {5}
                );

            return script;
        }