[isidorus-cvs] r51 - in trunk/src/ajax: css javascripts

Lukas Giessmann lgiessmann at common-lisp.net
Fri Jun 19 10:17:28 UTC 2009


Author: lgiessmann
Date: Fri Jun 19 06:17:27 2009
New Revision: 51

Log:
ajax-client: fixed a bug by committing fragments without an associationcontainer

Modified:
   trunk/src/ajax/css/frame.css
   trunk/src/ajax/javascripts/create.js
   trunk/src/ajax/javascripts/datamodel.js
   trunk/src/ajax/javascripts/edit.js
   trunk/src/ajax/javascripts/requests.js

Modified: trunk/src/ajax/css/frame.css
==============================================================================
--- trunk/src/ajax/css/frame.css	(original)
+++ trunk/src/ajax/css/frame.css	Fri Jun 19 06:17:27 2009
@@ -29,4 +29,9 @@
 li.errorMessage {
     margin-top: 1em;
     font-size: 1.2em;
+}
+
+input[value="generate fragment"] {
+    margin-top: 10px;
+    margin-bottom: 10px;
 }
\ No newline at end of file

Modified: trunk/src/ajax/javascripts/create.js
==============================================================================
--- trunk/src/ajax/javascripts/create.js	(original)
+++ trunk/src/ajax/javascripts/create.js	Fri Jun 19 06:17:27 2009
@@ -23,111 +23,111 @@
 	var liTopicSelect = new Element("li", {"class" : CLASSES.instanceOfFrame()});
 	fragmentFrame.insert({"bottom" : liTopicSelect});
 
+	function innerMakeFragment(psis, constraints){
+	    makeFragment(liTopicSelect, psis, constraints);
+	}
+
+	function onSuccessHandler(xhr){
+	    var json = null;
+	    try{
+		json = xhr.responseText.evalJSON();
+	    }
+	    catch(innerErr){
+		alert("Got bad JSON data from " + xhr.request.url + "\n\n" + innerErr);
+	    }
+	    var instanceOf = null;
+	    try{
+		instanceOf = new InstanceOfC(json.flatten().sort(), innerMakeFragment);
+		liTopicSelect.insert({"bottom" : instanceOf.getFrame()});
+	    }
+	    catch(innerErr){
+		alert("There occurred an error by creating an InstanceOfC frame, please reload this page!\n\n" + innerErr);
+	    }
+	} //onSuccessHandler
 	
-	function makeInstanceOfFrame(context){
-	    function makeFragment(psis, constraints){
-		clearFragment();
-		var instanceOfs = new Array();
-		for(var i = 0; psis && i !== psis.length; ++i){
-		    instanceOfs.push(new Array(psis[i]));
-		}
-		var topic = new TopicC(null, (constraints ? constraints.topicConstraints : null), instanceOfs);
-		var liT = new Element("li", {"class" : CLASSES.topicFrame()}).update(topic.getFrame());
-		context.insert({"after" : liT});
-
-		var liA = null;
-		var associations = null;
-		if(constraints && constraints.associationsConstraints && constraints.associationsConstraints.length !== 0){
-		    addTopicAsPlayer((constraints ? constraints.associationsConstraints : null), topic.getContent().instanceOfs);
-		    associations = new AssociationContainerC(null, (constraints ? constraints.associationsConstraints : null));
-		    liA = new Element("li", {"class" : CLASSES.associationContainer()}).update(associations.getFrame());
-		    liT.insert({"after" : liA});
-		}
-		else {
-		    liA = liT;
-		}
-
-		var tmId = new TmIdC(null);
-		var liTm = new Element("li", {"class" : CLASSES.tmIdFrame()}).update(tmId.getFrame());
-		liA.insert({"after" : liTm});
-
-		var commitButton = new Element("input", {"type" : "button", "value" : "commit fragment", "style" : "float: right; margin-top: -10px;"})
-		commitButton.observe("click", function(event){
-		    // --- validates the given data
-		    var ret = true;
-		    if(topic.isValid() === false) ret = false;
-		    if(associations.isValid() === false) ret = false;
-		    if(tmId.isValid() === false) ret = false;
-
-		    if(ret === false){
-			alert("The fragment wasn't committed!");
-			return;
-		    }
-
-		    // --- if the validation succeeded the fragment will be sent to the server
-		    var tPsis = topic.getContent().subjectIdentifiers;
-		    var referencedTopics = topic.getReferencedTopics();
-		    if(associations){
-			referencedTopics = referencedTopics.concat(associations.getReferencedTopics()).without(CURRENT_TOPIC).uniq();
-		    }
-
-		    function onSuccessHandler(topicStubs){
-			var tsStr = "null";
-			if(topicStubs && topicStubs.length !== 0){
-			    tsStr = "[";
-			    for(var i = 0; i !== topicStubs.length; ++i){
-				tsStr += topicStubs[i];
-				if(i !== topicStubs.length - 1) tsStr += ",";
-			    }
-			    tsStr += "]";
-			}
-			var jTopic = "\"topic\":" + topic.toJSON();
-			var jTopicStubs = "\"topicStubs\":" + tsStr;
-			var jAssociations = "\"associations\":" + (associations ? associations.toJSON().gsub(CURRENT_TOPIC_ESCAPED, tPsis) : "null");
-			var jTmId = "\"tmIds\":" + tmId.toJSON();
-			var json = "{" + jTopic + "," + jTopicStubs + "," + jAssociations + "," + jTmId + "}";
-			commitFragment(json, function(xhr){ alert("The fragment was committed succesfully!"); }, null);
-		    }
-		    
-		    function onErrorHandler(){
-			// --- currently there is not needed a special handling for errors
-			// --- occurred during this operation
-		    }
-		    getTopicStubs(referencedTopics, onSuccessHandler, onErrorHandler);
-		});
-		var liCB = new Element("li", {"class" : CLASSES.commitButton()});
-		liCB.update(commitButton);
-		liTm.insert({"after" : liCB});
-	    } //makeFragment
-
-	    function onSuccessHandler(xhr){
-		var json = null;
-		try{
-		    json = xhr.responseText.evalJSON();
-		}
-		catch(innerErr){
-		    alert("Got bad JSON data from " + xhr.request.url + "\n\n" + innerErr);
-		}
-		var instanceOf = null;
-		try{
-  		    instanceOf = new InstanceOfC(json.flatten().sort(), makeFragment);
-		    context.insert({"bottom" : instanceOf.getFrame()});
-		}
-		catch(innerErr){
-		    alert("There occurred an error by creating an InstanceOfC frame, please reload this page!\n\n" + innerErr);
-		}
-	    } //onSuccessHandler
-
-	    getTypePsis(onSuccessHandler, null);
-	} //makeInstanceOfFrame
-
-	makeInstanceOfFrame(liTopicSelect);
+	getTypePsis(onSuccessHandler, null);
     }catch(err){
 	alert("From makeCreate(): " + err);
     }
 }
 
 
+// --- Creates the sub-elemts Topic, Associations and Topic Maps ID of a Fragment element.
+function makeFragment(context, psis, constraints){
+    clearFragment();
+    
+    var instanceOfs = new Array();
+    for(var i = 0; psis && i !== psis.length; ++i){
+	instanceOfs.push(new Array(psis[i]));
+    }
+    var topic = new TopicC(null, (constraints ? constraints.topicConstraints : null), instanceOfs);
+    var liT = new Element("li", {"class" : CLASSES.topicFrame()}).update(topic.getFrame());
+    context.insert({"after" : liT});
+    
+    var liA = null;
+    var associations = null;
+    if(constraints && constraints.associationsConstraints && constraints.associationsConstraints.length !== 0){
+	addTopicAsPlayer((constraints ? constraints.associationsConstraints : null), topic.getContent().instanceOfs);
+	associations = new AssociationContainerC(null, (constraints ? constraints.associationsConstraints : null));
+	liA = new Element("li", {"class" : CLASSES.associationContainer()}).update(associations.getFrame());
+	liT.insert({"after" : liA});
+    }
+    else {
+	liA = liT;
+    }
+    
+    var tmId = new TmIdC(null);
+    var liTm = new Element("li", {"class" : CLASSES.tmIdFrame()}).update(tmId.getFrame());
+    liA.insert({"after" : liTm});
+    var commitButton = new Element("input", {"type" : "button", "value" : "commit fragment", "style" : "float: right; margin-top: -10px;"})
+    commitButton.observe("click", function(event){
+	// --- validates the given data
+	var ret = true;
+	if(topic.isValid() === false) ret = false;
+	if(associations && associations.isValid() === false) ret = false;
+	if(tmId.isValid() === false) ret = false;
+
+	if(ret === false){
+	    alert("The fragment wasn't committed - Please correct your input date!");
+	    return;
+	}
+	
+	// --- if the validation succeeded the fragment will be sent to the server
+	var tPsis = topic.getContent().subjectIdentifiers;
+	var referencedTopics = topic.getReferencedTopics();
+	if(associations){
+	    referencedTopics = referencedTopics.concat(associations.getReferencedTopics()).without(CURRENT_TOPIC).uniq();
+	}
+	function onSuccessHandler(topicStubs){
+	    var tsStr = "null";
+	    if(topicStubs && topicStubs.length !== 0){
+		tsStr = "[";
+		for(var i = 0; i !== topicStubs.length; ++i){
+		    tsStr += topicStubs[i];
+		    if(i !== topicStubs.length - 1) tsStr += ",";
+		}
+		tsStr += "]";
+	    }
+	    var jTopic = "\"topic\":" + topic.toJSON();
+	    var jTopicStubs = "\"topicStubs\":" + tsStr;
+	    var jAssociations = "\"associations\":" + (associations ? associations.toJSON().gsub(CURRENT_TOPIC_ESCAPED, tPsis) : "null");
+	    var jTmId = "\"tmIds\":" + tmId.toJSON();
+	    var json = "{" + jTopic + "," + jTopicStubs + "," + jAssociations + "," + jTmId + "}";
+	    commitFragment(json, function(xhr){ alert("The fragment was committed succesfully!"); }, null);
+	}
+	
+	function onErrorHandler(){
+	    // --- currently there is not needed a special handling for errors
+	    // --- occurred during this operation
+	}
+	getTopicStubs(referencedTopics, onSuccessHandler, onErrorHandler);
+    });
+    var liCB = new Element("li", {"class" : CLASSES.commitButton()});
+    liCB.update(commitButton);
+    liTm.insert({"after" : liCB});
+}
+
+
 // --- removes old elements from the fragment frame
 function clearFragment()
 {

Modified: trunk/src/ajax/javascripts/datamodel.js
==============================================================================
--- trunk/src/ajax/javascripts/datamodel.js	(original)
+++ trunk/src/ajax/javascripts/datamodel.js	Fri Jun 19 06:17:27 2009
@@ -255,7 +255,7 @@
                                             	    throw "From InstanceOfC(): The following exception was thrown:\n" + err;
                                             	    this.__container__ = null;
                                                 }
-                                                this.__commit__ = new Element("input", {"type" : "button", "value" : "get constraints"});
+                                                this.__commit__ = new Element("input", {"type" : "button", "value" : "generate fragment"});
 
                                                 function setHandler(myself){
 						    function onSuccessHandler(xhr){
@@ -442,68 +442,64 @@
 						return content.length === 0 ? "null" : content.toJSON();
 					    },
 					    "isValid" : function(){
-						try {
-						    var allIdentifiers = new Array();
-						    var errorStr = "";
-						    var ret = true;
-						    
-						    // --- checks if there are any constraints
-						    if((!this.__constraints__ || this.__constraints__.length === 0) && this.__containers__.length !== 0){
-							for(var i = 0; i !== this.__containers__.length; ++i){
-							    for(var j = 0; this.__containers__[i].__frames__ && j !== this.__containers__[i].__frames__.length; ++j){
-								this.__containers__[i].__frames__[j].showError("No constraints found for this identifier!");
-							    }
-							}
-							return false;
-						    }
-						    else if(!this.__constraints__ || this.__constraints__.length === 0) return true;
-
-						    // --- collects all non-empty identifiers
+						var allIdentifiers = new Array();
+						var errorStr = "";
+						var ret = true;
+						
+						// --- checks if there are any constraints
+						if((!this.__constraints__ || this.__constraints__.length === 0) && this.__containers__.length !== 0){
 						    for(var i = 0; i !== this.__containers__.length; ++i){
 							for(var j = 0; this.__containers__[i].__frames__ && j !== this.__containers__[i].__frames__.length; ++j){
-							    var row = this.__containers__[i].__frames__[j];
-							    row.hideError();
-							    if(row.isUsed() === true && row.getContent().strip().length !== 0) allIdentifiers.push(row);
+							    this.__containers__[i].__frames__[j].showError("No constraints found for this identifier!");
 							}
 						    }
+						    return false;
+						}
+						else if(!this.__constraints__ || this.__constraints__.length === 0) return true;
+						
+						// --- collects all non-empty identifiers
+						for(var i = 0; i !== this.__containers__.length; ++i){
+						    for(var j = 0; this.__containers__[i].__frames__ && j !== this.__containers__[i].__frames__.length; ++j){
+							var row = this.__containers__[i].__frames__[j];
+							row.hideError();
+							if(row.isUsed() === true && row.getContent().strip().length !== 0) allIdentifiers.push(row);
+						    }
+						}
+						
+						var checkedIdentifiers = new Array();
+						for(var i = 0; i !== this.__constraints__.length; ++i){
+						    var regexp = new RegExp(this.__constraints__[i].regexp);
+						    var cardMin = parseInt(this.__constraints__[i].cardMin);
+						    var cardMax = this.__constraints__[i].cardMax === MAX_INT ? MMAX_INT : parseInt(this.__constraints__[i].cardMax);
+						    var currentIdentifiers = new Array();
+						    for(var j = 0; j !== allIdentifiers.length; ++j){
+							if(regexp.match(allIdentifiers[j].getContent()) === true) currentIdentifiers.push(allIdentifiers[j]);
+						    }
+						    checkedIdentifiers = checkedIdentifiers.concat(currentIdentifiers);
 						    
-						    var checkedIdentifiers = new Array();
-						    for(var i = 0; i !== this.__constraints__.length; ++i){
-							var regexp = new RegExp(this.__constraints__[i].regexp);
-							var cardMin = parseInt(this.__constraints__[i].cardMin);
-							var cardMax = this.__constraints__[i].cardMax === MAX_INT ? MMAX_INT : parseInt(this.__constraints__[i].cardMax);
-							var currentIdentifiers = new Array();
-							for(var j = 0; j !== allIdentifiers.length; ++j){
-							    if(regexp.match(allIdentifiers[j].getContent()) === true) currentIdentifiers.push(allIdentifiers[j]);
-							}
-							checkedIdentifiers = checkedIdentifiers.concat(currentIdentifiers);
-
-							// --- checks card-min and card-max for the current constraint
-							if(cardMin > currentIdentifiers.length){
-							    errorStr += "card-min of the constraint regexp: \"" + this.__constraints__[i].regexp + "\" card-min: " + cardMin + " card-max: " + cardMax + " is not satisfied (" + cardMin + ")!<br/>";
-							    ret = false;
-							}
-							if(cardMax !== MMAX_INT && cardMax < currentIdentifiers.length){
-							    errorStr += "card-max of the constraint regexp: \"" + this.__constraints__[i].regexp + "\" card-min: " + cardMin + " card-max: " + cardMax + " is not satisfied (" + cardMax + ")!<br/>";
-							    ret = false;
-							}
+						    // --- checks card-min and card-max for the current constraint
+						    if(cardMin > currentIdentifiers.length){
+							errorStr += "card-min of the constraint regexp: \"" + this.__constraints__[i].regexp + "\" card-min: " + cardMin + " card-max: " + cardMax + " is not satisfied (" + cardMin + ")!<br/>";
+							ret = false;
 						    }
-
-						    // --- checks if there are some identifiers which don't satisfies any constraint
-						    checkedIdentifiers = checkedIdentifiers.uniq();
-						    if(checkedIdentifiers.length < allIdentifiers.length){							
+						    if(cardMax !== MMAX_INT && cardMax < currentIdentifiers.length){
+							errorStr += "card-max of the constraint regexp: \"" + this.__constraints__[i].regexp + "\" card-min: " + cardMin + " card-max: " + cardMax + " is not satisfied (" + cardMax + ")!<br/>";
 							ret = false;
-							for(var i = 0; i !== allIdentifiers.length; ++i){
-							    if(checkedIdentifiers.indexOf(allIdentifiers[i]) === -1) allIdentifiers[i].showError("This Identifier does not satisfie any constraint!");
-							}
 						    }
-
-						    if(ret === true) this.hideError();
-						    else this.showError(errorStr);
-						    return ret;
-						}catch(err){ alert("err: " + err); }
-
-
+						}
+						
+						// --- checks if there are some identifiers which don't satisfies any constraint
+						checkedIdentifiers = checkedIdentifiers.uniq();
+						if(checkedIdentifiers.length < allIdentifiers.length){							
+						    ret = false;
+						    for(var i = 0; i !== allIdentifiers.length; ++i){
+							if(checkedIdentifiers.indexOf(allIdentifiers[i]) === -1) allIdentifiers[i].showError("This Identifier does not satisfie any constraint!");
+						    }
+						}
+						
+						if(ret === true) this.hideError();
+						else this.showError(errorStr);
+						return ret;
 					    }});
 
 
@@ -1754,7 +1750,6 @@
 					   return this.__subjectIdentifier__.getContent(true, true).length !== 0;
 				       },
 				       "isValid" : function(){
-					   try{
 					   var ret = true;
 					   if(this.__topicid__.__frames__[0].getContent().strip().length === 0){
 					       ret = false;
@@ -1768,7 +1763,6 @@
 					   if(this.__subjectIdentifier__.isValid() === false) ret = false;
 					   if(this.__name__.isValid() === false) ret = false;
 					   if(this.__occurrence__.isValid() === false) ret = false;
-					   }catch(err){ alert("err: " + err); }
 					   return ret;
 				       },
 				       "getReferencedTopics" : function(){

Modified: trunk/src/ajax/javascripts/edit.js
==============================================================================
--- trunk/src/ajax/javascripts/edit.js	(original)
+++ trunk/src/ajax/javascripts/edit.js	Fri Jun 19 06:17:27 2009
@@ -18,7 +18,35 @@
     $(CLASSES.subPage()).insert({"bottom" : content});
 
     try{
+	var fragmentFrame = new Element("ul", {"class" : CLASSES.fragmentFrame()});
+	content.insert({"bottom" : fragmentFrame});
+	var liTopicSelect = new Element("li", {"class" : CLASSES.instanceOfFrame()});
+	fragmentFrame.insert({"bottom" : liTopicSelect});
+
+	// --- creates the sub-elements topic, associations and topic map id
+	function innerMakeFragment(psis, constraints){
+	    makeFragment(liTopicSelect, psis, constraints);
+	}
+	
+	function onSuccessHandler(xhr){
+	    var json = null;
+	    try{
+		json = xhr.responseText.evalJSON();
+		}
+	    catch(innerErr){
+		alert("Got bad JSON data from " + xhr.request.url + "\n\n" + innerErr);
+	    }
+	    var instanceOf = null;
+	    try{
+		instanceOf = new InstanceOfC(json.flatten().sort(), innerMakeFragment);
+		liTopicSelect.insert({"bottom" : instanceOf.getFrame()});
+	    }
+	    catch(innerErr){
+		alert("There occurred an error by creating an InstanceOfC frame, please reload this page!\n\n" + innerErr);
+	    }
+	} //onSuccessHandler
 	
+	getTypePsis(onSuccessHandler, null);
     }
     catch(err){
 	alert("From makeEdit(): " + err);

Modified: trunk/src/ajax/javascripts/requests.js
==============================================================================
--- trunk/src/ajax/javascripts/requests.js	(original)
+++ trunk/src/ajax/javascripts/requests.js	Fri Jun 19 06:17:27 2009
@@ -27,12 +27,9 @@
 function createXHRHandler(handler, timeFun)
 {
     function fun(xhr){
-	try{
-	    clearTimeout(timeFun);
-	    hideLoad();
-	    handler(xhr);
-	}
-	catch(err) {alert("err: " + err); }
+	clearTimeout(timeFun);
+	hideLoad();
+	handler(xhr);
     }
     return fun;
 }




More information about the Isidorus-cvs mailing list