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

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

Zeddy map work. 1. Now supports saving when map editor is selected and key s is pressed.. The saved shapes are now reloaded on page (re)load. 2. If you make a change and didn't save it and try to leave the page, there's now a default warning (can't yet control the warning message, but it's helpful enough at this stage). 3. Some more fixes. 4. Some cleaning up of unused code. 5. Still some debugging statements left in, check for console.log() for instance. 6. Gone back to using javascript instead of jQuery for keyboard shortcuts so it will work for PDF docs too, but kept some additional changes made earlier so that things still work on Firefox besides Chrome.

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