source: main/trunk/greenstone3/web/interfaces/default/js/documentedit_scripts.js@ 32802

Last change on this file since 32802 was 32802, checked in by ak19, 5 years ago

Added the feature for PDF documents to load more than one map at the same time

File size: 14.3 KB
Line 
1/** Javascript file for editing a single document's content - metadata and text */
2/** uses other functions in documentedit_scripts_util.js */
3
4/* some vars for document editing */
5/* 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 */
6var dynamic_metadata_set_list = true;
7/* if false, will hide the metadata list selector. So the user will only get to see the default metadata set. */
8var display_metadata_set_selector = true;
9/* if true, will make the editing controls stay visible even on page scrolling */
10var keep_editing_controls_visible = true;
11/* Here you can choose which save buttons you like. Choose from 'save', 'rebuild', 'saveandrebuild' */
12var save_and_rebuild_buttons = ["saveandrebuild"];
13//var save_and_rebuild_buttons = ["save", "rebuild", "saveandrebuild"];
14
15/* What kind of metadata element selection do we provide?
16plain: just a text input box
17fixedlist: a drop down menu with a fixed list of options (provided by the availableMetadataElements list)
18autocomplete: 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
19 */
20var new_metadata_field_input_type = "plain";
21/* add all metadata button? only valid with fixedlist or autocomplete metadata element selection */
22var enable_add_all_metadata_button = true;
23
24/* Metadata elements to be used in the fixedlist/autocomplete options above */
25var availableMetadataElements = ["dc.Title", "dc.Subject"];
26/* metadata elements that have a list of values/suggestions */
27var autocompleteMetadata = new Array();
28/* 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.
29for example
30var autocompleteMetadata = ["dc.Subject"];
31var dcSubject_values = ["Kings", "Queens", "others"];
32 */
33
34/* The metadata specified in multiValuedMetadata array will be treated as a delimited list, using mvm_delimiter. On saving, the values will be separated and saved individually */
35
36var multiValuedMetadata = new Array(); // eg ["xx.Person", "xx.Location"];
37var mvm_delimiter = ";";
38var mapsIdsArray = []; //An array for the IDs of all the maps created
39
40/************************
41 * METADATA EDIT SCRIPTS *
42 ************************/
43
44function addEditMetadataLink(cell) {
45 cell = $(cell);
46 var id = cell.attr("id").substring(6);
47 var metaTable = gs.jqGet("meta" + id);
48 var row = cell.parent();
49 var newCell = $("<td>", {
50 "style": "font-size:0.7em; padding:0px 10px",
51 "class": "editMetadataButton"
52 });
53 var linkSpan = $("<span>", {
54 "class": "ui-state-default ui-corner-all",
55 "style": "padding: 2px; float:left;"
56 });
57
58 var linkLabel = $("<span>" + gs.text.de.edit_metadata + "</span>");
59 var linkIcon = $("<span>", {
60 "class": "ui-icon ui-icon-folder-collapsed"
61 });
62 newCell.linkIcon = linkIcon;
63 newCell.linkLabel = linkLabel;
64
65 var uList = $("<ul>", {
66 "style": "outline: 0 none; margin:0px; padding:0px;"
67 });
68 var labelItem = $("<li>", {
69 "style": "float:left; list-style:none outside none;"
70 });
71 var iconItem = $("<li>", {
72 "style": "float:left; list-style:none outside none;"
73 });
74
75 uList.append(iconItem);
76 uList.append(labelItem);
77 labelItem.append(linkLabel);
78 iconItem.append(linkIcon);
79
80 var newLink = $("<a>", {
81 "href": "javascript:;"
82 });
83 newLink.click(function () {
84 console.log(metaTable.metaNameField);
85 if (metaTable.css("display") == "none") {
86 linkLabel.html(gs.text.de.hide_metadata);
87 linkIcon.attr("class", "ui-icon ui-icon-folder-open");
88 metaTable.css("display", "block");
89 metaTable.metaNameField.css("display", "inline");
90 metaTable.addRowButton.css("display", "inline");
91 if (enable_add_all_metadata_button == true) {
92 metaTable.addAllButton.css("display", "inline");
93 }
94 } else {
95 linkLabel.html(gs.text.de.edit_metadata);
96 linkIcon.attr("class", "ui-icon ui-icon-folder-collapsed");
97 metaTable.css("display", "none");
98 metaTable.metaNameField.css("display", "none");
99 metaTable.addRowButton.css("display", "none");
100 if (enable_add_all_metadata_button == true) {
101 metaTable.addAllButton.css("display", "none");
102 }
103 }
104 });
105
106 newLink.append(uList);
107 linkSpan.append(newLink);
108 newCell.append(linkSpan);
109 row.append(newCell);
110
111 addFunctionalityToTable(metaTable);
112 metaTable.metaNameField.css("display", "none");
113 metaTable.addRowButton.css("display", "none");
114 if (enable_add_all_metadata_button == true) {
115 metaTable.addAllButton.css("display", "none");
116 }
117}
118
119var gsmap_store = {};
120
121function addEditMapGPSLink(cell) {
122 cell = $(cell);
123 var id = cell.attr("id").substring(6);
124 //console.log(id);
125 var mapGPScontainer = gs.jqGet("map-and-controls-" + id);
126 var row = cell.parent();
127 var newCell = $("<td>", {
128 "style": "font-size:0.7em; padding:0px 10px",
129 "class": "editMapGPSButton"
130 });
131 var linkSpan = $("<span>", {
132 "class": "ui-state-default ui-corner-all",
133 "style": "padding: 2px; float:left;"
134 });
135
136 var linkLabel = $("<span>" + gs.text.de.edit_map_gps + "</span>");
137 var linkIcon = $("<span>", {
138 "class": "ui-icon ui-icon-folder-collapsed"
139 });
140 newCell.linkIcon = linkIcon;
141 newCell.linkLabel = linkLabel;
142
143 var uList = $("<ul>", {
144 "style": "outline: 0 none; margin:0px; padding:0px;"
145 });
146 var labelItem = $("<li>", {
147 "style": "float:left; list-style:none outside none;"
148 });
149 var iconItem = $("<li>", {
150 "style": "float:left; list-style:none outside none;"
151 });
152
153 uList.append(iconItem);
154 uList.append(labelItem);
155 labelItem.append(linkLabel);
156 iconItem.append(linkIcon);
157
158 var mapEditor = new MapEditor(id);
159 gsmap_store["map-" + id] = mapEditor;
160
161 var newLink = $("<a>", {
162 "href": "javascript:;"
163 });
164 newLink.click(function () {
165 console.log("Show/Hide Map Editor");
166
167 // Only if this 'id' element hasn't been initialied, then do the following 2 lines
168 if (mapEditor.map !== null) {
169 console.log(mapEditor.map.mapId);
170 console.log(mapsIdsArray.includes(id));
171 }
172
173 var clicked_mapEditor = gsmap_store["map-" + id];
174
175 if (clicked_mapEditor.map == null) {
176 console.log("Initializing map for id: " + id);
177
178 clicked_mapEditor.initMapEditorControls();
179 clicked_mapEditor.initMapEditor();
180 //mapsIdsArray.push(clicked_mapEditor.map.mapId);
181 } /*
182 else if (mapsIdsArray.includes(id) == false) {
183 //mapEditor.initMapEditorControls();
184 //mapEditor.initMapEditor();
185 mapsIdsArray.push(mapEditor.map.mapId)
186 }
187*/
188 if (mapGPScontainer.css("display") == "none") {
189
190 linkLabel.html(gs.text.de.hide_map_gps);
191 linkIcon.attr("class", "ui-icon ui-icon-folder-open");
192 mapGPScontainer.css("display", "block");
193
194 } else {
195 linkLabel.html(gs.text.de.edit_map_gps);
196
197 linkIcon.attr("class", "ui-icon ui-icon-folder-collapsed");
198 mapGPScontainer.css("display", "none");
199
200 }
201 });
202
203 newLink.append(uList);
204 linkSpan.append(newLink);
205 newCell.append(linkSpan);
206 row.append(newCell);
207
208 mapGPScontainer.css("display", "none");
209
210 addFunctionalityToTable(mapGPScontainer);
211 mapGPScontainer.metaNameField.css("display", "none");
212 mapGPScontainer.addRowButton.css("display", "none");
213 if (enable_add_all_metadata_button == true) {
214 mapGPScontainer.addAllButton.css("display", "none");
215 }
216
217}
218
219function setEditingFeaturesVisible(visible) {
220 if (visible) {
221 $("#editContentButton").html(gs.text.de.hide_editor);
222 $("#editContentButtonDiv").attr("class", "ui-state-default ui-corner-all");
223 } else {
224 $("#editContentButton").html(gs.text.de.edit_content);
225 $("#editContentButtonDiv").attr("class", "");
226 }
227
228 var visibility = (visible ? "" : "none");
229 if (display_metadata_set_selector == true) {
230 $("#metadataListLabel, #metadataSetList").css("display", visibility);
231 }
232
233 $(".editMetadataButton").each(function () {
234 $(this).css("display", visibility);
235 $(this.linkLabel).html(gs.text.de.edit_metadata);
236 $(this.linkIcon).attr("class", "ui-icon ui-icon-folder-collapsed");
237 });
238 /*
239 $(".editMapGPS").each(function(){
240 $(this).css("display", visibility);
241 $(this.linkLabel).html(gs.text.de.edit_map_gps);
242 $(this.linkIcon).attr("class", "ui-icon ui-icon-folder-collapsed");
243 });
244 */
245
246 $("table").each(function () {
247 if ($(this).attr("id") && $(this).attr("id").search(/^meta/) != -1) {
248 $(this).css("display", "none");
249 $(this.metaNameField).css("display", "none");
250 $(this.addRowButton).css("display", "none");
251 if (enable_add_all_metadata_button == true) {
252 $(this.addAllButton).css("display", "none");
253 }
254 }
255 });
256}
257
258/* override this function in other interface/site/collection if you want
259a different set of metadata sets
260Use in conjunction with the dynamic_metadata_set_list variable. */
261function setStaticMetadataSets(list) {
262 addOptionToList(list, "All", gs.text.de.all_metadata);
263}
264
265function readyPageForEditing() {
266
267 // CKEDITOR.on('instanceReady', function(evt) {
268 // addCKEEditableState(evt,editableInitStates);
269 // });
270
271 if ($("#metadataSetList").length) {
272 var setList = $("#metadataSetList");
273 if (!setList.css("display") || setList.css("display") == "") {
274 setEditingFeaturesVisible(false);
275 } else {
276 setEditingFeaturesVisible(true);
277 }
278 return;
279 }
280
281 $("#editContentButton").html(gs.text.de.hide_editor);
282 //wait for 0.5 sec to let ckeditor up
283 setTimeout(function () {
284 $(".sectionText").each(function () {
285 addEditableState(this, editableInitStates);
286 });
287 }, 500);
288 var editBar = $("#editBarLeft");
289
290 var visibleMetadataList = $("<select>", {
291 "id": "metadataSetList",
292 "class": "ui-state-default"
293 });
294 setStaticMetadataSets(visibleMetadataList);
295
296 if (display_metadata_set_selector == true) {
297 var metadataListLabel = $("<span>", {
298 "id": "metadataListLabel",
299 "style": "margin-left:20px;"
300 });
301 metadataListLabel.html(gs.text.de.visible_metadata);
302 editBar.append(metadataListLabel);
303 } else {
304 visibleMetadataList.css("display", "none");
305 }
306 editBar.append(visibleMetadataList);
307 visibleMetadataList.change(onVisibleMetadataSetChange);
308 editBar.append("<br>");
309
310 for (var i = 0; i < save_and_rebuild_buttons.length; i++) {
311 var button_type = save_and_rebuild_buttons[i];
312 if (button_type == "save") {
313 var saveButton = $("<button>", {
314 "id": "saveButton",
315 "class": "ui-state-default ui-corner-all"
316 });
317 saveButton.click(save);
318 saveButton.html(gs.text.de.save);
319 editBar.append(saveButton);
320 } else if (button_type == "rebuild") {
321 var rebuildButton = $("<button>", {
322 "id": "rebuildButton",
323 "class": "ui-state-default ui-corner-all"
324 });
325 rebuildButton.click(rebuildCurrentCollection);
326 rebuildButton.html(gs.text.de.rebuild);
327 editBar.append(rebuildButton);
328 } else if (button_type == "saveandrebuild") {
329 var saveAndRebuildButton = $("<button>", {
330 "id": "saveAndRebuildButton",
331 "class": "ui-state-default ui-corner-all"
332 });
333 saveAndRebuildButton.click(saveAndRebuild);
334 saveAndRebuildButton.html(gs.text.de.saverebuild);
335 editBar.append(saveAndRebuildButton);
336
337 }
338 }
339 var statusBarDiv = $("<div>");
340 editBar.append(statusBarDiv);
341 _statusBar = new StatusBar(statusBarDiv[0]);
342
343 var titleDivs = $(".sectionTitle");
344 for (var i = 0; i < titleDivs.length; i++) {
345 addEditMetadataLink(titleDivs[i]);
346 addEditMapGPSLink(titleDivs[i]);
347 }
348
349 _baseURL = gs.xsltParams.library_name;
350 onVisibleMetadataSetChange(); // make sure that the selected item in the list is active
351}
352
353// override the one in documentmaker_scripts_util
354// currently not used if other one is present. need to get the js include order right
355function enableSaveButtons(enabled) {
356 if (enabled) {
357 $("#saveButton, #rebuildButton, #saveAndRebuildButton").removeAttr("disabled");
358 } else {
359 $("#saveButton, #rebuildButton, #saveAndRebuildButton").attr("disabled", "disabled");
360 }
361}
362
363/* this is a cut down version of save() from documentmaker_scripts_util.js
364going back to using save, will delete this once everything working*/
365function saveMetadataChangesOld() {
366
367 console.log("Saving metadata changes");
368
369 // get collection name
370 var collection = gs.cgiParams.c; ;
371
372 // get document id
373 var docID = gs.cgiParams.d;
374
375 var metadataChanges = new Array();
376 if (_deletedMetadata.length > 0) {
377
378 for (var i = 0; i < _deletedMetadata.length; i++) {
379
380 var currentRow = _deletedMetadata[i];
381
382 //Get metadata name
383 var cells = currentRow.getElementsByTagName("TD");
384 var nameCell = cells[0];
385 var name = nameCell.innerHTML;
386 var valueCell = cells[1];
387 var value = valueCell.innerHTML;
388 metadataChanges.push({
389 type: 'delete',
390 docID: docID,
391 name: name,
392 value: value
393 });
394 removeFromParent(currentRow);
395 }
396 }
397
398 /*var changes = null;
399 //var changes = de.Changes.getChangedEditableSections();
400 for(var i = 0; i < changes.length; i++) {
401
402 var changedElem = changes[i];
403
404 //Get metadata name
405 var row = changedElem.parentNode;
406 var cells = row.getElementsByTagName("TD");
407 var nameCell = cells[0];
408 var name = nameCell.innerHTML;
409 var value = changedElem.innerHTML;
410 value = value.replace(/&nbsp;/g, " ");
411
412 var orig = changedElem.originalValue;
413 if (orig) {
414 orig = orig.replace(/&nbsp;/g, " ");
415 }
416 metadataChanges.push({collection:collection, docID:docID, name:name, value:value, orig:orig});
417 changedElem.originalValue = changedElem.innerHTML;
418
419 }
420 */
421 if (metadataChanges.length == 0) {
422 console.log(gs.text.de.no_changes);
423 return;
424 }
425
426 var processChangesLoop = function (index) {
427 var change = metadataChanges[index];
428
429 var callbackFunction;
430 if (index + 1 == metadataChanges.length) {
431 callbackFunction = function () {
432 console.log("Completed saving metadata changes. You must rebuild the collection for the changes to take effect.");
433 };
434 } else {
435 callbackFunction = function () {
436 processChangesLoop(index + 1)
437 };
438 }
439 if (change.type == "delete") {
440 gs.functions.removeArchivesMetadata(collection, gs.xsltParams.site_name, change.docID, change.name, null, change.value, function () {
441 callbackFunction();
442 });
443 } else {
444 if (change.orig) {
445 gs.functions.setArchivesMetadata(collection, gs.xsltParams.site_name, docID, change.name, null, change.value, change.orig, "override", function () {
446 callbackFunction();
447 });
448 } else {
449 gs.functions.setArchivesMetadata(collection, gs.xsltParams.site_name, docID, change.name, null, change.value, null, "accumulate", function () {
450 callbackFunction();
451 });
452 }
453 }
454 }
455 processChangesLoop(0);
456 /* need to clear the changes from the page */
457 while (_deletedMetadata.length > 0) {
458 _deletedMetadata.pop();
459 }
460
461}
Note: See TracBrowser for help on using the repository browser.