Xpages - Add a flag via through a button click on a repeat item

160 views Asked by At

enter image description here

The cards above are populated via a repeat and the view is not categorised. What I want to add now is the ability to append a delete flag to any of the card in any order.

Below is the code for the delete button:

<xp:link>
  <span class="glyphicon glyphicon-trash pull-right text-primary"></span>
    <xp:eventHandler event="onclick" submit="true" refreshMode="complete">
      <xp:this.action><xp:actionGroup><xp:executeScript>
            <xp:this.script><![CDATA[#{javascript:
        var name=getComponent("FullName").getValue();
        var vec:NotesView = database.getView("SupportTeam");
        var docEv:NotesDocument = vec.getFirstDocument();
        if (name == docEv.getItemValueString("FullName")) {
            docEv.replaceItemValue("SupportAction", "Delete");          
            docEv.save();
        }
  }]]></xp:this.script>
                                            </xp:executeScript>
                                        </xp:actionGroup>
                                    </xp:this.action></xp:eventHandler>
                                    </xp:link>

The code above works, but the delete button need to be clicked twice for it work and it has to be in the order, that is if 'Test 6' is clicked it will not delete since 'Test 5' is in the way.

I tried using the getdocumentbykey() but the view will need to be categorised which will then show multiple entries. In this case, it will display lots of blank cards.

Your help will be appreciated.

2

There are 2 answers

0
Chris Richards On

We need to see your repeat code, however, aslong as you set the var property of your repeat to something, that then makes row data available to you, so you could use something like:

var id = rowData.getUniversalID();
var docEv:NotesDocument = database.getDocumentByUNID(id);
docEv.replaceItemValue("SupportAction", "Delete");          
docEv.save();
//Or to do a hard delete
docEv.remove(true);
0
Samuel Omopariola On

I decided to loop through the collection twice using the while loop to get the collection and then the for loop for the action and that seems to work, but I'm sure there should be a better way of doing this. Below is the final code:

var name = getComponent("FullName").getValue();
var vec:NotesView = database.getView("SupportTeam");
var docEv:NotesDocument = vec.getFirstDocument();
var collection = [];
while (docEv != null){
   try{
        var member = docEv.getItemValueString("SupportFullName"), memberLength = collection.length;
        collection.push(member);

        for (var i = 0; i < memberLength; i++) {
            if(memberLength != null && name == docEv.getItemValueString("SupportFullName")){
                docEv.replaceItemValue("SupportAction", "Delete");          
                docEv.save();
            }
        }
    }catch(e){
        print("error: " + e.toString());
    }

    var tmp = vec.getNextDocument(docEv);
    docEv.recycle();
    docEv = tmp;
}

Thanks for all the response.