Bitwyse1
Bitwyse1

Reputation: 339

Can someone help me learn how to use the javascript connections code?

I am trying to access data from Connections. I need to use some of the javascript api code: https://greenhouse.lotus.com/sbt/SBTPlayground.nsf/JavaScriptSnippets.xsp#snippet=Social_Files_Get_My_Files

But I do not know how to build the app using xPages. I tried a new xPage and pasted the code into a script block but I get compile errors.

Can someone show me how to use the Javascript samples from the playground?

Upvotes: 1

Views: 137

Answers (1)

Bitwyse1
Bitwyse1

Reputation: 339

Paul's suggestion to use the openntf ticket tracking was brilliant! Here is the code that ultimately worked. Thank you again Paul!

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xe="http://www.ibm.com/xsp/coreex">

    <xe:dataView id="myFilesDataView" var="file" rows="110"
        columnTitles="true" styleClass="filesDataView">
        <xe:this.extraColumns>
            <xe:viewExtraColumn columnTitle="Filetype">
            </xe:viewExtraColumn>
            <xe:viewExtraColumn columnTitle="Size">
            </xe:viewExtraColumn>
        </xe:this.extraColumns>
        <xe:this.summaryColumn>
            <xe:viewSummaryColumn columnTitle="Filename">
            </xe:viewSummaryColumn>
        </xe:this.summaryColumn>
        <xp:this.value>
            <![CDATA[#{javascript:
                try{
                    var filesService = new com.ibm.sbt.services.client.connections.files.FileService( "connectionsSSO" ); 
                    //  ps:100 is page size of 100 files
                    var myFiles = filesService.getMyFiles({ps:100});
                    viewScope.myFilesAvailable = true;
                    return myFiles;
                }catch(exception){
                    println("getFiles value error: " + exception);
                    viewScope.myFilesAvailable = false;
                    return null;
                }}]]>
        </xp:this.value>
        <xp:this.facets>
            <xp:panel xp:key="noRows" id="emptyMyFilesPanel">
                <xp:div styleClass="lotusWidgetBody">
                    <xp:text>
                        <xp:this.value>
                            <![CDATA[#{javascript:
                                return (viewScope.myFilesAvailable ? "No  files found." : "Files unavailable.");
                            }]]>
                        </xp:this.value>
                    </xp:text>
                </xp:div>
            </xp:panel>
            <xp:panel id="summaryPanel" xp:key="summary" style="white-space:nowrap;">
                <xp:link escape="true" id="link7" target="_blank"
                    text="#{javascript:return file.getTitle();}" styleClass="dataViewLink">
                    <xp:this.value><![CDATA[#{javascript:return file.getContentUrl();}]]>
                    </xp:this.value>
                </xp:link>
            </xp:panel>
            <xp:panel id="typePanel" xp:key="extra0"
                style="width: 20%;white-space:nowrap;">
                <xp:text>
                    <xp:this.value><![CDATA[#{javascript:return file.getType();}]]></xp:this.value>
                </xp:text>
            </xp:panel>
            <xp:panel id="sizePanel" xp:key="extra1"
                style="width: 15%;white-space:nowrap;">
                <xp:text>
                    <xp:this.value><![CDATA[#{javascript:
                        var size = file.getSize();
                        var kilobyte = 1024;
                        var megabyte = kilobyte *1024;
                        if(size < kilobyte) {
                            return (size + " B");
                        }else if(size < megabyte) {
                            return (Math.round(size/kilobyte) + " KB");
                        }else {
                            return (Math.round(size/megabyte) + " MB");
                        }}]]>
                    </xp:this.value>
                </xp:text>
            </xp:panel>
        </xp:this.facets>
    </xe:dataView>
</xp:view>

Upvotes: 2

Related Questions