Commits

Clayton Sims  committed 5ab6f73

Implemented the necessary methodology to handle repeat instance creation in the controller rather than in views.

  • Participants
  • Parent commits 4582f30

Comments (0)

Files changed (3)

File core/src/org/javarosa/core/model/FormDef.java

 		return relev;
 	}
 
-	public boolean canCreateRepeat(TreeReference repeatRef) {
-		//no-op currently
-		//TODO: check # child constraints on parent
+	public boolean canCreateRepeat(TreeReference repeatRef, FormIndex repeatIndex) {
+		GroupDef repeat = (GroupDef)this.getChild(repeatIndex);
+		
+		//Check to see if this repeat can have children added by the user
+		if(repeat.noAddRemove) {
+			//Check to see if there's a count to use to determine how many children this repeat
+			//should have
+			if(repeat.getCountReference() != null) {
+				int currentMultiplicity = repeatIndex.getElementMultiplicity();
+				
+				//get the total multiplicity possible
+				long fullcount = ((Integer)this.getInstance().getDataValue(repeat.getCountReference()).getValue()).intValue();
+				
+				if(fullcount <= currentMultiplicity) {
+					return false;
+				}
+			} else {
+				//Otherwise the user can never add repeat instances 
+				return false;
+			}
+		}
+		
+		//TODO: If we think the node is still relevant, we also need to figure out a way to test that assumption against
+		//the repeat's constraints.
+		
+		
 		return true;
 	}
 	

File core/src/org/javarosa/form/api/FormEntryCaption.java

 		ro.header = getRepeatText("mainheader");
 		
 		ro.add = null;
-    	if (form.canCreateRepeat(form.getChildInstanceRef(index))) {
+    	if (form.canCreateRepeat(form.getChildInstanceRef(index), index)) {
     		ro.add = getRepeatText(has_repetitions ? "add" : "add-empty");
     	}
     	ro.delete = null;

File core/src/org/javarosa/form/api/FormEntryModel.java

         
         boolean relevant;
         if (isAskNewRepeat) {
-            relevant = form.isRepeatRelevant(ref) && form.canCreateRepeat(ref);
+            relevant = form.isRepeatRelevant(ref) && form.canCreateRepeat(ref, index);
             //repeat junctures are still relevant if no new repeat can be created; that option
             //is simply missing from the menu
         } else if (isRepeatJuncture) {