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

Revision 24005, 7.0 KB (checked in by davidb, 9 years ago)

Further improvements.

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