source: DASISH/t5.6/client/branches/webannotator-basic-current-xsd/chrome/markingcollection/content/markingcollection/treeproperty.js @ 5703

Last change on this file since 5703 was 5703, checked in by stephanie.roth@snd.gu.se, 10 years ago

Initial commit of current status quo from GitHub. TODO: Adjust client code to work with updated xsd file.

  • Property svn:executable set to *
File size: 17.2 KB
Line 
1/////////////////////////////////////////////////////////////////////
2/////////////////////////////////////////////////////////////////////
3var mcPropertyView = {
4        _dispID : "",
5        _dispObj : null,
6
7        get BUTTON()   { return document.getElementById("mcToolbarPropertyViewButton"); },
8        get VBOX()     { return document.getElementById("mcPropertyViewVBox"); },
9        get SPLITTER() { return document.getElementById("mcPropertyViewSplitter"); },
10        get TITLE()    { return document.getElementById("mcPropTitleTextbox"); },
11        get NOTE()     { return document.getElementById("mcPropNoteTextbox"); },
12        get SAMPLE()   { return document.getElementById("mcPropSampleLabel"); },
13        get MARKER_G() { return document.getElementById("mcPropMarkerGroup"); },
14        get MARKER_C() { return document.getElementById("mcPropMarkerCustomButton"); },
15        get BUTTON_U() { return document.getElementById("mcPropMarkerUpdateButton"); },
16
17        get EXTENDED_MESSAGE() { return document.getElementById("mcPropertyExtendedMessageVBox"); },
18        get LOGICAL_PAGE()     { return document.getElementById("mcPropExtendedMessageLogicalPageTextbox"); },
19        get PHYSICAL_PAGE()    { return document.getElementById("mcPropExtendedMessagePhysicalPageTextbox"); },
20
21        get MEDLINE_MESSAGE() { return document.getElementById("mcPropertyExtendedMessageMedlineVBox"); },
22        get MEDLINE_PMCID()   { return document.getElementById("mcPropertyExtendedMessageMedlinePMCIDTextbox"); },
23        get MEDLINE_PMID()    { return document.getElementById("mcPropertyExtendedMessageMedlinePMIDTextbox"); },
24        get MEDLINE_SO()      { return document.getElementById("mcPropertyExtendedMessageMedlineSOTextbox"); },
25
26        get URL_BOX()  { return document.getElementById("mcPropertyURLVBox"); },
27        get URL()      { return document.getElementById("mcPropURLTextbox"); },
28
29        get METACAPTURE_BOX() { return document.getElementById("mcPropertyMetaCaptureVBox"); },
30        get METACAPTURE() { return document.getElementById("mcPropertyMetaCaptureTextbox"); },
31
32        get DataSource() { return window.top.bitsObjectMng.DataSource; },
33        get Common()     { return window.top.bitsObjectMng.Common;     },
34        get Database()   { return window.top.bitsObjectMng.Database;   },
35        get XML()        { return window.top.bitsObjectMng.XML;   },
36        get gBrowser()   { return window.top.bitsObjectMng.getBrowser();},
37
38        get isChecked() {
39                var checked = this.BUTTON.getAttribute("checked");
40                if(!checked || checked == "false"){
41                        checked = false;
42                }else{
43                        checked = true;
44                }
45                return checked;
46        },
47
48        clear : function(){
49                this.TITLE.value = "";
50                this.NOTE.value = "";
51                this.URL.value = "";
52                this.BUTTON_U.setAttribute("disabled",true);
53                this._resource = null;;
54                this._title = "";
55                this._note = "";
56                this._property = "";
57                this._url = "";
58                this._index = "";
59                this._style = "";
60                this._editmode = "";
61                this._extended_message = null;
62                this._logical_page = "";
63                this._physical_page = "";
64        },
65
66        init : function(){
67                this._dispID = "";
68                this.clear();
69                var propertyview = nsPreferences.getBoolPref("wiredmarker.propertyview", false);
70                this.BUTTON.setAttribute("checked",propertyview);
71                this.VBOX.setAttribute("hidden",!propertyview);
72                if(this.SPLITTER) this.SPLITTER.setAttribute("hidden",!propertyview);
73                this.dispProperty();
74        },
75
76        done : function(){
77                this.VBOX.setAttribute("hidden",true);
78                if(this.SPLITTER) this.SPLITTER.setAttribute("hidden",true);
79                this.BUTTON.setAttribute("checked",false);
80                this.clear();
81        },
82
83        onClick : function(aEvent){
84                var checked = this.isChecked;
85                if(!checked){
86                        checked = true;
87                }else{
88                        checked = false;
89                }
90                this.BUTTON.setAttribute("checked",checked);
91                this.VBOX.setAttribute("hidden",!checked);
92                if(this.SPLITTER) this.SPLITTER.setAttribute("hidden",!checked);
93                nsPreferences.setBoolPref("wiredmarker.propertyview",checked);
94                aEvent.stopPropagation();
95        },
96
97        xmlEncode : function(aString){
98                return aString.replace(/&/mg,"&amp;").replace(/</mg,"&lt;").replace(/>/mg,"&gt;").replace(/\"/mg,"&quot;");
99        },
100
101        dispProperty : function(aDispItem){
102                var rtn = false;
103                var checked = this.isChecked;
104                this._dispObj = aDispItem;
105                if(aDispItem){
106                        this._resource = null;
107                        this._id = (aDispItem.fid!=undefined?aDispItem.fid:aDispItem.oid);
108                        this._pfid = aDispItem.pfid;
109                        this._dbtype = aDispItem.dbtype;
110                        this._editmode = (aDispItem.fid_mode!=undefined?aDispItem.fid_mode:aDispItem.oid_mode);
111                        this._style = null;
112                        var rValue = [aDispItem];
113                        if(rValue[0]){
114                                if(rValue[0].fid_style){
115                                        this._style = rValue[0].fid_style.replace(/([:;\(,])\s+/mg,"$1")
116                                }else if(rValue[0].pfid != undefined){
117                                        var folders = this.Database.getFolderFormID(rValue[0].pfid,this._dbtype);
118                                        if(folders) this._style = folders[0].fid_style.replace(/([:;\(,])\s+/mg,"$1")
119                                }
120                        }
121                        if(rValue){
122                                this._url = "";
123                                this._metacapture = "";
124                                if(aDispItem.fid!=undefined){
125                                        this._title = rValue[0].fid_title;
126                                        this._property = rValue[0].fid_property;
127                                        this._extended_message = null;
128                                }else{
129                                        this._title = rValue[0].oid_title;
130                                        this._url = rValue[0].con_url;
131                                        this._metacapture = rValue[0].doc_title;
132                                        this._property = rValue[0].oid_property;
133                                        this._extended_message = (rValue[0].oid_type == "application/pdf" ? true : null);
134                                }
135                                this._note = "";
136                                this._logical_page = "";
137                                this._physical_page = "";
138                                this._medline = {
139                                        PMCID : "",
140                                        PMID  : "",
141                                        SO    : ""
142                                };
143                                if(this._property != ""){
144                                        try{
145                                                var parser = new DOMParser();
146                                                var xmldoc = parser.parseFromString(this._property,"text/xml");
147                                                parser = undefined;
148                                                var xmlnode = xmldoc.getElementsByTagName("NOTE")[0];
149                                                if(xmlnode) this._note = xmlnode.textContent;
150                                                var xmlnode = xmldoc.getElementsByTagName("HYPER_ANCHOR")[0];
151                                                if(xmlnode) this._url = xmlnode.textContent;
152                                                var xmlnode = xmldoc.getElementsByTagName("LOGICAL_PAGE")[0];
153                                                if(xmlnode) this._logical_page = xmlnode.textContent;
154                                                var xmlnode = xmldoc.getElementsByTagName("PHYSICAL_PAGE")[0];
155                                                if(xmlnode) this._physical_page = xmlnode.textContent;
156                                                var xmlnode = xmldoc.getElementsByTagName("PMCID")[0];
157                                                if(xmlnode) this._medline.PMCID = xmlnode.textContent;
158                                                var xmlnode = xmldoc.getElementsByTagName("PMID")[0];
159                                                if(xmlnode) this._medline.PMID = xmlnode.textContent;
160                                                var xmlnode = xmldoc.getElementsByTagName("SO")[0];
161                                                if(xmlnode) this._medline.SO = xmlnode.textContent;
162                                                var xmlnode = xmldoc.getElementsByTagName("METACAPTURE")[0];
163                                                if(xmlnode) this._metacapture = xmlnode.getAttribute("content");
164                                        }catch(ex3){
165                                        }
166                                }
167                                if(this._url == "" && rValue[0].con_url && rValue[0].bgn_dom){
168                                        this._url = rValue[0].con_url;
169                                        if(rValue[0].bgn_dom) this._url += "#hyperanchor:"+this.xmlEncode(rValue[0].bgn_dom);
170                                        if(rValue[0].end_dom) this._url += "&"+this.xmlEncode(rValue[0].end_dom);
171                                        if(this._style) this._url += "&"+this.xmlEncode(this._style);
172                                }
173                        }else{
174                                this._title = "";
175                                this._note = "";
176                                this._url = "";
177                                this._metacapture = "";
178                        }
179                        this.TITLE.value = this._title;
180                        this.TITLE.defaultValue = this._title;
181                        this.NOTE.value = this._note;
182                        this.URL.value = this._url;
183                        this.METACAPTURE.value = this._metacapture;
184                        if(this._extended_message){
185                                this.EXTENDED_MESSAGE.removeAttribute("hidden");
186                                this.LOGICAL_PAGE.value = this._logical_page;
187                                this.PHYSICAL_PAGE.value = this._physical_page;
188                        }else{
189                                this.EXTENDED_MESSAGE.setAttribute("hidden","true");
190                        }
191                        if(this._medline.PMCID || this._medline.PMID || this._medline.SO){
192                                this.MEDLINE_MESSAGE.removeAttribute("hidden");
193                                this.MEDLINE_PMCID.value = this._medline.PMCID;
194                                this.MEDLINE_PMID.value = this._medline.PMID;
195                                this.MEDLINE_SO.value = this._medline.SO;
196                        }else{
197                                this.MEDLINE_MESSAGE.setAttribute("hidden","true");
198                        }
199                        if(this._url){
200                                this.URL_BOX.removeAttribute("hidden");
201                        }else{
202                                this.URL_BOX.setAttribute("hidden","true");
203                        }
204                        if(this._metacapture){
205                                this.METACAPTURE_BOX.removeAttribute("hidden");
206                        }else{
207                                this.METACAPTURE_BOX.setAttribute("hidden","true");
208                        }
209                        this.SAMPLE.setAttribute("style", this._style);
210                        if(this._editmode && (parseInt(this._editmode) & 0xFFFF)){
211                                if((parseInt(this._editmode) & 0x0001)){
212                                        this.MARKER_C.setAttribute("disabled",true);
213                                }else{
214                                        this.MARKER_C.removeAttribute("disabled");
215                                }
216                                if((parseInt(this._editmode) & 0x0002)){
217                                        this.MARKER_G.setAttribute("hidden",true);
218                                }else{
219                                        this.MARKER_G.removeAttribute("hidden");
220                                }
221                                if(parseInt(this._editmode) & 0x00F0){
222                                        this.TITLE.setAttribute("readonly",true);
223                                }else{
224                                        this.TITLE.removeAttribute("readonly");
225                                }
226                                if(parseInt(this._editmode) & 0x0F00){
227                                        this.NOTE.setAttribute("readonly",true);
228                                }else{
229                                        this.NOTE.removeAttribute("readonly");
230                                }
231                        }else{
232                                this.TITLE.removeAttribute("readonly");
233                                this.NOTE.removeAttribute("readonly");
234                                if(this._resource && !this.DataSource.isContainer(this._resource)){
235                                        this.MARKER_G.setAttribute("hidden",true);
236                                }else{
237                                        this.MARKER_C.removeAttribute("disabled");
238                                        this.MARKER_G.removeAttribute("hidden");
239                                }
240                        }
241                }else{
242                        this.clear();
243                        this.TITLE.setAttribute("readonly",true);
244                        this.NOTE.setAttribute("readonly",true);
245                        this.MARKER_C.setAttribute("disabled",true);
246                        this.EXTENDED_MESSAGE.hidden = true;
247                        this.MEDLINE_MESSAGE.hidden = true;
248                        this.METACAPTURE_BOX.hidden = true;
249                }
250                this.BUTTON_U.setAttribute("disabled",true);
251                this.MARKER_G.setAttribute("hidden",true);
252                if(this._dispID != this._id){
253                        try{this.TITLE.editor.transactionManager.clear();}catch(ex2){}
254                        try{this.NOTE.editor.transactionManager.clear();}catch(ex2){}
255                        this._dispID = this._id;
256                }
257                return rtn;
258        },
259
260        openDialog : function(){
261                var result = {
262                        accept : false,
263                        style  : this._style,
264                };
265                if(!this._index) this._index = -1;
266                window.openDialog('chrome://markingcollection/content/markerCustom.xul', '', 'modal,centerscreen,chrome',this._index,result);
267                if(result.accept){
268                        this._style = result.style;
269                        this.SAMPLE.setAttribute("style",this._style);
270                        this.DataSource.setProperty(this._resource,"style",this._style);
271                }
272        },
273
274        updateTitle : function(aValue){
275                this.BUTTON_U.removeAttribute("disabled");
276        },
277
278        updateNote : function(aValue){
279                this.BUTTON_U.removeAttribute("disabled");
280        },
281
282        undoTitle : function(){
283                try{
284                        while(this.TITLE.editor.transactionManager.numberOfUndoItems>0){
285                                this.TITLE.editor.undo(1);
286                                var title = this.TITLE.value;
287                                title = title.replace(/\t/mg,"        ");
288                                title = this.Common.exceptCode(title);
289                                title = title.replace(/[\r\n]/mg, " ").replace(/^\s*/img,"").replace(/\s*$/img,"");
290                                if(title != "") break;
291                        }
292                }catch(ex2){_dump(ex2);}
293                setTimeout(function(){mcPropertyView.TITLE.focus();},100);
294        },
295
296        update : function(aEvent,aElem){
297                var title = this.TITLE.value;
298                var note = this.NOTE.value;
299                note = note.replace(/\t/mg,"        ");
300                note = note.replace(/\x0D\x0A|\x0D|\x0A/g," __BR__ ");
301                note = this.Common.exceptCode(note);
302                note = note.replace(/ __BR__ /mg,"\n");
303                title = title.replace(/\t/mg,"        ");
304                title = this.Common.exceptCode(title);
305                var logical_page = null;
306                var physical_page = null;
307                if(this._extended_message){
308                        logical_page = this.LOGICAL_PAGE.value;
309                        logical_page = logical_page.replace(/\t/mg,"        ");
310                        logical_page = this.Common.exceptCode(logical_page);
311                        physical_page = this.PHYSICAL_PAGE.value;
312                        physical_page = physical_page.replace(/\t/mg,"        ");
313                        physical_page = this.Common.exceptCode(physical_page);
314                }
315                if(this._dispObj && this._title != title){
316                        var chkTitle = title.replace(/[\r\n]/g, " ").replace(/^\s*/g,"").replace(/\s*$/g,"");
317                        if(chkTitle == ""){
318                                this.Common.alert(mcMainService.STRING.getString("ERROR_NOT_ENTER_TITLE"));
319//                              this.undoTitle();
320                                this.TITLE.value = this.TITLE.defaultValue;
321                                aEvent.preventDefault();
322                                aEvent.stopPropagation();
323                                var self = this;
324                                setTimeout(function(){ self.TITLE.focus(); },0);
325                                return false;
326                        }
327                        if(this._dispObj.fid != undefined){
328                                var i;
329                                var listTitle = "";
330                                var listRes = this.Database.getFolderFormPID(this._dispObj.pfid,this._dispObj.dbtype);
331                                if(listRes){
332                                        for(i=0;i<listRes.length;i++){
333                                                if(listRes[i].fid == this._dispObj.fid) continue;
334                                                listTitle = listRes[i].fid_title;
335                                                listTitle = listTitle.replace(/^\s*/img,"").replace(/\s*$/img,"");
336                                                if(listTitle == chkTitle) break;
337                                        }
338                                        if(listTitle == chkTitle){
339                                                this.Common.alert(mcMainService.STRING.getString("ERROR_INVALID_TITLE") + "[ " + chkTitle + " ]");
340//                                              this.undoTitle();
341                                                this.TITLE.value = this.TITLE.defaultValue;
342                                                aEvent.preventDefault();
343                                                aEvent.stopPropagation();
344                                                var self = this;
345                                                setTimeout(function(){ self.TITLE.focus(); },0);
346                                                return false;
347                                        }
348                                }else{
349                                        return;
350                                }
351                        }
352                }
353                if(this._title != title || this._note != note || (this._extended_message && (this._logical_page != logical_page || this._physical_page != physical_page))){
354                        if(this._note != note || (this._extended_message && (this._logical_page != logical_page || this._physical_page != physical_page))){
355                                if(!this._property || this._property == "") this._property = "<PROPERTY/>";
356                                try{
357                                        var parser = new DOMParser();
358                                        var xmldoc = parser.parseFromString(this._property,"text/xml");
359                                        parser = undefined;
360                                        if(this._note != note){
361                                                var xmlnode = xmldoc.getElementsByTagName("NOTE")[0];
362                                                if(!xmlnode){
363                                                        xmlnode = xmldoc.createElement("NOTE");
364                                                        xmldoc.documentElement.appendChild(xmlnode);
365                                                }
366                                                while(xmlnode.hasChildNodes()) xmlnode.removeChild(xmlnode.lastChild);
367                                                var elemS = xmldoc.createTextNode(note);
368                                                if(elemS) xmlnode.appendChild(elemS);
369                                        }
370                                        if(this._extended_message && (this._logical_page != logical_page || this._physical_page != physical_page)){
371                                                var extras_msg = xmldoc.getElementsByTagName("EXTENDED_MESSAGE")[0];
372                                                if(!extras_msg){
373                                                        extras_msg = xmldoc.createElement("EXTENDED_MESSAGE");
374                                                        xmldoc.documentElement.appendChild(extras_msg);
375                                                }
376                                                var xmlnode = xmldoc.getElementsByTagName("LOGICAL_PAGE")[0];
377                                                if(!xmlnode){
378                                                        xmlnode = xmldoc.createElement("LOGICAL_PAGE");
379                                                        extras_msg.appendChild(xmlnode);
380                                                }
381                                                if(xmlnode){
382                                                        while(xmlnode.hasChildNodes()){ xmlnode.removeChild(xmlnode.lastChild); }
383                                                        if(logical_page) xmlnode.appendChild(xmldoc.createTextNode(logical_page));
384                                                }
385                                                var xmlnode = xmldoc.getElementsByTagName("PHYSICAL_PAGE")[0];
386                                                if(!xmlnode){
387                                                        xmlnode = xmldoc.createElement("PHYSICAL_PAGE");
388                                                        extras_msg.appendChild(xmlnode);
389                                                }
390                                                if(xmlnode){
391                                                        while(xmlnode.hasChildNodes()){ xmlnode.removeChild(xmlnode.lastChild); }
392                                                        if(physical_page) xmlnode.appendChild(xmldoc.createTextNode(physical_page));
393                                                }
394                                        }
395                                        var s = new XMLSerializer();
396                                        this._property = s.serializeToString(xmldoc);
397                                        s = undefined;
398                                }catch(ex3){
399                                }
400                                try{
401                                        var parser = new DOMParser();
402                                        var xmldoc = parser.parseFromString(this._property,"text/xml");
403                                        if(xmldoc && xmldoc.documentElement.nodeName == "parsererror") xmldoc = undefined;
404                                        if(!xmldoc){
405                                                this.Common.alert("Read Error!!");
406                                                return false;
407                                        }
408                                }catch(ex3){
409                                        alert(ex3);
410                                }
411                        }
412                        var rtn = false;
413                        if(this._dispObj.fid != undefined){
414                                rtn = this.Database.updateFolder({fid:this._id, fid_title:title, fid_property:this._property},this._dbtype);
415                                if(rtn){
416                                        this._dispObj.fid_title = title;
417                                        this._dispObj.fid_property = this._property;
418                                }
419                        }else{
420                                rtn = this.Database.updateObject({oid:this._id, oid_title:title, oid_property:this._property},this._dbtype);
421                                if(rtn){
422                                        this._dispObj.oid_title = title;
423                                        this._dispObj.oid_property = this._property;
424                                }
425                        }
426                        if(rtn){
427                                var About = this.DataSource.getID2About(this._id,this._pfid,this._dbtype);
428                                if(About && this._title != title){
429                                        var res = this.Common.RDF.GetResource(About);
430                                        if(this.DataSource.isContainer(res)){
431                                                this.DataSource.setProperty(res,"title",title);
432                                        }else{
433                                                var contResList = this.DataSource.flattenResources(this.Common.RDF.GetResource(this.DataSource.ABOUT_ROOT), 2, true);
434                                                var i;
435                                                for(i=0;i<contResList.length;i++){
436                                                        var id = this.DataSource.getProperty(contResList[i],"id");
437                                                        var dbtype = this.DataSource.getProperty(contResList[i],"dbtype");
438                                                        if(this._id != id || this._dbtype != dbtype) continue;
439                                                        this.DataSource.setProperty(contResList[i],"title",title);
440                                                }
441                                        }
442                                        this.DataSource.flush();
443                                }
444                                if(mcItemView.isChecked) mcItemView.refresh();
445                        }
446                        this._title = title;
447                        this._note = note;
448                        if(this._extended_message){
449                                this._logical_page = logical_page;
450                                this._physical_page = physical_page;
451                        }
452                }
453                if(this.NOTE.value != note) this.NOTE.value = note;
454                if(this.TITLE.value != title) this.TITLE.value = title;
455                if(this._extended_message){
456                        if(this.LOGICAL_PAGE.value != logical_page) this.LOGICAL_PAGE.value = logical_page;
457                        if(this.PHYSICAL_PAGE.value != physical_page) this.PHYSICAL_PAGE.value = physical_page;
458                }
459                return true;
460        },
461
462};
463function _dump2(aString){
464        if(!nsPreferences.getBoolPref("wiredmarker.debug", false)) return;
465        var dumpString = new String(aString);
466        var aConsoleService = Components.classes["@mozilla.org/consoleservice;1"]
467                              .getService(Components.interfaces.nsIConsoleService);
468        aConsoleService.logStringMessage(dumpString);
469        window.dump(aString+"\n");
470}
Note: See TracBrowser for help on using the repository browser.