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

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

Edit Map GPS and Hide Map GPS buttons

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