📄 recordeditor.js
字号:
/*
* Isomorphic SmartClient
* Version 6.5 (2008-04-30)
* Copyright(c) 1998-2007 Isomorphic Software, Inc. All rights reserved.
* "SmartClient" is a trademark of Isomorphic Software, Inc.
*
* licensing@smartclient.com
*
* http://smartclient.com/license
*/
//> @class RecordEditor//// This is a helper class for ListGrids, used to implement showing a filterEditor row.// They are created automatically by a ListGrid instance with the 'showFilterEditor' flag set to// true, and used to enter criteria, which will then be used to filter the ListGrid.//// RecordEditors are implemented as a subclass of ListGrid, showing no header and a single // row always drawn in the editable state, allowing the user to modify the values at any time.// An "action button" is included to perform the filter action action (may also be triggered // by other user interactions).// The List Grid that created the RecordEditor will handle sizing, positioning// scrolling, field changes/reordering etc. on the RecordEditor.////<// declare the class itselfisc.ClassFactory.defineClass("RecordEditor", "ListGrid");isc.RecordEditor.addProperties({ //> @attr recordEditor.sourceWidget (ListGrid : undefined : RW) // Target ListGrid widget for which we're editing data. Should be defined on // a per-instance basis at init time. //< // sourceWidget:null, autoDraw:false, cellSpacing:0, cellPadding:0, selectionType:"none", showRollOver:false, baseStyle:"recordEditorCell", // Don't show the header for the list showHeader:false, // If we're set up with no fields, we won't be showing the edit row until setFields is // called. In this case don't show the empty message. showEmptyMessage:false, bodyOverflow:"hidden", fixedRecordHeights:true, // skinImgDir - used for the button images // [Note we are not showing a header so do not need access to the standard listGrid images] skinImgDir:"images/RecordEditor/", // Images to show on the action button - either add (plus) or filter (funnel) saveImg:{src:"[SKIN]add.png", width:16, height:16, showOver:true}, filterImg:{src:"[SKIN]filter.png", width:16, height:16, showOver:true}, actionButtonStyle:"normal", // Setting listEndEditAction to "next" allows this list to show an edit row with no associated // record in the data object listEndEditAction:"next", // Don't show the edit click mask - we are not dismissing edits on click outside. _showEditClickMask : function () {}, // specify canEdit true to allow the editRowForm to be shown. // Note that we aren't setting an editEvent - this widget is *always* in editable state canEdit:true, // Always show the entire row as editable editByCell:false, // avoid focussing on the ListGrid body - we only want to be able to focus on the edit // form items within the ListGrid. canFocus:false, // set _resizeWithMaster to false. We want to resize horizontally with the master, but // not vertically - we need to move in order to remain in position below the master instead // This is handled by custom logic in listGrid.resizePeersBy() _resizeWithMaster:false, // Apply "normal" style to the body - we don't expect it to have any borders, etc which // could get applied to the GR class as a whole bodyStyleName:"normal" });//!>Deferredisc.RecordEditor.addMethods({ initWidget : function () { if (this.sourceWidget != null) { // We want the width to match the sourceWidget's width. // This allows the fields to align with sourceWidget's the body columns var source = this.sourceWidget; this.setWidth(source.getWidth()-(source.getLeftMargin() + source.getRightMargin())); // If the sourceWidget is not leaving a scrollbar gap, we shouldn't either - the // button will still float over the scrollbar area, but this ensures that any // fields of width "*" will size the same in this widget as in the sourceWidget this.leaveScrollbarGap = this.sourceWidget.leaveScrollbarGap; // If this is a filter editor, perform a filter whenever the user changes fields // if this.sourceWidget.filterByCell is true if (this.actionType == "filter") { this.actOnCellChange = this.sourceWidget.filterByCell; this.actOnKeypress = this.sourceWidget.filterOnKeypress; } else { // Otherwise, if saveByCell is true, perform a save whenever the user changes // fields. this.actOnCellChange = this.sourceWidget.saveByCell; } // ensure that the editForm is autoFocus:false, we don't want to jump focus into // the form everytime it gets redrawn. isc.addProperties(this.editFormDefaults, {autoFocus:false}); // Pick up field ID and fields from the source widget. this.fieldIDProperty = this.sourceWidget.fieldIDProperty; this.fields = this.sourceWidget.completeFields.duplicate(); // For filter editors, clear out editing related properties such as custom change // handlers from the field. These are not appropriate on the filter editor since // we're not actually performing an edit of a record in the source widget. // See also 'getEditorProperties()' if (this.actionType == "filter") { for (var i = 0; i < this.fields.length; i++) { var field = this.fields[i]; delete field.defaultValue; delete field.changed; delete field.change; delete field.defaultDynamicValue; delete field.icons; delete field.showPickerIcon; } } } else { this.logWarn("RecordEditor initialized without a sourceWidget property. " + "This widget is not supported as a standalone component."); } return this.Super(this._$initWidget); }, // Override 'draw()' to ensure that we're editable draw : function () { var firstEditCell = this.findNextEditCell(0,0,1,true,true); if (firstEditCell == null) { this.logWarn("No editable fields in this record editor." + (this.actionType == "filter" ? " Check the 'canFilter' property for each field in " : " Check the 'canEdit' property for each field in " ) + this.sourceWidget.getID()); } else { // Set up a starting set of edit values based on // for filtering: the current filter if there is one, otherwise the field-wise // defaultFilterValue for each field // for editing: the default value of the field var isFilter = this.actionType == "filter", vals; if (isFilter) { vals = this.sourceWidget._getFilterEditorValues(); } else { var undefined; vals = {}; for (var i = 0; i < this.fields.length; i++) { var field = this.fields[i]; if (field.defaultValue !== undefined) { vals[field[this.fieldIdProperty]] = field.defaultValue; } } } this.setEditValues(0, vals); var firstEditCol = firstEditCell[1]; // Note if we don't have any fields, this is a no-op this._startEditing(0,firstEditCol); } this.Super("draw", arguments); // Ensure the actionButton shows up on top of the body this._actionButton.bringToFront(); }, setFields : function () { this.Super("setFields", arguments); // If we're drawn(), but we didn't have fields before this setFields call, startEditing // now var firstEditCell = this.findNextEditCell(0,0,1,true,true); if (this.isDrawn() && !this._editorShowing) this._startEditing(0, firstEditCell[1]); }, // Override createChildren to make the actionButton createChildren : function () { this.Super("createChildren", arguments); // Never allow the body to protrude past the end of the action-button if (!this._actionButton) this.makeActionButton(); }, // MakeActionButton -- this is a button that will float on top of the RecordEditor body, // aligned with the scrollbar of the sourceWidget, with click set to perform the filter // or save action using the current set of edit values. makeActionButton : function () { var actionIcon; if (this.actionType == "filter") { actionIcon = this.filterImg; } else { actionIcon = this.saveImg; } this._actionButton = isc.Button.create({ // Note we want the height to match the rendered inner height of this ListGrid // which is the visible height of the body. However the body hasn't been drawn // yet, so we handle this via an override to adjustOverflow(), which also ensures // we'll be resized if the body is resized //height:this.body.getVisibleHeight(), // Float the button over where the body scrollbar would normally appear left:this.getInnerWidth() - this.getScrollbarSize(), width:this.getScrollbarSize(), autoDraw: false, // use button icon only, no title baseStyle: this.actionButtonStyle, skinImgDir: this.skinImgDir, icon: actionIcon.src, showRollOverIcon: actionIcon.showOver, // Pick up showFocused if specified showFocusedIcon:actionIcon.showFocused, showFocusedAsOver:false, click : function () {this.parentElement.performAction();} }); this.addChild(this._actionButton); // use setTabAfter to ensure that the user will tab to the button after tabbing through // the edit form fields, which will pick up their tab index from this widget's tabIndex this._actionButton._setTabAfter(this); }, performAction : function (suppressPrompt) { if (this.actionType == "filter") this.performFilter(suppressPrompt); else this.performSave(suppressPrompt); }, // performFilter() - filter the source widget with the values from this widget performFilter : function (suppressPrompt) { var criteria = this.getValues(); criteria = isc.DataSource.filterCriteriaForFormValues(criteria); var context = {}; if (suppressPrompt) context.showPrompt = false; this.sourceWidget.filterData(criteria, null, context);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -