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

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


Author: lgiessmann
Date: Fri Jun 19 09:17:20 2009
New Revision: 52

Log:
ajax-client: fixed a few bugs and prepared the client for the implementation of editing existing fragments

Modified:
   trunk/src/ajax/css/frame.css
   trunk/src/ajax/javascripts/constants.js
   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 09:17:20 2009
@@ -34,4 +34,9 @@
 input[value="generate fragment"] {
     margin-top: 10px;
     margin-bottom: 10px;
+}
+
+input[value="commit fragment"] {
+    margin-top: -20px;
+    float: right;
 }
\ No newline at end of file

Modified: trunk/src/ajax/javascripts/constants.js
==============================================================================
--- trunk/src/ajax/javascripts/constants.js	(original)
+++ trunk/src/ajax/javascripts/constants.js	Fri Jun 19 09:17:20 2009
@@ -82,6 +82,7 @@
 	       "__divTmIdFrame__" : "tmIdFrame",
 	       "__divLoad__" : "loadFrame",
 	       "__imgAjaxLoader__" : "ajaxLoader",
+	       "__divEditFrame__" : "editFrame",
 
 	       "page" : function(){ return this.__divPage__; },
 	       "subPage" : function(){ return this.__divSubPage__; },
@@ -124,5 +125,6 @@
 	       "commitButton" : function(){ return this.__inputCommitButton__; },
 	       "tmIdFrame" : function(){ return this.__divTmIdFrame__; },
 	       "load" : function(){ return this.__divLoad__; },
-	       "ajaxLoader" : function(){ return this.__imgAjaxLoader__; }
+	       "ajaxLoader" : function(){ return this.__imgAjaxLoader__; },
+	       "editFrame" : function(){ return this.__divEditFrame__; }
 	      };
\ 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 09:17:20 2009
@@ -10,6 +10,7 @@
 //+-----------------------------------------------------------------------------
 
 
+// --- Creates the "create"-sub-page.
 function makeCreate(psi)
 {
     var content = new Element("div", {"class" : CLASSES.content()});
@@ -24,7 +25,7 @@
 	fragmentFrame.insert({"bottom" : liTopicSelect});
 
 	function innerMakeFragment(psis, constraints){
-	    makeFragment(liTopicSelect, psis, constraints);
+	    makeFragment(liTopicSelect, psis, constraints, null);
 	}
 
 	function onSuccessHandler(xhr){
@@ -45,7 +46,7 @@
 	    }
 	} //onSuccessHandler
 	
-	getTypePsis(onSuccessHandler, null);
+	getPsis(onSuccessHandler, null, true);
     }catch(err){
 	alert("From makeCreate(): " + err);
     }
@@ -53,22 +54,31 @@
 
 
 // --- Creates the sub-elemts Topic, Associations and Topic Maps ID of a Fragment element.
-function makeFragment(context, psis, constraints){
+function makeFragment(context, psis, constraints, contents){
     clearFragment();
+
+    var topicContent = null;
+    var associationsContent = null;
+    var tmContent = null;
+    if(contents){
+	topicContent = contents.topic;
+	associationsContent = contents.associations;
+	tmContent = contents.tmIds;
+    }
     
     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 topic = new TopicC(topicContent, (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){
+    if((constraints && constraints.associationsConstraints && constraints.associationsConstraints.length !== 0) || associationsContent && associationsContent.length !== 0){
 	addTopicAsPlayer((constraints ? constraints.associationsConstraints : null), topic.getContent().instanceOfs);
-	associations = new AssociationContainerC(null, (constraints ? constraints.associationsConstraints : null));
+	associations = new AssociationContainerC(associationsContent, (constraints ? constraints.associationsConstraints : null));
 	liA = new Element("li", {"class" : CLASSES.associationContainer()}).update(associations.getFrame());
 	liT.insert({"after" : liA});
     }
@@ -76,10 +86,10 @@
 	liA = liT;
     }
     
-    var tmId = new TmIdC(null);
+    var tmId = new TmIdC(tmContent);
     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;"})
+    var commitButton = new Element("input", {"type" : "button", "value" : "commit fragment"})
     commitButton.observe("click", function(event){
 	// --- validates the given data
 	var ret = true;

Modified: trunk/src/ajax/javascripts/datamodel.js
==============================================================================
--- trunk/src/ajax/javascripts/datamodel.js	(original)
+++ trunk/src/ajax/javascripts/datamodel.js	Fri Jun 19 09:17:20 2009
@@ -242,6 +242,51 @@
 			       }});
 
 
+// --- Representation of a
+var EditC = Class.create(ContainerC, {"initialize" : function($super, contents, successFun){
+                                          $super();
+                                          this.__frame__.writeAttribute({"class" : CLASSES.editFrame()});
+                                          this.__container__ = new Object();
+                                          try{
+					      var row = new SelectrowC(contents, this.__container__, 1, 1);
+					      this.__error__.insert({"before" : row.getFrame()});
+					  }
+                                          catch(err){
+					      throw "From EditC(): The following exception was thrown:\n" + err;
+					      this.__container__ = null;
+					  }
+                                          this.__commit__ = new Element("input", {"type" : "button", "value" : "generate fragment"});
+
+                                          function setHandler(myself){
+					      function onSuccessHandler(xhr){
+						  var json = null;
+						  try{
+						      json = xhr.responseText.evalJSON();
+						  }
+						  catch(err){
+						      alert("Got bad JSON data from " + xhr.request.url + "!\n\n" + err);
+						  }
+						  successFun(new Array(myself.getContent()), json);
+					      }
+					      
+                                              myself.__commit__.observe("click", function(event){
+						  myself.hideError();
+						  clearFragment();
+                                                  requestConstraints("[" + myself.toJSON() + "]", onSuccessHandler, null)
+                                              });
+                                          }
+                                          setHandler(this);
+
+                                          this.__error__.insert({"before" : this.__commit__});
+                                      },
+				      "getContent" : function(){
+					  return this.__container__.__frames__[0].getContent();
+				      },
+				      "toJSON" : function(){
+					  return this.getContent().toJSON();
+				      }});
+
+
 // --- Represents a container for all instanceOf-Psis of a fragment's topic
 var InstanceOfC = Class.create(ContainerC, {"initialize" : function($super, contents, successFun){
                                                 $super();
@@ -281,10 +326,7 @@
 								    str += "<br/>";
 								}
 							    }
-							    var items = $$("li." + CLASSES.topicFrame());
-							    for(var i = 0; i != items.length; ++i){
-								items[i].remove();
-							    }
+							    clearFragment();
 							    myself.showError(str);
 							}
 							else {						    
@@ -295,7 +337,7 @@
                                             	    myself.__commit__.observe("click", function(event){
 							myself.hideError();
 							clearFragment();
-                                                        requestConstraints(myself.toJSON(true), onSuccessHandler, null);
+                                                        requestConstraints(myself.toJSON(true), onSuccessHandler, null, true);
                                                     });
                                                 }
                                                 setHandler(this);
@@ -479,11 +521,11 @@
 						    
 						    // --- 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/>";
+							errorStr += "card-min of the constraint regexp: \"" + this.__constraints__[i].regexp + "\" card-min: " + cardMin + " card-max: " + cardMax + " is not satisfied (" + currentIdentifiers.length + ")!<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/>";
+							errorStr += "card-max of the constraint regexp: \"" + this.__constraints__[i].regexp + "\" card-min: " + cardMin + " card-max: " + cardMax + " is not satisfied (" + currentIdentifiers.length + ")!<br/>";
 							ret = false;
 						    }
 						}
@@ -842,8 +884,15 @@
 					     this.__dblClickHandler__ = dblClickHandler;
     
                                              try{
+						 var itemIdentityContent = null;
+						 var scopesContent = null;
+						 if(contents){
+						     itemIdentityContent = contents.itemIdentities;
+						     scopesContent = contents.scopes;
+						 }
+
 						 // --- control row + itemIdentity
-						 makeControlRow(this, 4, contents ? contents.itemIdentities : null);
+						 makeControlRow(this, 4, itemIdentityContent);
 						 checkRemoveAddButtons(owner, 1, -1);
 						 setRemoveAddHandler(this, owner, 1, -1, function(){
 						     return new VariantC(null, owner, dblClickHandler, parent);
@@ -1037,8 +1086,21 @@
                                           this.__dblClickHandler__ = dblClickHandler;
     
                                           try{
+					      var itemIdentityContent = null;
+					      var typeContent = null;
+					      var scopesContent = null;
+					      var valueContent = "";
+					      var variantsContent = null;
+					      if(contents){
+						  itemIdentityContent = contents.itemIdentities;
+						  typeContent = contents.type;
+						  scopesContent = contents.scopes;
+						  valueContent = contents.value;
+						  variantsContent = contents.variants;
+					      }
+
 					      // --- control row + ItemIdentity
-					      makeControlRow(this, 5, contents ? contents.itemIdentities : null);
+					      makeControlRow(this, 5, itemIdentityContent);
 					      checkRemoveAddButtons(owner, min, max);
 					      setRemoveAddHandler(this, owner, min, max, function(){
 						  return new NameC(null, nametypescopes, simpleConstraint, owner, min, max, cssTitle, dblClickHandler);
@@ -1049,7 +1111,7 @@
 					      for(var i = 0; nametypescopes && i !== nametypescopes.length; ++i){
 						  for(var j = 0; j != nametypescopes[i].nameType.length; ++j){
 						      types.push(nametypescopes[i].nameType[j]);
-						      if(contents && contents.type && contents.type[0] === nametypescopes[i].nameType[j]){
+						      if(typeContent && typeContent[0] === nametypescopes[i].nameType[j]){
 							  var selected = nametypescopes[i].nameType[j];
 							  types[types.length - 1] = types[0];
 							  types[0] = selected;
@@ -1061,7 +1123,7 @@
 					      this.__table__.insert({"bottom" : tr});
 					      
 					      // --- scopes
-					      this.__scope__ = new ScopeContainerC(contents && contents.scopes ? scopes : null, nametypescopes && nametypescopes[0].scopeConstraints ? nametypescopes[0].scopeConstraints : null);
+					      this.__scope__ = new ScopeContainerC(scopesContent, nametypescopes && nametypescopes[0].scopeConstraints ? nametypescopes[0].scopeConstraints : null);
 					      this.__table__.insert({"bottom" : newRow(CLASSES.scopeContainer(), "Scope", this.__scope__.getFrame())});
 					      onTypeChangeScope(this, contents ? contents.scopes : null, nametypescopes, "name");
 
@@ -1071,11 +1133,11 @@
 					      var _max = simpleConstraint.cardMax !== MAX_INT ? parseInt(simpleConstraint.cardMax) : MMAX_INT;
 					      var cssTitleV = "min: " + _min + "   max: " + _max + "   regular expression: " + (simpleConstraint ? simpleConstraint.regexp : ".*");
 					      this.__cssTitle__ = cssTitle;
-					      new TextrowC((contents ? contents.value : ""), (simpleConstraint ? simpleConstraint.regexp : ".*"), this.__value__, 1, 1, cssTitleV);
+					      new TextrowC(valueContent, (simpleConstraint ? simpleConstraint.regexp : ".*"), this.__value__, 1, 1, cssTitleV);
 					      this.__table__.insert({"bottom" : newRow(CLASSES.valueFrame(), "Value", this.__value__.__frames__[0].getFrame())});
 					      
 					      // --- variants
-					      this.__variants__ = new VariantContainerC(contents? contents.variants : null, this);
+					      this.__variants__ = new VariantContainerC(variantsContent, this);
 					      this.__table__.insert({"bottom" : newRow(CLASSES.variantContainer(), "Variants", this.__variants__.getFrame())});
 					      
 					      // --- adds a second show handler, so the variants will be hidden, when the entire
@@ -1348,8 +1410,17 @@
                                                 this.__dblClickHandler__ = dblClickHandler;
 
                                                 try{
+						    var itemIdentityContent = null;
+						    var typeContent = null;
+						    var scopesContent = null;
+						    if(contents){
+							itemIdentityContent = contents.itemIdentities;
+							typeContent = contents.type;
+							scopesContent = contents.scopes;
+						    }
+						    
 						    // --- control row + itemIdentity
-						    makeControlRow(this, 5, contents ? contents.itemIdentities : null);
+						    makeControlRow(this, 5, itemIdentityContent);
 						    checkRemoveAddButtons(owner, 1, max);
 						    setRemoveAddHandler(this, owner, 1, max, function(){
 							return new OccurrenceC(null, occurrenceTypes, constraint, uniqueConstraints, owner, min, max, cssTitle, dblClickHandler);
@@ -1360,7 +1431,7 @@
 						    for(var i = 0; occurrenceTypes && i !== occurrenceTypes.length; ++i){
 							for(var j = 0; j != occurrenceTypes[i].occurrenceType.length; ++j){
 							    types.push(occurrenceTypes[i].occurrenceType[j]);
-							    if(contents && contents.type && contents.type[0] === ooccurrenceTypes[i].occurrenceType[j]){
+							    if(typeContent && typeContent[0] === ooccurrenceTypes[i].occurrenceType[j]){
 								var selected = occurrenceTypes[i].occurrenceType[j];
 								types[types.length - 1] = types[0];
 								types[0] = selected;
@@ -1372,7 +1443,7 @@
 						    this.__table__.insert({"bottom" : tr});
 
 						    // --- scopes
-						    this.__scope__ = new ScopeContainerC(contents && contents.scopes ? contents.scopes : null, occurrenceTypes && occurrenceTypes[0].scopeConstraints ? occurrenceTypes[0].scopeConstraints : null);
+						    this.__scope__ = new ScopeContainerC(scopesContent, occurrenceTypes && occurrenceTypes[0].scopeConstraints ? occurrenceTypes[0].scopeConstraints : null);
 						    this.__table__.insert({"bottom" : newRow(CLASSES.scopeContainer(), "Scope", this.__scope__.getFrame())});
 						    onTypeChangeScope(this, contents && contents.scopes ? contents.scopes : null, occurrenceTypes, "occurrence");
 
@@ -1655,6 +1726,20 @@
                                            this.__instanceOfs__ = (!instanceOfs || instanceOfs.length === 0 ? null : instanceOfs);
 
                                            try{
+					       var topicidContent = null;
+					       var itemIdentityContent = null;
+					       var subjectLocatorContent = null;
+					       var subjectIdentifierContent = null;
+					       var namesContent = null;
+					       var occurrencesContent = null;
+					       if(content){
+						   topicidContent = content.id
+						   itemIdentityContent = content.itemIdentities
+						   subjectLocatorContent = content.subjectLocators;
+						   subjectIdentifierContent = content.subjectIdentifiers;
+						   namesContent = content.names;
+						   occurrencesContent = content.occurrences;
+					       }
 					       this.__frame__ .writeAttribute({"class" : CLASSES.topicFrame()});
 					       this.__table__ = new Element("table", {"class" : CLASSES.topicFrame()});
 					       this.__frame__.insert({"top" : this.__table__});
@@ -1670,35 +1755,31 @@
 					       
 					       // --- topic id
 					       this.__topicid__ = new Object();
-					       new TextrowC((content ? content.topicid : null), ".*", this.__topicid__, 1, 1, null);
+					       new TextrowC(topicidContent, ".*", this.__topicid__, 1, 1, null);
 					       this.__table__.insert({"bottom" : newRow(CLASSES.topicIdFrame(), "Topic ID", this.__topicid__.__frames__[0].getFrame())});
 					       
 					       // --- itemIdentity
-					       this.__itemIdentity__ = new ItemIdentityC(content ? content.itemIdentities : null, this);
+					       this.__itemIdentity__ = new ItemIdentityC(itemIdentityContent, this);
 					       this.__table__.insert({"bottom" : newRow(CLASSES.itemIdentityFrame(), "ItemIdentity", this.__itemIdentity__.getFrame())});
 
 					       // --- subjectLocator
-					       var _contents = (content ? content.subjectLocators : null);
 					       var _constraints = (constraints ? constraints.subjectLocatorConstraints : null);
-					       this.__subjectLocator__ = new IdentifierC(_contents, _constraints, CLASSES.subjectLocatorFrame());
+					       this.__subjectLocator__ = new IdentifierC(subjectLocatorContent, _constraints, CLASSES.subjectLocatorFrame());
 					       this.__table__.insert({"bottom" : newRow(CLASSES.subjectLocatorFrame(), "SubjectLocator", this.__subjectLocator__.getFrame())});
 
 					       // --- subjectIdentifier
-					       _contents = (content ? content.subjectIdentifiers : null);
 					       _constraints = (constraints ? constraints.subjectIdentifierConstraints : null);
-					       this.__subjectIdentifier__ = new IdentifierC(_contents, _constraints, CLASSES.subjectIdentifierFrame());
+					       this.__subjectIdentifier__ = new IdentifierC(subjectIdentifierContent, _constraints, CLASSES.subjectIdentifierFrame());
 					       this.__table__.insert({"bottom" : newRow(CLASSES.subjectIdentifierFrame(), "SubjectIdentifier", this.__subjectIdentifier__.getFrame())});
 
 					       // --- names
-					       _contents = (content ? content.names : null);
 					       _constraints = (constraints ? constraints.topicNameConstraints : null);
-					       this.__name__ = new NameContainerC(_contents, _constraints);
+					       this.__name__ = new NameContainerC(namesContent, _constraints);
 					       this.__table__.insert({"bottom" : newRow(CLASSES.nameContainer(), "Names", this.__name__.getFrame())});
 					       
 					       // --- occurrences
-					       _contents = (content ? content.occurrences : null);
 					       _constraints = (constraints ? constraints.topicOccurrenceConstraints : null);
-					       this.__occurrence__ = new OccurrenceContainerC(_contents, _constraints);
+					       this.__occurrence__ = new OccurrenceContainerC(occurrencesContent, _constraints);
 					       this.__table__.insert({"bottom" : newRow(CLASSES.occurrenceContainer(), "Occurrences", this.__occurrence__.getFrame())});
 					   }catch(err){
 					       alert("From TopciC(): " + err);
@@ -2689,8 +2770,20 @@
                                                  this.__dblClickHandler__ = dblClickHandlerF;
 
 					         try{
+						     var itemIdentityContent = null;
+						     var typeContent = null;
+						     var scopesContent = null;
+						     var rolesContent = null;
+						     if(contents){
+							 itemIdentityContent = contents.itemIdentities;
+							 typeContent = contents.type;
+							 scopesContent = contents.scopes;
+							 rolesContent = contents.roles;
+						     }
+
+
 						     // --- control row + ItemIdentity
-						     makeControlRow(this, 4, contents ? contents.itemIdentities : null);
+						     makeControlRow(this, 4, itemIdentityContent);
 						     checkRemoveAddButtons(owner, 1, -1);
 						     setRemoveAddHandler(this, owner, 1, -1, function(){
 							 return new AssociationC(null, constraints, owner);
@@ -2701,7 +2794,7 @@
 						     for(var i = 0; constraints && i !== constraints.length; ++i){
 							 for(var j = 0; j != constraints[i].associationType.length; ++j){
 							     types.push(constraints[i].associationType[j]);
-							     if(contents && contents.type && contents.type[0] === constraints[i].associationType[j]){
+							     if(typeContent && typeContent[0] === constraints[i].associationType[j]){
 								 var selected = constraints[i].associationType[j];
 								 types[types.length - 1] = types[0];
 								 types[0] = selected;
@@ -2713,7 +2806,7 @@
 						     this.__table__.insert({"bottom" : tr});
 						     
 						     // --- scopes
-						     this.__scope__ = new ScopeContainerC(this.__contents__ && this.__contents__.scopes ? this.__contents__.scopes : null, this.__constraints__ && this.__constraints__[0].scopeConstraints ? this.__constraints__[0].scopeConstraints : null);
+						     this.__scope__ = new ScopeContainerC(scopesContent, this.__constraints__ && this.__constraints__[0].scopeConstraints ? this.__constraints__[0].scopeConstraints : null);
 						     this.__table__.insert({"bottom" : newRow(CLASSES.scopeContainer(), "Scope", this.__scope__.getFrame())});
 
 						     // --- roles
@@ -2724,7 +2817,7 @@
 							 _otherRoleConstraints = this.__constraints__[0].otherRoleConstraints;
 						     }
 
-						     this.__roles__ = new RoleContainerC(this.__contents__ ? this.__contents__.roles : null, _roleConstraints, _playerConstraints, _otherRoleConstraints, this);
+						     this.__roles__ = new RoleContainerC(rolesContent, _roleConstraints, _playerConstraints, _otherRoleConstraints, this);
 						     this.__table__.insert({"bottom" : newRow(CLASSES.roleContainer(), "Roles", this.__roles__.getFrame())});
 						     
 						     // --- registers the onChangeHandler of the Type-selectrow

Modified: trunk/src/ajax/javascripts/edit.js
==============================================================================
--- trunk/src/ajax/javascripts/edit.js	(original)
+++ trunk/src/ajax/javascripts/edit.js	Fri Jun 19 09:17:20 2009
@@ -25,28 +25,37 @@
 
 	// --- creates the sub-elements topic, associations and topic map id
 	function innerMakeFragment(psis, constraints){
-	    makeFragment(liTopicSelect, psis, constraints);
+	    function rSuccessHandler(xhr){
+		var json = null;
+		try{
+		    json = xhr.responseText.evalJSON();
+		}
+		catch(innrErr){}
+
+		makeFragment(liTopicSelect, psis, constraints, json);
+	    }
+	    requestFragment(psis && psis.length !== 0 ? psis[0] : null, rSuccessHandler, null)
 	}
 	
 	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;
+	    catch(err){
+		alert("Got bad JSON data from " + xhr.request.url + "\n\n" + err);
+	    }
+	    var edit = null;
+	    
 	    try{
-		instanceOf = new InstanceOfC(json.flatten().sort(), innerMakeFragment);
-		liTopicSelect.insert({"bottom" : instanceOf.getFrame()});
+		edit = new EditC(json.flatten().sort(), innerMakeFragment);
+		liTopicSelect.insert({"bottom" : edit.getFrame()});
 	    }
-	    catch(innerErr){
-		alert("There occurred an error by creating an InstanceOfC frame, please reload this page!\n\n" + innerErr);
+	    catch(err){
+		alert("There occurred an error by creating an EditC frame, please reload this page!\n\n" + err);
 	    }
-	} //onSuccessHandler
-	
-	getTypePsis(onSuccessHandler, null);
+	}
+	getPsis(onSuccessHandler, null, false);
     }
     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 09:17:20 2009
@@ -81,36 +81,43 @@
 }
 
 
-// --- Gets all type psis from the server.
-function getTypePsis(onSuccessHandler, onFailureHandler)
+// --- Gets all psis from the server. If typePsis is set to true
+// --- there will be requested only TopicType's psis.
+function getPsis(onSuccessHandler, onFailureHandler, typePsis)
 {
     try{
 	var onFailure = onFailureHandler ? onFailureHandler : defaultFailureHandler;
 	var timeFun = setAjaxTimeout(TIMEOUT, TYPE_PSIS_URL);
 	onLoad("Requesting all type PSIs");
 
-	new Ajax.Request(TYPE_PSIS_URL, {
+	var url = ALL_PSIS_URL;
+	if(typePsis === true) url = TYPE_PSIS_URL;
+
+	new Ajax.Request(url, {
 	    "method" : "get",
 	    "requestHeaders" : INIT_DATE,
 	    "onSuccess" : createXHRHandler(onSuccessHandler, timeFun),
 	    "onFailure" : createXHRHandler(onFailure, timeFun)});
     }
     catch(err){
-	alert("Could not request all type PSIs, please try again!\n\n" + err);
+	alert("From getTypePsis(): could not request all type PSIs, please try again!\n\n" + err);
     }
 }
 
 
 // --- Sends a post-request to the server with the passed psis as postBody.
 // --- Gets a constraint-object.
-function requestConstraints(psis, onSuccessHandler, onFailureHandler)
+function requestConstraints(psis, onSuccessHandler, onFailureHandler, typeConstraints)
 {
     try{
 	var onFailure = onFailureHandler ? onFailureHandler : defaultFailureHandler;
 	var timeFun = setAjaxTimeout(TIMEOUT, TMCL_TYPE_URL);
 	onLoad("Requesting all constraints for the psis:\<br/>" + psis.gsub("\\[", "").gsub("\\]", ""));
 
-	new Ajax.Request(TMCL_TYPE_URL, {
+	url = TMCL_INSTANCE_URL;
+	if(typeConstraints === true) url = TMCL_TYPE_URL;
+
+	new Ajax.Request(url, {
 	    "method" : "post",
 	    "postBody" : psis,
 	    "onSuccess" : createXHRHandler(onSuccessHandler, timeFun),
@@ -198,4 +205,29 @@
     catch(err){
 	alert("From commitFragment(): " + err);
     }
+}
+
+
+// --- Requests a JSON-Fragment for the passed psi and calls the onSuccessHandler function
+// --- after a succeeded request.
+function requestFragment(psi, onSuccessHandler, onFailureHandler)
+{
+    if(!psi || !onSuccessHandler) throw "From requestFragment(): psi and onSuccessHandler must be set!";
+
+    try{
+	var onFailure = onFailureHandler ? onFailureHandler : defaultFailureHandler;
+	var timeFun = setAjaxTimeout(TIMEOUT, COMMIT_URL);
+	onLoad("Requesting fragment for the topic " + psi);
+	
+	var url = GET_PREFIX + psi.gsub("#", "%23");
+
+	new Ajax.Request(url, {
+	    "method" : "get",
+	    "requestHeaders" : INIT_DATE,
+	    "onSuccess" : createXHRHandler(onSuccessHandler, timeFun),
+	    "onFailure" : createXHRHandler(onFailure, timeFun)});
+    }
+    catch(err){
+	alert("From requestFragment(): " + err);
+    }
 }
\ No newline at end of file




More information about the Isidorus-cvs mailing list