Changeset 427 for trunk/src/ajax


Ignore:
Timestamp:
04/21/11 09:56:59 (14 years ago)
Author:
lgiessmann
Message:

JSON-Interface: all / that are not escaped will be escaped after calling prototypes toJSON method, because prototype does not escape /; if no topics for a player-constraint or other-player-constraint exist there is no error message thrown, instead the constraint is ignored as long as there are to few topics; the backend now escapes all /, too

Location:
trunk/src/ajax/javascripts
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/src/ajax/javascripts/create.js

    r328 r427  
    131131            return;
    132132        }
    133        
     133
     134
    134135        // --- if the validation succeeded the fragment will be sent to the server
    135136        var tPsis = topic.getContent().subjectIdentifiers;
     
    151152        }
    152153
     154
    153155        function onSuccessHandler(topicStubs){
    154156            var tsStr = "null";
     
    161163                tsStr += "]";
    162164            }
     165   
    163166            var jTopic = "\"topic\":" + topic.toJSON();
    164167            var jTopicStubs = "\"topicStubs\":" + tsStr;
     
    166169            var jTmId = "\"tmIds\":" + tmId.toJSON();
    167170            var json = "{" + jTopic + "," + jTopicStubs + "," + jAssociations + "," + jTmId + "}";
     171
    168172            commitFragment(json, function(xhr){ alert("The fragment was committed succesfully!"); }, null);
    169173        }
    170        
     174               
    171175        function onErrorHandler(){
    172176            // --- currently there is not needed a special handling for errors
    173             // --- occurred during this operation
     177            // --- occurring during this operation
    174178        }
    175179        getTopicStubs(referencedTopics, onSuccessHandler, onErrorHandler);
  • TabularUnified trunk/src/ajax/javascripts/datamodel.js

    r354 r427  
    550550                                            "toJSON" : function(unique, removeNull){
    551551                                                var content = this.getContent(unique, removeNull);
    552                                                 return content.length === 0 ? "null" : content.toJSON();
     552                                                if(!content || content.length === 0) return "null";
     553                                                return content.toJSON();
    553554                                            },
    554555                                            "isValid" : function(){
     
    26662667                                                   }
    26672668                                                   catch(err){
    2668                                                        alert("From RoleContainerC(): " + err);
    2669                                                    }
     2669                                                       alert("From RoleContainerC(): " + err);
     2670                                                   }
    26702671                                               },
    26712672                                               "__orderContentsToRoles__" : function(contents, roleContainer, usedContents, alreadyUsedRoles){
     
    29212922                                                   var usedContents = new Array();
    29222923                                                   var alreadyUsedRoles = new Array();
    2923                                                        
     2924                                                     
    29242925                                                   // --- searches for associaitonrole-constraints and roleplayer-constraints
    29252926                                                   var ret = this.__orderContentsToRoles__(cContents, this.__arContainer__.__frames__, usedContents, alreadyUsedRoles);
     
    29272928                                                   usedContents = ret.usedContents;
    29282929                                                   alreadyUsedRoles = ret.alreadyUsedRoles;
    2929 
     2930                                                 
    29302931                                                   // --- searches for otherrole-constraints
    29312932                                                   ret = this.__orderContentsToRoles__(cContents, this.__orContainer__.__frames__, usedContents, alreadyUsedRoles);
     
    29332934                                                   usedContents = ret.usedContents;
    29342935                                                   alreadyUsedRoles = ret.alreadyUsedRoles;
    2935                                                    
     2936                                                 
    29362937                                                   // --- creates additional roles (associationrole-constraints)
    29372938                                                   ret = this.__createAdditionalRolesFromContents__(cContents, usedContents, alreadyUsedRoles, true);
     
    29392940                                                   usedContents = ret.usedContents;
    29402941                                                   alreadyUsedRoles = ret.alreadyUsedRoles;
    2941 
     2942                                                 
    29422943                                                   // --- creates additional roles (associationrole-constraints)
    29432944                                                   ret = this.__createAdditionalRolesFromContents__(cContents, usedContents, alreadyUsedRoles, false);
     
    29452946                                                   usedContents = ret.usedContents;
    29462947                                                   alreadyUsedRoles = ret.alreadyUsedRoles;
    2947 
     2948                                                 
    29482949                                                   this.__createNewRolesFromContents__(cContents);
    29492950                                               },
     
    29952996                                                   var roleMinOrg = parseInt(associationRoleConstraint.cardMin);
    29962997                                                   for(var i = 0; i !== rolePlayerConstraints.length; ++i){
     2998                                                       // if no player is available for a rolePlayerConstraint the constraint is ignored and no warning is thrown
     2999                                                       if(!rolePlayerConstraints[i].players || rolePlayerConstraints[i].players.length < playerMin) continue;
     3000                                                       
     3001
    29973002                                                       var playerMin = rolePlayerConstraints[i].cardMin === 0 ? 1 : parseInt(rolePlayerConstraints[i].cardMin);
    2998                                                        if(rolePlayerConstraints[i].players.length < playerMin) throw "From __makeRolesFromARC__(): not enough players(=" + rolePlayerConstraints[i].players.length + ") to reach card-min(=" + playerMin + ") of roletype\"" + roleType.flatten()[0] + "\"!";
    29993003                                                       for(var k = 0; k !== playerMin; ++k){
    30003004                                                           // --- creates a new role
     
    30233027                                                           // existing roles --> all roles that owns a player which is selected of those listed in the roleplayer-constraint
    30243028                                                           var existingRoles = this.getExistingRoles(roleType, rolePlayerConstraints[i].players, this.__arContainer__.__frames__);
    3025                                                            var availablePlayers = rolePlayerConstraints[i].players;
     3029                                                           var availablePlayers = (rolePlayerConstraints[i].players ? rolePlayerConstraints[i].players : new Array());
    30263030                                                           if(existingRoles.length < rolePlayerConstraints[i].cardMax && availablePlayers.length > existingRoles.length){
    30273031                                                               var currentAvailablePlayers = rolePlayerConstraints[i].players;
     
    30483052                                                           }
    30493053                                                       }
    3050                                                        if(currentlyCreated === 0) throw "Not enough players to create all needed roles of the type \"" + roleType.flatten()[0] + "\"!";
     3054
     3055                                                       // not enough roles created so an association with zero roles can be made
     3056                                                       if(currentlyCreated === 0) break;
    30513057                                                   };
    30523058                                                   this.__checkARCButtons__(currentRoles, allAvailablePlayers, associationRoleConstraint);
     
    30653071                                                       var cMin = orpcs[i].cardMin === 0 ? 1 : parseInt(orpcs[i].cardMin);
    30663072                                                       var cMinOrg = parseInt(orpcs[i].cardMin);
    3067                                                        if(!cOtherPlayers || cOtherPlayers.length < cMin) throw "from __makeRolesFromORC__(): not enough players(=" + cOtherPlayers.length + ") for roletype + \"" + cOtherRoleType.flatten()[0] + "\"!";
     3073
     3074                                                       // if there are not enough other players  the constraint is ignored and no error message is thrown
     3075                                                       if(!cOtherPlayers || cOtherPlayers.length < cMin) continue;
     3076
     3077
    30683078                                                       var existingRoles = this.getExistingRoles(cOtherRoleType, cOtherPlayers, this.__orContainer__.__frames__);
    30693079                                                       for(var j = 0; j < cMin - existingRoles.length; ++j){
     
    34723482                                                   var rpcs = this.__rolePlayerConstraints__;
    34733483                                                   
    3474                                                    // --- checks if there exist any constraints
     3484                                                   // --- checks if there exist aniy constraints
    34753485                                                   if(!arcs || arcs.length === 0){
    34763486                                                       this.showError("No association-constraints found for this association!");
     
    34863496                                                   var allAroles = new Array();
    34873497                                                   var allAroles2 = new Array();
    3488                                                    for(var i = 0; this.__arContainer__.__frames__ && i !== this.__arContainer__.__frames__.length; ++i){
    3489                                                        this.__arContainer__.__frames__[i].hideError();
    3490                                                        if(this.__arContainer__.__frames__[i].isUsed() === true){
    3491                                                            allAroles.push(this.__arContainer__.__frames__[i]);
    3492                                                            allAroles2.push(this.__arContainer__.__frames__[i]);
     3498                                                   if(this.__arContainer__ && this.__arContainer__.__frames__){
     3499                                                       for(var i = 0; this.__arContainer__.__frames__ && i !== this.__arContainer__.__frames__.length; ++i){
     3500                                                           this.__arContainer__.__frames__[i].hideError();
     3501                                                           if(this.__arContainer__.__frames__[i].isUsed() === true){
     3502                                                               allAroles.push(this.__arContainer__.__frames__[i]);
     3503                                                               allAroles2.push(this.__arContainer__.__frames__[i]);
     3504                                                           }
    34933505                                                       }
    34943506                                                   }
     
    34963508                                                   // --- collects all used roles depending on otherrole-constraints
    34973509                                                   var allOroles = new Array();
    3498                                                    for(var i = 0; i !== this.__orContainer__.__frames__.length; ++i){
    3499                                                        this.__orContainer__.__frames__[i].hideError();
    3500                                                        if(this.__orContainer__.__frames__[i].isUsed() === true)
    3501                                                            allOroles.push(this.__orContainer__.__frames__[i]);
     3510                                                   if(this.__orContainer__ && this.__orContainer__.__frames__){
     3511                                                       for(var i = 0; i !== this.__orContainer__.__frames__.length; ++i){
     3512                                                           this.__orContainer__.__frames__[i].hideError();
     3513                                                           if(this.__orContainer__.__frames__[i].isUsed() === true)
     3514                                                               allOroles.push(this.__orContainer__.__frames__[i]);
     3515                                                       }
    35023516                                                   }
    35033517                                                   
  • TabularUnified trunk/src/ajax/javascripts/requests.js

    r328 r427  
    1010//+  trunk/src/ajax/javascripts/external/MIT-LICENSE.txt.
    1111//+-----------------------------------------------------------------------------
     12
     13
     14// --- replaces every / character that is not prefixed by a \ character
     15function escapeSlashInJSON(jsonString){
     16    return jsonString.replace(/([^\\])\//g, '$1\\/').replace(/([^\\])\//g, '$1\\/');
     17}
     18
    1219
    1320// --- Sets a timeout function which alerts a message.
     
    209216        new Ajax.Request(COMMIT_URL, {
    210217            "method" : "post",
    211             "postBody" : json,
     218            "postBody" : escapeSlashInJSON(json),
    212219            "onSuccess" : createXHRHandler(onSuccessHandler, timeFun),
    213220            "onFailure" : createXHRHandler(onFailure, timeFun)});
     
    229236        new Ajax.Request(MARK_AS_DELETED_URL, {
    230237            "method" : "delete",
    231             "postBody" : json,
     238            "postBody" : escapeSlashInJSON(json),
    232239            "onSuccess" : createXHRHandler(onSuccessHandler, timeFun),
    233240            "onFailure" : createXHRHandler(onFailure, timeFun)});
  • TabularUnified trunk/src/ajax/javascripts/tmcl_tools.js

    r328 r427  
    164164
    165165    for(var i = 0; i !== anyConstraints.length; ++i){
     166        if(!anyConstraints[i].players) return players;
    166167        for(var j = 0; j !== anyConstraints[i].players.length; ++j){
    167168            players.push(anyConstraints[i].players[j])
Note: See TracChangeset for help on using the changeset viewer.