mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-09-13 01:18:04 +00:00
(js) New file structure for Angular modules
JavaScript files are now merged by the 'js' Grunt task.
This commit is contained in:
+3
-3
@@ -31,7 +31,7 @@
|
||||
* @desc The factory we'll use to register with Angular
|
||||
* @returns the Account constructor
|
||||
*/
|
||||
Account.$factory = ['$q', '$timeout', '$log', 'sgSettings', 'sgResource', 'sgMailbox', 'sgMessage', function($q, $timeout, $log, Settings, Resource, Mailbox, Message) {
|
||||
Account.$factory = ['$q', '$timeout', '$log', 'sgSettings', 'Resource', 'Mailbox', 'Message', function($q, $timeout, $log, Settings, Resource, Mailbox, Message) {
|
||||
angular.extend(Account, {
|
||||
$q: $q,
|
||||
$timeout: $timeout,
|
||||
@@ -46,7 +46,7 @@
|
||||
|
||||
/* Factory registration in Angular module */
|
||||
angular.module('SOGo.MailerUI')
|
||||
.factory('sgAccount', Account.$factory);
|
||||
.factory('Account', Account.$factory);
|
||||
|
||||
/**
|
||||
* @memberof Account
|
||||
@@ -70,7 +70,7 @@
|
||||
* @function $getMailboxes
|
||||
* @memberof Account.prototype
|
||||
* @desc Fetch the list of mailboxes for the current account.
|
||||
* @param {object} [options] - force a reload
|
||||
* @param {object} [options] - force a reload by setting 'reload' to true
|
||||
* @returns a promise of the HTTP operation
|
||||
*/
|
||||
Account.prototype.$getMailboxes = function(options) {
|
||||
+8
-3
@@ -9,6 +9,7 @@
|
||||
* @param {object} futureMailboxData - either an object literal or a promise
|
||||
*/
|
||||
function Mailbox(account, futureMailboxData) {
|
||||
this.$isLoading = false;
|
||||
this.$account = account;
|
||||
// Data is immediately available
|
||||
if (typeof futureMailboxData.then !== 'function') {
|
||||
@@ -37,7 +38,7 @@
|
||||
* @desc The factory we'll use to register with Angular
|
||||
* @returns the Mailbox constructor
|
||||
*/
|
||||
Mailbox.$factory = ['$q', '$timeout', '$log', 'sgSettings', 'sgResource', 'sgMessage', 'sgMailbox_PRELOAD', function($q, $timeout, $log, Settings, Resource, Message, PRELOAD) {
|
||||
Mailbox.$factory = ['$q', '$timeout', '$log', 'sgSettings', 'Resource', 'Message', 'sgMailbox_PRELOAD', function($q, $timeout, $log, Settings, Resource, Message, PRELOAD) {
|
||||
angular.extend(Mailbox, {
|
||||
$q: $q,
|
||||
$timeout: $timeout,
|
||||
@@ -61,7 +62,7 @@
|
||||
SIZE: 100
|
||||
})
|
||||
/* Factory registration in Angular module */
|
||||
.factory('sgMailbox', Mailbox.$factory);
|
||||
.factory('Mailbox', Mailbox.$factory);
|
||||
|
||||
/**
|
||||
* @memberof Mailbox
|
||||
@@ -180,6 +181,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
this.$isLoading = true;
|
||||
futureMailboxData = Mailbox.$$resource.post(this.id, 'view', options);
|
||||
|
||||
return this.$unwrap(futureMailboxData);
|
||||
@@ -388,7 +390,7 @@
|
||||
|
||||
/**
|
||||
* @function $newMailbox
|
||||
* @memberof Account.prototype
|
||||
* @memberof Mailbox.prototype
|
||||
* @desc Create a new mailbox on the server and refresh the list of mailboxes.
|
||||
* @returns a promise of the HTTP operations
|
||||
*/
|
||||
@@ -435,6 +437,8 @@
|
||||
_this.uidsMap = {};
|
||||
|
||||
if (_this.uids) {
|
||||
Mailbox.$log.debug('unwrapping ' + data.uids.length + ' messages');
|
||||
|
||||
// First entry of 'headers' are keys
|
||||
headers = _.invoke(_this.headers[0], 'toLowerCase');
|
||||
_this.headers.splice(0, 1);
|
||||
@@ -469,6 +473,7 @@
|
||||
});
|
||||
}
|
||||
Mailbox.$log.debug('mailbox ' + _this.id + ' ready');
|
||||
_this.$isLoading = false;
|
||||
deferred.resolve(_this.$messages);
|
||||
});
|
||||
}, function(data) {
|
||||
@@ -0,0 +1,20 @@
|
||||
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @ngInject
|
||||
*/
|
||||
MailboxController.$inject = ['$scope', '$rootScope', '$stateParams', 'stateAccount', 'stateMailbox', '$timeout', 'sgFocus', 'Dialog', 'Account', 'Mailbox'];
|
||||
function MailboxController($scope, $rootScope, $stateParams, stateAccount, stateMailbox, $timeout, focus, Dialog, Account, Mailbox) {
|
||||
$scope.account = stateAccount;
|
||||
$rootScope.mailbox = stateMailbox;
|
||||
$rootScope.currentFolder = stateMailbox;
|
||||
}
|
||||
|
||||
angular
|
||||
.module('SOGo.MailerUI')
|
||||
.controller('MailboxController', MailboxController);
|
||||
})();
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @ngInject
|
||||
*/
|
||||
MailboxesController.$inject = ['$scope', '$rootScope', '$stateParams', '$state', '$timeout', 'sgFocus', 'encodeUriFilter', 'Dialog', 'sgSettings', 'Account', 'Mailbox', 'stateAccounts'];
|
||||
function MailboxesController($scope, $rootScope, $stateParams, $state, $timeout, focus, encodeUriFilter, Dialog, Settings, Account, Mailbox, stateAccounts) {
|
||||
$scope.activeUser = Settings.activeUser;
|
||||
$scope.accounts = stateAccounts;
|
||||
|
||||
$scope.newFolder = function(parentFolder) {
|
||||
Dialog.prompt(l('New folder'),
|
||||
l('Enter the new name of your folder :'))
|
||||
.then(function(name) {
|
||||
parentFolder.$newMailbox(parentFolder.id, name);
|
||||
});
|
||||
};
|
||||
$scope.editFolder = function(folder) {
|
||||
$scope.editMode = folder.path;
|
||||
focus('mailboxName_' + folder.path);
|
||||
};
|
||||
$scope.revertEditing = function(folder) {
|
||||
folder.$reset();
|
||||
$scope.editMode = false;
|
||||
};
|
||||
$scope.selectFolder = function(account, folder) {
|
||||
if ($scope.editMode == folder.path)
|
||||
return;
|
||||
$rootScope.currentFolder = folder;
|
||||
$scope.editMode = false;
|
||||
$rootScope.message = null;
|
||||
$state.go('mail.account.mailbox', { accountId: account.id, mailboxId: encodeUriFilter(folder.path) });
|
||||
};
|
||||
$scope.saveFolder = function(folder) {
|
||||
folder.$rename();
|
||||
};
|
||||
$scope.exportMails = function() {
|
||||
window.location.href = ApplicationBaseURL + '/' + $rootScope.currentFolder.id + '/exportFolder';
|
||||
};
|
||||
$scope.confirmDelete = function(folder) {
|
||||
if (folder.path != $scope.currentFolder.path) {
|
||||
// Counter the possibility to click on the "hidden" secondary button
|
||||
$scope.selectFolder(folder.$account, folder);
|
||||
return;
|
||||
}
|
||||
Dialog.confirm(l('Confirmation'), l('Do you really want to move this folder into the trash ?'))
|
||||
.then(function() {
|
||||
folder.$delete()
|
||||
.then(function() {
|
||||
$rootScope.currentFolder = null;
|
||||
$state.go('mail');
|
||||
}, function(data, status) {
|
||||
Dialog.alert(l('An error occured while deleting the mailbox "%{0}".', folder.name),
|
||||
l(data.error));
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
if ($state.current.name == 'mail' && $scope.accounts.length > 0 && $scope.accounts[0].$mailboxes.length > 0) {
|
||||
// Redirect to first mailbox of first account if no mailbox is selected
|
||||
var account = $scope.accounts[0];
|
||||
var mailbox = account.$mailboxes[0];
|
||||
$state.go('mail.account.mailbox', { accountId: account.id, mailboxId: encodeUriFilter(mailbox.path) });
|
||||
}
|
||||
}
|
||||
|
||||
angular
|
||||
.module('SOGo.MailerUI')
|
||||
.controller('MailboxesController', MailboxesController);
|
||||
})();
|
||||
|
||||
+2
-2
@@ -34,7 +34,7 @@
|
||||
* @desc The factory we'll use to register with Angular
|
||||
* @returns the Message constructor
|
||||
*/
|
||||
Message.$factory = ['$q', '$timeout', '$log', '$sce', 'sgSettings', 'sgResource', function($q, $timeout, $log, $sce, Settings, Resource) {
|
||||
Message.$factory = ['$q', '$timeout', '$log', '$sce', 'sgSettings', 'Resource', function($q, $timeout, $log, $sce, Settings, Resource) {
|
||||
angular.extend(Message, {
|
||||
$q: $q,
|
||||
$timeout: $timeout,
|
||||
@@ -52,7 +52,7 @@
|
||||
|
||||
/* Factory registration in Angular module */
|
||||
angular.module('SOGo.MailerUI')
|
||||
.factory('sgMessage', Message.$factory);
|
||||
.factory('Message', Message.$factory);
|
||||
|
||||
/**
|
||||
* @function filterTags
|
||||
@@ -0,0 +1,40 @@
|
||||
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @ngInject
|
||||
*/
|
||||
MessageController.$inject = ['$scope', '$rootScope', '$stateParams', '$state', 'stateAccount', 'stateMailbox', 'stateMessage', '$timeout', 'encodeUriFilter', 'sgFocus', 'Dialog', 'Account', 'Mailbox'];
|
||||
function MessageController($scope, $rootScope, $stateParams, $state, stateAccount, stateMailbox, stateMessage, $timeout, encodeUriFilter, focus, Dialog, Account, Mailbox) {
|
||||
$rootScope.message = stateMessage;
|
||||
$scope.tags = {};
|
||||
$scope.addOrRemoveTag = function(operation, tag) {
|
||||
if (tag) {
|
||||
stateMessage.$addOrRemoveTag(operation, tag);
|
||||
}
|
||||
};
|
||||
$scope.markAsFlaggedOrUnflagged = function() {
|
||||
var operation = (stateMessage.isflagged ? 'remove' : 'add');
|
||||
stateMessage.$markAsFlaggedOrUnflagged(operation).then(function() {
|
||||
stateMessage.isflagged = !stateMessage.isflagged;
|
||||
});
|
||||
};
|
||||
$scope.doDelete = function() {
|
||||
stateMailbox.$deleteMessages([stateMessage.uid]).then(function() {
|
||||
// Remove card from list of addressbook
|
||||
stateMailbox.$messages = _.reject(stateMailbox.$messages, function(o) {
|
||||
return o.uid == stateMessage.uid;
|
||||
});
|
||||
// Remove card object from scope
|
||||
$rootScope.message = null;
|
||||
$state.go('mail.account.mailbox', { accountId: stateAccount.id, mailboxId: encodeUriFilter(stateMailbox.path) });
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
angular
|
||||
.module('SOGo.MailerUI')
|
||||
.controller('MessageController', MessageController);
|
||||
})();
|
||||
@@ -0,0 +1,87 @@
|
||||
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @ngInject
|
||||
*/
|
||||
MessageEditorController.$inject = ['$scope', '$rootScope', '$stateParams', '$state', '$q', 'FileUploader', 'stateAccounts', 'stateMessage', '$timeout', 'encodeUriFilter', 'sgFocus', 'Dialog', 'Account', 'Mailbox', 'AddressBook'];
|
||||
function MessageEditorController($scope, $rootScope, $stateParams, $state, $q, FileUploader, stateAccounts, stateMessage, $timeout, encodeUriFilter, focus, Dialog, Account, Mailbox, AddressBook) {
|
||||
$scope.autocomplete = {to: {}, cc: {}, bcc: {}};
|
||||
$scope.hideCc = true;
|
||||
$scope.hideBcc = true;
|
||||
$scope.hideAttachments = true;
|
||||
if ($stateParams.actionName == 'reply') {
|
||||
stateMessage.$reply().then(function(msgObject) {
|
||||
console.debug("foo");
|
||||
|
||||
$scope.message = msgObject;
|
||||
$scope.hideCc = (!msgObject.editable.cc || msgObject.editable.cc.length == 0);
|
||||
$scope.hideBcc = (!msgObject.editable.bcc || msgObject.editable.bcc.length == 0);
|
||||
$scope.hideAttachments = true;
|
||||
});
|
||||
}
|
||||
else if ($stateParams.actionName == 'replyall') {
|
||||
stateMessage.$replyAll().then(function(msgObject) {
|
||||
$scope.message = msgObject;
|
||||
$scope.hideCc = (!msgObject.editable.cc || msgObject.editable.cc.length == 0);
|
||||
$scope.hideBcc = (!msgObject.editable.bcc || msgObject.editable.bcc.length == 0);
|
||||
$scope.hideAttachments = true;
|
||||
});
|
||||
}
|
||||
else if ($stateParams.actionName == 'forward') {
|
||||
stateMessage.$forward().then(function(msgObject) {
|
||||
$scope.message = msgObject;
|
||||
$scope.hideCc = true;
|
||||
$scope.hideBcc = true;
|
||||
$scope.hideAttachments = (!msgObject.editable.attachmentAttrs || msgObject.editable.attachmentAttrs.length == 0);
|
||||
});
|
||||
}
|
||||
else if (angular.isDefined(stateMessage)) {
|
||||
$scope.message = stateMessage;
|
||||
}
|
||||
$scope.identities = _.pluck(_.flatten(_.pluck(stateAccounts, 'identities')), 'full');
|
||||
$scope.cancel = function() {
|
||||
if ($scope.mailbox)
|
||||
$state.go('mail.account.mailbox', { accountId: $scope.mailbox.$account.id, mailboxId: encodeUriFilter($scope.mailbox.path) });
|
||||
else
|
||||
$state.go('mail');
|
||||
};
|
||||
$scope.send = function(message) {
|
||||
message.$send().then(function(data) {
|
||||
$rootScope.message = null;
|
||||
$state.go('mail');
|
||||
}, function(data) {
|
||||
console.debug('failure ' + JSON.stringify(data, undefined, 2));
|
||||
});
|
||||
};
|
||||
$scope.userFilter = function($query) {
|
||||
var deferred = $q.defer();
|
||||
AddressBook.$filterAll($query).then(function(results) {
|
||||
deferred.resolve(_.invoke(results, '$shortFormat', $query));
|
||||
});
|
||||
return deferred.promise;
|
||||
};
|
||||
$scope.uploader = new FileUploader({
|
||||
url: stateMessage.$absolutePath({asDraft: true}) + '/save',
|
||||
autoUpload: true,
|
||||
alias: 'attachments',
|
||||
onProgressItem: function(item, progress) {
|
||||
console.debug(item); console.debug(progress);
|
||||
},
|
||||
onSuccessItem: function(item, response, status, headers) {
|
||||
stateMessage.$setUID(response.uid);
|
||||
stateMessage.$reload();
|
||||
console.debug(item); console.debug('success = ' + JSON.stringify(response, undefined, 2));
|
||||
},
|
||||
onErrorItem: function(item, response, status, headers) {
|
||||
console.debug(item); console.debug('error = ' + JSON.stringify(response, undefined, 2));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
angular
|
||||
.module('SOGo.MailerUI')
|
||||
.controller('MessageEditorController', MessageEditorController);
|
||||
})();
|
||||
Reference in New Issue
Block a user