Changeset 31748 for main/trunk


Ignore:
Timestamp:
06/26/17 12:15:10 (4 years ago)
Author:
kjdon
Message:

trying to make document editing javascript more easy to follow. document_scripts now contains no editing functionality. Content editing (metadata and text) is now in documentedit_scripts.js, which also uses documentedit_scripts_util.js. documentmaker_scripts is for the functionality where sections are moved around?? not sure, as we have never got it working. this also uses documentedit_scripts_util.js (which was just renamed from documentmaker_scripts_util.js)

Location:
main/trunk/greenstone3/web/interfaces/default/js
Files:
1 added
2 edited
1 moved

Legend:

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

    r31740 r31748  
     1/** Javascript file for viewing documents */
     2
    13var _imageZoomEnabled = false;
    24// Choose which types of filtering you want: sectionnum, or sectiontitle or both
     
    810var _linkCellMap = new Array();
    911var _onCells = new Array();
    10 
    11 /* some vars for document editing */
    12 /* if true, will look through all the metadata for the document, and add each namespace into the list of metadata sets. If set to false, will only add in the ones defined in setStaticMetadataSets function (defined below) - override this function to make a custom list of sets */
    13 var dynamic_metadata_set_list = true;
    14 /* if true, will make the editing controls stay visible even on page scrolling */
    15 var keep_editing_controls_visible = true;
    16 /* Here you can choose which save buttons you like. Choose from 'save', 'rebuild', 'saveandrebuild' */
    17 var save_and_rebuild_buttons = ["saveandrebuild"];
    18 //var save_and_rebuild_buttons = ["save", "rebuild", "saveandrebuild"];
    1912
    2013
     
    2417var editableLastStates = new Array();
    2518
    26 /* What kind of metadata element selection do we provide?
    27    plain: just a text input box
    28    fixedlist: a drop down menu with a fixed list of options (provided by the availableMetadataElements list)
    29    autocomplete: a text input box with a list of suggestions to choose from (provided by the availableMetadataElements list). Allows additional input other than the fixed list
    30 */
    31 var new_metadata_field_input_type = "plain";
    32 /* Metadata elements to be used in the fixedlist/autocomplete options above */
    33 var availableMetadataElements = ["dc.Title", "dc.Subject"];
    34 /* metadata elements that have a list of values/suggestions */
    35 var autocompleteMetadata = new Array();
    36 /* for each metadata element specified here, one should provide an array of values. The name is the meta_name + "_values", but you must strip . and _ from the name.
    37 for example
    38 var autocompleteMetadata = ["dc.Subject"];
    39 var dcSubject_values = ["Kings", "Queens", "others"];
    40 */
    4119
    4220/********************
     
    11821160}
    11831161
    1184 /************************
    1185 *    CHANGES SCRIPTS    *
    1186 ************************/
    1187 
    1188 function addCKEEditableState(evt,stateArray)
    1189 {
    1190     // Event->Editor->CKE DOM Inline Element that editor was for->underlying jquery element
    1191     element = evt.editor.element.$;
    1192     nodeText = element.innerHTML;
    1193          stateArray.push({
    1194              editableNode : element,
    1195              initHTML : nodeText
    1196          });
    1197    
    1198 }
    1199 function addEditableState(editable,stateArray)
    1200 {
    1201 
    1202     if(editable.tagName == 'TEXTAREA')
    1203     {
    1204         nodeText = editable.value;
    1205     }
    1206     else
    1207     {
    1208         nodeText = editable.innerHTML;
    1209     }
    1210 
    1211         stateArray.push({
    1212                 editableNode : editable,
    1213                 initHTML : nodeText
    1214         });
    1215 
    1216 }
    1217 
    1218 function getLastEditableStates()
    1219 {   
    1220     editableLastStates = [];
    1221         $(".sectionText").each(function(){addEditableState(this,editableLastStates);});
    1222         $(".metaTableCellArea").each(function(){addEditableState(this,editableLastStates);});
    1223 
    1224 }
    1225 
    1226 function changesToUpdate()
    1227 {
    1228     var resultArray = new Array();
    1229     getLastEditableStates();
    1230     for (var j in editableLastStates)
    1231     {   
    1232         if (isNodeChanged(editableLastStates[j]))
    1233         {
    1234             resultArray.push(editableLastStates[j].editableNode);
    1235         }
    1236     }
    1237     return resultArray;
    1238 }
    1239 
    1240 
    1241 function isNodeChanged(StateToCheck){
    1242     for (var i in editableInitStates)
    1243     {
    1244         if ((StateToCheck.editableNode === editableInitStates[i].editableNode)) {
    1245         if ( StateToCheck.initHTML === editableInitStates[i].initHTML )
    1246         {
    1247             return false;
    1248         }
    1249         return true;
    1250         }
    1251    
    1252     }
    1253     return true;
    1254 }
    1255 /************************
    1256 * METADATA EDIT SCRIPTS *
    1257 ************************/
    1258 
    1259 function addEditMetadataLink(cell)
    1260 {
    1261     cell = $(cell);
    1262     var id = cell.attr("id").substring(6);
    1263     var metaTable = gs.jqGet("meta" + id);
    1264 
    1265     var row = cell.parent();
    1266     var newCell = $("<td>", {"style": "font-size:0.7em; padding:0px 10px", "class": "editMetadataButton"});
    1267     var linkSpan = $("<span>", {"class": "ui-state-default ui-corner-all", "style": "padding: 2px; float:left;"});
    1268    
    1269         var linkLabel = $("<span>"+gs.text.de.edit_metadata+"</span>");
    1270     var linkIcon = $("<span>", {"class": "ui-icon ui-icon-folder-collapsed"});
    1271     newCell.linkIcon = linkIcon;
    1272     newCell.linkLabel = linkLabel;
    1273    
    1274     var uList = $("<ul>", {"style": "outline: 0 none; margin:0px; padding:0px;"});
    1275     var labelItem = $("<li>", {"style": "float:left; list-style:none outside none;"});
    1276     var iconItem = $("<li>", {"style": "float:left; list-style:none outside none;"});
    1277 
    1278     uList.append(iconItem);
    1279     uList.append(labelItem);
    1280     labelItem.append(linkLabel);
    1281     iconItem.append(linkIcon);
    1282    
    1283     var newLink = $("<a>", {"href": "javascript:;"});
    1284     newLink.click(function()
    1285     {
    1286         if(metaTable.css("display") == "none")
    1287         {
    1288             linkLabel.html(gs.text.de.hide_metadata);
    1289             linkIcon.attr("class", "ui-icon ui-icon-folder-open");
    1290             metaTable.css("display", "block");
    1291             metaTable.metaNameField.css("display", "inline");
    1292             metaTable.addRowButton.css("display", "inline");
    1293         }
    1294         else
    1295         {
    1296             linkLabel.html(gs.text.de.edit_metadata);
    1297             linkIcon.attr("class", "ui-icon ui-icon-folder-collapsed");
    1298             metaTable.css("display", "none");
    1299             metaTable.metaNameField.css("display", "none");
    1300             metaTable.addRowButton.css("display", "none");
    1301         }
    1302     });
    1303 
    1304     newLink.append(uList);
    1305     linkSpan.append(newLink);
    1306     newCell.append(linkSpan);
    1307     row.append(newCell);
    1308    
    1309     addFunctionalityToTable(metaTable);
    1310     metaTable.metaNameField.css("display", "none");
    1311     metaTable.addRowButton.css("display", "none");
    1312 }
    1313 
    1314 function setEditingFeaturesVisible(visible)
    1315 {
    1316     if(visible)
    1317     {
    1318         $("#editContentButton").html(gs.text.de.hide_editor);
    1319         $("#editContentButtonDiv").attr("class", "ui-state-default ui-corner-all");
    1320     }
    1321     else
    1322     {
    1323         $("#editContentButton").html(gs.text.de.edit_content);
    1324         $("#editContentButtonDiv").attr("class", "");
    1325     }
    1326    
    1327     var visibility = (visible ? "" : "none");
    1328     $("#metadataListLabel, #metadataSetList").css("display", visibility);
    1329    
    1330     $(".editMetadataButton").each(function()
    1331     {
    1332         $(this).css("display", visibility);
    1333         $(this.linkLabel).html(gs.text.de.edit_metadata);
    1334         $(this.linkIcon).attr("class", "ui-icon ui-icon-folder-collapsed");
    1335     });
    1336    
    1337     $("table").each(function()
    1338     {
    1339         if($(this).attr("id") && $(this).attr("id").search(/^meta/) != -1)
    1340         {
    1341             $(this).css("display", "none");
    1342             $(this.metaNameField).css("display", "none");
    1343             $(this.addRowButton).css("display", "none");
    1344         }
    1345     });
    1346 }
    1347 
    1348 /* override this function in other interface/site/collection if you want
    1349    a different set of metadata sets
    1350   Use in conjunction with the dynamic_metadata_set_list variable. */
    1351 function setStaticMetadataSets(list) {
    1352   addOptionToList(list, "All", gs.text.de.all_metadata);
    1353 }
    1354 
    1355 function readyPageForEditing()
    1356 {
    1357     CKEDITOR.on('instanceReady', function(evt) {
    1358     addCKEEditableState(evt,editableInitStates);
    1359     });
    1360 
    1361     if($("#metadataSetList").length)
    1362     {
    1363         var setList = $("#metadataSetList");
    1364         if(!setList.css("display") || setList.css("display") == "")
    1365         {
    1366             setEditingFeaturesVisible(false);
    1367         }
    1368         else
    1369         {
    1370             setEditingFeaturesVisible(true);
    1371         }
    1372         return;
    1373     }
    1374 
    1375     $("#editContentButton").html(gs.text.de.hide_editor);
    1376     //wait for 0.5 sec to let ckeditor up
    1377     //setTimeout(function(){ $(".sectionText").each(function(){addEditableState(this,editableInitStates);}); }, 500);   
    1378     var editBar = $("#editBarLeft");
    1379    
    1380     var visibleMetadataList = $("<select>", {"id": "metadataSetList", "class": "ui-state-default"});
    1381     setStaticMetadataSets(visibleMetadataList);
    1382 
    1383     var metadataListLabel = $("<span>", {"id": "metadataListLabel", "style": "margin-left:20px;"});
    1384     metadataListLabel.html(gs.text.de.visible_metadata);
    1385     editBar.append(metadataListLabel);
    1386     editBar.append(visibleMetadataList);
    1387     visibleMetadataList.change(onVisibleMetadataSetChange);
    1388     editBar.append("<br>");
    1389     for (var i=0; i< save_and_rebuild_buttons.length; i++) {
    1390       var button_type = save_and_rebuild_buttons[i];
    1391       if (button_type == "save") {
    1392         var saveButton = $("<button>", {"id": "saveButton", "class": "ui-state-default ui-corner-all"});
    1393         saveButton.click(save);
    1394         saveButton.html(gs.text.de.save);
    1395         editBar.append(saveButton);
    1396       } else if(button_type == "rebuild") {
    1397         var rebuildButton = $("<button>", {"id": "rebuildButton", "class": "ui-state-default ui-corner-all"});
    1398         rebuildButton.click(rebuildCurrentCollection);
    1399         rebuildButton.html(gs.text.de.rebuild);
    1400         editBar.append(rebuildButton);
    1401       } else if (button_type == "saveandrebuild") {
    1402         var saveAndRebuildButton = $("<button>", {"id": "saveAndRebuildButton", "class": "ui-state-default ui-corner-all"});
    1403         saveAndRebuildButton.click(saveAndRebuild);
    1404         saveAndRebuildButton.html(gs.text.de.saverebuild);
    1405         editBar.append(saveAndRebuildButton);
    1406 
    1407       }
    1408     }
    1409     var statusBarDiv = $("<div>");
    1410     editBar.append(statusBarDiv);
    1411     _statusBar = new StatusBar(statusBarDiv[0]);
    1412    
    1413     var titleDivs = $(".sectionTitle");
    1414     for(var i = 0; i < titleDivs.length; i++)
    1415     {
    1416         addEditMetadataLink(titleDivs[i]);
    1417     }
    1418    
    1419     _baseURL = gs.xsltParams.library_name;
    1420     onVisibleMetadataSetChange(); // make sure that the selected item in the list is active
    1421 }
    1422 
    1423 // override the one in documentmaker_scripts_util
    1424 // currently not used if other one is present. need to get the js include order right
    1425 function enableSaveButtons(enabled) {
    1426   if (enabled) {
    1427     $("#saveButton, #rebuildButton, #saveAndRebuildButton").removeAttr("disabled");
    1428   } else {
    1429     $("#saveButton, #rebuildButton, #saveAndRebuildButton").attr("disabled", "disabled");
    1430   }
    1431 }
    1432 
    1433 /* this is a cut down version of save() from documentmaker_scripts_util.js
    1434  going back to using save, will delete this once everything working*/
    1435 function saveMetadataChangesOld() {
    1436 
    1437   console.log("Saving metadata changes");
    1438  
    1439   // get collection name
    1440   var collection = gs.cgiParams.c;;
    1441 
    1442   // get document id
    1443   var docID = gs.cgiParams.d;
    1444 
    1445   var metadataChanges = new Array();
    1446   if (_deletedMetadata.length > 0) {
    1447 
    1448     for(var i = 0; i < _deletedMetadata.length; i++) {
    1449      
    1450       var currentRow = _deletedMetadata[i];
    1451      
    1452       //Get metadata name
    1453       var cells = currentRow.getElementsByTagName("TD");
    1454       var nameCell = cells[0];
    1455       var name = nameCell.innerHTML;
    1456       var valueCell = cells[1];
    1457       var value = valueCell.innerHTML;
    1458       metadataChanges.push({type:'delete', docID:docID, name:name, value:value});
    1459       removeFromParent(currentRow);
    1460     }
    1461   }
    1462 
    1463   /*var changes = null;
    1464     //var changes = de.Changes.getChangedEditableSections();
    1465   for(var i = 0; i < changes.length; i++) {
    1466    
    1467     var changedElem = changes[i];
    1468        
    1469     //Get metadata name
    1470     var row = changedElem.parentNode;
    1471     var cells = row.getElementsByTagName("TD");
    1472     var nameCell = cells[0];
    1473     var name = nameCell.innerHTML;
    1474     var value = changedElem.innerHTML;
    1475     value = value.replace(/&nbsp;/g, " ");
    1476    
    1477     var orig = changedElem.originalValue;
    1478     if (orig) {
    1479       orig = orig.replace(/&nbsp;/g, " ");
    1480     }
    1481     metadataChanges.push({collection:collection, docID:docID, name:name, value:value, orig:orig});
    1482     changedElem.originalValue = changedElem.innerHTML;
    1483    
    1484   }
    1485 */
    1486   if (metadataChanges.length ==0) {
    1487       console.log(gs.text.de.no_changes);
    1488     return;
    1489   }
    1490 
    1491   var processChangesLoop = function(index)
    1492     {
    1493       var change = metadataChanges[index];
    1494      
    1495       var callbackFunction;
    1496       if(index + 1 == metadataChanges.length)
    1497     {
    1498       callbackFunction = function(){console.log("Completed saving metadata changes. You must rebuild the collection for the changes to take effect.");};
    1499     }
    1500       else
    1501     {
    1502       callbackFunction = function(){processChangesLoop(index + 1)};
    1503     }
    1504       if (change.type == "delete") {
    1505     gs.functions.removeArchivesMetadata(collection, gs.xsltParams.site_name, change.docID, change.name, null, change.value, function(){callbackFunction();});
    1506       } else {
    1507     if(change.orig)
    1508       {
    1509         gs.functions.setArchivesMetadata(collection, gs.xsltParams.site_name, docID, change.name, null, change.value, change.orig, "override", function(){callbackFunction();});
    1510       }
    1511     else
    1512       {
    1513         gs.functions.setArchivesMetadata(collection, gs.xsltParams.site_name, docID, change.name, null, change.value, null, "accumulate", function(){callbackFunction();});
    1514       }
    1515       }
    1516     }
    1517   processChangesLoop(0);
    1518   /* need to clear the changes from the page */
    1519   while (_deletedMetadata.length>0) {
    1520     _deletedMetadata.pop();
    1521   }
    1522    
    1523 }
    1524 
    1525 
    1526 
    15271162
    15281163
  • main/trunk/greenstone3/web/interfaces/default/js/documentedit_scripts_util.js

    r31747 r31748  
     1/** Javascript file containing useful functions used by both documentedit_scripts.js and documentmaker_scripts.js */
     2
     3
    14//Some "constants" to match the server constants
    25var SUCCESS = 1;
     
    69var COMPLETED = 11;
    710var HALTED = 12;
     11
     12var _transactions = new Array();
     13var _collectionsToBuild = new Array();
     14var _allContents = new Array();
     15var _deletedSections = new Array();
     16var _deletedMetadata = new Array();
     17var _undoOperations = new Array();
     18var _baseURL;
     19var _statusBar;
     20var _metadataSetList = new Array();
    821
    922function encodeDelimiters(meta_value) {
  • main/trunk/greenstone3/web/interfaces/default/js/documentmaker_scripts.js

    r29861 r31748  
    1 var _transactions = new Array();
    2 var _collectionsToBuild = new Array();
    3 var _allContents = new Array();
     1/** Javascript file for the document maker, which is where you can split documents up etc. Not used at the moment until we work out exactly what it does. */
     2/** requires documentedit_scripts_util.js and documentmaker_scripts_util.js */
     3/** does it also need documentedit_scripts.js?? */
     4
     5
     6//var _transactions = new Array();
     7//var _collectionsToBuild = new Array();
     8//var _allContents = new Array();
    49var _idCounter = 0;
    510var _indexCounter = 0;
    6 var _deletedSections = new Array();
    7 var _deletedMetadata = new Array();
    8 var _undoOperations = new Array();
    9 var _baseURL;
    10 var _statusBar;
    11 var _metadataSetList = new Array();
     11//var _deletedSections = new Array();
     12//var _deletedMetadata = new Array();
     13//var _undoOperations = new Array();
     14//var _baseURL;
     15//var _statusBar;
     16//var _metadataSetList = new Array();
    1217
    1318function initDocumentMaker()
Note: See TracChangeset for help on using the changeset viewer.