⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dateitem.js

📁 javascript 很酷的类库
💻 JS
📖 第 1 页 / 共 3 页
字号:
        if (this.useTextField) {                        var textField = isc.addProperties({textAlign:this.textAlign},                                               DI.TEXT_FIELD, this.textFieldProperties);            // If we have a specified height, expand the text box to fill the available space                        if (this.height && (!this.textFieldProperties || !this.textFieldProperties.height))             {                textField.height = this.getTextBoxHeight();            }            itemList.add(textField);                //>EditMode for dynamically changing useTextField            var undef;            this.daySelector = this.yearSelector = this.monthSelector = undef;            //<EditMode                } else {            // If we're not showing the text field, force our width to 200px            this.width = 200;		    		// iterate through the characters of the format    		for (var i = 0; i < format.length; i++) {    			var field = format.charAt(i);    			// assigning the selector for that format to the itemList                var dayField, monthField, yearField;                if (field == "D") {                    var dayField;                    if (this.daySelectorProperties != null) {                        dayField = isc.addProperties({}, DI.DAY_SELECTOR, this.daySelectorProperties);                    } else {                        dayField = isc.addProperties({}, DI.DAY_SELECTOR);                    }                    itemList.add(dayField);                } else if (field == "M") {                    var monthField;                    if (this.monthSelectorProperties != null) {                        monthField = isc.addProperties({}, DI.MONTH_SELECTOR, this.monthSelectorProperties);                    } else {                        monthField = isc.addProperties({}, DI.MONTH_SELECTOR);                    }                                    itemList.add(monthField);                } else if (field == "Y") {                    var yearField;                    if (this.yearSelectorProperties != null) {                        yearField = isc.addProperties({}, DI.YEAR_SELECTOR, this.yearSelectorProperties);                    } else {                        yearField = isc.addProperties({}, DI.YEAR_SELECTOR);                    }                    itemList.add(yearField);                }    		}        }        		// call the superclass routine to properly set the items		this.Super("setItems", [itemList]);	},    // Override isEditable() to indicate that the user can edit this items value directly    isEditable : function () {        return true;    },	//>	@method	dateItem.setValue()	(A)	//  Override setValue to set the values for the sub-items of the date.	//<	setValue : function (value) {        this._setValueCalled = true;                    // may still be null if we're working with a text field        var setToDefault = false;        if (value == null) {            value = this.getDefaultValue();                setToDefault = true;        }                var invalidDate;        // allow null values if useTextField is true and field is blank        // Note - we currently don't suport setting null dates on date items showing selectors -         // not clear how this mechanism would work         // - once a date was null, presumably all 3 selectors would be showing "".         // - when the user then chose a value from one selector, would we default the other 2 to        //   some default?        // - similarly if the 3 selectors showed a valid date, how would the user set it to an        //   empty date (one at a time?)        if (isc.is.emptyString(value)) value = null;        if (value == null) {            invalidDate = !this.useTextField;        } else {                        var date = this.parseDate(value);            // parseDate returns null if passed something it doesn't understand            if (date == null) {                invalidDate = true;                if (this.enforceDate) value = null;            } else {                value = date;            }        }        if (invalidDate && (!this.useTextField || this.enforceDate)) {        	//>DEBUG			this.logInfo("dateItem.setValue(): invalid date passed: '" + value +                             "'.  Not updating value.");			//<DEBUG                                    if (this.useTextField) {                var textField = this.dateTextField,                    textFieldValue = textField.getValue();                this._suppressUpdates = true;                if (textFieldValue != null) textField.setElementValue(textFieldValue);                this._suppressUpdates = null;            }            // return false in case anyone is checking the return value            return false;        }        // clear errors if we have any        if (this._invalidDate) {            delete this._invalidDate;            this.clearErrors();            this.redraw();        }                 // hang onto the value passed in if it is not invalid        this.saveValue(value, setToDefault);                // Avoid attempting to parse / correct the dates in response to these setValues calls        this._suppressUpdates = true;        if (this.useTextField) {            var textValue;                        if (isc.isA.Date(value)) textValue = value.toShortDate(this.displayFormat);            else {                // we may be hanging onto a local, invalid value entered by the user - clear that                // if that's the case.                if (value == null || this.enforceDate) textValue = isc.emptyString;                else textValue = value;            }                       this.dateTextField.setValue(textValue);        }		// set the day, month and year selectors		if (this.daySelector) 		this.daySelector.setValue(value.getDate());		if (this.monthSelector) 	this.monthSelector.setValue(value.getMonth());		if (this.yearSelector)		this.yearSelector.setValue(value.getFullYear());        delete this._suppressUpdates;        return true;	},            // if we're doing a direct submit of the DateItem value, convert it to the     // dbDate format so it can be parsed on the server.    _setHiddenDataElementValue : function (value) {        var hde = this._getHiddenDataElement();        if (hde != null) {            if (isc.isA.Date(value)) hde.value = value.toDBDate();                        else hde.value = value;        }    },        // Override getCellHeight() to ensure the containing form leaves enough space for this item.        getCellHeight : function () {        var cellHeight = this.Super("getCellHeight", arguments);        if (isc.Browser.isIE && this.useTextField && isc.isA.Number(cellHeight)) cellHeight += 2;        return cellHeight;    },                elementChanged : function () {        return;    },        // Override updateValue to verify that the contents of the element(s) make a valid date.    updateValue : function () {        // _suppressUpdates flag set when we're in the process of setting our sub items' values        // to represent a known, valid date.                if (this._suppressUpdates) return;        // We're likely to manipulate the values of the form items as this method runs - avoid        // re-running updateValue in response to 'saveValue()' on the sub items.        this._suppressUpdates = true;        var date;        if (this.useTextField) {                    // Note: this method is called from "saveValue()" on the sub-items (after saving out             // their values) so typically the sub item values will be up to date.            // However this method may also be called externally while the text item is pending            // an update (from blur [or keypress]).            // Call updateValue() to ensure the text field value matches the current element            // value for that field.            this.dateTextField.updateValue();            var value = this.dateTextField.getValue();                        if (value == isc.emptyString || value == null) date = null;            else {                // This will return a null value if the date string is invalid.                                date = this.parseDate(value);                if (date == null) {                    if (this.enforceDate) {                        this.logInfo("Invalid date string entered in date text field :"+ value);                                                if (!this._invalidDate) {                            this._invalidDate = true;                            this.setError(this.invalidDateStringMessage);                        }                        // We need to redraw to show the error. We don't want the user's entry                        // to vanish, so we store it under a temp var. which the text field will                        // display                                                this.redraw();                    }                                                            this.saveValue(value);                    delete this._suppressUpdates;                    return;                                    } else {                                           // If the date was valid, the format may have slightly changed                    // (01/01/01 -> 1/1/2001, for example) - if necessary update the text                    // field here.                    var dateString = date.toShortDate(this.displayFormat);                    if (value != dateString) {                        // we've set _suppressUpdates, so we won't end up in an infinite loop                         // from this call                        this.dateTextField.setValue(dateString);                    }                }            }            // at this point we want to make sure we're not showing an old invalid date / error            if (this._invalidDate) {                delete this._invalidDate;                this.clearErrors();                this.redraw();            }                    } else {                    // If we're not showing a text field, start with the last remembered date, and update            // that based on the values in the selector items            date = (this._value || this.getDefaultValue());            // copy the date object to allow us to reset to _value if change handler fails            date = date.duplicate();            var day, month, year;            if (this.yearSelector) {                year = this.yearSelector.getValue()                date.setYear(year);            }            if (this.monthSelector) {                month = this.monthSelector.getValue();                                // If we have a daySelector, we set the date to 1 so that setting the month will                // not lead to an invalid date like Feb 30.                // This avoids the case where                 //  - the selectors are set to Feb 30, and the previous date was Jan 30.                //  - the date object has 'setMonth()' called, setting the month is set to "Feb",                 //    causing the date to be automatically updated to March 2                //  - the day is set to 30 (from the date selector), leaving us with a date of                //    March 30.                //  At this point the logic to roll the days back to the end of the month would fail                if (this.daySelector) date.setDate(1);                                date.setMonth(month);            }            if (this.daySelector) {                day = this.daySelector.getValue();                date.setDate(day);            }                                    // If set to an invalid date, such as Feb 30, or Feb 29th on a non-leap year, the month             // will have been rolled forward (making it easy to catch such errors)            // make sure the date's month is the same as that specified in the list            // if it's not, we should roll back the day selector, and update the date to the             // appropriate day / month            if (month != date.getMonth()) {                // This rolls the date back to the end of the previous month                day = day - date.getDate();                if (this.daySelector) this.daySelector.setValue(day);                date.setMonth(month);                date.setDate(day);            }                 }        delete this._suppressUpdates;                // now fire the default handlers:        if (this.handleChange(date, this._value) == false) return;        // In case the change handler modified the date        date = this._changeValue;                // save the value        this.saveValue(date);            // fire the 'changed' handler        this.handleChanged(date);                        },    		//>	@method	dateItem.resetValue()	//      Overridden to get the value from the old value stored in the form, rather than    //      replacing this item's value with the date object	//		@group	elements	//<	resetValue : function () {		var oldValue = this.form._oldValues[this.getFieldName()];        if (isc.isA.Date(oldValue) && isc.isA.Date(this._value)) 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -