source: DASISH/t5.6/client/chrome/markingcollection/content/markingcollection/property.js @ 2709

Last change on this file since 2709 was 2709, checked in by sroth, 11 years ago

Wired-Marker initial source code with minor adjustments.

  • Property svn:executable set to *
File size: 31.0 KB
Line 
1var mcPropService = {
2
3        get STRING()     { return document.getElementById("mcPropString"); },
4        get ICON()       { return document.getElementById("mcPropIcon"); },
5        get TITLE()      { return document.getElementById("mcPropTitle"); },
6        get NOTE()       { return document.getElementById("mcPropNote"); },
7        get TAG()        { return document.getElementById("mcPropTagTextbox"); },
8        get DB_PATH()    { return document.getElementById("mcPropDBPath"); },
9        get DB_DATE()    { return document.getElementById("mcPropDBDate"); },
10        get DB_SIZE()    { return document.getElementById("mcPropDBSize"); },
11        get ICON_SIZE()  { return document.getElementById("mcPropIconsize"); },
12        get ICON_SIZE_S(){ return document.getElementById("mcPropIconsizeSmall"); },
13        get ICON_SIZE_L(){ return document.getElementById("mcPropIconsizeLarge"); },
14        get ICON_SIZE_I(){ return document.getElementById("mcPropIconsizeImage"); },
15
16        get TITLE_HBOX() { return document.getElementById("mcPropTitleHBox"); },
17
18        get TABBOX()     { return document.getElementById("mcPropTabbox"); },
19
20        get GENERAL_TAB() { return document.getElementById("mcPropGeneralTab"); },
21        get NOTE_TAB()    { return document.getElementById("mcPropNoteTab"); },
22
23        get EXTENDED_MESSAGE_TAB() { return document.getElementById("mcPropExtendedMessageTab"); },
24        get LOGICAL_PAGE()         { return document.getElementById("mcPropExtendedMessageLogicalPageTextbox"); },
25        get PHYSICAL_PAGE()        { return document.getElementById("mcPropExtendedMessagePhysicalPageTextbox"); },
26
27        get URL_TAB()    { return document.getElementById("mcPropURLTab"); },
28        get URL_PANEL()  { return document.getElementById("mcPropURLTabpanel"); },
29        get URL()        { return document.getElementById("mcPropURLTextbox"); },
30
31        get METACAPTURE_TAB()   { return document.getElementById("mcPropMetaCaptureTab"); },
32        get METACAPTURE_PANEL() { return document.getElementById("mcPropMetaCaptureTabpanel"); },
33        get METACAPTURE()       { return document.getElementById("mcPropMetaCaptureTextbox"); },
34
35        get MEDLINE_TAB()   { return document.getElementById("mcPropMedlineTab"); },
36        get MEDLINE_PMCID() { return document.getElementById("mcPropMedlinePMCIDTextbox"); },
37        get MEDLINE_PMID()  { return document.getElementById("mcPropMedlinePMIDTextbox"); },
38        get MEDLINE_SO()    { return document.getElementById("mcPropMedlineSOTextbox"); },
39
40        get SC_DISABLED(){ return document.getElementById("mcPropShortcutDisabled"); },
41        get SC_SHIFT()   { return document.getElementById("mcPropShortcutShift"); },
42        get SC_ALT()     { return document.getElementById("mcPropShortcutAlt"); },
43        get SC_ACCEL()   { return document.getElementById("mcPropShortcutAccel"); },
44        get SC_KEY()     { return document.getElementById("mcPropShortcutKey"); },
45        get SC_MOD()     { return document.getElementById("mcPropShortcutModifiers"); },
46
47        get DataSource() { return window.opener.top.bitsObjectMng.DataSource; },
48        get Common()     { return window.opener.top.bitsObjectMng.Common;     },
49        get XPath()      { return window.opener.top.bitsObjectMng.XPath;      },
50        get Database()   { return window.opener.top.bitsObjectMng.Database;   },
51        get XML()        { return window.opener.top.bitsObjectMng.XML;        },
52        get gBrowser()   { return window.opener.top.bitsObjectMng.getBrowser();},
53        get mcItemView() { return window.opener.mcItemView;},
54
55        id       : null,
56        item     : null,
57        resource : null,
58        property : "",
59        _xmldoc : null,
60
61        get xmldoc(){ return this._xmldoc; },
62
63        init : function(){
64                try {
65                        if(window.arguments[1] && window.arguments[1].id){
66                                this.id = window.arguments[1].id;
67                        }else{
68                                this.id = window.arguments[0];
69                        }
70                }catch(ex){
71                        document.location.href.match(/\?id\=(.*)$/);
72                        this.id = RegExp.$1;
73                }
74                if(!this.id) return;
75                this.item = this.Common.newItem();
76                this.resource = this.Common.RDF.GetResource(this.DataSource.ABOUT_ITEM + this.id);
77                var prop;
78                var value;
79                for(prop in this.item){
80                        value = undefined;
81                        if(window.arguments[1] && window.arguments[1][prop]){
82                                value = window.arguments[1][prop];
83                        }else{
84                                value = this.DataSource.getProperty(this.resource, prop);
85                        }
86                        if(value == undefined) continue;
87                        this.item[prop] = value;
88                }
89                if(this.item["editmode"] == undefined) this.item["editmode"] = this.DataSource.getProperty(this.resource, "editmode");
90                this.TITLE.value = this.item.title;
91                this.TITLE.defaultValue = this.item.title;
92                try{this.TITLE.editor.transactionManager.clear();}catch(ex2){}
93                this._extended_message = null;
94                if(this.item.dbtype){
95                        this.dbtype = this.item.dbtype;
96                }else{
97                        this.dbtype = this.DataSource.getProperty(this.resource, "dbtype");
98                }
99                this.GENERAL_TAB.setAttribute("hidden","true");
100                this.NOTE_TAB.setAttribute("hidden","true");
101                this.URL_TAB.setAttribute("hidden","true");
102                this.METACAPTURE_TAB.setAttribute("hidden","true");
103                this.MEDLINE_TAB.setAttribute("hidden","true");
104                this.EXTENDED_MESSAGE_TAB.setAttribute("hidden","true");
105                if(this.item.property){
106                        this.property = this.item.property;
107                }else{
108                        this.property = "";
109                        if(this.DataSource.isContainer(this.resource)){
110                                var rValue = this.Database.getFolderFormID(this.item.id,this.dbtype);
111                                if(rValue) this.property = rValue[0].fid_property;
112                        }else{
113                                var rValue = this.Database.getObjectFormID(this.item.id,this.dbtype);
114                                if(rValue){
115                                        this.property = rValue[0].oid_property;
116                                        this.URL.value = rValue[0].con_url;
117                                        this.METACAPTURE.value = rValue[0].doc_title;
118                                        this._extended_message = (rValue[0].oid_type == "application/pdf" ? true : null);
119                                        this.URL_TAB.removeAttribute("hidden");
120                                        this.METACAPTURE_TAB.removeAttribute("hidden");
121                                }
122                        }
123                }
124                var parser = new DOMParser();
125                var xmldoc;
126                if(this.property != "") xmldoc = parser.parseFromString(this.property, "text/xml");
127                parser = undefined;
128                var note_elem;
129                var iconsize_elem;
130                var propertyOverlay_elem;
131                var tag_elem;
132                var url_elem;
133                var metacapture_elem;
134                var logical_elem;
135                var physical_elem;
136                var medline_pmcid_elem;
137                var medline_pmid_elem;
138                var medline_so_elem;
139                if(xmldoc){
140                        note_elem = xmldoc.getElementsByTagName("NOTE")[0];
141                        iconsize_elem = xmldoc.getElementsByTagName("ICON_SIZE")[0];
142                        propertyOverlay_elem = xmldoc.getElementsByTagName("PROPERTYOVERLAY")[0];
143                        tag_elem = xmldoc.getElementsByTagName("TAG")[0];
144                        url_elem = xmldoc.getElementsByTagName("HYPER_ANCHOR")[0];
145                        logical_elem = xmldoc.getElementsByTagName("LOGICAL_PAGE")[0];
146                        physical_elem = xmldoc.getElementsByTagName("PHYSICAL_PAGE")[0];
147                        metacapture_elem = xmldoc.getElementsByTagName("METACAPTURE")[0];
148
149                        medline_pmcid_elem = xmldoc.getElementsByTagName("PMCID")[0];
150                        medline_pmid_elem = xmldoc.getElementsByTagName("PMID")[0];
151                        medline_so_elem = xmldoc.getElementsByTagName("SO")[0];
152                }
153                if(url_elem){
154                        this.URL.value = url_elem.textContent;
155                }
156                if(metacapture_elem){
157                        this.METACAPTURE.value = metacapture_elem.getAttribute("content");
158                }
159                if(this._extended_message){
160                        this.EXTENDED_MESSAGE_TAB.removeAttribute("hidden");
161                        if(logical_elem){
162                                this.LOGICAL_PAGE.value = logical_elem.textContent;
163                                this.item.logical = logical_elem.textContent;
164                        }
165                        if(physical_elem){
166                                this.PHYSICAL_PAGE.value = physical_elem.textContent;
167                                this.item.physical = physical_elem.textContent;
168                        }
169                }
170                if(medline_pmcid_elem || medline_pmid_elem || medline_so_elem){
171                        this.MEDLINE_TAB.removeAttribute("hidden");
172                        this.MEDLINE_PMCID.value = medline_pmcid_elem.textContent;
173                        this.MEDLINE_PMID.value = medline_pmid_elem.textContent;
174                        this.MEDLINE_SO.value = medline_so_elem.textContent;
175                }
176                this.item.note = "";
177                if(note_elem){
178                        this.item.note = note_elem.textContent;
179                }else if(this.property != ""){
180                        this.property = this.property.replace(/[\r\n\t]/mg," __BR__ ");
181                        if(this.property.match(/^.*<NOTE>(.*?)<\/NOTE>.*$/m)){
182                                this.item.note = RegExp.$1;
183                        }else if(this.property.match(/^<PROPERTY>.*<\/PROPERTY>.*$/m)){
184                                this.item.note = "";
185                        }else{
186                                this.item.note = this.property;
187                        }
188                        this.item.note = this.item.note.replace(/&/mg,"&amp;").replace(/</mg,"&lt;").replace(/>/mg,"&gt;").replace(/\"/mg,"&quot;");
189                        this.property = this.property.replace(/ __BR__ /mg,"\n");
190                        this.item.note = this.item.note.replace(/ __BR__ /mg,"\n");
191                }
192                this.item.iconsize = "small";
193                if(iconsize_elem){
194                        this.item.iconsize = iconsize_elem.textContent;
195                }else if(this.property != ""){
196                        var property = this.property.replace(/[\r\n\t]/mg," __BR__ ");
197                        if(property.match(/^.*<ICON_SIZE>(.*?)<\/ICON_SIZE>.*$/m)){
198                                this.item.iconsize = RegExp.$1;
199                        }
200                        this.item.iconsize = this.item.iconsize.replace(/ __BR__ /mg,"\n");
201                }
202                var info = Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULAppInfo);
203                if(parseInt(info.version)>2 && this.mcItemView.isChecked){
204                        if(this.item.iconsize == "small"){
205                                this.ICON_SIZE_S.setAttribute("selected",true);
206                                this.ICON_SIZE_L.removeAttribute("selected");
207                        }else{
208                                this.ICON_SIZE_L.setAttribute("selected",true);
209                                this.ICON_SIZE_S.removeAttribute("selected");
210                        }
211                        this.ICON_SIZE_I.setAttribute("iconsize",this.item.iconsize);
212                }else{
213                        this.ICON_SIZE_L.setAttribute("disabled","true");
214                        this.ICON_SIZE_S.setAttribute("disabled","true");
215                }
216                this.NOTE.value = this.item.note;
217                try{this.NOTE.editor.transactionManager.clear();}catch(ex2){}
218                if(tag_elem) this.item.tag = tag_elem.textContent;
219                if(this.item.tag != undefined) this.TAG.value = this.item.tag;
220                try{this.TAG.editor.transactionManager.clear();}catch(ex2){}
221                document.getElementById("mcPropSample").setAttribute("style",this.item.style);
222                if(this.item.editmode && (parseInt(this.item.editmode) & 0xFFFF)){
223                        if((parseInt(this.item.editmode) & 0x0001)){
224                                document.getElementById("mcPropMarkerCustomButton").setAttribute("disabled",true);
225                        }
226                        if((parseInt(this.item.editmode) & 0x0002)){
227                                document.getElementById("mcPropMarkerGroup").setAttribute("hidden",true);
228                                document.getElementById("mcPropTagGroup").setAttribute("hidden",true);
229                                document.getElementById("mcPropShortcutGroup").setAttribute("hidden",true);
230                        }
231                        if((parseInt(this.item.editmode) & 0x0004)){
232                                document.getElementById("mcPropTagGroup").setAttribute("hidden",true);
233                                document.getElementById("mcPropShortcutGroup").setAttribute("hidden",true);
234                        }
235                        if(!(parseInt(this.item.editmode) & 0x00F0)){
236                                this.TITLE.removeAttribute("readonly");
237                                this.TITLE.removeAttribute("style");
238                                this.TAG.removeAttribute("readonly");
239                                this.TAG.removeAttribute("style");
240                        }
241                        if(!(parseInt(this.item.editmode) & 0x0F00)){
242                                this.NOTE.removeAttribute("readonly");
243                                this.NOTE.removeAttribute("style");
244                        }
245                }else if(!this.DataSource.isContainer(this.resource)){
246                        document.getElementById("mcPropMarkerGroup").setAttribute("hidden",true);
247                        document.getElementById("mcPropTagGroup").setAttribute("hidden",true);
248                        document.getElementById("mcPropShortcutGroup").setAttribute("hidden",true);
249                        document.getElementById("mcPropIconsizeGroup").setAttribute("hidden",true);
250                        this.TITLE.removeAttribute("readonly");
251                        this.TITLE.removeAttribute("style");
252                        this.TAG.removeAttribute("readonly");
253                        this.TAG.removeAttribute("style");
254                        this.NOTE.removeAttribute("readonly");
255                        this.NOTE.removeAttribute("style");
256                }else{
257                        this.TITLE.removeAttribute("readonly");
258                        this.TITLE.removeAttribute("style");
259                        this.TAG.removeAttribute("readonly");
260                        this.TAG.removeAttribute("style");
261                        this.NOTE.removeAttribute("readonly");
262                        this.NOTE.removeAttribute("style");
263                }
264                document.getElementById("mcPropDatabaseGroup").setAttribute("hidden",true);
265                if(parseInt(this.item.editmode) & 0x1000){
266                        var aDBFile = this.Database.getDatabaseFile(this.dbtype);
267                        if(aDBFile){
268                                var aFile = this.Common.convertPathToFile(aDBFile.path);
269                                this.DB_PATH.value = aFile.path;
270                                this.DB_DATE.value = (new Date(aFile.lastModifiedTime)).toLocaleString();
271                                this.DB_SIZE.value = this.formatFileSize(aFile.fileSize);
272                                document.getElementById("mcPropDatabaseGroup").removeAttribute("hidden");
273                        }
274                }
275                if(!document.getElementById("mcPropShortcutGroup").hasAttribute("hidden")){
276                        var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
277                        this._opener = wm.getMostRecentWindow("navigator:browser");
278                        var osString = Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULRuntime).OS;
279                        if(osString == "Darwin"){
280                                this.SC_ALT.setAttribute('label','Option');
281                                this.SC_ACCEL.setAttribute('label','Command');
282                        }
283                        if(!this.id || !this.dbtype || !this._opener){
284                                this.SC_DISABLED.setAttribute("disabled","true");
285                                this.SC_SHIFT.setAttribute("disabled","true");
286                                this.SC_ALT.setAttribute("disabled","true");
287                                this.SC_ACCEL.setAttribute("disabled","true");
288                                this.SC_KEY.setAttribute("disabled","true");
289                        }else{
290                                var bitsShortcutService = this._opener.top.bitsShortcutService;
291                                if(bitsShortcutService){
292                                        var sc = bitsShortcutService.getShortcut(this.id,this.dbtype);
293                                        if(!sc || sc.disabled){
294                                                this.SC_DISABLED.checked = false;
295                                        }else{
296                                                this.SC_DISABLED.checked = true;
297                                        }
298                                        if(!this.SC_DISABLED.checked){
299                                                this.SC_SHIFT.setAttribute("disabled","true");
300                                                this.SC_ALT.setAttribute("disabled","true");
301                                                this.SC_ACCEL.setAttribute("disabled","true");
302                                                this.SC_KEY.setAttribute("disabled","true");
303                                        }
304                                        if(sc){
305                                                this.SC_SHIFT.checked = sc.shift;
306                                                this.SC_ALT.checked = sc.alt;
307                                                this.SC_ACCEL.checked = sc.accel;
308                                                if(sc.key){
309                                                        this.SC_KEY.value = sc.key;
310                                                        var acceltext = [];
311                                                        if(sc.accel){
312                                                                if(osString == "Darwin"){
313                                                                        acceltext.push('Command');
314                                                                }else{
315                                                                        acceltext.push('Ctrl');
316                                                                }
317                                                        }
318                                                        if(sc.shift) acceltext.push('Shift');
319                                                        if(sc.alt){
320                                                                if(osString == "Darwin"){
321                                                                        acceltext.push('Option');
322                                                                }else{
323                                                                        acceltext.push('Alt');
324                                                                }
325                                                        }
326                                                        this.SC_MOD.value = acceltext.join("+")+" +";
327                                                }
328                                        }
329                                }
330                        }
331                        try{this.SC_KEY.editor.transactionManager.clear();}catch(ex2){}
332                }
333                if(propertyOverlay_elem){
334                        document.loadOverlay(propertyOverlay_elem.textContent, null);
335                        setTimeout(function(){
336                                window.sizeToContent();
337                                setTimeout(function(){ window.sizeToContent(); },500);
338                        },100);
339                }
340                this.NOTE_TAB.removeAttribute("hidden");
341                this.GENERAL_TAB.removeAttribute("hidden");
342                document.title = this.item.title;
343                return;
344        },
345
346        _createXMLDoc : function(aContent){
347                var parser = new DOMParser();
348                this._xmldoc = parser.parseFromString(aContent, "text/xml");
349                parser = undefined;
350        },
351
352        _xmlSerializer : function(){
353                var s = new XMLSerializer();
354                var aContent = s.serializeToString(this.xmldoc);
355                s = undefined;
356                return aContent;
357        },
358
359        accept : function(){
360                var newVals = {
361                        title    : this.TITLE.value,
362                        tag      : this.TAG.value,
363                        style    : document.getElementById("mcPropSample").style.cssText,
364                        note     : this.Common.escapeComment(this.NOTE.value),
365                        iconsize : (this.ICON_SIZE.disabled?"small":this.ICON_SIZE.value),
366                };
367                if(this._extended_message){
368                        newVals["logical"] = this.LOGICAL_PAGE.value;
369                        newVals["logical"] = newVals["logical"].replace(/\t/mg,"        ");
370                        newVals["logical"] = this.Common.exceptCode(newVals["logical"]);
371                        newVals["logical"] = newVals["logical"].replace(/\x0D\x0A|\x0D|\x0A/g, " ").replace(/^\s*/g,"").replace(/\s*$/g,"");
372
373                        newVals["physical"] = this.PHYSICAL_PAGE.value;
374                        newVals["physical"] = newVals["physical"].replace(/\t/mg,"        ");
375                        newVals["physical"] = this.Common.exceptCode(newVals["physical"]);
376                        newVals["physical"] = newVals["physical"].replace(/\x0D\x0A|\x0D|\x0A/g, " ").replace(/^\s*/g,"").replace(/\s*$/g,"");
377                }
378
379                var changed = this.DataSource.isContainer(this.resource);
380                if(!this.DataSource.isContainer(this.resource) && newVals.style) delete newVals.style;
381
382                newVals["title"] = newVals["title"].replace(/\t/mg,"        ");
383                newVals["title"] = this.Common.exceptCode(newVals["title"]);
384                newVals["title"] = newVals["title"].replace(/\x0D\x0A|\x0D|\x0A/g, " ").replace(/^\s*/g,"").replace(/\s*$/g,"");
385                if(newVals["title"] == ""){
386                        this.TITLE.value = this.TITLE.defaultValue;
387                        this.TABBOX.selectedTab = this.GENERAL_TAB;
388                        var self = this;
389                        setTimeout(function(){ self.TITLE.focus(); },0);
390                        return false;
391                }
392                if(this.DataSource.isContainer(this.resource)){
393                        var parRes = this.DataSource.findParentResource(this.resource);
394                        if(!parRes) return;
395                        var i;
396                        var listTitle = "";
397                        var listRes = this.DataSource.flattenResources(parRes,1,false);
398                        for(i=0;i<listRes.length;i++){
399                                if(listRes[i].Value == this.resource.Value) continue;
400                                listTitle = this.DataSource.getProperty(listRes[i],"title");
401                                listTitle = listTitle.replace(/^\s*/img,"").replace(/\s*$/img,"");
402                                if(listTitle == newVals["title"]) break;
403                                listTitle = "";
404                        }
405                        if(listTitle == newVals["title"]){
406                                this.TITLE.value = this.TITLE.defaultValue;
407                                var self = this;
408                                setTimeout(function(){ self.TITLE.focus(); },0);
409                                return false;
410                        }
411                }
412
413                newVals["tag"] = newVals["tag"].replace(/\t/mg,"        ");
414                newVals["tag"] = this.Common.exceptCode(newVals["tag"]);
415                newVals["tag"] = newVals["tag"].replace(/\x0D\x0A|\x0D|\x0A/g, " ").replace(/^\s*/g,"").replace(/\s*$/g,"");
416
417                newVals["note"] = newVals["note"].replace(/\t/mg,"        ");
418                newVals["note"] = newVals["note"].replace(/\x0D\x0A|\x0D|\x0A/g," __BR__ ");
419                newVals["note"] = this.Common.exceptCode(newVals["note"]);
420                newVals["note"] = newVals["note"].replace(/[\r\n]/mg, " ").replace(/ __BR__ /mg,"\n");
421
422                var props;
423                for(props in newVals){
424                        if(this.item[props] == newVals[props]) continue;
425                        this.item[props] = newVals[props];
426                        changed = true;
427                }
428
429                if(!this.DataSource.isContainer(this.resource) && this.item.style) delete this.item.style;
430
431                if(changed){
432                        if(this.item.title) this.item.title = this.item.title.replace(/[\r\n]/mg, " ");
433                        //最新の情報を取埗
434                        var dbitem = {};
435                        if(this.item.id){
436                                if(this.item.tag || this.item.note || this.item.iconsize || this.item.logical || this.item.physical){
437                                        if(this.property == "") this.property = "<PROPERTY/>";
438                                        this._createXMLDoc(this.property);
439                                        if(this.xmldoc){
440                                                if(this.item.tag != undefined){
441                                                        var tag = this.xmldoc.getElementsByTagName("TAG")[0];
442                                                        if(this.item.tag != "" && !tag){
443                                                                tag = this.xmldoc.createElement("TAG");
444                                                                this.xmldoc.documentElement.appendChild(tag);
445                                                        }else if(this.item.tag == "" && tag){
446                                                                tag.parentNode.removeChild(tag);
447                                                                tag = undefined;
448                                                        }
449                                                        if(tag){
450                                                                while(tag.hasChildNodes()){ tag.removeChild(tag.lastChild); }
451                                                                tag.appendChild(this.xmldoc.createTextNode(this.item.tag));
452                                                        }
453                                                }
454                                                if(this.item.note != undefined){
455                                                        var note = this.xmldoc.getElementsByTagName("NOTE")[0];
456                                                        if(this.item.note != "" && !note){
457                                                                note = this.xmldoc.createElement("NOTE");
458                                                                this.xmldoc.documentElement.appendChild(note);
459                                                        }else if(this.item.note == "" && note){
460                                                                note.parentNode.removeChild(note);
461                                                                note = undefined;
462                                                        }
463                                                        if(note){
464                                                                while(note.hasChildNodes()){ note.removeChild(note.lastChild); }
465                                                                note.appendChild(this.xmldoc.createTextNode(this.item.note));
466                                                        }
467                                                }
468                                                if(this.item.iconsize && this.DataSource.isContainer(this.resource)){
469                                                        var iconsize = this.xmldoc.getElementsByTagName("ICON_SIZE")[0];
470                                                        if(!iconsize){
471                                                                iconsize = this.xmldoc.createElement("ICON_SIZE");
472                                                                this.xmldoc.documentElement.appendChild(iconsize);
473                                                        }
474                                                        while(iconsize.hasChildNodes()){ iconsize.removeChild(iconsize.lastChild); }
475                                                        iconsize.appendChild(this.xmldoc.createTextNode(this.item.iconsize));
476                                                }
477                                                if(this.item.logical != undefined){
478                                                        var logical = this.xmldoc.getElementsByTagName("LOGICAL_PAGE")[0];
479                                                        if(this.item.logical != "" && !logical){
480                                                                logical = this.xmldoc.createElement("LOGICAL_PAGE");
481                                                                var extras_msg = this.xmldoc.getElementsByTagName("EXTENDED_MESSAGE")[0];
482                                                                if(!extras_msg){
483                                                                        extras_msg = this.xmldoc.createElement("EXTENDED_MESSAGE");
484                                                                        this.xmldoc.documentElement.appendChild(extras_msg);
485                                                                }
486                                                                extras_msg.appendChild(logical);
487                                                        }else if(this.item.logical == "" && logical){
488                                                                logical.parentNode.removeChild(logical);
489                                                                logical = undefined;
490                                                        }
491                                                        if(logical){
492                                                                while(logical.hasChildNodes()){ logical.removeChild(logical.lastChild); }
493                                                                logical.appendChild(this.xmldoc.createTextNode(this.item.logical));
494                                                        }
495                                                }
496                                                if(this.item.physical != undefined){
497                                                        var physical = this.xmldoc.getElementsByTagName("PHYSICAL_PAGE")[0];
498                                                        if(this.item.physical != "" && !physical){
499                                                                physical = this.xmldoc.createElement("PHYSICAL_PAGE");
500                                                                var extras_msg = this.xmldoc.getElementsByTagName("EXTENDED_MESSAGE")[0];
501                                                                if(!extras_msg){
502                                                                        extras_msg = this.xmldoc.createElement("EXTENDED_MESSAGE");
503                                                                        this.xmldoc.documentElement.appendChild(extras_msg);
504                                                                }
505                                                                extras_msg.appendChild(physical);
506                                                        }else if(this.item.physical == "" && physical){
507                                                                physical.parentNode.removeChild(physical);
508                                                                physical = undefined;
509                                                        }
510                                                        if(physical){
511                                                                while(physical.hasChildNodes()){ physical.removeChild(physical.lastChild); }
512                                                                physical.appendChild(this.xmldoc.createTextNode(this.item.physical));
513                                                        }
514                                                }
515                                                this.property = this._xmlSerializer();
516                                        }
517                                }
518                                if(this.DataSource.isContainer(this.resource)){
519                                        dbitem.fid = this.id;
520                                        if(this.item.title != undefined) dbitem.fid_title = this.item.title;
521                                        if(this.item.note != undefined)  dbitem.fid_property = this.property;
522                                        if(this.item.style != undefined) dbitem.fid_style = this.item.style;
523                                        if(this.item.note != undefined || this.item.iconsize != undefined) dbitem.fid_property = this.property;
524                                        changed = this.Database.updateFolder(dbitem,this.dbtype);
525                                }else{
526                                        dbitem.oid = this.id;
527                                        if(this.item.title != undefined)   dbitem.oid_title = this.item.title;
528                                        if(this.item.note != undefined) dbitem.oid_property = this.property;
529                                        changed = this.Database.updateObject(dbitem,this.dbtype);
530                                }
531                        }
532                }
533                if(changed){
534                        for(props in this.item){
535                                if(props == "tag") continue;
536                                if(props == "note") continue;
537                                if(props == "index") continue;
538                                if(props == "addon_id") continue;
539                                if(props == "iconsize") continue;
540                                this.DataSource.setProperty(this.resource, props, this.item[props]);
541                        }
542                        if(this.DataSource.isContainer(this.resource)) this.DataSource.setProperty(this.resource,"cssrule",'css_'+this.dbtype+'_'+this.id);
543                        try{
544                                var update_id = this.DataSource.getProperty(this.resource,"id");
545                                var listRes2 = this.DataSource.flattenResources(this.Common.RDF.GetResource(this.DataSource.ABOUT_ROOT),2,true);
546                                for(var j=0;j<listRes2.length;j++){
547                                        var id = this.DataSource.getProperty(listRes2[j],"id");
548                                        if(id != update_id) continue;
549                                        this.DataSource.setProperty(listRes2[j],"title",this.item.title);
550                                }
551                        }catch(e){}
552                        this.DataSource.flush();
553                }
554                if(window.arguments[1]) window.arguments[1].accept = changed;
555
556                if(!document.getElementById("mcPropShortcutGroup").hasAttribute("hidden") && this.id && this.dbtype && this._opener){
557                        var bitsShortcutService = this._opener.top.bitsShortcutService;
558                        if(bitsShortcutService){
559                                var sc = bitsShortcutService.getShortcut(this.id,this.dbtype);
560                                if(!sc) sc = {disabled:true};
561                                sc.disabled = !this.SC_DISABLED.checked;
562                                sc.shift    = this.SC_SHIFT.checked;
563                                sc.alt      = this.SC_ALT.checked;
564                                sc.accel    = this.SC_ACCEL.checked;
565                                sc.title    = this.item.title;
566                                sc.style    = this.item.style;
567
568                                var key = this.SC_KEY.value;
569                                key = key.replace(/\t/mg,"        ");
570                                key = this.Common.exceptCode(key);
571                                key = key.replace(/[\r\n]/mg, " ").replace(/^\s*/g,"").replace(/\s*$/g,"");
572                                if(key){
573                                        sc.key = key;
574                                }else{
575                                        sc.disabled = true;
576                                }
577                                bitsShortcutService.setShortcut(this.id,this.dbtype,sc);
578                        }
579                }
580                return true;
581        },
582
583        cancel : function(){
584                if(window.arguments[1]) window.arguments[1].accept = false;
585        },
586
587        undoTitle : function(){
588                try{
589                        while(this.TITLE.editor.transactionManager.numberOfUndoItems>0){
590                                this.TITLE.editor.undo(1);
591                                var title = this.TITLE.value;
592                                title = title.replace(/\t/mg,"        ");
593                                title = this.Common.exceptCode(title);
594                                title = title.replace(/[\r\n]/mg, " ").replace(/^\s*/img,"").replace(/\s*$/img,"");
595                                if(title != "") break;
596                        }
597                }catch(ex2){_dump(ex2);}
598                window.focus();
599                var self = this;
600                setTimeout(function(){self.TITLE.focus();},100);
601        },
602
603        inputTitle : function(aEvent){
604                var title = this.TITLE.value;
605                title = title.replace(/\t/g,"        ");
606                title = this.Common.exceptCode(title);
607                title = title.replace(/[\r\n]/g, " ").replace(/^\s*/g,"").replace(/\s*$/g,"");
608                if(title == ""){
609                        this.TITLE_HBOX.style.borderColor = 'red';
610                }else{
611                        this.TITLE_HBOX.style.borderColor = 'transparent';
612                }
613        },
614
615        checkedTitle : function(aEvent){
616                var title = this.TITLE.value;
617                title = title.replace(/\t/g,"        ");
618                title = this.Common.exceptCode(title);
619                title = title.replace(/[\r\n]/g, " ").replace(/^\s*/g,"").replace(/\s*$/g,"");
620                if(title == ""){
621                        aEvent.preventDefault();
622                        aEvent.stopPropagation();
623                        this.TABBOX.selectedTab = this.GENERAL_TAB;
624                        if(Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULRuntime).OS != "Darwin"){
625                                this.Common.alert(this.STRING.getString("ERROR_NOT_ENTER_TITLE"));
626//                              this.undoTitle();
627                                this.TITLE.value = this.TITLE.defaultValue;
628                                var self = this;
629                                setTimeout(function(){ self.TITLE.focus(); },0);
630                        }
631                        var title = this.TITLE.value;
632                        title = title.replace(/\t/g,"        ");
633                        title = this.Common.exceptCode(title);
634                        title = title.replace(/[\r\n]/g, " ").replace(/^\s*/g,"").replace(/\s*$/g,"");
635                        if(title == ""){
636                                this.TITLE_HBOX.style.borderColor = 'red';
637                        }else{
638                                this.TITLE_HBOX.style.borderColor = 'transparent';
639                        }
640                        return false;
641                }
642                if(this.DataSource.isContainer(this.resource)){
643                        var parRes = this.DataSource.findParentResource(this.resource);
644                        if(!parRes) return;
645                        var i;
646                        var listTitle = "";
647                        var listRes = this.DataSource.flattenResources(parRes,1,false);
648                        for(i=0;i<listRes.length;i++){
649                                if(listRes[i].Value == this.resource.Value) continue;
650                                listTitle = this.DataSource.getProperty(listRes[i],"title");
651                                listTitle = listTitle.replace(/^\s*/img,"").replace(/\s*$/img,"");
652                                if(listTitle == title) break;
653                        }
654                        if(listTitle != title) return true;
655                        if(Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULRuntime).OS != "Darwin"){
656                                this.Common.alert(this.STRING.getString("ERROR_INVALID_TITLE"));
657                                this.TITLE.value = this.TITLE.defaultValue;
658                                var self = this;
659                                setTimeout(function(){ self.TITLE.focus(); },0);
660                        }else{
661                                this.TITLE.value = "";
662                        }
663                        aEvent.preventDefault();
664                        aEvent.stopPropagation();
665                        return false;
666                }else{
667                        return true;
668                }
669                this.undoTitle();
670                return false;
671        },
672
673        updateNoteTab : function(aNote){
674                var elem = this.NOTE_TAB;
675                if(aNote != undefined)
676                        elem.setAttribute("image", "chrome://markingcollection/skin/edit_comment.png");
677                else
678                        elem.removeAttribute("image");
679        },
680
681        checkedTag : function(){
682                var tag = this.TAG.value.replace(/[\r\n]/mg, " ").replace(/^\s*/img,"").replace(/\s*$/img,"");
683                if(tag.match(/^[^a-z]/i)) this.Common.alert(this.STRING.getString("WARNING_NOT_BEGIN_ENGLISH_TAG"));
684        },
685
686        commandColor : function(event){
687                document.getElementById("mcPropSample").style.backgroundColor = event.target.style.backgroundColor;
688                document.getElementById("mcPropSample").style.color = event.target.style.color;
689        },
690
691        commandBorderStyle : function(event){
692                document.getElementById("mcPropSample").style.borderStyle = event.target.style.borderStyle;
693        },
694
695        commandBorderColor : function(event){
696                document.getElementById("mcPropSample").style.borderColor = event.target.style.backgroundColor;
697        },
698
699        commandBorderWidth : function(event){
700                document.getElementById("mcPropSample").style.borderWidth = event.target.style.borderWidth;
701        },
702
703        commandIconsize : function(event){
704                this.ICON_SIZE_I.setAttribute("iconsize",this.ICON_SIZE.value);
705        },
706
707        openDialog : function(){
708                var result = {
709                        accept : false,
710                        style  : document.getElementById("mcPropSample").style.cssText,
711                };
712                if(!this.item.index) this.item.index = -1;
713
714                window.openDialog('chrome://markingcollection/content/markerCustom.xul', '', 'modal,centerscreen,chrome',this.item.index,result);
715                if(result.accept) document.getElementById("mcPropSample").setAttribute("style",result.style);
716        },
717
718        formatFileSize : function(aBytes){
719                if(aBytes > 1000 * 1000){
720                        return this.divideBy100( Math.round( aBytes / 1024 / 1024 * 100 ) ) + " MB";
721                }else if( aBytes == 0 ){
722                        return "0 KB";
723                }else{
724                        var kbytes = Math.round( aBytes / 1024 );
725                        return (kbytes == 0 ? 1 : kbytes) + " KB";
726                }
727        },
728
729        divideBy100 : function(aInt){
730                if(aInt % 100 == 0){
731                        return aInt / 100 + ".00";
732                }else if(aInt % 10 == 0){
733                        return aInt / 100 + "0";
734                }else{
735                        return aInt / 100;
736                }
737        },
738
739        vacuumDB : function(){
740                this.Database.vacuum(this.dbtype);
741                setTimeout(
742                        function(){
743                                document.getElementById("mcPropDatabaseGroup").setAttribute("hidden",true);
744                                if(parseInt(mcPropService.item.editmode) & 0x1000){
745                                        var aDBFile = mcPropService.Database.getDatabaseFile(mcPropService.dbtype);
746                                        if(aDBFile){
747                                                mcPropService.DB_PATH.value = aDBFile.path;
748                                                mcPropService.DB_DATE.value = (new Date(aDBFile.lastModifiedTime)).toLocaleString();
749                                                mcPropService.DB_SIZE.value = mcPropService.formatFileSize(aDBFile.fileSize);
750                                                document.getElementById("mcPropDatabaseGroup").removeAttribute("hidden");
751                                        }
752                                }
753                },500);
754        },
755
756        commandShortcut : function(aEvent){
757                if(!this.SC_DISABLED.checked){
758                        this.SC_SHIFT.setAttribute("disabled","true");
759                        this.SC_ALT.setAttribute("disabled","true");
760                        this.SC_ACCEL.setAttribute("disabled","true");
761                        this.SC_KEY.setAttribute("disabled","true");
762                }else{
763                        this.SC_SHIFT.removeAttribute("disabled");
764                        this.SC_ALT.removeAttribute("disabled");
765                        this.SC_ACCEL.removeAttribute("disabled");
766                        this.SC_KEY.removeAttribute("disabled");
767                        this.SC_KEY.focus();
768                }
769                        this.SC_SHIFT.setAttribute("disabled","true");
770                        this.SC_ALT.setAttribute("disabled","true");
771                        this.SC_ACCEL.setAttribute("disabled","true");
772
773        },
774        inputShortcut : function(aEvent){
775                var osString = Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULRuntime).OS;
776                var sc = {
777                        key     : ""+String.fromCharCode(aEvent.charCode).toUpperCase(),
778                        shift   : aEvent.shiftKey,
779                        alt     : aEvent.altKey,
780                        accel   : (osString == "Darwin" ? aEvent.metaKey: aEvent.ctrlKey)
781                };
782                this.SC_KEY.value = '';
783                this.SC_MOD.value = '';
784                if(!sc.key || !(sc.shift||sc.alt||sc.accel)) return;
785                this.SC_SHIFT.checked = sc.shift;
786                this.SC_ALT.checked = sc.alt;
787                this.SC_ACCEL.checked = sc.accel;
788
789                var acceltext = [];
790                if(sc.accel){
791                        if(osString == "Darwin"){
792                                acceltext.push('Command');
793                        }else{
794                                acceltext.push('Ctrl');
795                        }
796                }
797                if(sc.shift) acceltext.push('Shift');
798                if(sc.alt){
799                        if(osString == "Darwin"){
800                                acceltext.push('Option');
801                        }else{
802                                acceltext.push('Alt');
803                        }
804                }
805                this.SC_MOD.value = acceltext.join("+")+" +";
806
807                this.SC_KEY.value = sc.key;
808                this.SC_KEY.focus();
809        },
810};
811
812function _dump(aString){
813        window.opener.top.bitsMarkingCollection._dump(aString);
814}
Note: See TracBrowser for help on using the repository browser.