Simple "Trash" Folder c/w Selectable Rows & Restore Functionality

Code 1 - view.xsp XPage:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" style="padding:20px">
	<xp:button value="Create New Entry" id="button2">
		<xp:eventHandler event="onclick" submit="false">
			<xp:this.script><![CDATA[window.location.href = "#{javascript:@FullUrl('form.xsp')}" + "?action=newDocument"]]></xp:this.script>
		</xp:eventHandler>
	</xp:button>
	<xp:br></xp:br>
	<xp:br></xp:br>
	<xp:span style="font-style:italic;font-weight:bold">My View</xp:span>
	<xp:br></xp:br>
	<xp:br></xp:br>
	<xp:button id="button4" value="Trash Selected">
		<xp:eventHandler event="onclick" submit="true"
			refreshMode="complete">
			<xp:this.action><![CDATA[#{javascript:var vp1 = getComponent("viewPanel1");
if(null != vp1){
	var dm:com.ibm.xsp.model.domino.DominoViewDataModel = vp1.getDataModel();
	if(null != dm){
		var idsIter = dm.getSelectedIds();
		while(null != idsIter && idsIter.hasNext()){
			var id = idsIter.next();
			if(null != id){
				var doc:NotesDocument = database.getDocumentByID(id);
				if(null != doc){
					doc.putInFolder("($myTrash)");
					var formName = doc.getItemValueString("Form");
					doc.replaceItemValue("Form", "_DELETED_");
					doc.replaceItemValue("OriginalForm", formName);
					doc.save();
				}
			}
		}
	}
}}]]></xp:this.action>
		</xp:eventHandler>
	</xp:button>
	<xp:br></xp:br>
	<xp:br></xp:br>
	<xp:viewPanel rows="10" id="viewPanel1" showColumnHeader="false"
		pageName="/form.xsp" viewStyle="width:250px">
		<xp:this.data>
			<xp:dominoView var="view1" viewName="myView"></xp:dominoView>
		</xp:this.data>
		<xp:viewColumn columnName="SKU" id="viewColumn1"
			showCheckbox="true" displayAs="link">
			<xp:viewColumnHeader value="SKU" id="viewColumnHeader1"></xp:viewColumnHeader>
		</xp:viewColumn>
	</xp:viewPanel>
	<xp:br></xp:br>
	<xp:br></xp:br>
	<xp:span style="font-style:italic;font-weight:bold">Trash</xp:span>
	<xp:br></xp:br>
	<xp:br></xp:br>
	<xp:button value="Restore Selected" id="button3">
		<xp:eventHandler event="onclick" submit="true"
			refreshMode="complete">
			<xp:this.action><![CDATA[#{javascript:var vp2 = getComponent("viewPanel2");
if(null != vp2){
	var dm:com.ibm.xsp.model.domino.DominoViewDataModel = vp2.getDataModel();
	if(null != dm){
		var idsIter = dm.getSelectedIds();
		while(null != idsIter && idsIter.hasNext()){
			var id = idsIter.next();
			if(null != id){
				var doc:NotesDocument = database.getDocumentByID(id);
				if(null != doc){
					doc.removeFromFolder("($myTrash)");
					var formName = doc.getItemValueString("OriginalForm");
					doc.replaceItemValue("Form", formName);
					doc.removeItem("OriginalForm");
					doc.save();
				}
			}
		}
	}
}}]]></xp:this.action>
		</xp:eventHandler>
	</xp:button>
	<xp:button value="Empty My Trash" id="button1">
		<xp:eventHandler event="onclick" submit="true"
			refreshMode="complete">
			<xp:this.action>

				<xp:actionGroup>
					<xp:confirm>
						<xp:this.message><![CDATA[#{javascript:var mtf = database.getView("($myTrash)");
var msg = "Empty the trash folder?";
if(null != mtf){
	var es = mtf.getAllEntries();
	var count = es.getCount();
	if(count > 0){
		msg = "Proceed to permanently delete " + es.getCount() +
			" entries from the trash folder?";
	}
}
return msg;}]]></xp:this.message>
					</xp:confirm>
					<xp:executeScript>
						<xp:this.script><![CDATA[#{javascript:var mtf = database.getView("($myTrash)");
if(null != mtf){
	var es = mtf.getAllEntries();
	es.removeAllFromFolder("($myTrash)");
}}]]></xp:this.script>
					</xp:executeScript>
					
				</xp:actionGroup>
			</xp:this.action>
		</xp:eventHandler>
	</xp:button>
	<xp:br></xp:br>
	<xp:br></xp:br>
	<xp:viewPanel rows="10" id="viewPanel2" showColumnHeader="false"
		pageName="/form.xsp" viewStyle="width:250px">
		<xp:this.data>
			<xp:dominoView var="view2" viewName="($myTrash)"></xp:dominoView>
		</xp:this.data>
		<xp:viewColumn columnName="SKU" id="viewColumn3"
			displayAs="link" openDocAsReadonly="true" showCheckbox="true">
			<xp:viewColumnHeader value="SKU" id="viewColumnHeader3"></xp:viewColumnHeader>
		</xp:viewColumn>
	</xp:viewPanel>
</xp:view>

Code 2 - form.xsp XPage:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" style="padding:20px">
	<xp:this.data>
		<xp:dominoDocument var="document1" formName="myForm"></xp:dominoDocument>
	</xp:this.data>
	<xp:table>
		<xp:tr>
			<xp:td>
				<xp:label value="SKU:" id="sKU_Label1" for="sKU1"></xp:label>
			</xp:td>
			<xp:td>
				<xp:inputText value="#{document1.SKU}" id="sKU1"></xp:inputText>
			</xp:td>
		</xp:tr>
	</xp:table>
	<xp:br></xp:br>
	<xp:br></xp:br>
	<xp:button value="Save" id="button1">
		<xp:eventHandler event="onclick" submit="true"
			refreshMode="complete">
			<xp:this.action>
				<xp:save name="/view.xsp"></xp:save>
			</xp:this.action>
		</xp:eventHandler>
	</xp:button>
	<xp:button value="Cancel" id="button2">
		<xp:eventHandler event="onclick" submit="false">
			<xp:this.script>
				<![CDATA[window.location.href = "view.xsp"]]>
			</xp:this.script>
		</xp:eventHandler>
	</xp:button>
</xp:view>

Code 3 - $Trash folder DXL:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE folder SYSTEM 'xmlschemas/domino_8_5_4.dtd'>
<folder name='($myTrash)' xmlns='http://www.lotus.com/dxl' version='8.5' maintenanceversion='4.0'
 replicaid='8025795E00346598' showinmenu='false' noreplace='true' publicaccess='false'
 designerversion='8.5.3' unreadmarks='none' onopengoto='lastopened' onrefresh='displayindicator'
 headers='beveled' opencollapsed='false' showresponsehierarchy='true' showmargin='true'
 shrinkrows='false' extendlastcolumn='false' showhierarchies='false' unreadcolor='black'
 rowlinecount='1' headerlinecount='1' rowspacing='1' bgcolor='white' totalscolor='black'
 headerbgcolor='white' boldunreadrows='false' evaluateactions='false' allownewdocuments='false'
 allowcustomizations='true' hidemarginborder='false' marginwidth='0px' marginbgcolor='white'
 uniquekeys='false'>
<noteinfo noteid='19e' unid='2C55B03575DFA5408025795F0037F3DC' sequence='5'>
<created><datetime>20111207T101109,08+00</datetime></created>
<modified><datetime>20111214T121021,16+00</datetime></modified>
<revised><datetime>20111214T121021,15+00</datetime></revised>
<lastaccessed><datetime>20111214T121021,16+00</datetime></lastaccessed>
<addedtofile><datetime>20111207T101109,11+00</datetime></addedtofile></noteinfo>
<updatedby><name>CN=Tony McGuckin/OU=Ireland/O=IBM</name></updatedby>
<wassignedby><name>CN=Tony McGuckin/OU=Ireland/O=IBM</name></wassignedby>
<column hidedetailrows='false' itemname='$0' width='10' resizable='true' separatemultiplevalues='false'
 sortnoaccent='true' sortnocase='true' showaslinks='false'><columnheader title='#'><font
 size='9pt' style='bold'/></columnheader><code event='value'><formula>@DocNumber</formula></code></column>
<column hidedetailrows='false' itemname='SKU' width='10' resizable='true'
 separatemultiplevalues='false' sortnoaccent='false' sortnocase='true' showaslinks='false'><columnheader
 title='SKU'><font size='9pt' style='bold'/></columnheader></column>
<item name='$Name' sign='true'><text>($Trash)</text></item></folder>






A simple "trash" folder implementation in XPages complete with selectable view rows and restore functionality.

XPages
Tony McGuckin
April 3, 2012 4:07 AM
Rating
160

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.



No comments yetLogin first to comment...