");
editBar.append(statusBarDiv);
_statusBar = new StatusBar(statusBarDiv[0]);
var titleDivs = $(".sectionTitle");
for (var i = 0; i < titleDivs.length; i++) {
addEditMetadataLink(titleDivs[i]);
addEditMapGPSLink(titleDivs[i]);
}
// We need to keep track of editableElementsInitialisationProgress: the number of editable elements that need to be initialised/need to finish initialising
// As CKEditors will be added, meaning more editable elements, must increment our counter editableElementsInitialisationProgress
//var $num_editable_textareas = $(".sectionText"); // consider searching for 'contenteditable="true"' as this is what CKEDITOR is looking for (we think!)
// I think for us it's always a
that has contenteditable="true", but to get all elements with attr contenteditable set to true,
// see https://stackoverflow.com/questions/4958081/find-all-elements-with-a-certain-attribute-value-in-jquery
// which has inefficient and slightly more efficient ways of doing that
var $num_editable_textareas = $('div[contenteditable="true"]');
editableElementsInitialisationProgress += $num_editable_textareas.length;
_baseURL = gs.xsltParams.library_name;
onVisibleMetadataSetChange(); // make sure that the selected item in the list is active
// If the user is attempting to leave the page, check if there are unsaved changes
// and if so, display an "Are you sure you want to leave" message.
// https://stackoverflow.com/questions/7080269/javascript-before-leaving-the-page
// Newer versions of Firefox/Chrome don't display custom message (security feature):
// https://stackoverflow.com/questions/22776544/why-is-jquery-onbeforeunload-not-working-in-chrome-and-firefox
// and http://jsfiddle.net/XZAWS/
// jquery bind() is deprecated: https://stackoverflow.com/questions/33654716/is-jquery-bind-deprecated
$(window).on("beforeunload", function(event) {
if(gs.cgiParams.docEdit == "1") { // like document.xsl, which checks the same var upon onload
// shouldn't check for whether changes are saved unless on Doc Editing page (DocEdit=1)
// else the following pop up always ends up appearing when attempting
// to leave a doc view page in Doc Editing Mode (when not yet actually Doc Editing)
// Because we've done extra work now in maintaining "editableElementsInitialisationProgress", which is
// the number of editable elements that still need to finish initialising, we can now be confident that
// the call to changesToUpdate() below won't return the wrong answers if a page with docEdit turned on
// is asked to unload (e.g. by pressing Reload) before the page has finished loading.
var changes = changesToUpdate();
//console.log("#### CHANGES before page reload: ", changes);
if(changes.length > 0) {
console.log("The collection hasn't yet been saved after editing. Are you sure you want to leave?");
return "The collection hasn't yet been saved after editing. Are you sure you want to leave?";
}
}
});
}
// override the one in documentmaker_scripts_util
// currently not used if other one is present. need to get the js include order right
function enableSaveButtons(enabled) {
if (enabled) {
$("#saveButton, #rebuildButton, #saveAndRebuildButton").removeAttr("disabled");
} else {
$("#saveButton, #rebuildButton, #saveAndRebuildButton").attr("disabled", "disabled");
}
}
/* this is a cut down version of save() from documentmaker_scripts_util.js
going back to using save, will delete this once everything working*/
function saveMetadataChangesOld() {
console.log("Saving metadata changes");
// get collection name
var collection = gs.cgiParams.c;
// get document id
var docID = gs.cgiParams.d;
var metadataChanges = new Array();
if (_deletedMetadata.length > 0) {
for (var i = 0; i < _deletedMetadata.length; i++) {
var currentRow = _deletedMetadata[i];
//Get metadata name
var cells = currentRow.getElementsByTagName("TD");
var nameCell = cells[0];
var name = nameCell.innerHTML;
var valueCell = cells[1];
var value = valueCell.innerHTML;
metadataChanges.push({
type: 'delete',
docID: docID,
name: name,
value: value
});
removeFromParent(currentRow);
}
}
if (metadataChanges.length == 0) {
console.log(gs.text.de.no_changes);
return;
}
var processChangesLoop = function (index) {
var change = metadataChanges[index];
var callbackFunction;
if (index + 1 == metadataChanges.length) {
callbackFunction = function () {
console.log("Completed saving metadata changes. You must rebuild the collection for the changes to take effect.");
};
} else {
callbackFunction = function () {
processChangesLoop(index + 1)
};
}
if (change.type == "delete") {
gs.functions.removeArchivesMetadata(collection, gs.xsltParams.site_name, change.docID, change.name, null, change.value, function () {
callbackFunction();
});
} else {
if (change.orig) {
gs.functions.setArchivesMetadata(collection, gs.xsltParams.site_name, docID, change.name, null, change.value, change.orig, "override", function () {
callbackFunction();
});
} else {
gs.functions.setArchivesMetadata(collection, gs.xsltParams.site_name, docID, change.name, null, change.value, null, "accumulate", function () {
callbackFunction();
});
}
}
}
processChangesLoop(0);
/* need to clear the changes from the page */
while (_deletedMetadata.length > 0) {
_deletedMetadata.pop();
}
}