2013-09-04 15:01:32 -04:00
|
|
|
define(function(require) {
|
2013-09-04 12:39:26 -04:00
|
|
|
'use strict';
|
|
|
|
|
2013-09-05 04:59:55 -04:00
|
|
|
var appController = require('js/app-controller'),
|
|
|
|
moment = require('moment');
|
2013-09-04 12:39:26 -04:00
|
|
|
|
|
|
|
var MessageListCtrl = function($scope) {
|
|
|
|
$scope.folderName = 'Inbox';
|
|
|
|
|
|
|
|
$scope.select = function(email) {
|
|
|
|
$scope.selected = email;
|
|
|
|
};
|
2013-09-04 15:01:32 -04:00
|
|
|
|
2013-09-05 04:59:55 -04:00
|
|
|
fetchList(function(emails) {
|
2013-09-04 15:01:32 -04:00
|
|
|
$scope.emails = emails;
|
|
|
|
$scope.$apply();
|
|
|
|
});
|
2013-09-04 12:39:26 -04:00
|
|
|
};
|
|
|
|
|
2013-09-04 15:01:32 -04:00
|
|
|
function fetchList(callback) {
|
|
|
|
appController.fetchOAuthToken('passphrase', function(err) {
|
|
|
|
if (err) {
|
|
|
|
console.log(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
appController._emailDao.imapListMessages({
|
|
|
|
folder: 'INBOX',
|
|
|
|
offset: -6,
|
|
|
|
num: 0
|
2013-09-05 04:59:55 -04:00
|
|
|
}, function(err, emails) {
|
|
|
|
if (err) {
|
|
|
|
console.log(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
emails.forEach(function(email) {
|
|
|
|
// set display date
|
|
|
|
email.displayDate = moment(email.sentDate).format('DD.MM.YY');
|
|
|
|
});
|
|
|
|
|
|
|
|
callback(emails);
|
|
|
|
});
|
2013-09-04 15:01:32 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-09-04 12:39:26 -04:00
|
|
|
return MessageListCtrl;
|
|
|
|
});
|