📄 valuesmanager.js
字号:
hasFieldErrors : function (fieldName) { var form = this.getMemberForField(fieldName); if (form && form.hasFieldErrors(fieldName)) return true; var hiddenErrors = this.getHiddenErrors(true); if (hiddenErrors && hiddenErrors[fieldName] != null) return true; return false; }, //> @method valuesManager.showErrors() // Method to explicitly show the latest set of validation errors present on this // ValuesManager.<br> // Will redraw all member forms to display (or clear) currently visible errors, and // fire +link{valuesManager.handleHiddenValidationErrors()} to allow custom handling of // hidden errors. // @group errors // @visibility external //< // suppressHiddenErrorSynch parameter: indicates we know our stored hidden errors match the // currently visible set of fields [so we just ran validate() or setErrors()]. // passed through to _handleHiddenValidationErrors() showErrors : function (suppressHiddenErrorSynch) { if (this.members) { for (var i= 0; i < this.members.length; i++) { if (!this.members[i].isDrawn() || !this.members[i].isVisible()) continue; this.members[i].markForRedraw("ValuesManager validation errors"); } } if (this.hiddenErrors != null) { this._handleHiddenValidationErrors(suppressHiddenErrorSynch); } }, //> @method valuesManager.showFieldErrors() // Method to explicitly show the latest set of validation errors present on some field // within this ValuesManager.<br> // If the field in question is present as a visible item in a member form, the form item // will be redrawn to display the error message(s). // Otherwise +link{valuesManager.handleHiddenValidationErrors()} will be fired to allow // custom handling of hidden errors. // @group errors // @visibility external //< showFieldErrors : function (fieldName) { var form = this.getMemberForField(fieldName); if (form && form.isVisible() && form.isDrawn()) { var item = form.getItem(fieldName); if (item && item.visible) { item.redraw("Validation errors modified"); return; } } // At this point we know we have a hidden error for the field - fire the // handleHiddenValidationErrors method. Of course that actually 'shows' the // errors for all hidden fields, not just this one. this._handleHiddenValidationErrors(); }, // Flow Methods: //>@method getFilterCriteria() // Return the set of filter criteria for this valuesManager based on its current set of // values // @return (object) set of name:values pairs to be used as filter criteria //< getFilterCriteria : function () { // get filter criteria from all my members var crit = {}; if (this.members) { for (var i =0; i < this.members.length; i++) { isc.addProperties(crit, this.members[i].getFilterCriteria()); } } // Mix in any values we have that didn't come from member forms var values = this.getValues(), undef; for (var field in values) { if (crit[field] !== undef) delete values[field]; } // filterCriteriaForFormValues will clear out null values, and handle arrays with an // empty entry (Implies a null criterion) isc.addProperties(crit, isc.DataSource.filterCriteriaForFormValues(values)); return crit; }, // ======================================================================================== // Values Management APIs // ======================================================================================== //>@method ValuesManager.getValues() // Returns the current set of values for the values manager instance. This includes the // values from any form managed by this manager, as well as any values explicitly applied // via +link{valuesManager.setValues()}. // @return (object) a map of the values for this manager // @visibility external // @group formValues //< getValues : function () { // if one of our member forms has focus, ensure its focus-item's value has been saved // out [which will update this.values] if (this.members != null) { var fc = isc.EH.getFocusCanvas(); if (this.members.contains(fc)) fc.updateFocusItemValue(); } // Never let this.values be externally accessible. return isc.addProperties({}, this.values); }, //>@method ValuesManager.setValues() // Set the values for this values manager. Member forms will be updated as required by // this change. // Note that pre-existant values in other fields are cleared out by this. // // @param values (object) new set of values for this values manager. // @visibility external // @group formValues //< setValues : function (values) { if (isc.isAn.Array(values)) { var useFirst = isc.isA.Object(values[0]); this.logWarn("values specified as an array." + (useFirst ? " Treating the first item in the array as intended values." : " Ignoring specified values.")); if (useFirst) values = values[0]; else values = null; } // Duplicate the values object so we can manipulate it and apply it directly to // this.values without interfering with external code. values = isc.addProperties({}, values); var undef; for (var i = 0; i < this.members.length; i++) { var form = this.members[i], fields = form.getItems().getProperty(form.fieldIdProperty), changedValues = {}; for (var ii = 0; ii < fields.length; ii++) { var fieldName = fields[ii]; if (values[fieldName] !== undef) { changedValues[fieldName] = values[fieldName]; // If we've set the value on a form item, clear it out of the values object // passed in - so values will end up as a minimal list of values below delete values[fieldName] } } // set the values on the form form.setValues(changedValues); } // The values param now contains just the values passed in that didn't exist in any // member form. // use _updateValuesFromMembers() to add the values from every form, including any // defaults for the form item values this.values = values; this._updateValuesFromMembers(); // remember values for resetting this.rememberValues(); }, //>@method ValuesManager.setData() // Set the data (values) on this valuesManager [synonym for <code>setValues()</code>]. //< // setData() is used in dataBinding rather than setValues. setData : function (values) { return this.setValues(values); }, //>@method ValuesManager.clearValues() // Clear out all the values managed by this values manager. // @visibility external // @group formValues //< clearValues : function () { this.setValues({}); }, //>@method ValuesManager.getMemberValues() // Returns the subset of this valuesManager's values associated with some member form. // // @param ID (string) ID of the member form for which we want to retrieve the values. // @return (object) a map of the values for the appropriate member form. // @visibility external // @group formValues //< getMemberValues : function (ID) { var member = this.getMember(ID); if (member != null) return member.getValues(); }, //>@method ValuesManager.setMemberValues() // Set the values for some member form // @param ID (string) ID of the member form to update // @param values (object) new values for the form // @visibility external // @group formValues //< setMemberValues : function (ID, values) { var member = this.getMember(ID); if (member != null) return member.setValues(values); }, //> @method ValuesManager.rememberValues ([A]) // @include dynamicForm.rememberValues() //< // Values may change as a result of // - adding a new member and picking up values for fields for which we previously had no // value // - the user modifying values in a field // - calls to 'setValue()' [not setValues as that will re-remember the values after setting] rememberValues : function () { var values = this.getValues(); // create a new object to hold the values this._oldValues = {} for (var prop in values) { if (!isc.isA.Function(values[prop])) { // Special case for dates - duplicate them rather than copying the object // across if (isc.isA.Date(values[prop])) { this._oldValues[prop] = new Date(); this._oldValues[prop].setTime(values[prop].getTime()); } else { this._oldValues[prop] = values[prop]; } } } return this._oldValues; }, //> @method ValuesManager.resetValues ([A]) // @include dynamicForm.resetValues() //< resetValues : function () { // pull the values from form._oldValues into ValuesManager.values var values = {}; for (var prop in this._oldValues) { // special case for dates - we want to reset the value of the date, but not actually // replace the object if (isc.isA.Date(this._oldValues[prop])) { var currentVal = this.getValue(prop); if (isc.isA.Date(currentVal)) { currentVal.setTime(this._oldValues[prop].getTime()) values[prop] = currentVal; } else { values[prop] = this._oldValues[prop].duplicate(); } } else { values[prop] = this._oldValues[prop]; } } this.setValues(values); }, //> @method ValuesManager.valuesHaveChanged ([A]) // @include dynamicForm.valuesHaveChanged() //< valuesHaveChanged : function () { var values = isc.addProperties({}, this.getValues()), prevValues = this._oldValues, different = false; for (var i in prevValues) { if (isc.isA.Date(prevValues[i])) { if (!isc.isA.Date(values[i]) || Date.compareDates(values[i], prevValues[i]) != 0) { different = true; } } else { if (prevValues[i] != values[i]) different = true; } // If we found a difference, return true. // Otherwise remove the field from the cloned values object - we can use this to // check whether any new fields have been added to the values object. if (different) return true; else delete values[i]; } // if we have any new values, return true for (var i in values) { if (values[i] && !isc.isA.Function(values[i])) return true; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -