source: DASISH/t5.6/client/branches/webannotator-basic/chrome/markingcollection/content/markingcollection/confirmAddTextDialog.js @ 5428

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

Added new branch for work on schema change related client fixes.

File size: 10.2 KB
Line 
1var wmConfirmAddTextDialog = {
2
3/////////////////////////////////////////////////////////////////////
4        get STRING()     { return document.getElementById("wmConfirmAddTextDialogString"); },
5        get DataSource() { return window.opener.top.bitsObjectMng.DataSource; },
6        get Common()     { return window.opener.top.bitsObjectMng.Common;     },
7        get XPath()      { return window.opener.top.bitsObjectMng.XPath;      },
8        get Database()   { return window.opener.top.bitsObjectMng.Database;   },
9        get gBrowser()   { return window.opener.top.bitsObjectMng.getBrowser();},
10
11        get URL()      { return document.getElementById("wmUrl"); },
12        get TITLE()    { return document.getElementById("wmTitle"); },
13        get NOTE()     { return document.getElementById("wmNote"); },
14        get LPAGE()    { return document.getElementById("wmLogicalPage"); },
15        get PPAGE()    { return document.getElementById("wmPhysicalPage"); },
16        get PTITLE()   { return document.getElementById("wmPageTitle"); },
17        get TITLE_HBOX(){ return document.getElementById("wmTitleHBox"); },
18
19        info    : null,
20        _xmldoc : null,
21
22        get xmldoc(){ return this._xmldoc; },
23
24/////////////////////////////////////////////////////////////////////
25        init : function(){
26                if(wmConfirmAddTextDialog._init) return;
27
28                try {
29                        this.info = window.arguments[0];
30                }catch(ex){
31                }
32
33                this.URL.value = this.info.con_url;
34                this.TITLE.value  = this.info.title;
35                this.PTITLE.value  = this.info.doc_title;
36
37                this.info.note = "";
38                if(this.info.property){
39                        this._createXMLDoc(this.info.property);
40                        if(this.xmldoc){
41                                var note_elem = this.xmldoc.getElementsByTagName("NOTE")[0];
42                                if(note_elem) this.info.note = note_elem.textContent.replace(/&/mg,"&amp;").replace(/</mg,"&lt;").replace(/>/mg,"&gt;").replace(/\"/mg,"&quot;");
43
44                                var lpage_elem = this.xmldoc.getElementsByTagName("LOGICAL_PAGE")[0];
45                                if(lpage_elem) this.info.logical_page = lpage_elem.textContent;
46
47                                var ppage_elem = this.xmldoc.getElementsByTagName("PHYSICAL_PAGE")[0];
48                                if(ppage_elem) this.info.physical_page = ppage_elem.textContent;
49                        }
50                }
51                if(this.info.note != undefined) this.NOTE.value = this.info.note;
52                if(this.info.logical_page != undefined)  this.LPAGE.value = this.info.logical_page;
53                if(this.info.physical_page != undefined) this.PPAGE.value = this.info.physical_page;
54
55                try{this.URL.editor.transactionManager.clear();}catch(ex2){}
56                try{this.TITLE.editor.transactionManager.clear();}catch(ex2){}
57                try{this.NOTE.editor.transactionManager.clear();}catch(ex2){}
58                try{this.LPAGE.editor.transactionManager.clear();}catch(ex2){}
59                try{this.PPAGE.editor.transactionManager.clear();}catch(ex2){}
60                try{this.PTITLE.editor.transactionManager.clear();}catch(ex2){}
61
62                try{
63                        this._init = true;
64                }catch(ex){
65                        this.Common.alert("wmConfirmAddTextDialog.init():"+ex);
66                }
67        },
68
69/////////////////////////////////////////////////////////////////////
70        done : function(event){
71                if(this._init){
72                        this._init = false;
73                }
74        },
75
76/////////////////////////////////////////////////////////////////////
77        _createXMLDoc : function(aContent){
78                var parser = new DOMParser();
79                this._xmldoc = parser.parseFromString(aContent, "text/xml");
80                parser = undefined;
81        },
82
83/////////////////////////////////////////////////////////////////////
84        _xmlSerializer : function(){
85                var s = new XMLSerializer();
86                var aContent = s.serializeToString(this.xmldoc);
87                s = undefined;
88                return aContent;
89        },
90
91/////////////////////////////////////////////////////////////////////
92        undoTitle : function(){
93                try{
94                        while(this.TITLE.editor.transactionManager.numberOfUndoItems>0){
95                                this.TITLE.editor.undo(1);
96                                var title = this.TITLE.value;
97                                title = title.replace(/\t/mg,"        ");
98                                title = this.Common.exceptCode(title);
99                                title = title.replace(/[\r\n]/g, " ").replace(/^\s*/g,"").replace(/\s*$/g,"");
100                                if(title != "") break;
101                        }
102                }catch(ex2){_dump(ex2);}
103                window.focus();
104                var self = this;
105                setTimeout(function(){self.TITLE.focus();},100);
106        },
107
108/////////////////////////////////////////////////////////////////////
109        inputTitle : function(aEvent){
110                var title = this.TITLE.value;
111                title = title.replace(/\t/g,"        ");
112                title = this.Common.exceptCode(title);
113                title = title.replace(/[\r\n]/g, " ").replace(/^\s*/g,"").replace(/\s*$/g,"");
114                if(title == ""){
115                        this.TITLE_HBOX.style.borderColor = 'red';
116                }else{
117                        this.TITLE_HBOX.style.borderColor = 'transparent';
118                }
119        },
120
121/////////////////////////////////////////////////////////////////////
122        changeTitle : function(aEvent){
123                var title = this.TITLE.value;
124                title = title.replace(/\t/g,"        ");
125                title = this.Common.exceptCode(title);
126                title = title.replace(/[\r\n]/g, " ").replace(/^\s*/g,"").replace(/\s*$/g,"");
127                if(title == ""){
128                        aEvent.preventDefault();
129                        aEvent.stopPropagation();
130                        if(Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULRuntime).OS != "Darwin"){
131                                this.Common.alert(this.STRING.getString("ERROR_NOT_ENTER_TITLE"));
132                                this.undoTitle();
133                        }
134                        var title = this.TITLE.value;
135                        title = title.replace(/\t/g,"        ");
136                        title = this.Common.exceptCode(title);
137                        title = title.replace(/[\r\n]/g, " ").replace(/^\s*/g,"").replace(/\s*$/g,"");
138                        if(title == ""){
139                                this.TITLE_HBOX.style.borderColor = 'red';
140                        }else{
141                                this.TITLE_HBOX.style.borderColor = 'transparent';
142                        }
143                }
144        },
145
146/////////////////////////////////////////////////////////////////////
147        accept : function(aEvent){
148                window.arguments[0].accept = 1;
149                var newVals = {
150                        title         : this.TITLE.value,
151                        note          : this.Common.escapeComment(this.NOTE.value),
152                        logical_page  : this.LPAGE.value,
153                        physical_page : this.PPAGE.value,
154                        doc_title     : this.PTITLE.value
155                };
156                newVals["title"] = newVals["title"].replace(/\t/g,"        ");
157                newVals["title"] = this.Common.exceptCode(newVals["title"]);
158                newVals["title"] = newVals["title"].replace(/\x0D\x0A|\x0D|\x0A/g, " ").replace(/^\s*/g,"").replace(/\s*$/g,"");
159                if(newVals["title"] == "") return false;
160
161                newVals["note"] = newVals["note"].replace(/\t/mg,"        ");
162                newVals["note"] = newVals["note"].replace(/\x0D\x0A|\x0D|\x0A/g," __BR__ ");
163                newVals["note"] = this.Common.exceptCode(newVals["note"]);
164                newVals["note"] = newVals["note"].replace(/[\r\n]/mg, " ").replace(/ __BR__ /mg,"\n");
165
166                newVals["logical_page"] = newVals["logical_page"].replace(/\t/mg,"        ");
167                newVals["logical_page"] = this.Common.exceptCode(newVals["logical_page"]);
168                newVals["logical_page"] = newVals["logical_page"].replace(/\x0D\x0A|\x0D|\x0A/g, " ").replace(/^\s*/g,"").replace(/\s*$/g,"");
169
170                newVals["physical_page"] = newVals["physical_page"].replace(/\t/mg,"        ");
171                newVals["physical_page"] = this.Common.exceptCode(newVals["physical_page"]);
172                newVals["physical_page"] = newVals["physical_page"].replace(/\x0D\x0A|\x0D|\x0A/g, " ").replace(/^\s*/g,"").replace(/\s*$/g,"");
173
174                newVals["doc_title"] = newVals["doc_title"].replace(/\t/mg,"        ");
175                newVals["doc_title"] = this.Common.exceptCode(newVals["doc_title"]);
176                newVals["doc_title"] = newVals["doc_title"].replace(/\x0D\x0A|\x0D|\x0A/g, " ").replace(/^\s*/g,"").replace(/\s*$/g,"");
177
178                var changed = false;
179                var props;
180                for(props in newVals){
181                        if(this.info[props] == newVals[props]) continue;
182                        this.info[props] = newVals[props];
183                        changed = true;
184                }
185
186                if(changed){
187                        if(this.info.title) this.info.title = this.info.title.replace(/[\r\n]/mg, " ");
188                        if(this.info.doc_title) this.info.doc_title = this.info.doc_title.replace(/[\r\n]/mg, " ");
189                        if(this.info.note || this.info.logical_page || this.info.physical_page){
190                                if(this.info.property == "") this.info.property = "<PROPERTY/>";
191                                this._createXMLDoc(this.info.property);
192                                if(this.xmldoc){
193                                        if(this.info.note != undefined){
194                                                var note = this.xmldoc.getElementsByTagName("NOTE")[0];
195                                                if(this.info.note != "" && !note){
196                                                        note = this.xmldoc.createElement("NOTE");
197                                                        this.xmldoc.documentElement.appendChild(note);
198                                                }else if(this.info.note == "" && note){
199                                                        note.parentNode.removeChild(note);
200                                                        note = undefined;
201                                                }
202                                                if(note){
203                                                        while(note.hasChildNodes()){ note.removeChild(note.lastChild); }
204                                                        note.appendChild(this.xmldoc.createTextNode(this.info.note));
205                                                }
206                                        }
207                                        if(this.info.logical_page != undefined){
208                                                var extras_msg = this.xmldoc.getElementsByTagName("EXTENDED_MESSAGE")[0];
209                                                if(!extras_msg){
210                                                        extras_msg = this.xmldoc.createElement("EXTENDED_MESSAGE");
211                                                        this.xmldoc.documentElement.appendChild(extras_msg);
212                                                }
213                                                var lpage_elem = this.xmldoc.getElementsByTagName("LOGICAL_PAGE")[0];
214                                                if(this.info.logical_page != "" && !lpage_elem){
215                                                        lpage_elem = this.xmldoc.createElement("LOGICAL_PAGE");
216                                                        extras_msg.appendChild(lpage_elem);
217                                                }else if(this.info.logical_page == "" && lpage_elem){
218                                                        lpage_elem.parentNode.removeChild(lpage_elem);
219                                                        lpage_elem = undefined;
220                                                }
221                                                if(lpage_elem){
222                                                        while(lpage_elem.hasChildNodes()){ lpage_elem.removeChild(lpage_elem.lastChild); }
223                                                        lpage_elem.appendChild(this.xmldoc.createTextNode(this.info.logical_page));
224                                                }
225                                        }
226
227                                        if(this.info.physical_page != undefined){
228                                                var extras_msg = this.xmldoc.getElementsByTagName("EXTENDED_MESSAGE")[0];
229                                                if(!extras_msg){
230                                                        extras_msg = this.xmldoc.createElement("EXTENDED_MESSAGE");
231                                                        this.xmldoc.documentElement.appendChild(extras_msg);
232                                                }
233                                                var ppage_elem = this.xmldoc.getElementsByTagName("PHYSICAL_PAGE")[0];
234                                                if(this.info.physical_page != "" && !ppage_elem){
235                                                        ppage_elem = this.xmldoc.createElement("PHYSICAL_PAGE");
236                                                        extras_msg.appendChild(ppage_elem);
237                                                }else if(this.info.physical_page == "" && ppage_elem){
238                                                        ppage_elem.parentNode.removeChild(ppage_elem);
239                                                        ppage_elem = undefined;
240                                                }
241                                                if(ppage_elem){
242                                                        while(ppage_elem.hasChildNodes()){ ppage_elem.removeChild(ppage_elem.lastChild); }
243                                                        ppage_elem.appendChild(this.xmldoc.createTextNode(this.info.physical_page));
244                                                }
245                                        }
246
247                                        this.info.property = this._xmlSerializer();
248                                }
249                        }
250                }
251                return true;
252        },
253
254/////////////////////////////////////////////////////////////////////
255        cancel : function(aEvent){
256                window.arguments[0].accept = 0;
257        },
258
259/////////////////////////////////////////////////////////////////////
260        _dump : function(aString){
261                if(nsPreferences.getBoolPref("wiredmarker.debug", false)) window.dump(aString+"\n");
262        },
263};
Note: See TracBrowser for help on using the repository browser.