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

📄 actionmethods.js

📁 javascript 很酷的类库
💻 JS
📖 第 1 页 / 共 3 页
字号:
/*
 * 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
 */
 isc.Canvas.addMethods({    // create a DSRequest object in the context of a dataBound component, by gathering    // various component-level settings that affect how an operation is performed, and     // creating a dsRequest object (called a "context" for legacy reasons)    buildRequest : function (context, operationType, callback) {		if (!context) context = {};        // "afterFlowCallback": supported by the DataSource system, this is a second callback        // that fires after dsRequest.callback.  This is a convenience for action methods which        // need to call a basic dataSource method (eg ds.updateData()) and get called back to        // do post-processing and *also* need to provide a callback to the end developer.        // "afterFlowCallback" fires after the callback passed to dataSource methods like        // addData().        if (callback) context.afterFlowCallback = callback;            // text match style:         // - support the legacy "filter" operationType.        // - pick up setting on ListGrids and DynamicForms        if (operationType == "filter") {            operationType = "fetch";            // If textMatchStyle was explicitly specified respect it - otherwise mark            // as a substring match (filter rather than fetch)            if (context.textMatchStyle == null) context.textMatchStyle = "substring";        }        if (this.textMatchStyle != null) context.textMatchStyle = this.textMatchStyle;                // support old operationType synonyms        operationType = isc.DS._getStandardOperationType(operationType);        // pick up component.dataPageSize for fetches        if (this.dataPageSize) context.dataPageSize = this.dataPageSize;        // pick up an operation name from the component, according to the type of operation        // being performed.  NOTE: if context.operation is already specified, give it        // precedence, as this indicates manual invocation with an explicitly specified        // operation.        var operation = context.operation;        if (operation == null) {            switch (operationType) {                // NOTE: "saveOperation", "deleteOperation" and the non-specific                // "this.operation"  are backCompat                case "fetch":                    operation = this.fetchOperation; break;                case "add":                    operation = this.addOperation || this.saveOperation; break;                case "update":                    operation = this.updateOperation || this.saveOperation; break;                case "remove":                    operation = this.removeOperation || this.deleteOperation; break;                case "validate":                    operation = this.validateOperation; break;            }            context.operation = operation || this.operation;        }        return isc.rpc.addDefaultOperation(context, this.dataSource, operationType);    },        // create a ResultTree dataModel based on the component's current config    createResultTree : function (criteria, callback, requestProperties, type) {        // The callback is passed in from fetchData() so should be fired when the server        // responds with the requested nodes.        this._initialFetchCallback = callback;                 if (type == null) type = "fetch";		requestProperties = this.buildRequest(requestProperties, type,                                                 {target:this, methodName:"_fireFetchCallback"});        // put together Tree-specific properties for the data model we're auto-creating        var tree = isc.addProperties({initialData: this.initialData},                                     this.dataProperties,                                     requestProperties.dataProperties                                     //>!BackCompat 2006.10.19                                     // Provide back-compat support for 'treeProperties'                                      ,this.treeProperties,                                     requestProperties.treeProperties                                     //<!BackCompat                                     );        tree.criteria = criteria;        tree.operation = requestProperties.operation;        tree.context = requestProperties;        tree.dataSource = this.dataSource;                // mark as autoCreated so it gets auto-destroyed, removing DS<->RS links        tree._autoCreated = true;        // pick up load data on demand for TreeGrids        if (this.loadDataOnDemand != null) tree.loadDataOnDemand = this.loadDataOnDemand;        // for multi-DS trees: cross-DS relations        if (this.treeDataRelations) tree.treeRelations = this.treeDataRelations;        if (this.multiDSTree != null) tree.multiDSTree = this.multiDSTree;        var resultTreeClass = this.getDataSource().resultTreeClass || "ResultTree";        return isc.ClassFactory.getClass(resultTreeClass).create(tree);    },    _fireFetchCallback : function (dsResponse,data,dsRequest) {        // callback fired whenever we get new data from the server.        // use this to fire the callback passed into fetchData if there was one (and then        // drop that callback so we don't fire it repeatedly as the user opens child-nodes etc)        if (this._initialFetchCallback) {            this.fireCallback(this._initialFetchCallback, "dsResponse,data,dsRequest", arguments);            delete this._initialFetchCallback;        }    }});//>ValuesManager : add buildRequest to ValuesManager, which isn't a Canvasif (isc.ValuesManager) {    isc.ValuesManager.addMethods({        buildRequest : isc.Canvas.getInstanceProperty("buildRequest")    });}//<ValuesManager// Many flow methods are identical on databound DynamicForms and ValuesManagers.// Define these methods in an interface to mix into both classes.isc.ClassFactory.defineInterface("EditorActionMethods");isc.EditorActionMethods.addInterfaceMethods({        // Editing and Saving    //-------------------------------------------------------------------------------    //>!BackCompat 2004.7.23	save : function (context) { return this.saveData(context) },	editSelected : function (selectionComponent, context) {         return this.editSelectedData(selectionComponent, context)     },	editNew : function (initialValues, context) {         return this.editNewRecord(initialValues, context)     },    //<!BackCompat        // NOTE: editNewRecord / editRecord / editSelectedData et al do not go to the server,    // although in a future implementation of editSelected() it may be necessary to go to the    // server to get fields not being shown in the selection component.    //>	@method dynamicForm.editNewRecord()    //    // Prepare to edit a new record by clearing the current set of values (or replacing them     // with initialValues if specified).    // <br>    // Subsequent calls to <code>saveData()</code> will use an <code>add</code> rather than    // an <code>update</code> operation.    //    // @param [initialValues] (object)    //     initial set of values for the editor as a map of field names to their corresponding    //     values    // @see dynamicForm.saveData()    //    // @group dataBoundComponentMethods    // @visibility external    //<	editNewRecord : function (initialValues) {        this.saveOperationType = "add";		this._editRecord(initialValues);	},        //>	@method dynamicForm.editRecord()    //    // Edit an existing record.  Updates this editors values to match the values of the record     // passed in.    // <P>    // Subsequent calls to <code>saveData()</code> will use an <code>update</code> rather than    // an <code>add</code> operation.    //    // @param record (object)    //     the record to be edited as a map of field names to their corresponding values    // @see dynamicForm.saveData()    //    // @group dataBoundComponentMethods    // @visibility external    //<	editRecord : function (record) {                this.saveOperationType = "update";        this._editRecord(record);	},        _editRecord : function (record) {        delete this._editRecordNum;        delete this._editList;        var record = isc.addProperties({}, record);        this.setData(record);    },    //>	@method dynamicForm.editSelectedData()    //    // Edit the record selected in the specified selection component (typically a    // +link{ListGrid}).    // <P>    // Updates the values of this editor to match the selected record's values.    // <P>    // If this form has a dataSource, then saving via +link{saveData()} will use the     // "update" operation type.    //    // @param selectionComponent (ListGrid or ID)    //     the ListGrid or ID of a +link{ListGrid} whose currently selected    //     record(s) is/are to be edited    // @see dynamicForm.saveData()    //    // @group dataBoundComponentMethods    // @visibility external    // @example updateOperation    //<    editSelectedData : function (selectionComponent) {        // support being passed an ID        if (isc.isA.String(selectionComponent)) selectionComponent = window[selectionComponent];        if (!selectionComponent) return;                var selection = selectionComponent.selection.getSelection();        if (selection && selection.length > 0) this.editList(selection);    	},				editList : function (recordList) {        this.saveOperationType = "update";		this._editRecords(recordList);	},        // actually start editing a recordList (start with the first record in the list)     _editRecords : function (recordList) {        this._editRecordNum = 0;        this._editList = recordList;        var record = isc.addProperties({},recordList[this._editRecordNum]);        this.setData(record);    },    editNextRecord : function () {        this.editOtherRecord(true);	},   	editPrevRecord : function () {        this.editOtherRecord(false);	},    editOtherRecord : function (next) {        // not valid if we never had a call to editList.        if (!this._editList) return;        		if (this.isVisible() && this.valuesHaveChanged()) {            // remember whether we're editing next or previous            this._next = next;            this.saveData({target:this, methodName:"editOtherReply"});            return;        };                if (next && this._editRecordNum >= this._editList.length-1) {            this.logWarn("Unable to edit next record - this is the last selected record");            return false;        }        if (!next && this._editRecordNum <= 0) {            this.logWarn("Unable to edit previous record - this is the first selected record");            return false;        }        this._editRecordNum += (next ? 1 : -1);        var nextRecord = isc.addProperties({}, this._editList[this._editRecordNum]);        this.setData(nextRecord);    },	// reply to the 'save editor' call	editOtherReply : function (response, data, request) {		        var next = this._next;        delete this._next;        		// error occurred: the presence of response.errors indicates it's a validation error, which		// we can handle.  Note we assume the developer meant a validation error if        // response.errors was provided, regardless of whether you set the correct validation        // error status code.		if (response.status < 0 && response.errors) {			return this.setErrors(response.errors, true);		}		// some error we weren't expecting occurred, bail with an error dialog		if (response.status < 0) return isc.RPCManager._handleError(response, request);                // remember the values in the form and in the _editlist...        this.rememberValues();        this._editList[this._editRecordNum] = this.getValues();                // call editOther - to show the next record        this.editOtherRecord(next)		return true;	},            //> @method dynamicForm.validateData()    //    // Perform validation on the client and the server.    //    // @group validation    // @visibility external    //<    validateData : function (callback, requestProperties) {        // do simple client side validation first         if (!this.validate()) return false;        var values = this.getValues();                // validate the data on the server        // Note: As written, if a callback is not supplied we use 'saveDataReply' which will        // redraw the form to show errors - otherwise we rely on the callback to apply errors        // to the form.        var context = this.buildRequest(requestProperties, "validate");            context.willHandleError = true;        context.editor = this;        // valuesAsParams - also sends the DSRequest values as request parameters        if (context.valuesAsParams) {            if (!context.params) context.params = {};            isc.addProperties(context.params, values);        }		var dataSource = this.getDataSource();        return dataSource.performDSOperation(                    context.operation.type, values,                     callback ? callback : {target:this, methodName:"saveEditorReply"},                     context                );    },    //>	@method	dynamicForm.reset()   ([])

⌨️ 快捷键说明

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