Changeset 32060

Show
Ignore:
Timestamp:
06.11.2017 18:17:26 (2 years ago)
Author:
ak19
Message:

1. On leaving the page when there are unsaved changes, there's now a popup warning about this. 2. After a rebuild, the page is automatically reloaded to display the changes.

Files:
1 modified

Legend:

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

    r31909 r32060  
    2020var _metadataSetList = new Array(); 
    2121 
     22 
     23// If the user is attempting to leave the page, check if there are unsaved changes 
     24// and if so, display an "Are you sure you want to leave" message. 
     25// https://stackoverflow.com/questions/7080269/javascript-before-leaving-the-page 
     26// Newer versions of Firefox/Chrome don't display custom message (security feature): 
     27// https://stackoverflow.com/questions/22776544/why-is-jquery-onbeforeunload-not-working-in-chrome-and-firefox 
     28// and http://jsfiddle.net/XZAWS/ 
     29// jquery bind() is deprecated: https://stackoverflow.com/questions/33654716/is-jquery-bind-deprecated 
     30$(window).on("beforeunload", function(event) { 
     31    if(gs.cgiParams.docEdit == "1") { // like document.xsl, which checks the same var upon onload 
     32    // shouldn't check for whether changes are saved unless on Doc Editing page (DocEdit=1) 
     33    // else the following pop up always ends up appearing when attempting 
     34    // to leave a doc view page in Doc Editing Mode (when not yet actually Doc Editing) 
     35    var changes = changesToUpdate(); 
     36     
     37    if(changes.length > 0) { 
     38        return "The collection hasn't yet been saved after editing. Are you sure you want to leave?";    
     39    } 
     40 
     41    } 
     42 
     43}); 
     44 
     45 
    2246function encodeDelimiters(meta_value) { 
    2347 
     
    218242  var collectionsArray = new Array(); 
    219243  collectionsArray.push(collection); 
    220   buildCollections(collectionsArray); 
    221 } 
     244  buildCollections(collectionsArray, null, reloadUponRebuild); // passing in callback to reload the page after build, as requested by Kathy 
     245} 
     246 
     247 
     248function reloadUponRebuild() { 
     249   // finished rebuilding - reload the page after rebuild, but first 
     250   // clear transactions array of saved changes, now that we're done processing these changes during rebuild, 
     251   // since we don't want the "are you sure to leave page" popup which appears on _transactions array being non-empty 
     252    _transactions = null;     
     253    location.reload(true); // force reload, not from cache, https://www.w3schools.com/jsref/met_loc_reload.asp  
     254} 
     255 
    222256 
    223257function saveAndRebuild(rebuild)  
     
    276310                } 
    277311                if (rebuild) { 
    278                   buildCollections(_collectionsToBuild); 
     312                    buildCollections(_collectionsToBuild, null, reloadUponRebuild); 
    279313                } else { 
    280314                  // reset the save button here 
    281                   enableSaveButtons(true); 
     315                    enableSaveButtons(true); 
     316                    // saving to archives is now done, clear the transactions 
     317                    // that were keeping track of the full text changes that have now 
     318                    // been performed to archives (no member var keeps track of meta changes, only a local var) 
     319                    _transactions = new Array(); 
    282320                } 
    283321            }