1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-26 10:52:17 -05:00

removed backbone views

This commit is contained in:
Tankred Hase 2013-09-04 21:23:12 +02:00
parent cf8a12c75c
commit 6d3f7dcd47
8 changed files with 0 additions and 588 deletions

View File

@ -1,17 +0,0 @@
define(['jquery', 'underscore', 'backbone', 'js/app-config'], function($, _, Backbone, app) {
'use strict';
var AccountsView = Backbone.View.extend({
initialize: function() {
this.template = _.template(app.util.tpl.get('accounts'));
},
render: function() {
$(this.el).html(this.template());
return this;
}
});
return AccountsView;
});

View File

@ -1,191 +0,0 @@
define(['jquery', 'underscore', 'backbone', 'js/app-config'], function($, _, Backbone, app) {
'use strict';
var ComposeView = Backbone.View.extend({
initialize: function(args) {
var self = this;
this.template = _.template(app.util.tpl.get('compose'));
this.account = args.account;
this.folder = args.folder;
if (args.folder && args.messageId) {
// fetch reply-to email model
// post message to main window
app.util.postMessage('getEmail', {
folder: args.folder,
messageId: args.messageId
}, function(resArgs) {
var err = resArgs.err;
if (err) {
window.alert(JSON.stringify(err));
return;
}
// set mail to reply to
self.replyTo = resArgs.email;
args.callback(self);
});
} else {
args.callback(self);
}
},
render: function() {
var self = this,
page = $(this.el);
page.html(this.template());
// prefill fields for reply
if (this.replyTo) {
self.fillFields();
}
// handle file picker for attachments
page.find('#files').on('change', function(e) {
var files = e.target.files,
i, reader;
// check if files exist
if (!files || files.length < 1) {
return;
}
// init attachments array if non exists
if (!self._attachments) {
self._attachments = [];
}
function addAttachment(file) {
reader = new FileReader();
reader.onloadend = function(f) {
self._attachments.push({
fileName: file.name,
contentType: file.type,
binStr: f.target.result
});
};
reader.readAsBinaryString(file);
}
for (i = 0; i < files.length; i++) {
addAttachment(files[i]);
}
});
// handle back button
page.find('#backBtn').on('vmousedown', function(e) {
e.preventDefault();
self.goBackToLastPage();
});
// handle send button
page.find('#sendBtn').on('vmousedown', function() {
self.sendEmail();
});
return this;
},
fillFields: function() {
var page = $(this.el),
re = this.replyTo,
from = re.from[0],
subject = re.subject;
// fill recipient field
var replyToAddress = from.address;
page.find('#toInput').val(replyToAddress);
// fill subject
subject = 'Re: ' + ((subject) ? subject.replace('Re: ', '') : '');
page.find('#subjectInput').val(subject);
// fill text body
var body = '\n\n' + re.sentDate + ' ' + from.name + ' <' + from.address + '>\n';
var bodyRows = re.body.split('\n');
var isHtml = false;
_.each(bodyRows, function(row) {
if (row.indexOf('</') !== -1) {
isHtml = true;
}
body += (!isHtml) ? '> ' + row + '\n' : '';
});
page.find('#bodyTextarea').text(body);
},
/**
* Send an email via the email dao
*/
sendEmail: function() {
var self = this,
page = $(this.el);
$.mobile.loading('show', {
text: 'sending...',
textVisible: true
});
// validate recipients
var to = page.find('#toInput').val().replace(/\s/g, '').split(/[,;]/);
if (!to || to.length < 1) {
window.alert('Seperate recipients with a comma!');
return;
}
var email = {
to: [],
subject: page.find('#subjectInput').val(),
body: page.find('#bodyTextarea').val()
};
email.from = [{
name: '',
address: self.account
}];
to.forEach(function(address) {
email.to.push({
name: '',
address: address
});
});
// add attachments
email.attachments = self._attachments;
// post message to main window
app.util.postMessage('sendEmail', {
email: email
}, function(resArgs) {
var err = resArgs.err;
$.mobile.loading('hide');
if (err) {
window.alert(JSON.stringify(err));
return;
}
// break attachments reference from memory
delete self._attachments;
self.goBackToLastPage();
});
},
/**
* Go back to the last activity
* depending from where to compose dialog was opened
*/
goBackToLastPage: function() {
if (this.folder) {
window.location = '#accounts/' + this.account + '/folders/' + this.folder;
} else {
window.location = '#accounts/' + this.account + '/folders';
}
}
});
return ComposeView;
});

View File

@ -1,70 +0,0 @@
define(['jquery', 'underscore', 'backbone', 'js/app-config',
'js/view/folderlistitem-view'
], function($, _, Backbone, app, FolderListItemView) {
'use strict';
var FolderListView = Backbone.View.extend({
initialize: function() {
this.template = _.template(app.util.tpl.get('folderlist'));
},
render: function() {
var page = $(this.el);
page.html(this.template(this.options));
// change page for folder links on vmousedown instead of waiting on vmouseup
page.on('vmousedown', 'li a', function(e) {
e.preventDefault();
var href = $(e.currentTarget).attr('href');
window.location = href;
});
return this;
},
listFolder: function() {
var self = this,
page = $(this.el),
list = page.find('#folder-list'),
listItemArgs;
// show loading msg during init
$.mobile.loading('show', {
text: 'Fetching folders...',
textVisible: true,
theme: 'c'
});
// post message to main window
app.util.postMessage('listFolders', {}, function(resArgs) {
var err = resArgs.err;
if (err || !resArgs.folders) {
$.mobile.loading('hide');
window.alert('Error listing folders: ' + err.errMsg);
return;
}
// clear list
list.html('');
// append folder to list
resArgs.folders.forEach(function(folder) {
listItemArgs = {
account: self.options.account,
model: folder
};
list.append(new FolderListItemView(listItemArgs).render().el);
});
// refresh list view
list.listview('refresh');
$.mobile.loading('hide');
});
}
});
return FolderListView;
});

View File

@ -1,22 +0,0 @@
define(['jquery', 'underscore', 'backbone', 'js/app-config'], function($, _, Backbone, app) {
'use strict';
var FolderListItemView = Backbone.View.extend({
tagName: "li",
initialize: function() {
this.template = _.template(app.util.tpl.get('folderlistitem'));
},
render: function() {
var params = this.model;
params.account = this.options.account;
$(this.el).html(this.template(params));
return this;
}
});
return FolderListItemView;
});

View File

@ -1,55 +0,0 @@
define(['jquery', 'underscore', 'backbone', 'js/app-config'], function($, _, Backbone, app) {
'use strict';
var LoginView = Backbone.View.extend({
initialize: function() {
this.template = _.template(app.util.tpl.get('login'));
},
render: function() {
var self = this,
page = $(this.el);
page.html(this.template());
page.attr('data-theme', 'a');
page.find('#loginBtn').on('vmousedown', function() {
self.login();
});
return this;
},
login: function() {
var page = $(this.el),
userId = page.find('#userId').val(),
password = page.find('#password').val();
// show loading msg during init
$.mobile.loading('show', {
text: 'Unlocking...',
textVisible: true,
theme: 'c'
});
// post message to main window
app.util.postMessage('login', {
userId: userId,
password: password
}, function(resArgs) {
var err = resArgs.err;
$.mobile.loading('hide');
if (err) {
window.alert(err.errMsg);
return;
}
window.location = '#accounts/' + resArgs.userId + '/folders';
});
}
});
return LoginView;
});

View File

@ -1,109 +0,0 @@
define(['jquery', 'underscore', 'backbone', 'js/app-config',
'js/view/messagelistitem-view'
], function($, _, Backbone, app, MessageListItemView) {
'use strict';
var MessageListView = Backbone.View.extend({
initialize: function(args) {
this.template = _.template(app.util.tpl.get('messagelist'));
this.folder = args.folder;
},
render: function() {
var self = this,
page = $(this.el);
page.html(this.template(this.options));
page.find('#refreshBtn').on('vmousedown', function() {
self.syncFolder();
});
return this;
},
/**
* Synchronize emails from the cloud
*/
syncFolder: function() {
var self = this;
$.mobile.loading('show', {
text: 'Syncing...',
textVisible: true
});
// post message to main window
app.util.postMessage('syncEmails', {
folder: self.folder
}, function(resArgs) {
var err = resArgs.err;
$.mobile.loading('hide');
// check for error
if (err) {
window.alert('Syncing failed!');
return;
}
// read local storage and add to list view
self.loadItems();
});
},
/**
* Load items from local storage
*/
loadItems: function() {
var self = this,
page = $(this.el),
list = page.find('#message-list'),
listItemArgs, i, email;
$.mobile.loading('show', {
text: 'decrypting...',
textVisible: true
});
// post message to main window
app.util.postMessage('listEmails', {
folder: self.folder,
offset: -10,
num: 0
}, function(resArgs) {
var err = resArgs.err;
var emails = resArgs.emails;
// check for error
if (err) {
$.mobile.loading('hide');
window.alert('Loading items from storage failed!');
return;
}
// clear list
list.html('');
// append items to list in reverse order so mails with the most recent date will be displayed first
for (i = 0; i < emails.length; i++) {
email = emails[i];
listItemArgs = {
account: self.options.account,
folder: self.folder,
model: email
};
list.append(new MessageListItemView(listItemArgs).render().el);
}
// refresh list view
list.listview('refresh');
$.mobile.loading('hide');
});
}
});
return MessageListView;
});

View File

@ -1,29 +0,0 @@
define(['jquery', 'underscore', 'backbone', 'js/app-config'], function($, _, Backbone, app) {
'use strict';
var MessageListItemView = Backbone.View.extend({
tagName: "li",
initialize: function() {
this.template = _.template(app.util.tpl.get('messagelistitem'));
},
render: function() {
var params = this.model;
params.account = this.options.account;
params.folder = this.options.folder;
params.id = encodeURIComponent(params.id);
// var util = new cryptoLib.Util(window, null);
// var date = util.parseDate(params.sentDate);
// params.displayDate = date.getDate() + '.' + (date.getMonth() + 1) + '. ' + date.getHours() + ':' + date.getMinutes();
params.displayDate = params.sentDate;
$(this.el).html(this.template(params));
return this;
}
});
return MessageListItemView;
});

View File

@ -1,95 +0,0 @@
define(['jquery', 'underscore', 'backbone', 'js/app-config'], function($, _, Backbone, app) {
'use strict';
var ReadView = Backbone.View.extend({
initialize: function(args) {
var self = this;
this.template = _.template(app.util.tpl.get('read'));
this.account = args.account;
this.folder = args.folder;
app.util.postMessage('getEmail', {
folder: args.folder,
messageId: args.messageId
}, function(resArgs) {
var err = resArgs.err;
if (err) {
window.alert(JSON.stringify(err));
return;
}
// set mail to reply to
self.model = resArgs.email;
args.callback(self);
});
},
render: function() {
var params = this.model;
params.account = this.account;
params.folder = this.folder;
params.id = encodeURIComponent(params.id);
$(this.el).html(this.template(params));
this.renderBody();
// set download link for attachment button
this.parseAttachments();
return this;
},
parseAttachments: function() {
var attachments = this.model.attachments;
if (!attachments || attachments.length < 1) {
// remove link if no attachments are present
$(this.el).find('#attachmentItem').remove();
return;
}
var attmt = attachments[0];
var blob = new Blob([attmt.uint8Array], {
type: attmt.contentType
});
var url = window.URL.createObjectURL(blob);
// set download link
$(this.el).find('#attachmentBtn').attr({
href: url,
download: attmt.fileName
}).text(attmt.fileName);
},
renderBody: function(tryHtml) {
var page = $(this.el),
emailBody = this.model.body;
if (!tryHtml && emailBody.indexOf('</') === -1) {
// render text email
page.find('#bodyItem').html('<textarea></textarea>');
page.find('#bodyItem textarea').text(emailBody);
} else if (tryHtml && emailBody.indexOf('</') !== -1) {
// render html email inside a sandboxed iframe
var iframe = page.find('#mailContentFrame');
iframe.load(function() {
// set listener for the answering call, which return the document height
window.onmessage = function(e) {
// resize
var newheight = e.data;
//var newwidth = iframeDoc.body.scrollWidth;
iframe[0].height = (newheight) + 'px';
//iframe[0].width = (newwidth) + 'px';
};
// send email body to content frame
document.getElementById('mailContentFrame').contentWindow.postMessage(emailBody, '*');
});
}
}
});
return ReadView;
});