Changeset 32893

Show
Ignore:
Timestamp:
11.03.2019 20:13:33 (3 months ago)
Author:
ak19
Message:

Part 2 of 2 commits to do with getting errorCallBack working on documentEditing for determining when changes have been saved or not to decided whether editableInitStates can finally be overwritten with current (saved) values. Tested with editing doc meta and doc map meta. Also tested special cases for both: with an meta edit followed by a tomcat restart, which then already warned you it requires a relogin for building to work, until which time editableInitStates is still not overwritten, so that it can warn you of unsaved changes if you attempt to leave the page at any point. The only time these changes don't work as expected (but still works better than original code which just loses your local changes) is when editing doc meta instead of map meta and there's the server restart in the middle and the new value ends up accumulating instead of replacing/overriding the previous value. In the old version of the code, new values were lost and the collection rebuilt, all silently without telling you of data loss.

Location:
main/trunk/greenstone3/web/interfaces/default/js
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/interfaces/default/js/documentedit_scripts_util.js

    r32873 r32893  
    330330} 
    331331 
     332function changesSaved() { 
     333    console.log("Replacing init states with current states"); 
     334    // Clean changes. We're here because setting meta for all meta changes was successful, so 
     335    // - update doc's metadata initial states to current: 
     336    editableInitStates = editableLastStates;         
     337    // - update doc's map editors' initial states to current: 
     338    var map_editors_array = Object.values(gsmap_store); 
     339    for(var i = 0; i < map_editors_array.length; i++) { 
     340        var map_editor = map_editors_array[i]; 
     341        map_editor.savedOverlays = JSON.stringify(ShapesUtil.overlayToJSON(map_editor.overlays)); 
     342    } 
     343} 
     344 
    332345 
    333346function saveAndRebuild(rebuild)  
     
    345358    var sendBuildRequest = function() 
    346359    { 
    347         console.log("Replacing init states with current states"); 
    348         // Clean changes. We're here because setting meta for all meta changes was successful, so 
    349         // - update doc's metadata initial states to current: 
    350         editableInitStates = editableLastStates;         
    351         // - update doc's map editors' initial states to current: 
    352         var map_editors_array = Object.values(gsmap_store); 
    353         for(var i = 0; i < map_editors_array.length; i++) { 
    354             var map_editor = map_editors_array[i]; 
    355             map_editor.savedOverlays = JSON.stringify(ShapesUtil.overlayToJSON(map_editor.overlays)); 
    356         } 
    357          
    358          
    359360        var request = "["; 
    360361        for(var i = 0; i < _transactions.length; i++) 
     
    399400                if (rebuild) { 
    400401                    buildCollections(_collectionsToBuild, null, reloadUponRebuild); 
    401                 } else { 
     402                } else { // no rebuilding 
     403                    // We're past possible errors at this point. So changes have by now been definitely saved to archives. 
     404                    // and as there is no rebuilding of the collection, we're now ready to set init states to current states                     
     405                    changesSaved(); 
     406                     
    402407                  // reset the save button here 
    403408                    enableSaveButtons(true); 
     
    537542 
    538543     
     544    var errorCallback = function() {         
     545        alert("A server side error occurred during setArchivesMetadata. (Is the server running?)\nNot proceeding further with saving and rebuilding."); 
     546        return true; 
     547         
     548    } 
     549     
     550    // called on success callback, to check for errors in response. Returns true if response contains the error status code 3 
     551    var hadErrorResponseOnSave = function(response) { 
     552         
     553        // check response for error status code 3 
     554        //<status code="3" 
     555         
     556        parser = new DOMParser(); 
     557        xmlDoc = parser.parseFromString(response,"text/xml"); 
     558         
     559        // Response may have no status code if metadata changes made and the the server stopped and then restarted and docEditor's building button pressed: 
     560        // response message returned is that the user is not logged in. Don't handle this scenario here. This function solely checks for error status code===3 in responses. 
     561        if(xmlDoc.getElementsByTagName("status").length > 0) { 
     562         
     563            var status_code = xmlDoc.getElementsByTagName("status")[0].getAttribute("code"); 
     564            if(status_code === "3") { // status code 3 means error (see GSStatus.java::ERROR) 
     565                alert("An error occurred during setArchivesMetadata.\nNot proceeding further with saving and rebuilding.\nSee browser's console log for details."); 
     566                console.log("@@@ Error on setting archive metadata. Got error message: " + response); 
     567                return true; 
     568            } 
     569        } 
     570        return false; 
     571 
     572    } 
    539573     
    540574    var processChangesLoop = function(index) 
     
    560594                // collection, site, documentID, metadataName, metadataPosition, metadataValue, prevMetadataValue, metamode, responseFunction                
    561595                //console.log("@@@ metapos! change: ", change); 
    562                 gs.functions.setArchivesMetadata(change.collection, gs.xsltParams.site_name, change.docID, change.name, change.metapos, encodeDelimiters(change.value), null, "override", function(){callbackFunction();}); 
     596                gs.functions.setArchivesMetadata(change.collection, gs.xsltParams.site_name, change.docID, change.name, change.metapos, encodeDelimiters(change.value), null, "override", 
     597                    function(response){ if(!hadErrorResponseOnSave(response)) callbackFunction(); }, 
     598                    errorCallback);                  
    563599            } 
    564600          else if(change.orig) 
    565601            { 
    566             gs.functions.setArchivesMetadata(change.collection, gs.xsltParams.site_name, change.docID, change.name, null, encodeDelimiters(change.value), encodeDelimiters(change.orig), "override", function(){callbackFunction();}); 
     602            gs.functions.setArchivesMetadata(change.collection, gs.xsltParams.site_name, change.docID, change.name, null, encodeDelimiters(change.value), encodeDelimiters(change.orig), "override", 
     603                function(response){ if(!hadErrorResponseOnSave(response)) callbackFunction(); }, 
     604                errorCallback); 
    567605            } 
    568606          else 
    569607            { 
    570             gs.functions.setArchivesMetadata(change.collection, gs.xsltParams.site_name, change.docID, change.name, null, encodeDelimiters(change.value), null, "accumulate", function(){callbackFunction();}); 
     608            gs.functions.setArchivesMetadata(change.collection, gs.xsltParams.site_name, change.docID, change.name, null, encodeDelimiters(change.value), null, "accumulate", 
     609                function(response){ if(!hadErrorResponseOnSave(response)) callbackFunction(); }, 
     610                errorCallback); 
    571611            } 
    572612        } 
     
    681721                                    if(counter == collections.length - 1) 
    682722                                    { 
     723                                        // We're here because rebuilding has now completed with no errors. 
     724                                        // This means changes were definitely successfully saved to archives AND have been rebuilt with NO errors, 
     725                                        // so set init states to current states: 
     726                                        changesSaved(); 
     727                                         
    683728                                        removeCollectionsFromBuildList(collections); 
    684729                                        if(callback) 
  • main/trunk/greenstone3/web/interfaces/default/js/javascript-global-functions.js

    r32873 r32893  
    533533         
    534534        if(successResponseFunction != null) { 
    535              
     535            //console.log("XXXX callMetaServer - Got response: " + response); 
    536536            successResponseFunction(response); 
    537537        } 
    538538        }) 
    539         .error(function() { 
     539        .error(function(response) { 
    540540            if(errorResponseFunction != null) {  
    541541                errorResponseFunction(response);