summaryrefslogtreecommitdiff
path: root/program/js/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'program/js/app.js')
-rw-r--r--program/js/app.js132
1 files changed, 72 insertions, 60 deletions
diff --git a/program/js/app.js b/program/js/app.js
index ce7570468..afaebec9c 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -48,7 +48,7 @@ function rcube_webmail()
this.env.request_timeout = 180; // seconds
this.env.draft_autosave = 0; // seconds
this.env.comm_path = './';
- this.env.blankpage = 'program/blank.gif';
+ this.env.blankpage = 'program/resources/blank.gif';
// set jQuery ajax options
$.ajaxSetup({
@@ -58,6 +58,8 @@ function rcube_webmail()
beforeSend: function(xmlhttp){ xmlhttp.setRequestHeader('X-Roundcube-Request', ref.env.request_token); }
});
+ $(window).bind('beforeunload', function() { rcmail.unload = true; });
+
// set environment variable(s)
this.set_env = function(p, value)
{
@@ -459,7 +461,7 @@ function rcube_webmail()
this.gui_containers.foldertray = $(this.gui_objects.folderlist);
// activate html5 file drop feature (if browser supports it and if configured)
- if (this.gui_objects.filedrop && this.env.filedrop && ((XMLHttpRequest && XMLHttpRequest.prototype.sendAsBinary) || window.FormData)) {
+ if (this.gui_objects.filedrop && this.env.filedrop && ((window.XMLHttpRequest && XMLHttpRequest.prototype && XMLHttpRequest.prototype.sendAsBinary) || window.FormData)) {
$(document.body).bind('dragover dragleave drop', function(e){ return ref.document_drag_hover(e, e.type == 'dragover'); });
$(this.gui_objects.filedrop).addClass('droptarget')
.bind('dragover dragleave', function(e){ return ref.file_drag_hover(e, e.type == 'dragover'); })
@@ -920,15 +922,9 @@ function rcube_webmail()
break;
case 'savedraft':
- var form = this.gui_objects.messageform, msgid;
-
// Reset the auto-save timer
clearTimeout(this.save_timer);
- // saving Drafts is disabled
- if (!form)
- break;
-
// compose form did not change
if (this.cmp_hash == this.compose_field_hash()) {
this.auto_save_start();
@@ -938,35 +934,17 @@ function rcube_webmail()
// re-set keep-alive timeout
this.start_keepalive();
- msgid = this.set_busy(true, 'savingmessage');
-
- form.target = "savetarget";
- form._draft.value = '1';
- form.action = this.add_url(form.action, '_unlock', msgid);
- form.submit();
+ this.submit_messageform(true);
break;
case 'send':
- if (!this.gui_objects.messageform)
- break;
-
if (!props.nocheck && !this.check_compose_input(command))
break;
// Reset the auto-save timer
clearTimeout(this.save_timer);
- // all checks passed, send message
- var lang = this.spellcheck_lang(),
- form = this.gui_objects.messageform,
- msgid = this.set_busy(true, 'sendingmessage');
-
- form.target = 'savetarget';
- form._draft.value = '';
- form.action = this.add_url(form.action, '_unlock', msgid);
- form.action = this.add_url(form.action, '_lang', lang);
- form.submit();
-
+ this.submit_messageform();
break;
case 'send-attachment':
@@ -3031,6 +3009,29 @@ function rcube_webmail()
.attr('autocomplete', 'off');
};
+ this.submit_messageform = function(draft)
+ {
+ var form = this.gui_objects.messageform;
+
+ if (!form)
+ return;
+
+ // all checks passed, send message
+ var msgid = this.set_busy(true, draft ? 'savingmessage' : 'sendingmessage'),
+ lang = this.spellcheck_lang(),
+ files = [];
+
+ // send files list
+ $('li', this.gui_objects.attachmentlist).each(function() { files.push(this.id.replace(/^rcmfile/, '')); });
+ $('input[name="_attachments"]', form).val(files.join());
+
+ form.target = 'savetarget';
+ form._draft.value = draft ? '1' : '';
+ form.action = this.add_url(form.action, '_unlock', msgid);
+ form.action = this.add_url(form.action, '_lang', lang);
+ form.submit();
+ };
+
this.compose_recipient_select = function(list)
{
this.enable_command('add-recipient', list.selection.length > 0);
@@ -4275,7 +4276,7 @@ function rcube_webmail()
if (!this.gui_objects.contactslist)
return false;
- var c, list = this.contact_list,
+ var c, col, list = this.contact_list,
row = document.createElement('tr');
row.id = 'rcmrow'+this.html_identifier(cid);
@@ -4715,11 +4716,11 @@ function rcube_webmail()
{
if (form && form.elements._photo.value) {
this.async_upload_form(form, 'upload-photo', function(e) {
- rcmail.set_busy(false, null, rcmail.photo_upload_id);
+ rcmail.set_busy(false, null, rcmail.file_upload_id);
});
// display upload indicator
- this.photo_upload_id = this.set_busy(true, 'uploading');
+ this.file_upload_id = this.set_busy(true, 'uploading');
}
};
@@ -4734,8 +4735,8 @@ function rcube_webmail()
this.photo_upload_end = function()
{
- this.set_busy(false, null, this.photo_upload_id);
- delete this.photo_upload_id;
+ this.set_busy(false, null, this.file_upload_id);
+ delete this.file_upload_id;
};
this.set_photo_actions = function(id)
@@ -5358,13 +5359,6 @@ function rcube_webmail()
}
};
- // enable/disable buttons for page shifting
- this.set_page_buttons = function()
- {
- this.enable_command('nextpage', 'lastpage', (this.env.pagecount > this.env.current_page));
- this.enable_command('previouspage', 'firstpage', (this.env.current_page > 1));
- };
-
// set event handlers on registered buttons
this.init_buttons = function()
{
@@ -5372,7 +5366,7 @@ function rcube_webmail()
if (typeof cmd !== 'string')
continue;
- for (var i=0; i< this.buttons[cmd].length; i++) {
+ for (var i=0; i<this.buttons[cmd].length; i++) {
init_button(cmd, this.buttons[cmd][i]);
}
}
@@ -5391,28 +5385,31 @@ function rcube_webmail()
button = a_buttons[n];
obj = document.getElementById(button.id);
+ if (!obj)
+ continue;
+
// get default/passive setting of the button
- if (obj && button.type == 'image' && !button.status) {
+ if (button.type == 'image' && !button.status) {
button.pas = obj._original_src ? obj._original_src : obj.src;
// respect PNG fix on IE browsers
if (obj.runtimeStyle && obj.runtimeStyle.filter && obj.runtimeStyle.filter.match(/src=['"]([^'"]+)['"]/))
button.pas = RegExp.$1;
}
- else if (obj && !button.status)
+ else if (!button.status)
button.pas = String(obj.className);
// set image according to button state
- if (obj && button.type == 'image' && button[state]) {
+ if (button.type == 'image' && button[state]) {
button.status = state;
obj.src = button[state];
}
// set class name according to button state
- else if (obj && button[state] !== undefined) {
+ else if (button[state] !== undefined) {
button.status = state;
obj.className = button[state];
}
// disable/enable input buttons
- if (obj && button.type=='input') {
+ if (button.type == 'input') {
button.status = state;
obj.disabled = !state;
}
@@ -5635,6 +5632,13 @@ function rcube_webmail()
this.messages = {};
};
+ // enable/disable buttons for page shifting
+ this.set_page_buttons = function()
+ {
+ this.enable_command('nextpage', 'lastpage', (this.env.pagecount > this.env.current_page));
+ this.enable_command('previouspage', 'firstpage', (this.env.current_page > 1));
+ };
+
// mark a mailbox as selected and set environment variable
this.select_folder = function(name, prefix, encode)
{
@@ -6168,6 +6172,10 @@ function rcube_webmail()
this.set_busy(false, null, lock);
request.abort();
+ // don't display error message on page unload (#1488547)
+ if (this.unload)
+ return;
+
if (request.status && errmsg)
this.display_message(this.get_label('servererror') + ' (' + errmsg + ')', 'error');
else if (status == 'timeout')
@@ -6204,7 +6212,7 @@ function rcube_webmail()
// have to do it this way for IE
// otherwise the form will be posted to a new window
if (document.all) {
- var html = '<iframe name="'+frame_name+'" src="program/blank.gif" style="width:0;height:0;visibility:hidden;"></iframe>';
+ var html = '<iframe name="'+frame_name+'" src="program/resources/blank.gif" style="width:0;height:0;visibility:hidden;"></iframe>';
document.body.insertAdjacentHTML('BeforeEnd', html);
}
else { // for standards-compilant browsers
@@ -6254,7 +6262,7 @@ function rcube_webmail()
// prepare multipart form data composition
var files = e.target.files || e.dataTransfer.files,
formdata = window.FormData ? new FormData() : null,
- fieldname = this.env.filedrop.fieldname || '_file',
+ fieldname = (this.env.filedrop.fieldname || '_file') + (this.env.filedrop.single ? '' : '[]'),
boundary = '------multipartformboundary' + (new Date).getTime(),
dashdash = '--', crlf = '\r\n',
multipart = dashdash + boundary + crlf;
@@ -6269,7 +6277,8 @@ function rcube_webmail()
content = '<span>' + (multiple ? ref.get_label('uploadingmany') : files[0].name) + '</span>';
// add to attachments list
- ref.add2attachment_list(ts, { name:'', html:content, classname:'uploading', complete:false });
+ if (!ref.add2attachment_list(ts, { name:'', html:content, classname:'uploading', complete:false }))
+ ref.file_upload_id = ref.set_busy(true, 'uploading');
// complete multipart content and post request
multipart += dashdash + boundary + dashdash + crlf;
@@ -6277,10 +6286,11 @@ function rcube_webmail()
$.ajax({
type: 'POST',
dataType: 'json',
- url: ref.url(ref.env.filedrop.action||'upload', { _id:ref.env.compose_id||'', _uploadid:ts, _remote:1 }),
+ url: ref.url(ref.env.filedrop.action||'upload', { _id:ref.env.compose_id||ref.env.cid||'', _uploadid:ts, _remote:1 }),
contentType: formdata ? false : 'multipart/form-data; boundary=' + boundary,
processData: false,
data: formdata || multipart,
+ headers: {'X-Roundcube-Request': ref.env.request_token},
beforeSend: function(xhr, s) { if (!formdata && xhr.sendAsBinary) xhr.send = xhr.sendAsBinary; },
success: function(data){ ref.http_response(data); },
error: function(o, status, err) { ref.http_error(o, status, err, null, 'attachment'); }
@@ -6289,7 +6299,7 @@ function rcube_webmail()
// get contents of all dropped files
var last = this.env.filedrop.single ? 0 : files.length - 1;
- for (var i=0, f; i <= last && (f = files[i]); i++) {
+ for (var j=0, i=0, f; j <= last && (f = files[i]); i++) {
if (!f.name) f.name = f.fileName;
if (!f.size) f.size = f.fileSize;
if (!f.type) f.type = 'application/octet-stream';
@@ -6306,8 +6316,8 @@ function rcube_webmail()
// do it the easy way with FormData (FF 4+, Chrome 5+, Safari 5+)
if (formdata) {
- formdata.append(fieldname + '[]', f);
- if (i == last)
+ formdata.append(fieldname, f);
+ if (j == last)
return submit_data();
}
// use FileReader supporetd by Firefox 3.6
@@ -6315,33 +6325,35 @@ function rcube_webmail()
var reader = new FileReader();
// closure to pass file properties to async callback function
- reader.onload = (function(file, i) {
+ reader.onload = (function(file, j) {
return function(e) {
- multipart += 'Content-Disposition: form-data; name="' + fieldname + '[]"';
+ multipart += 'Content-Disposition: form-data; name="' + fieldname + '"';
multipart += '; filename="' + (f.name_bin || file.name) + '"' + crlf;
multipart += 'Content-Length: ' + file.size + crlf;
multipart += 'Content-Type: ' + file.type + crlf + crlf;
multipart += e.target.result + crlf;
multipart += dashdash + boundary + crlf;
- if (i == last) // we're done, submit the data
+ if (j == last) // we're done, submit the data
return submit_data();
}
- })(f,i);
+ })(f,j);
reader.readAsBinaryString(f);
}
// Firefox 3
else if (f.getAsBinary) {
- multipart += 'Content-Disposition: form-data; name="' + fieldname + '[]"';
+ multipart += 'Content-Disposition: form-data; name="' + fieldname + '"';
multipart += '; filename="' + (f.name_bin || f.name) + '"' + crlf;
multipart += 'Content-Length: ' + f.size + crlf;
multipart += 'Content-Type: ' + f.type + crlf + crlf;
multipart += f.getAsBinary() + crlf;
multipart += dashdash + boundary +crlf;
- if (i == last)
+ if (j == last)
return submit_data();
}
+
+ j++;
}
};
@@ -6538,7 +6550,7 @@ function rcube_webmail()
img.onload = function() { rcmail.env.browser_capabilities.tif = 1; };
img.onerror = function() { rcmail.env.browser_capabilities.tif = 0; };
- img.src = 'program/blank.tif';
+ img.src = 'program/resources/blank.tif';
};
this.pdf_support_check = function()