Edit Record using onclick

Hello,

We are retrieving information from iSheet and displaying it in a custom table. Each row in the table has an "Edit Item" button that uses the same onclick function as the regular "Edit" button.

 

When the "Edit Item" button is clicked, the "Edit Record" modal opens with the correct iSheet entry. However, when we try to save any changes, the system displays an unlimited loading icon and the changes are not saved.

 

We are wondering if there is a way to use the "Edit Record" feature in this manner and if there are any configurations that we might be missing.

 

Thanks!

Parents
  •   ,

    Hi Alex,

    Firstly, I would state that this isn't a supported function yet, i.e. you cannot add an Edit Sheet Item link, from the FCKEditor link function, for dashboards or wikis.
    I've lost count of the number of years this feature has been repeatedly asked for (in the Client Community).

    Secondly, the function you are calling is an internal function that HighQ have created for use in the iSheet module. So, as you have found, outside of this module the modal this generates does not quite operate how you would want - it breaks!

    Thirdly, if you intend to go down this path then I should warn you that you will need to re-test after every upgrade to Collaborate as your code may now not work as HighQ are under no obligation to make sure your code still works when this function is not meant to be used by you. I would also add that I would only take this path if you or your team have a good grasp of Javascript - otherwise you may be creating "a rod for your own back" where there is now an expectation on your team that this needs to keep working, regardless of upgrade issues.

    Now that's out the way, the reason this is not working for you is because the iSheet modal (form) created - by you calling AddSheetItemCollection.editItem() - is missing a few dependencies that are present in the iSheet module.

    You would have noticed that the column conditions are also broken in your form, and that fields are not displaying or hiding based on their specified conditions.  This is due to a missing global variable (sheetHomePageVar) that would have contained some key configuration details.

    There is also the problem that when you submit the iSheet form, nothing happens. This is due in part to the same issue as above. However, by solving that hurdle you will then be faced with the next: post-operations after the form has been submitted. One of these post-ops is to essentially update the iSheet view with the now modified data-set.  This post-op again requires several dependencies to be present for it to work and not send you to the dreaded "Access restricted" page (error_Permission.action).

    I've attached a library that helps "navigate" these particular features.

    So if you were to include/load the library, then given your example, you would call the library as such:

    // to add an item...
    CommunityExamples.Sheet.addItem({
       siteID:986,
       sheetID:1282
    });
    	
    // to edit an existing item...
    CommunityExamples.Sheet.editItem({
       siteID:986,
       sheetID:1282,
       sheetViewID:7183,
       itemID:143380
    });
    	
    // to edit an existing item, without prior check to
    // see if site/sheet/view exists...
    CommunityExamples.Sheet.editItem({
       siteID:986,
       sheetID:1282,
       sheetViewID:7183,
       itemID:143380,
       checkAccess:false
    });
    

    The calls are asynchronous and wrapped in Promises, so you can then/await as you wish:

    CommunityExamples.Sheet.editItem({ 
       siteID:986,
       sheetID:1282,
       sheetViewID:7183,
       itemID:143380
    }).then(res => {
    	
       // iSheet modal loading/loaded... 
    	
    });

    Again, I'll restate that I would only go down this path if you have the skills and the capacity to support it across future versions of Collaborate.

    Hope this helps,
    Andrew

    /*  
    	Copyright (c) Corrs Client and Digital Solutions
    
    	Permission is hereby granted, free of charge, to any person
    	obtaining a copy of this software and associated documentation
    	files (the "Software"), to deal in the Software without
    	restriction, including without limitation the rights to use,
    	copy, modify, merge, publish, distribute, sublicense, and/or sell
    	copies of the Software, and to permit persons to whom the
    	Software is furnished to do so, subject to the following
    	conditions:
    
    	The above copyright notice and this permission notice shall be
    	included in all copies or substantial portions of the Software.
    
    	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    	EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
    	OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    	NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
    	HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
    	WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    	OTHER DEALINGS IN THE SOFTWARE.
    */
    ;(function($, window, document, undefined) {
    	
    	const inSheetModule = () => window.collab_common_moduleName === "SITE_MODULE_ISHEET";
    	
    	if (!inSheetModule()) {
    		window.iSheetHomePageCollection = window.iSheetHomePageCollection || {};
    		window.iSheetHomePageCollection.changePage = () => null;
    		if (!window.iSheetHomePageCollection["@@ceFnSFA"]) {
    			window.iSheetHomePageCollection["@@ceFnSFA"] = window.iSheetHomePageCollection.submitFormAjax
    			window.iSheetHomePageCollection.submitFormAjax = function() {
    				switch($.trim(arguments[0])) {
    					case "sheetUserViewMiddlePane.action":
    						return;
    				}
    				return window.iSheetHomePageCollection["@@ceFnSFA"].apply(
    					window.iSheetHomePageCollection,
    					arguments
    				);
    			}
    		}
    	}
    
    	window.CommunityExamples = window.CommunityExamples || {};
    	window.CommunityExamples.Sheet = window.CommunityExamples.Sheet || {};
    		
    	window.CommunityExamples.Sheet.checkContentAccess = (params) => {
    		params = params || {};
    		params.siteID = params.siteID || ~~window.collab_common_metaDataSiteID;
    		if (!window.AddSheetItemCollection) {
    			throw new SyntaxError("CommunityExample: Missing base library");
    		}
    		if (!params.siteID) {
    			throw new SyntaxError("CommunityExample: Missing Site ID");
    		}
    		if (!params.sheetID) {
    			throw new SyntaxError("CommunityExample: Missing Sheet ID");
    		}
    		if (!!params.checkAccess === false) {
    			return Promise.resolve(true);
    		}
    		var dt = new Date(),
    			collabToken = {
    				name: window.collab_csrfTokenName,
    				value: window.collab_csrfTokenValue
    			},
    			urlCheckAccess = "checkContentAccess.action?" + $.param({
    				"metaData.siteID": params.siteID,
    				"metaData.sheetId": params.sheetID,
    				"metaData.sheetViewID": params.sheetViewID || 0,
    				"contentTypeAlias": "sheet",
    				"time": dt.toISOString(),
    				"metaData.screenWidth": $(window).width(),
    				"ts": + dt.getTime()
    			});
    		return new Promise((resolve, reject) => {
    			$.ajax({
    				url: `${urlCheckAccess}&${collabToken.name}=${collabToken.value}`,
    				type: "GET", 
    				dataType: "json"
    			}).done((result) => {
    				if (result && result.access) {
    					resolve(result.access);
    				} else {
    					var msg = window.systemProperty.NO_ACCESS_MESSAGE;
    					console.warn("CommunityExample: ", msg);
    					reject(msg);
    				}
    			}).fail((jqXHR, txtStatus) => {
    				console.error("CommunityExample: Request Access failed:", jqXHR, txtStatus);
    				reject(txtStatus);
    			});
    		});
    	};
    	
    	window.CommunityExamples.Sheet.addItem = (params) => {
    		params = params || {};
    		params.siteID = params.siteID || ~~window.collab_common_metaDataSiteID;
    		params.checkAccess = (params.checkAccess === undefined) ? true : !!params.checkAccess;
    		if (!_.isFunction(window?.AddSheetItemCollection?.addItemModal)) {
    			throw new SyntaxError("CommunityExample: Missing base function");
    		}
    		if (!window.AddSheetItemCollection) {
    			throw new SyntaxError("CommunityExample: Missing base library");
    		}
    		if (!params.siteID) {
    			throw new SyntaxError("CommunityExample: Missing Site ID");
    		}
    		if (!params.sheetID) {
    			throw new SyntaxError("CommunityExample: Missing Sheet ID");
    		}
    		return CommunityExamples.Sheet.checkContentAccess(params).then(res => {
    			window.addItemFromFlySheetHomePageVar = window.addItemFromFlySheetHomePageVar || {};
    			window.addItemFromFlySheetHomePageVar["metaData.siteID"] = params.siteID;
    			window.addItemFromFlySheetHomePageVar["metaData.sheetId"] = params.sheetID;
    			window.AddSheetItemCollection.addItemModal("ADD_ISHEET_ITEM_LINK");
    			return {
    				"action": "CE::SheetItem::Add",
    				"context": {
    					...params
    				}
    			};
    		});
    	};
    	
    	window.CommunityExamples.Sheet.editItem = (params) => {
    		params = params || {};
    		params.siteID = params.siteID || ~~window.collab_common_metaDataSiteID;
    		params.sheetViewID = params.sheetViewID || 0;
    		params.checkAccess = (params.checkAccess === undefined) ? true : !!params.checkAccess;
    		if (!_.isFunction(window?.AddSheetItemCollection?.editItem)) {
    			throw new SyntaxError("CommunityExample: Missing base function");
    		}
    		if (!params.siteID) {
    			throw new SyntaxError("CommunityExample: Missing Site ID");
    		}
    		if (!params.sheetID) {
    			throw new SyntaxError("CommunityExample: Missing Sheet ID");
    		}
    		if (!params.itemID) {
    			throw new SyntaxError("CommunityExample: Missing Sheet Item ID");
    		}
    		return CommunityExamples.Sheet.checkContentAccess(params).then(res => {
    
    			if (!inSheetModule()) {
    				window.sheetHomePageVar = {
    					...window.sheetHomePageVar,
    					sheetID: ~~params.sheetID,
    					siteID: ~~params.siteID,
    					isDraftView: 0,
    					totalRecordCount: 0,
    					idCounter: 0,
    					isDraftView: 0,
    					isImageLibrary: false
    				};
    			}
    			
    			window.AddSheetItemCollection.editItem(
    				params.itemID,
    				params.sheetID,
    				params.siteID,
    				params.sheetViewID
    			);
    			
    			return {
    				"action": "CE::SheetItem::Edit",
    				"context": {
    					...params
    				}					
    			};
    		});
    	};
    		
    })(jQuery.noConflict(), window, document);

  •  Thanks for sharing! It is working like a charm!

    Curious if you know if it will work with the new GridView for the iSheet.

  • Small mod was needed due to newer functions being called by the Collaborate iSheet codebase. I've added the small couple of lines to the editItem() example

    window.CommunityExamples.Sheet.editItem = (params) => {
    		params = params || {};
    		params.siteID = params.siteID || ~~window.collab_common_metaDataSiteID;
    		params.sheetViewID = params.sheetViewID || 0;
    		params.checkAccess = (params.checkAccess === undefined) ? true : !!params.checkAccess;
    		if (!_.isFunction(window?.AddSheetItemCollection?.editItem)) {
    			throw new SyntaxError("CommunityExample: Missing base function");
    		}
    		if (!params.siteID) {
    			throw new SyntaxError("CommunityExample: Missing Site ID");
    		}
    		if (!params.sheetID) {
    			throw new SyntaxError("CommunityExample: Missing Sheet ID");
    		}
    		if (!params.itemID) {
    			throw new SyntaxError("CommunityExample: Missing Sheet Item ID");
    		}
    		return CommunityExamples.Sheet.checkContentAccess(params).then(res => {
    
    			if (!inSheetModule()) {
    				window.sheetHomePageVar = {
    					...window.sheetHomePageVar,
    					sheetID: ~~params.sheetID,
    					siteID: ~~params.siteID,
    					isDraftView: 0,
    					totalRecordCount: 0,
    					idCounter: 0,
    					isDraftView: 0,
    					isImageLibrary: false
    				};
    				
    				// =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
    				// NEW: If we are NOT in iSheet Module AND wijmo Grid is enabled...
    				if (!!window.iSheetHomePageCollection?.wijmoGrid) {
    					window.AddSheetItemCollection.getWijmoEditRecordIndex = () => -1;
    				}
    				// =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
    			}
    			
    			window.AddSheetItemCollection.editItem(
    				params.itemID,
    				params.sheetID,
    				params.siteID,
    				params.sheetViewID
    			);
    			
    			return {
    				"action": "CE::SheetItem::Edit",
    				"context": {
    					...params
    				}					
    			};
    		});
    	};

  • Reply
    Children
    No Data