mail/src/js/controller/account.js

56 lines
1.5 KiB
JavaScript
Raw Normal View History

2013-10-21 11:10:45 -04:00
define(function(require) {
'use strict';
var appController = require('js/app-controller'),
emailDao;
//
// Controller
//
var AccountCtrl = function($scope) {
emailDao = appController._emailDao;
//
// scope functions
//
$scope.exportKeyFile = function() {
emailDao._crypto.exportKeys(function(err, keys) {
2013-10-21 11:10:45 -04:00
if (err) {
console.error(err);
return;
}
2013-10-22 10:45:50 -04:00
var id = keys.keyId.substring(8, keys.keyId.length);
download(keys.publicKeyArmored + keys.privateKeyArmored, id + '.asc', 'text/plain');
2013-10-21 11:10:45 -04:00
});
};
//
// helper functions
//
function download(content, filename, contentType) {
contentType = contentType || 'application/octet-stream';
2013-10-22 08:48:38 -04:00
chrome.fileSystem.chooseEntry({
type: 'saveFile',
suggestedName: filename
}, function(file) {
if (!file) {
return;
}
file.createWriter(function(writer) {
writer.onerror = console.error;
writer.onwriteend = function() {};
2013-10-22 10:45:50 -04:00
writer.write(new Blob([content], {
type: contentType
}));
2013-10-22 08:48:38 -04:00
}, console.error);
2013-10-21 11:10:45 -04:00
});
}
};
return AccountCtrl;
});