]> git.donarmstrong.com Git - roundcube.git/blob - plugins/enigma/enigma.js
Imported Upstream version 0.6+dfsg
[roundcube.git] / plugins / enigma / enigma.js
1 /* Enigma Plugin */
2
3 if (window.rcmail)
4 {
5     rcmail.addEventListener('init', function(evt)
6     {
7         if (rcmail.env.task == 'settings') {
8             rcmail.register_command('plugin.enigma', function() { rcmail.goto_url('plugin.enigma') }, true);
9             rcmail.register_command('plugin.enigma-key-import', function() { rcmail.enigma_key_import() }, true);
10             rcmail.register_command('plugin.enigma-key-export', function() { rcmail.enigma_key_export() }, true);
11
12             if (rcmail.gui_objects.keyslist)
13             {
14                 var p = rcmail;
15                 rcmail.keys_list = new rcube_list_widget(rcmail.gui_objects.keyslist,
16                     {multiselect:false, draggable:false, keyboard:false});
17                 rcmail.keys_list.addEventListener('select', function(o){ p.enigma_key_select(o); });
18                 rcmail.keys_list.init();
19                 rcmail.keys_list.focus();
20
21                 rcmail.enigma_list();
22
23                 rcmail.register_command('firstpage', function(props) {return rcmail.enigma_list_page('first'); });
24                 rcmail.register_command('previouspage', function(props) {return rcmail.enigma_list_page('previous'); });
25                 rcmail.register_command('nextpage', function(props) {return rcmail.enigma_list_page('next'); });
26                 rcmail.register_command('lastpage', function(props) {return rcmail.enigma_list_page('last'); });
27             }
28
29             if (rcmail.env.action == 'edit-prefs') {
30                 rcmail.register_command('search', function(props) {return rcmail.enigma_search(props); }, true);
31                 rcmail.register_command('reset-search', function(props) {return rcmail.enigma_search_reset(props); }, true);
32             }
33             else if (rcmail.env.action == 'plugin.enigma') {
34                 rcmail.register_command('plugin.enigma-import', function() { rcmail.enigma_import() }, true);
35                 rcmail.register_command('plugin.enigma-export', function() { rcmail.enigma_export() }, true);
36             }
37         }
38     });
39 }
40
41 /*********************************************************/
42 /*********    Enigma Settings/Keys/Certs UI      *********/
43 /*********************************************************/
44
45 // Display key(s) import form
46 rcube_webmail.prototype.enigma_key_import = function()
47 {
48     this.enigma_loadframe(null, '&_a=keyimport');
49 };
50
51 // Submit key(s) form
52 rcube_webmail.prototype.enigma_import = function()
53 {
54     var form, file;
55     if (form = this.gui_objects.importform) {
56         file = document.getElementById('rcmimportfile');
57         if (file && !file.value) {
58             alert(this.get_label('selectimportfile'));
59             return;
60         }
61         form.submit();
62         this.set_busy(true, 'importwait');
63         this.lock_form(form, true);
64    }
65 };
66
67 // list row selection handler
68 rcube_webmail.prototype.enigma_key_select = function(list)
69 {
70     var id;
71     if (id = list.get_single_selection())
72         this.enigma_loadframe(id);
73 };
74
75 // load key frame
76 rcube_webmail.prototype.enigma_loadframe = function(id, url)
77 {
78     var frm, win;
79     if (this.env.contentframe && window.frames && (frm = window.frames[this.env.contentframe])) {
80         if (!id && !url && (win = window.frames[this.env.contentframe])) {
81             if (win.location && win.location.href.indexOf(this.env.blankpage)<0)
82                 win.location.href = this.env.blankpage;
83             return;
84         }
85         this.set_busy(true);
86         if (!url)
87             url = '&_a=keyinfo&_id='+id;
88         frm.location.href = this.env.comm_path+'&_action=plugin.enigma&_framed=1' + url;
89     }
90 };
91
92 // Search keys/certs
93 rcube_webmail.prototype.enigma_search = function(props)
94 {
95     if (!props && this.gui_objects.qsearchbox)
96         props = this.gui_objects.qsearchbox.value;
97
98     if (props || this.env.search_request) {
99         var params = {'_a': 'keysearch', '_q': urlencode(props)},
100           lock = this.set_busy(true, 'searching');
101 //        if (this.gui_objects.search_filter)
102   //          addurl += '&_filter=' + this.gui_objects.search_filter.value;
103         this.env.current_page = 1;  
104         this.enigma_loadframe();
105         this.enigma_clear_list();
106         this.http_post('plugin.enigma', params, lock);
107     }
108
109     return false;
110 }
111
112 // Reset search filter and the list
113 rcube_webmail.prototype.enigma_search_reset = function(props)
114 {
115     var s = this.env.search_request;
116     this.reset_qsearch();
117
118     if (s) {
119         this.enigma_loadframe();
120         this.enigma_clear_list();
121
122         // refresh the list
123         this.enigma_list();
124     }
125
126     return false;
127 }
128
129 // Keys/certs listing
130 rcube_webmail.prototype.enigma_list = function(page)
131 {
132     var params = {'_a': 'keylist'},
133       lock = this.set_busy(true, 'loading');
134
135     this.env.current_page = page ? page : 1;
136
137     if (this.env.search_request)
138         params._q = this.env.search_request;
139     if (page)
140         params._p = page;
141
142     this.enigma_clear_list();
143     this.http_post('plugin.enigma', params, lock);
144 }
145
146 // Change list page
147 rcube_webmail.prototype.enigma_list_page = function(page)
148 {
149     if (page == 'next')
150         page = this.env.current_page + 1;
151     else if (page == 'last')
152         page = this.env.pagecount;
153     else if (page == 'prev' && this.env.current_page > 1)
154         page = this.env.current_page - 1;
155     else if (page == 'first' && this.env.current_page > 1)
156         page = 1;
157
158     this.enigma_list(page);
159 }
160
161 // Remove list rows
162 rcube_webmail.prototype.enigma_clear_list = function()
163 {
164     this.enigma_loadframe();
165     if (this.keys_list)
166         this.keys_list.clear(true);
167 }
168
169 // Adds a row to the list
170 rcube_webmail.prototype.enigma_add_list_row = function(r)
171 {
172     if (!this.gui_objects.keyslist || !this.keys_list)
173         return false;
174
175     var list = this.keys_list,
176         tbody = this.gui_objects.keyslist.tBodies[0],
177         rowcount = tbody.rows.length,
178         even = rowcount%2,
179         css_class = 'message'
180             + (even ? ' even' : ' odd'),
181         // for performance use DOM instead of jQuery here
182         row = document.createElement('tr'),
183         col = document.createElement('td');
184
185     row.id = 'rcmrow' + r.id;
186     row.className = css_class;
187
188     col.innerHTML = r.name;
189     row.appendChild(col);
190     list.insert_row(row);
191 }
192
193 /*********************************************************/
194 /*********        Enigma Message methods         *********/
195 /*********************************************************/
196
197 // Import attached keys/certs file
198 rcube_webmail.prototype.enigma_import_attachment = function(mime_id)
199 {
200     var lock = this.set_busy(true, 'loading');
201     this.http_post('plugin.enigmaimport', '_uid='+this.env.uid+'&_mbox='
202         +urlencode(this.env.mailbox)+'&_part='+urlencode(mime_id), lock);
203
204     return false;
205 };
206