5 rcmail.addEventListener('init', function(evt)
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);
12 if (rcmail.gui_objects.keyslist)
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();
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'); });
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);
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);
41 /*********************************************************/
42 /********* Enigma Settings/Keys/Certs UI *********/
43 /*********************************************************/
45 // Display key(s) import form
46 rcube_webmail.prototype.enigma_key_import = function()
48 this.enigma_loadframe(null, '&_a=keyimport');
52 rcube_webmail.prototype.enigma_import = function()
55 if (form = this.gui_objects.importform) {
56 file = document.getElementById('rcmimportfile');
57 if (file && !file.value) {
58 alert(this.get_label('selectimportfile'));
62 this.set_busy(true, 'importwait');
63 this.lock_form(form, true);
67 // list row selection handler
68 rcube_webmail.prototype.enigma_key_select = function(list)
71 if (id = list.get_single_selection())
72 this.enigma_loadframe(id);
76 rcube_webmail.prototype.enigma_loadframe = function(id, url)
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;
87 url = '&_a=keyinfo&_id='+id;
88 frm.location.href = this.env.comm_path+'&_action=plugin.enigma&_framed=1' + url;
93 rcube_webmail.prototype.enigma_search = function(props)
95 if (!props && this.gui_objects.qsearchbox)
96 props = this.gui_objects.qsearchbox.value;
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);
112 // Reset search filter and the list
113 rcube_webmail.prototype.enigma_search_reset = function(props)
115 var s = this.env.search_request;
116 this.reset_qsearch();
119 this.enigma_loadframe();
120 this.enigma_clear_list();
129 // Keys/certs listing
130 rcube_webmail.prototype.enigma_list = function(page)
132 var params = {'_a': 'keylist'},
133 lock = this.set_busy(true, 'loading');
135 this.env.current_page = page ? page : 1;
137 if (this.env.search_request)
138 params._q = this.env.search_request;
142 this.enigma_clear_list();
143 this.http_post('plugin.enigma', params, lock);
147 rcube_webmail.prototype.enigma_list_page = function(page)
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)
158 this.enigma_list(page);
162 rcube_webmail.prototype.enigma_clear_list = function()
164 this.enigma_loadframe();
166 this.keys_list.clear(true);
169 // Adds a row to the list
170 rcube_webmail.prototype.enigma_add_list_row = function(r)
172 if (!this.gui_objects.keyslist || !this.keys_list)
175 var list = this.keys_list,
176 tbody = this.gui_objects.keyslist.tBodies[0],
177 rowcount = tbody.rows.length,
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');
185 row.id = 'rcmrow' + r.id;
186 row.className = css_class;
188 col.innerHTML = r.name;
189 row.appendChild(col);
190 list.insert_row(row);
193 /*********************************************************/
194 /********* Enigma Message methods *********/
195 /*********************************************************/
197 // Import attached keys/certs file
198 rcube_webmail.prototype.enigma_import_attachment = function(mime_id)
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);