- Timestamp:
- 2019-03-11T20:13:33+13:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/web/interfaces/default/js/documentedit_scripts_util.js
r32873 r32893 330 330 } 331 331 332 function 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 332 345 333 346 function saveAndRebuild(rebuild) … … 345 358 var sendBuildRequest = function() 346 359 { 347 console.log("Replacing init states with current states");348 // Clean changes. We're here because setting meta for all meta changes was successful, so349 // - 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 359 360 var request = "["; 360 361 for(var i = 0; i < _transactions.length; i++) … … 399 400 if (rebuild) { 400 401 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 402 407 // reset the save button here 403 408 enableSaveButtons(true); … … 537 542 538 543 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 } 539 573 540 574 var processChangesLoop = function(index) … … 560 594 // collection, site, documentID, metadataName, metadataPosition, metadataValue, prevMetadataValue, metamode, responseFunction 561 595 //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); 563 599 } 564 600 else if(change.orig) 565 601 { 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); 567 605 } 568 606 else 569 607 { 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); 571 611 } 572 612 } … … 681 721 if(counter == collections.length - 1) 682 722 { 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 683 728 removeCollectionsFromBuildList(collections); 684 729 if(callback)
Note:
See TracChangeset
for help on using the changeset viewer.