source: main/trunk/greenstone3/web/interfaces/default/js/documentedit_scripts_maps.js@ 38766

Last change on this file since 38766 was 37780, checked in by kjdon, 12 months ago

moved the map stuff out of documentedit_scripts into documentedit_scripts_maps, so that it can be included only if editmapgps is enabled

File size: 3.8 KB
Line 
1/** Javascript file for editing map stuff in a documentediting situation */
2
3var gsmap_store = {};
4var gps_metadata_name = "GPS.mapOverlay";
5
6// Called by documentedit_scripts_util.js when saving and rebuilding.
7// This function should return all the doc sections' map overlay data so that
8// setArchivesMetadata can be called for each and the entire collection rebuilt with the changes
9function getDocMapsEditDataForSaving(collName) {
10 var map_editors_array = Object.values(gsmap_store);
11 var modifiedMaps = []; // the array that is the return value: an array of only all the modified maps
12
13
14 for(var i = 0; i < map_editors_array.length; i++) {
15 var map_editor = map_editors_array[i];
16 var oldMapData = map_editor.savedOverlays; // stringified JSON shape
17 var newMapData = JSON.stringify(ShapesUtil.overlayToJSON(map_editor.overlays)); // stringified JSON shape too
18
19 // We only consider a map editor's map data to have been modified in the following cases:
20 // - if oldMapData is null, new mapData should not be empty array
21 // - OR oldMapData had some value and it's not the same as newMapData
22 if(!oldMapData && newMapData !== "[]" || oldMapData && oldMapData !== newMapData) {
23 var nodeID = map_editors_array[i].id;
24 //console.log("old vs new mapdata for nodeID " + nodeID);
25 //console.log("OLD: " + oldMapData);
26 //console.log("NEW: " + newMapData);
27
28 modifiedMaps.push({
29 collection: collName,
30 docID: nodeID,
31 name:gps_metadata_name,
32 metapos: 0,
33 value:newMapData
34 });
35
36 //map_editor.savedOverlays = newMapData;
37 // Saving the new overlay values as the old ones, for the state after saving and rebuilding is done,
38 // now happens after all setArchivesMeta)_ calls have succeeded,
39 // which is just at the start of sendBuildRequest() in documentedit_scripts_util.js::saveAndRebuild()
40 }
41
42 }
43
44 return modifiedMaps;
45}
46
47
48function addEditMapGPSLink(cell) {
49 cell = $(cell);
50 var id = cell.attr("id").substring(6);
51 //console.log(id);
52 var mapGPScontainer = gs.jqGet("map-and-controls-" + id);
53 var row = cell.parent();
54 var newCell = $("<td>", {
55 "style": "font-size:0.7em; padding:0px 10px",
56 "class": "editMapGPSButton"
57 });
58 var linkSpan = $("<span>", {
59 "class": "ui-state-default ui-corner-all",
60 "style": "padding: 2px; float:left;"
61 });
62
63 var linkLabel = $("<span>" + gs.text.de.edit_map_gps + "</span>");
64 var linkIcon = $("<span>", {
65 "class": "ui-icon ui-icon-folder-collapsed"
66 });
67 newCell.linkIcon = linkIcon;
68 newCell.linkLabel = linkLabel;
69
70 var uList = $("<ul>", {
71 "style": "outline: 0 none; margin:0px; padding:0px;"
72 });
73 var labelItem = $("<li>", {
74 "style": "float:left; list-style:none outside none;"
75 });
76 var iconItem = $("<li>", {
77 "style": "float:left; list-style:none outside none;"
78 });
79
80 uList.append(iconItem);
81 uList.append(labelItem);
82 labelItem.append(linkLabel);
83 iconItem.append(linkIcon);
84
85 var mapEditor = new MapEditor(id);
86 gsmap_store["map-" + id] = mapEditor;
87
88 var newLink = $("<a>", {
89 "href": "javascript:;"
90 });
91 newLink.on("click", function () {
92 //console.log(" Show/Hide Map Editor ");
93 var clicked_mapEditor = gsmap_store["map-" + id];
94
95 if (clicked_mapEditor.map == null) {
96 clicked_mapEditor.initMapEditorControls();
97 clicked_mapEditor.initMapEditor();
98 }
99 if (mapGPScontainer.css("display") == "none") {
100 linkLabel.html(gs.text.de.hide_map_gps);
101 linkIcon.attr("class", "ui-icon ui-icon-folder-open");
102 mapGPScontainer.css("display", "block");
103 } else {
104 linkLabel.html(gs.text.de.edit_map_gps);
105 linkIcon.attr("class", "ui-icon ui-icon-folder-collapsed");
106 mapGPScontainer.css("display", "none");
107
108 }
109 });
110
111 newLink.append(uList);
112 linkSpan.append(newLink);
113 newCell.append(linkSpan);
114 row.append(newCell);
115
116 mapGPScontainer.css("display", "none");
117
118}
Note: See TracBrowser for help on using the repository browser.