Author: lgiessmann Date: Tue Jun 16 08:17:10 2009 New Revision: 44
Log: ajax-client: a fragment commit without validation is implemented; json-importer: to import a topic or a topicStub it is necessary to define a psi for this element - this is difference between the xtm-importer (there must be one of the elements psi, itemidentity, subjectlocator defined), because all topics are referenced via psis and not topicid's
Modified: trunk/src/ajax/javascripts/create.js trunk/src/ajax/javascripts/datamodel.js trunk/src/ajax/javascripts/requests.js trunk/src/json/json_importer.lisp
Modified: trunk/src/ajax/javascripts/create.js ============================================================================== --- trunk/src/ajax/javascripts/create.js (original) +++ trunk/src/ajax/javascripts/create.js Tue Jun 16 08:17:10 2009 @@ -36,6 +36,11 @@ items[i].remove(); }
+ items = $$("li." + CLASSES.tmIdFrame()); + for(var i = 0; i !== items.length; ++i){ + items[i].remove(); + } + items = $$("li." + CLASSES.commitButton()); for(var i = 0; i !== items.length; ++i){ items[i].remove(); @@ -49,10 +54,17 @@ var liT = new Element("li", {"class" : CLASSES.topicFrame()}).update(topic.getFrame()); context.insert({"after" : liT});
- addTopicAsPlayer((constraints ? constraints.associationsConstraints : null), topic.getContent().instanceOfs); - var associations = new AssociationContainerC(null, (constraints ? constraints.associationsConstraints : null)); - var liA = new Element("li", {"class" : CLASSES.associationContainer()}).update(associations.getFrame()); - liT.insert({"after" : liA}); + 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()); @@ -60,10 +72,12 @@
var commitButton = new Element("input", {"type" : "button", "value" : "commit fragment", "style" : "float: right; margin-top: -10px;"}) commitButton.observe("click", function(event){ - try{ var tPsis = topic.getContent().subjectIdentifiers; - var referencedTopics = topic.getReferencedTopics().concat(associations.getReferencedTopics()).without(CURRENT_TOPIC).uniq(); - + 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){ @@ -76,19 +90,18 @@ } var jTopic = ""topic":" + topic.toJSON(); var jTopicStubs = ""topicStubs":" + tsStr; - var jAssociations = ""associations":" + associations.toJSON().gsub(CURRENT_TOPIC_ESCAPED, tPsis) + var jAssociations = ""associations":" + (associations ? associations.toJSON().gsub(CURRENT_TOPIC_ESCAPED, tPsis) : "null"); var jTmId = ""tmIds":" + tmId.toJSON(); var json = "{" + jTopic + "," + jTopicStubs + "," + jAssociations + "," + jTmId + "}"; - alert(json); + commitFragment(json, function(xhr){ alert("The fragment was committed succesfully!"); }, null); } - + function onErrorHandler(){ - // --- currently there is not neede a special handling for errors + // --- currently there is not needed a special handling for errors // --- occurred during this operation } - + getTopicStubs(referencedTopics, onSuccessHandler, onErrorHandler); - }catch(err){ alert("test: " + err); } }); var liCB = new Element("li", {"class" : CLASSES.commitButton()}); liCB.update(commitButton);
Modified: trunk/src/ajax/javascripts/datamodel.js ============================================================================== --- trunk/src/ajax/javascripts/datamodel.js (original) +++ trunk/src/ajax/javascripts/datamodel.js Tue Jun 16 08:17:10 2009 @@ -650,6 +650,9 @@ catch(err){ return new Array(); } + + for(var i = 0; i !== values.length; ++i) + values[i] = new Array(values[i]); return values; }, "disable" : function(){ @@ -1486,7 +1489,7 @@ var scopes = names[i].scopes; if(scopes){ for(var j = 0; j !== scopes.length; ++j){ - if(referencedTopics.indexOf(scopes[j]) === -1) referencedTopics.push(scopes[j]); + if(referencedTopics.indexOf(scopes[j][0]) === -1) referencedTopics.push(scopes[j][0]); } } } @@ -1502,7 +1505,7 @@ var scopes = occurrences[i].scopes; if(scopes){ for(var j = 0; j !== scopes.length; ++j){ - if(referencedTopics.indexOf(scopes[j]) === -1) referencedTopics.push(scopes[j]); + if(referencedTopics.indexOf(scopes[j][0]) === -1) referencedTopics.push(scopes[j][0]); } } } @@ -2461,7 +2464,7 @@ var scopes = associations[i].scopes; if(scopes){ for(var j = 0; j !== scopes.length; ++j){ - if(referencedTopics.indexOf(scopes[j]) === -1) referencedTopics.push(scopes[j]); + if(referencedTopics.indexOf(scopes[j][0]) === -1) referencedTopics.push(scopes[j][0]); } } var roles = associations[i].roles;
Modified: trunk/src/ajax/javascripts/requests.js ============================================================================== --- trunk/src/ajax/javascripts/requests.js (original) +++ trunk/src/ajax/javascripts/requests.js Tue Jun 16 08:17:10 2009 @@ -89,7 +89,7 @@ function checkRequests(){ var delta = 100; neededTime += delta; - if(delta > maxTimeout){ + if(delta > maxTimeout && psis && psis.length !== 0){ alert("From getTopicStubs(): Please check your network-connection - the request timed out!!!"); onFailureHandler(); return; @@ -105,4 +105,22 @@ catch(err){ alert("From getTopicStubs(): Could not request topicStubs information for: " + psis + "\n\n" + err); } +} + + +function commitFragment(json, onSuccessHandler, onFailureHandler) +{ + if(!json || !onSuccessHandler) throw "From commitFragment(): json and onSuccessHandler must be set!"; + try{ + var onFailure = onFailureHandler ? onFailureHandler : defaultFailureHandler; + + new Ajax.Request(COMMIT_URL, { + "method" : "post", + "postBody" : json, + "onSuccess" : onSuccessHandler, + "onFailure" : onFailure}); + } + catch(err){ + alert("From commitFragment(): " + err); + } } \ No newline at end of file
Modified: trunk/src/json/json_importer.lisp ============================================================================== --- trunk/src/json/json_importer.lisp (original) +++ trunk/src/json/json_importer.lisp Tue Jun 16 08:17:10 2009 @@ -391,9 +391,8 @@ (t (error "json-importer:get-topicStub-values-from-json-string: bad item-specifier found in json-list")))) - (unless (or itemIdentities subjectLocators subjectIdentifiers) - (error "json-importer:get-topicStub-values-from-json-string: one of the elements - itemIdentity, sbjectLocator or subjectIdentifier must be set")) + (unless subjectIdentifiers + (error "json-importer:get-topicStub-values-from-json-string: the element subjectIdentifiers mus be set!")) (unless id (error "json-importer:get-topic-valuesStub-from-json-string: the element id must be set")) (list :id id @@ -433,9 +432,8 @@ (t (error "json-importer:get-topic-values-from-json-string: bad item-specifier found in json-list ~a" (car j-elem))))) - (unless (or itemIdentities subjectLocators subjectIdentifiers) - (error "json-importer:get-topic-values-from-json-string: one of the elements - itemIdentity, sbjectLocator or subjectIdentifier must be set")) + (unless subjectIdentifiers + (error "json-importer:get-topic-values-from-json-string: the element subjectIdentifiers must be set!")) (unless id (error "json-importer:get-topic-values-from-json-string: the element id must be set")) (let ((names-list (map 'list #'get-name-values-from-json-list names))