[isidorus-cvs] r35 - in trunk: docs src/ajax/javascripts src/json
Lukas Giessmann
lgiessmann at common-lisp.net
Wed Jun 10 07:15:19 UTC 2009
Author: lgiessmann
Date: Wed Jun 10 03:15:18 2009
New Revision: 35
Log:
ajax-client: fixed some problems in the onPlayerChangeHandler and added the possibility to use the new created topic as a player in associations which allows it
Modified:
trunk/docs/xtm_json.txt
trunk/src/ajax/javascripts/constants.js
trunk/src/ajax/javascripts/create.js
trunk/src/ajax/javascripts/datamodel.js
trunk/src/ajax/javascripts/tmcl_tools.js
trunk/src/json/json_tmcl.lisp
Modified: trunk/docs/xtm_json.txt
==============================================================================
--- trunk/docs/xtm_json.txt (original)
+++ trunk/docs/xtm_json.txt Wed Jun 10 03:15:18 2009
@@ -322,7 +322,7 @@
//+ in an association of a certain associationtype (the objects owner).
//+-----------------------------------------------------------------------------
{
- "roleType" : [ [ "topic-psi-1", "topic-psi-2", "..." ], ["subtype-1-psi-1", "..."], <...> ],
+ "roleType" : [ [ "topic-psi-1", "topic-psi-2", "..." ], [ "subtype-1-psi-1", "..."], <...> ],
"cardMin" : "unsigned integer in string representation",
"cardMax" : "unsigned integer in string representation or the string MAX_INT"
}
@@ -340,7 +340,8 @@
//+ association of a given type (= objects owner).
//+-----------------------------------------------------------------------------
{
- "players" : [ [ "topic-psi-1", "topic-psi-2", "..." ], [ "topic-2-psi-1", "..."], <...> ]
+ "playerType" : [ [ "topic-psi-1", "topic-psi-2", "..." ], [ "subtype-1-psi-1", "..." ], <...> ],
+ "players" : [ [ "topic-psi-1", "topic-psi-2", "..." ], [ "topic-2-psi-1", "..."], <...> ],
"roleType" : [ [ "topic-psi-1", "topic-psi-2", "..." ], [ "subtype-psi-1", "..." ], <...> ],
"cardMin" : "unsigned integer in string representation",
"cardMax" : "unsigned integer in string representation or the string MAX_INT"
@@ -356,8 +357,10 @@
//+ The values cardMin and cardMax defines the cardinality of otherRoleType.
//+-----------------------------------------------------------------------------
{
+ "playerType" : [ [ "topic-psi-1", "topic-psi-2", "..." ], [ "subtype-1-psi-1", "..." ], <...> ],
"players" : [ [ "topic-psi-1", "topic-psi-2", "..." ], [ "topic-2-psi-1", "..."], <...> ] ],
"roleType" : [ [ "topic-psi-1", "topic-psi-2", "..." ], [ "subtype-psi-1", "..." ], <...> ],
+ "otherPlayerType" : [ [ "topic-psi-1", "topic-psi-2", "..." ], [ "subtype-1-psi-1", "..." ], <...> ],
"otherPlayers" : [ "topic-psi-1", "topic-psi-2", "..." ], [ "topic-2-psi-1", "..."], <...> ] ],
"otherRoleType" : [ "topic-psi-1", "topic-psi-2", "..." ], [ "subtype-psi-1", "..." ], <...> ],
"cardMin" : "unsigned integer in string representation",
Modified: trunk/src/ajax/javascripts/constants.js
==============================================================================
--- trunk/src/ajax/javascripts/constants.js (original)
+++ trunk/src/ajax/javascripts/constants.js Wed Jun 10 03:15:18 2009
@@ -30,6 +30,7 @@
var ANY_URI = "http://www.w3.org/2001/XMLSchema#anyURI";
var STRING = "http://www.w3.org/2001/XMLSchema#string";
+var CURRENT_TOPIC = "**current-topic**";
// --- Contains most css classes used in this project
// --- There should be called only the function to be sure to don't override
Modified: trunk/src/ajax/javascripts/create.js
==============================================================================
--- trunk/src/ajax/javascripts/create.js (original)
+++ trunk/src/ajax/javascripts/create.js Wed Jun 10 03:15:18 2009
@@ -36,11 +36,16 @@
items[i].remove();
}
- var topic = new TopicC(null, (constraints ? constraints.topicConstraints : null));
+ 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 associations = new AssociationContainerC(null, (constraints ? constraints.associationsConstraints : null));
+ addTopicAsPlayer((constraints ? constraints.associationsConstraints : null), topic.getContent().instanceOfs);
+ var associations = new AssociationContainerC(null, (constraints ? constraints.associationsConstraints : null), topic);
var liA = new Element("li", {"class" : CLASSES.associationContainer()}).update(associations.getFrame());
liT.insert({"after" : liA});
}
Modified: trunk/src/ajax/javascripts/datamodel.js
==============================================================================
--- trunk/src/ajax/javascripts/datamodel.js (original)
+++ trunk/src/ajax/javascripts/datamodel.js Wed Jun 10 03:15:18 2009
@@ -243,7 +243,8 @@
myself.showError(str);
}
else {
- successFun(contents, json);
+ //successFun(contents, json);
+ successFun(myself.getContent(true, true), json);
}
}
@@ -1163,9 +1164,10 @@
// --- representation of a topic element.
-var TopicC = Class.create(ContainerC, {"initialize" : function($super, content, constraints){
+var TopicC = Class.create(ContainerC, {"initialize" : function($super, content, constraints, instanceOfs){
$super();
this.__minimized__ = false;
+ this.__instanceOfs__ = (!instanceOfs || instanceOfs.length === 0 ? null : instanceOfs);
try{
this.__frame__ .writeAttribute({"class" : CLASSES.topicFrame()});
this.__table__ = new Element("table", {"class" : CLASSES.topicFrame()});
@@ -1226,6 +1228,7 @@
"itemIdentities" : this.__itemIdentity__.getContent(true, true),
"subjectLocators" : this.__subjectLocator__.getContent(true, true),
"subjectIdentifiers" : this.__subjectIdentifier__.getContent(true, true),
+ "instanceOfs" : this.__instanceOfs__,
"names" : this.__name__.getContent(),
"occurrences" : this.__occurrence__.getContent()};
}
@@ -1239,6 +1242,7 @@
",\"itemIdentities\":" + this.__itemIdentity__.toJSON(true, true) +
",\"subjectLocators\":" + this.__subjectLocator__.toJSON(true, true) +
",\"subjectIdentifiers\":" + this.__subjectIdentifier__.toJSON(true, true) +
+ ",\"instanceOfs\":" + (!this.__instanceOfs__ ? "null" : this.__instanceOfs__.toJSON()) +
",\"names\":" + this.__name__.toJSON() +
",\"occurrences\":" + this.__occurrence__.toJSON() + "}";
}
@@ -1259,6 +1263,9 @@
else rows[i].show();
}
this.__minimized__ = !this.__minimized__;
+ },
+ "hasPsi" : function(){
+ return this.__subjectIdentifier__.getContent(true, true).length !== 0;
}});
@@ -1311,7 +1318,7 @@
},
"addPlayer" : function(player){
if(!player || player.length === 0) return;
- var selected = this.__player__.__frames__[0].getContent();
+ var selected = this.getPlayer();
var select = this.__player__.__frames__[0].getFrame().select("select")[0];
select.update("");
if(this.__rolePlayers__){
@@ -1338,6 +1345,7 @@
select.insert({"bottom" : opt});
}
else {
+ opt.writeAttribute({"selected" : "selected"});
select.insert({"top" : opt});
}
}
@@ -1345,7 +1353,7 @@
},
"removePlayer" : function(player){
if(!player || player.length === 0 || !this.__rolePlayers__ || this.__rolePlayers__.length === 0) return;
- var selected = this.__player__.__frames__[0].getContent();
+ var selected = this.getPlayer();
var select = this.__player__.__frames__[0].getFrame().select("select")[0];
select.update("");
var j = 0;
@@ -1364,6 +1372,7 @@
select.insert({"bottom" : opt});
}
else {
+ opt.writeAttribute({"selected" : "selected"});
select.insert({"top" : opt});
}
}
@@ -1773,9 +1782,10 @@
}});
-var AssociationContainerC = Class.create(ContainerC, {"initialize" : function($super, contents, constraints){
+var AssociationContainerC = Class.create(ContainerC, {"initialize" : function($super, contents, constraints, mainTopic){
$super();
this.__minimized__ = false;
+ this.__mainTopic__ = mainTopic;
try{
this.__frame__ .writeAttribute({"class" : CLASSES.associationContainer()});
this.__table__ = new Element("table", {"class" : CLASSES.associationContainer()});
@@ -1808,17 +1818,18 @@
});
}
setMinimizeHandler(this);
-/*
+
var button = new Element("input", {"type" : "button", "value" : "toJSON()"});
function test(myself){
button.observe("click", function(event){
+ try{
alert("content:\n\n" + myself.getContent());
- alert("JSON:\n\n" + myself.toJSON());
+ alert("JSON:\n\n" + myself.toJSON().gsub("\"topicRef\":\\[\"\\*\\*current-topic\\*\\*\"\\]", myself.__mainTopic__.getContent().subjectIdentifiers.toJSON()));
+ }catch(err){ alert("test: " + err); }
});
}
test(this);
this.getFrame().insert({"bottom" : button});
-*/
}
catch(err){
alert("From AssociationContainerC(): " + err);
Modified: trunk/src/ajax/javascripts/tmcl_tools.js
==============================================================================
--- trunk/src/ajax/javascripts/tmcl_tools.js (original)
+++ trunk/src/ajax/javascripts/tmcl_tools.js Wed Jun 10 03:15:18 2009
@@ -152,12 +152,6 @@
if(rpMax !== "*" && rpMax < arMin) throw "Not enough players available for roletype \"" + type + "\" (rpMax=" + rpMax + ", arMin=" + arMin + ")";
if(arMax !== "*" && rpMin > arMax) throw "Too much players for the roletype \"" + type + "\" (rpMin=" + rpMin + ", arMax=" + arMax + ")";
- /*
- if(rpMin < arMin) throw "sum of card-min(=" + rpMin + ") of all roleplayer-constraints < card-min(=" + arMin + ") of associationrole-constraint for the role \"" + type + "\"! not enough players";
- if(arMax !== "*" && (rpMax === "*" || rpMax > arMax)) throw "sum of card-max(=" + rpMax + ") of all roleplayer-constraints > card-max(=" + arMax + ") of associationrole-constraint for the role \"" + type + "\"! too much players"
- if(arMax !== "*" && rpMin > arMax) throw "sum of card-min(=" + rpMin + ") of all roleplayer-constraints > card-max(=" + arMax + ") of associationrole-constraint for the role \"" + type + "\"! too much players";
- if(rpMax !== "*" && rpMax < arMin) throw "sum of card-max(=" + rpMax + ") of all roleplayer-constraints > card-min(=" + arMin + ") of associationrole-constraint for the role \"" + type + "\"! not enough players";
- */
}
@@ -199,4 +193,51 @@
if(toDel === false) cleanedPlayers.push(allPlayers[i]);
}
return cleanedPlayers;
+}
+
+
+// --- Ads the new created topic as a player to all association constraints
+// --- where the player-type is one of the topic's instanceOf-topics.
+function addTopicAsPlayer(associationsConstraints, topicInstanceOfs){
+ if(!associationsConstraints || associationsConstraints.length === 0 || !topicInstanceOfs || topicInstanceOfs.length === 0) return;
+ var instanceOfsPsis = topicInstanceOfs.flatten();
+ for(var i = 0; i !== associationsConstraints.length; ++i){
+ // --- associationrole-constraints
+ if(associationsConstraints[i].rolePlayerConstraints){
+ rpcs = associationsConstraints[i].rolePlayerConstraints;
+ for(var j = 0; j !== rpcs.length; ++j){
+ for(var k = 0; k !== rpcs[j].playerType.length; ++k){
+ for(var l = 0; l !== rpcs[j].playerType[k].length; ++l){
+ if(instanceOfsPsis.indexOf(rpcs[j].playerType[k][l]) !== -1){
+ rpcs[j].players.push(new Array(CURRENT_TOPIC));
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ // --- otherrole-constraints
+ if(associationsConstraints[i].otherRoleConstraints){
+ orcs = associationsConstraints[i].otherRoleConstraints;
+ for(var j = 0; j !== orcs.length; ++j){
+ for(var k = 0; k !== orcs[j].playerType.length; ++k){
+ for(var l = 0; l !== orcs[j].playerType[k].length; ++l){
+ if(instanceOfsPsis.indexOf(orcs[j].playerType[k][l]) !== -1){
+ orcs[j].players.push(new Array(CURRENT_TOPIC));
+ break;
+ }
+ }
+ }
+ for(var k = 0; k !== orcs[j].otherPlayerType.length; ++k){
+ for(var l = 0; l !== orcs[j].otherPlayerType[k].length; ++l){
+ if(instanceOfsPsis.indexOf(orcs[j].otherPlayerType[k][l]) !== -1){
+ orcs[j].otherPlayers.push(new Array(CURRENT_TOPIC));
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
}
\ No newline at end of file
Modified: trunk/src/json/json_tmcl.lisp
==============================================================================
--- trunk/src/json/json_tmcl.lisp (original)
+++ trunk/src/json/json_tmcl.lisp Wed Jun 10 03:15:18 2009
@@ -187,7 +187,10 @@
(uri (first (psis (getf involved-topic-tupple :otherrole))))
constraint-lists))
- (let ((json-player
+ (let ((json-player-type
+ (concatenate 'string "\"playerType\":"
+ (topics-to-json-list (getf (list-subtypes (getf involved-topic-tupple :player) nil nil) :subtypes))))
+ (json-player
(concatenate 'string "\"players\":"
(topics-to-json-list
(list-instances (getf involved-topic-tupple :player) topictype topictype-constraint))))
@@ -195,6 +198,9 @@
(concatenate 'string "\"roleType\":"
(topics-to-json-list
(getf (list-subtypes (getf involved-topic-tupple :role) roletype roletype-constraint) :subtypes))))
+ (json-otherplayer-type
+ (concatenate 'string "\"otherPlayerType\":"
+ (topics-to-json-list (getf (list-subtypes (getf involved-topic-tupple :otherplayer) nil nil) :subtypes))))
(json-otherplayer
(concatenate 'string "\"otherPlayers\":"
(topics-to-json-list
@@ -209,7 +215,7 @@
(concatenate 'string "\"cardMax\":" (getf (first constraint-lists) :card-max))))
(setf cleaned-otherrole-constraints
(concatenate 'string cleaned-otherrole-constraints
- "{" json-player "," json-role "," json-otherplayer "," json-otherrole "," card-min "," card-max "},")))))
+ "{" json-player-type "," json-player "," json-role "," json-otherplayer-type "," json-otherplayer "," json-otherrole "," card-min "," card-max "},")))))
(if (string= cleaned-otherrole-constraints "[")
(setf cleaned-otherrole-constraints "null")
(setf cleaned-otherrole-constraints
@@ -272,7 +278,6 @@
:test #'(lambda(x y)
(and (eq (getf x :player) (getf y :player))
(eq (getf x :role) (getf y :role)))))))
-
(let ((cleaned-roleplayer-constraints "["))
(loop for role-player-tupple in role-player-tupples
do (let ((constraint-lists
@@ -286,7 +291,10 @@
(uri (first (psis (getf role-player-tupple :role))))
(uri (first (psis (getf role-player-tupple :player))))
constraint-lists))
- (let ((json-players
+ (let ((json-player-type
+ (concatenate 'string "\"playerType\":"
+ (topics-to-json-list (getf (list-subtypes (getf role-player-tupple :player) nil nil) :subtypes))))
+ (json-players
(concatenate 'string "\"players\":"
(topics-to-json-list
(list-instances (getf role-player-tupple :player) topictype topictype-constraint))))
@@ -300,7 +308,7 @@
(concatenate 'string "\"cardMax\":" (getf (first constraint-lists) :card-max))))
(setf cleaned-roleplayer-constraints
(concatenate 'string cleaned-roleplayer-constraints
- "{" json-players "," json-role "," card-min "," card-max "},")))))
+ "{" json-player-type "," json-players "," json-role "," card-min "," card-max "},")))))
(if (string= cleaned-roleplayer-constraints "[")
(setf cleaned-roleplayer-constraints "null")
(setf cleaned-roleplayer-constraints
More information about the Isidorus-cvs
mailing list