source: DASISH/t5.6/client/chrome/markingcollection/content/markingcollection/autocacheDialog.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: 4.5 KB
Line 
1var autocacheDialog = {
2
3/////////////////////////////////////////////////////////////////////
4        get STRING()     { return document.getElementById("autocacheDialogString"); },
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        get bitsAutocacheService() { return window.opener.top.bitsAutocacheService;},
11
12        get DIALOG() { return document.getElementById("autocacheDialog"); },
13        get LIST()   { return document.getElementById("autocacheListbox"); },
14        get REMOVE() { return document.getElementById("autocacheDialogRemove"); },
15
16/////////////////////////////////////////////////////////////////////
17        init : function(){
18                if(autocacheDialog._init) return;
19
20                try {
21                        this.info = window.arguments[0];
22                }catch(ex){
23                }
24
25                this.makeList();
26
27                try{
28                        this._init = true;
29                }catch(ex){
30                        this.Common.alert("autocacheDialog.init():"+ex);
31                }
32        },
33
34/////////////////////////////////////////////////////////////////////
35        done : function(event){
36                if(this._init){
37                        this._init = false;
38                }
39        },
40
41/////////////////////////////////////////////////////////////////////
42        select : function(aEvent){
43                this.DIALOG.setAttribute("buttondisabledaccept","true");
44                this.REMOVE.setAttribute("disabled","true");
45
46                if(this.LIST.selectedCount==1) this.DIALOG.removeAttribute("buttondisabledaccept");
47                if(this.LIST.selectedCount>0) this.REMOVE.removeAttribute("disabled");
48        },
49
50/////////////////////////////////////////////////////////////////////
51        remove : function(aEvent){
52                if(this.LIST.selectedItems.length<=0) return;
53                if(Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULRuntime).OS != "Darwin"){
54                        if(!this.Common.confirm( this.STRING.getString("CONFIRM_DELETE") )) return;
55                }
56
57                var i;
58                for(i=0;i<this.LIST.selectedItems.length;i++){
59                        if(!this.info.list[this.LIST.selectedItems[i].value].exists()) continue;
60                        this.info.list[this.LIST.selectedItems[i].value].remove(true);
61                }
62                this.makeList();
63        },
64
65/////////////////////////////////////////////////////////////////////
66        makeList : function(){
67                while(this.LIST.getRowCount()>0){
68                        this.LIST.removeItemAt(0);
69                }
70                try{
71                        var dir_arr = [];
72                        var entries = this.info.dir.directoryEntries;
73                        while(entries.hasMoreElements()){
74                                var entry = entries.getNext().QueryInterface(Components.interfaces.nsILocalFile);
75                                if(!entry.isDirectory() || (entry.isDirectory() && entry.leafName.match(/^\./))) continue;
76                                dir_arr.push(entry.clone());
77                        }
78                        if(dir_arr.length>0) dir_arr.sort(function(a, b) { return(parseInt(b.leafName) - parseInt(a.leafName)); });
79
80                        var i;
81                        for(i=0;i<dir_arr.length;i++){
82                                var label = dir_arr[i].leafName;
83                                if(label && label.match(/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/)) label = RegExp.$1+"/"+RegExp.$2+"/"+RegExp.$3+" "+RegExp.$4+":"+RegExp.$5+":"+RegExp.$6;
84                                var item = this.LIST.appendItem(label,i);
85                                if(!item) continue;
86                                var info = window.opener.top.bitsAutocacheService._getSaveCacheInfo(dir_arr[i]);
87                                if(info && info.INDEX){
88                                        var indexFile = dir_arr[i].clone();
89                                        indexFile.append(info.INDEX);
90                                        if(indexFile.exists()){
91                                                var listcell = document.createElement("listcell");
92                                                if(listcell){
93                                                        listcell.setAttribute("label",this.formatFileSize(indexFile.fileSize));
94                                                        item.appendChild(listcell);
95                                                }
96                                        }
97                                }
98                        }
99                        this.info.list = dir_arr.concat([]);
100                }catch(e){this._dump(e);}
101                this.select();
102        },
103
104/////////////////////////////////////////////////////////////////////
105        accept : function(aEvent){
106                window.arguments[0].accept = true;
107                try{ window.arguments[0].acceptdir = this.info.list[this.LIST.selectedIndex].clone(); }catch(e){}
108        },
109
110/////////////////////////////////////////////////////////////////////
111        cancel : function(aEvent){
112                window.arguments[0].accept = false;
113        },
114
115/////////////////////////////////////////////////////////////////////
116        formatFileSize : function(aBytes){
117                if(aBytes > 1000 * 1000){
118                        return this.divideBy100( Math.round( aBytes / 1024 / 1024 * 100 ) ) + " MB";
119                }else if( aBytes == 0 ){
120                        return "0 KB";
121                }else{
122                        var kbytes = Math.round( aBytes / 1024 );
123                        return (kbytes == 0 ? 1 : kbytes) + " KB";
124                }
125        },
126
127/////////////////////////////////////////////////////////////////////
128        _dump : function(aString){
129                if(nsPreferences.getBoolPref("wiredmarker.debug", false)) window.dump(aString+"\n");
130        },
131};
Note: See TracBrowser for help on using the repository browser.