📄 dynamicform.js
字号:
// Catch the case where we had no focusItem; if (itemIndex == -1) continue; var item = items[itemIndex], cw = item.containerWidget; if (cw == this || !item.isDrawn() || !item.isVisible()) continue; var cwID = cw.getID(); if (containerWidgets[cwID] == null) { containerWidgets[cwID] = cw.visibleAtPoint(x,y,withinViewport, ignoreWidgets); } if (!containerWidgets[cwID]) continue; var PL = item.getPageLeft(), PT = item.getPageTop(); if (PL <= x && (PL + item.getVisibleWidth()) >= x && PT <= y && (PT + item.getVisibleHeight()) >= y) { return true; } } return false;},// addItems - slot new items into the appropriate position in the items in this DynamicFormaddItems : function (newItems, position) { if (!isc.isAn.Array(newItems)) newItems = [newItems]; if (this.dataSource) { var ds = isc.DS.get(this.dataSource); for (var i = 0; i < newItems.length; i++) { newItems[i] = ds.combineFieldData(newItems[i]); } } if (position == null || position > this.items.length) position = this.items.length; this._addItems(newItems, position);},_$upload : "upload",_$mutex:"mutex",_addItems : function (newItems, position, fromSetItems, firstInit) { // adding items will almost always change the tab-index-span used by the form // If this increases, we need to catch the case where the tabIndex of our items overlaps // the next widget on the page var drawn = this.isDrawn(), oldSpan = drawn ? this.getTabIndexSpan() : null; //this.logWarn("addItems: " + this.echoAll(newItems)); // apply type-based field defaults to the items passed in // Note: this will not change the type of an already-instantiated form item, so we do this // before converting the items init objects to FormItems this.applyFieldDefaults(newItems); var sectionItems = []; // iterate through all the items, creating FormItems from object literals var haveUploadFields = false, foundFileItem = false, mutexSections = (this.sectionVisibilityMode == this._$mutex); for (var itemNum = 0; itemNum < newItems.length; itemNum++) { var item = newItems[itemNum]; // remove any empty items from the list if (!item) { newItems.removeItem(itemNum); itemNum--; continue; } var itemType = this.getEditorType(item); newItems[itemNum] = item = this.createItem(item, itemType); if (itemType == this._$upload) haveUploadFields = true; if (isc.FileItem && isc.isA.FileItem(item) && foundFileItem) { this.logWarn("Attempting to creating a form with multiple FileItems. This is " + "not currently supported - only the first file type field value will " + "be committed on submission of this form."); } // add to list of form sections that should start out hidden if (isc.isA.SectionItem(item)) { sectionItems.add(item); // remember the last visible section for mutex operation if (item.sectionExpanded && mutexSections) this._lastExpandedSection = item; } } // Actually store the items in this.items if (fromSetItems) this.items = newItems else this.items.addListAt(newItems, position); if (!firstInit) this.setItemValues(this.getValues(), false, true, newItems); // enable multipart encoding if upload fields are included // NOTE: imperfect: we aren't detecting all the ways you can include an UploadItem, eg // editorType:"UploadItem" isn't caught, neither would any subclasses be. if (haveUploadFields) this.encoding = isc.DynamicForm.MULTIPART_ENCODING; for (var i = 0; i < sectionItems.length; i++) { var sectionItem = sectionItems[i], isVisible = sectionItem.sectionExpanded; if (isVisible && (!mutexSections || (this._lastExpandedSection == sectionItem))) { // call expandSection on visible items to ensure that sections defined with an // inline items array have added their items to the form. sectionItem.expandSection(); } else { // hide form sections for section items that have sectionExpanded property set // to false // do this as separate for loop to ensure that all form items to be hidden have // been initialized sectionItem.collapseSection(); } } // set the _itemsChanged flag so we recalculate the layout this._itemsChanged = true; // If necessary, shift the next widget's tabIndex forward to make room for our new items. var tabIndex = this.getTabIndex(); if (drawn && tabIndex != -1) { // we have to explicitly call _assignTabIndices here so that getTabIndexSpan() will // return an updated value. Normally the items' tabIndices are assigned when // 'getTabIndex()' is called on them, which wouldn't happen until getInnerHTML() from // the delayed redraw (below). this._assignTabIndices(); var span = this.getTabIndexSpan(); if (span > oldSpan) { var nextWidget = this._getNextTabWidget(); if (nextWidget) { var nextWidgetIndex = nextWidget.getTabIndex(); if (nextWidgetIndex < (tabIndex+ span)) { nextWidget._shiftTabIndexForward((tabIndex + span) - nextWidgetIndex); } } } } this.markForRedraw("Form items added");},_knownProps : ["name", "editorType", "type", "valueMap", "defaultValue", "showTitle", "left", "top", "width", "height"],copyKnownProperties : function (target, props, propNames) { var undef; for (var i = 0; i < propNames.length; i++) { var propName = propNames[i], value = props[propName]; if (value !== undef) { target[propName] = value; delete props[propName]; } }},createItem : function (item, type) { // We may want to support having the user specify which form an item belongs to before it // is initialized as a FormItem instance. (The specified form will then handle values // management, etc.) // However this is not currently supported - we'll always have form items point back to the // form that created them. // (Note: We may want a customizable 'formProperty' property, rather than hardcoding the // "form" property) if (item.form != null && !(item.form == this.getID() || item.form != this)) { this.logWarn("Unsupported 'form' property [" + item.form + "] set on item:" + item + ". Ignoring."); } // convert from a simple object into a FormItem var className = isc.FormItemFactory.getItemClassName(item, type, this), classObject = isc.FormItemFactory.getItemClass(className); if (!classObject) { this.logWarn("Problem initializing item: "+isc.Log.echo(item) +" - derived FormItem class is: "+className +". Please make sure the relevant module is loaded"); return; } var itemConfig = item; item = classObject.createRaw(); // set up a pointer back to this form, and to the containerWidget, which might be a // different widget, eg a grid doing inline editing. // Note: several FormItem methods assume item.form will be set before init() is called. // CanvasItems at least need containerWidget in init as well. // set this up as the item's eventParent (for ISC bubbling) item.form = item.containerWidget = item.eventParent = this; if (isc.Browser.isIE && this.canAlterItems) { this.copyKnownProperties(item, itemConfig, this._knownProps); } if (this.autoChildItems) { // use the autoChild system to instantiate items with FormItem class-specific defaults // ensure an auto-ID is not assigned by the autoChild system if (item.ID == null) item.ID = null; this._completeCreationWithDefaults(classObject.Class, item, itemConfig); } else { //this.logWarn("item: " + this.echoLeaf(item) + ", item.form is: " + item.form + // ", itemConfig is: " + this.echo(itemConfig)); item.completeCreation(itemConfig); } item.form = this; if (item.destroyed) item.destroyed = false; // Log a warning if this item has no name, but is expected to save values // See comment in formItem.js next to the 'shouldSaveValue' property declaration. // (Note: we could put this check into FormItem.init) if (item.shouldSaveValue && (item[this.fieldIdProperty] == null || isc.isAn.emptyString(item[this.fieldIdProperty]))) { // 'shouldSaveValue' is a property denoting whether this item should be included // in the form's values object. // False by default for non-data items. this.logWarn(item.getClass() + " form item defined with no '" + this.fieldIdProperty + "' property - Value will not be saved." + " To explicitly exclude a form item from the set of values to " + "be saved, set 'shouldSaveValue' to false for this item.") item.shouldSaveValue = false; } return item;},//> @method dynamicForm.removeItems()// Removes some items from this form.// Marks form to be redrawn.//// @group elements// @param items (object[]) list of form items to remove from the form//<removeItems : function (items) { if (items == null) return; if (!isc.isAn.Array(items)) items = [items]; // If passed this.items, duplicate it - we want to be able to manipulate this.items without // changing the array passed in. if (items == this.items) items = this.items.duplicate(); items = this.map("getItem", items); this.items.removeList(items); // if we've removed any items from this form, destroy() them to for (var i = 0; i < items.length; i++) { var item = items[i]; // bad item name passed in, getItem() failed if (item == null) continue; // If this has sub-items, slot them in after this item in the items array if (item.items != null) { items.addList(item.items, i+1); } // don't leave a pointer to a destroyed focus item. if (this._focusItem == item) delete this._focusItem; if (!this.items.contains(item) && isc.isA.FormItem(item)) item.destroy(); } // set the _itemsChanged flag so we recalculate the layout this._itemsChanged = true; this.markForRedraw("Form items removed")},// canvas overridesaddField : function (field, position) { this.addItems(field, position) },removeField : function (field) { this.removeItems(field); },// obvious synonyms for single items addItem : function (item) { this.addItems(item); },removeItem : function (item) { this.removeItems(item); },// Synonymous addFields / removeFields methods for completenessaddFields : function (items, pos) { return this.addItems(items, pos);},removeFields : function (items) { return this.removeItems(items);},// tabIndex management// ---------------------------------------------------------------------------------------// Widget level _canFocus// If this method returns false we will not get keyboard events on the form.// Therefore check for our items' _canFocus() instead.// Only respect canFocus:false if we have no focusable items_canFocus : function (a,b,c,d) { // shortcut: allow canFocus:true if (this.canFocus == true) return true; var items = this.getItems(); for (var i = 0; i < items.length; i++) { if (items[i]._canFocus()) return true; } return this.invokeSuper(isc.DynamicForm, "_canFocus", a,b,c,d);},// Assign ascending tabIndices to form items with no explicitly as
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -