root/main/trunk/greenstone2/macros/seaweed.dm @ 23749

Revision 23749, 6.1 KB (checked in by davidb, 9 years ago)

Additinal logic (first cut) added to figure out if a document needs to be exploded to be able to correctly save the metadata in the 'import' folder

Line 
1package Global
2
3_seaweedscript_ {
4
5
6<!--
7.editable-metadata \{ background-color: \#ffffd0 \}
8.editable-text     \{ background-color: \#e0ffe0 \}
9-->
10
11<style type="text/css">
12
13span.editable-metadata \{
14    position:relative; /*this is the key*/
15    z-index:24;
16\}
17
18div.editable-text \{
19    position:relative; /*this is the key*/
20    z-index:24;
21\}
22
23span.tooltip \{ display: none \}
24
25</style>
26
27
28<script type="text/javascript" src="_httpscript_/seaweed.js"></script>
29
30
31<script type="text/javascript">
32
33  var tooltipParentElem = null;
34
35  function showTooltip(elem)
36  \{
37
38      if (de.getEditedElements) \{
39
40          // guard against getEditedElements() not being defined
41      // this can happen if we get a onmouseover event
42      // before the document is fully loaded
43
44          var editedHashSet = de.getEditedElements();
45
46          if (editedHashSet.contains(elem)) \{
47          return;
48          \}
49      \}
50
51      elem.style.zIndex="25";
52
53      var metaname = elem.getAttribute("metaname");
54      var tooltip = document.createElement("span");
55      tooltip.setAttribute("class","tooltip");
56      tooltip.setAttribute("id","tooltip");
57
58      tooltip.style.position = "absolute";
59      tooltip.style.zIndex = "26";
60      tooltip.style.top = "0.9em";
61      tooltip.style.left = "1em";
62      tooltip.style.height = "1.1em";
63      tooltip.style.border = "1px solid #660";
64      tooltip.style.backgroundColor = "#ffffe0";
65      tooltip.style.color = "\#000";
66      //tooltip.style.textAlign = "center";
67      tooltip.style.padding = "0.2em";
68
69      tooltip.innerHTML = "<nobr>Click (and then type) to edit <i>" + metaname + "</i> metadata</nobr>";
70
71      tooltipParentElem = elem;
72      setTimeout("delayedShowTooltip()", 2000);
73      elem.appendChild(tooltip);
74     
75  \}
76
77  function delayedShowTooltip()
78  \{
79      if (tooltipParentElem!=null) \{
80
81          if (de.getEditedElements) \{
82              var editedHashSet = de.getEditedElements();
83
84              if (editedHashSet.contains(tooltipParentElem)) \{
85                  tooltipParentElem = null;
86             return;
87              \}
88      \}
89
90          var tooltip = document.getElementById("tooltip");
91          tooltip.style.display = "block";
92          setTimeout("delayedHideTooltip()", 5000);
93      \}
94  \}
95
96
97  function hideTooltip(elem)
98  \{
99      var tooltip = document.getElementById("tooltip");
100      if (tooltip != null) \{
101          elem.removeChild(tooltip)
102          tooltip.style.display = "none";
103      \}
104
105      tooltipParentElem = null;
106
107      elem.style.zIndex="24";
108  \}
109
110  function delayedHideTooltip(elem)
111  \{
112      if (tooltipParentElem!=null) \{
113          hideTooltip(tooltipParentElem);
114      \}
115  \}
116
117
118  window.onload=function()\{
119      try \{
120      de.init();
121      if (window.addEventListener) \{
122          window.addEventListener('beforeunload',saveMetadata,true);
123           \}
124       else \{
125          window.attachEvent('onbeforeunload',saveMetadata);
126       \}
127       de.doc.declarePropertySets(\{
128                metadata: \{
129                    phMarkup: '<span style="background-color:#DDDDDD;color:black"><em>[Enter a value]</em></span>',
130                    name: "metadata"
131                \}
132       \});
133       
134      \}
135      catch(err) \{
136        alert("SeaWeed failed to initialise: " + err.message);
137      \}
138  \}
139
140 
141 
142  function saveMetadataElement(editedElem)
143  \{
144       var docoid = editedElem.getAttribute("docoid");
145       
146       if (gsdefined(docoid)) \{
147           var metaname = editedElem.getAttribute("metaname");
148           var metapos  = editedElem.getAttribute("metapos");
149           var metavalue= editedElem.innerHTML;
150       
151           var metavalue = metavalue.replace(/&nbsp;/g, " ");
152           metavalue = escape(metavalue);
153
154           // alert("docoid = " + docoid + " metaname = " + metaname + " metapos = " + metapos + " metavalue = " + metavalue);
155
156       // console.log("docoid = " + docoid + " metaname = " + metaname + " metapos = " + metapos + " metavalue = " + metavalue);
157
158
159           gsapi.setDocumentMetadata(docoid,metaname,metapos,metavalue);
160
161       // figure out if needs to be exploded or if can be save with setImportMetadata
162       var needsExploding = 0;
163
164       var metanameParts = metaname.split(/\\./);
165       if (metanameParts.length==1) \{
166             needsExploding = 1;
167       \}
168       else if (metanameParts[0] == "ex") \{
169             needsExploding = 1;
170       \}
171
172       var docParts = docoid.split(/\\./);
173           if (docParts.length>=2) \{
174             needsExploding = 1;
175       \}
176
177           if (needsExploding) \{
178          if (confirm("Document needs to be exploded for this edit of " + metaname + " to be retained.\\nProceed?")) \{
179             gsapi.explodeDocument(docoid);
180          \}
181       \}
182       else \{
183            gsapi.setImportMetadata(docoid,metaname,metapos,metavalue);
184       \}
185
186         \}
187
188      return true;
189  \}
190
191  function saveMetadata()
192  \{
193      var editedArray = de.Changes.getChangedEditableSections();
194      // editedHashSet.iterate(function(item) \{ console.log(item.innerHTML); return true \} );
195
196      if (editedArray.length>0) \{
197          var commitChanges = confirm("Commit edited metadata?");
198      if (commitChanges) \{
199        for (i=0; i<editedArray.length; i++)
200          \{
201                saveMetadataElement(editedArray[i]);
202          \}
203
204      \}
205
206      // whether commited or not, now clear list of edited values
207          //clearEditedElements();
208      \}
209
210
211  \}
212
213
214   
215  function seaweedReindexCollection() \{
216    var arc = document.getElementById("seaweedRC");
217    arc.innerHTML = "Reindexing ...";
218    gsapi.reindexCollection("incremental",seaweedReindexCallback);
219  \}
220
221  function seaweedReindexCallback(xmlHttp) \{
222    var arc = document.getElementById("seaweedRC");
223    arc.innerHTML = "Reindexing done.";
224  \}           
225   
226
227</script>
228
229}
230
231_first-metadata-spanwrap_ {<span metapos="0" metaname="_1_" docoid="_2_" class="editable-metadata">}
232_/first-metadata-spanwrap_ {</span>}
233
234_first-metadata-divwrap_ {<div metapos="0" metaname="_1_" docoid="_2_" class="editable-metadata">}
235_/first-metadata-divwrap_ {</div>}
Note: See TracBrowser for help on using the browser.