mail/js/routecontroller.js

169 строки
4.9 KiB
JavaScript
Исходник Обычный вид История

/**
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
*
* Mail
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
define(function(require) {
'use strict';
var _ = require('underscore');
var Backbone = require('backbone');
var Radio = require('radio');
var FolderController = require('controller/foldercontroller');
/**
* @class RoutingController
*/
var RoutingController = function(accounts) {
this.initialize(accounts);
};
RoutingController.prototype = {
accounts: undefined,
initialize: function(accounts) {
this.accounts = accounts;
Radio.navigation.on('folder', _.bind(this.showFolder, this));
Radio.navigation.on('search', _.bind(this.searchFolder, this));
Radio.navigation.on('setup', _.bind(this.showSetup, this));
add aliases feature add aliases feature add aliases feature mapper entity service and controller for aliases comments and fixes minor bug fix minor changes aliases js service, database update and some security fixes minor fixes for saving and loading aliases send mail from composer using alias small fixes fix most test, delete alias work, better ui set an alias name with alias id using alias name when sending email works big fixes big fixes reply composer using aliases bug fixes and aliases collection minor bug fixes minor fix radio for aliases controller and service fix for when refrshing settings page fix email length in the database [tx-robot] updated from transifex change to secure connection remove secure http: false [tx-robot] updated from transifex Correct return for getFolderById - fixes #1514 account !== folder fetch UIDs and DATEs of all messages and do the pagination client side use search strategy only if SORT is not supported update changelog for 0.5.2 Update composerlock to https remove more message button is obsolete with infinite scroll [tx-robot] updated from transifex [tx-robot] updated from transifex [tx-robot] updated from transifex refactor message 'load' event parameters messagecontent -> foldercontent pass account/folder via constructor also use the new collection when refreshing inject messages collection Fix jscs errors sync karma require config with runtime require config open first mailbox when clicking the account's email address fix jscs error update grunt 0.5.3 version bump update/unify license headers use underscore to debounce search filters; do not re-search the same term remove obsolete folder reset event + event handler smoother transition when adding another account remove user id from alias table and js bug fix and optimization add new keyboard channel and port existing key listener allow navigation with j, k allow left/right arrow to switch messages use 'mail' instead of 'Mail' for bower to prevent warning merge conflict resolve squash and rebase commits fix AccountsControllerTest::testIndex travis js fix alias collection update adding aliases collection and bug fixes big fixes show you when mail is sent to an alias or email select current account as default in composer fix for selecting default account on composer fix grunt issues fixes and improvments remove old code that prevented selecting default account on composer ui improvment
2016-06-08 11:32:30 +03:00
Radio.navigation.on('accountsettings', _.bind(this.showAccountSettings, this));
},
_navigate: function(route, options) {
options = options || {};
Backbone.history.navigate(route, options);
},
/**
* Handle mailto links
*
* @returns {boolean} whether the composer has been shown
*/
_handleMailto: function(params) {
var composerOptions = {};
params = params.split('&');
_.each(params, function(param) {
param = param.split('=');
var key = param[0];
var value = param[1];
value = decodeURIComponent((value).replace(/\+/g, '%20'));
switch (key) {
case 'mailto':
case 'to':
composerOptions.to = value;
break;
case 'cc':
composerOptions.cc = value;
break;
case 'bcc':
composerOptions.bcc = value;
break;
case 'subject':
composerOptions.subject = value;
break;
case 'body':
composerOptions.body = value;
break;
}
});
this.default();
Radio.ui.trigger('composer:show', composerOptions);
},
default: function() {
this._navigate('');
var _this = this;
if (this.accounts.isEmpty()) {
// No account configured -> show setup
_this.showSetup();
return;
}
// Show first folder of first account
var firstAccount = this.accounts.at(0);
2016-09-21 00:33:10 +03:00
var firstFolder = firstAccount.folders.at(0);
_this.showFolder(firstAccount.get('accountId'), firstFolder.get('id'));
},
showFolder: function(accountId, folderId, noSelect) {
this._navigate('accounts/' + accountId + '/folders/' + folderId);
var _this = this;
var account = this.accounts.get(accountId);
if (_.isUndefined(account)) {
// Unknown account id -> redirect
Radio.ui.trigger('error:show', t('mail', 'Invalid account'));
_this.default();
return;
}
var folder = account.getFolderById(folderId);
if (_.isUndefined(folder)) {
2016-09-21 00:33:10 +03:00
folder = account.folders.at(0);
Radio.ui.trigger('error:show', t('mail', 'Invalid folder'));
this._navigate('accounts/' + accountId + '/folders/' + folder.get('id'));
}
FolderController.showFolder(account, folder, noSelect);
},
searchFolder: function(accountId, folderId, query) {
if (!query || query === '') {
this.showFolder(accountId, folderId);
return;
}
this._navigate('accounts/' + accountId + '/folders/' + folderId + '/search/' + query);
var account = this.accounts.get(accountId);
if (_.isUndefined(account)) {
// Unknown account id -> redirect
Radio.ui.trigger('error:show', t('mail', 'Invalid account'));
this.default();
return;
}
var folder = account.getFolderById(folderId);
if (_.isUndefined(folder)) {
2016-09-21 00:33:10 +03:00
folder = account.folders.at(0);
Radio.ui.trigger('error:show', t('mail', 'Invalid folder'));
this._navigate('accounts/' + accountId + '/folders/' + folder.get('id'));
}
FolderController.searchFolder(account, folder, query);
},
mailTo: function(params) {
this._handleMailto(params);
},
showSetup: function() {
this._navigate('setup');
Radio.ui.trigger('composer:leave');
Radio.ui.trigger('navigation:hide');
Radio.ui.trigger('setup:show');
add aliases feature add aliases feature add aliases feature mapper entity service and controller for aliases comments and fixes minor bug fix minor changes aliases js service, database update and some security fixes minor fixes for saving and loading aliases send mail from composer using alias small fixes fix most test, delete alias work, better ui set an alias name with alias id using alias name when sending email works big fixes big fixes reply composer using aliases bug fixes and aliases collection minor bug fixes minor fix radio for aliases controller and service fix for when refrshing settings page fix email length in the database [tx-robot] updated from transifex change to secure connection remove secure http: false [tx-robot] updated from transifex Correct return for getFolderById - fixes #1514 account !== folder fetch UIDs and DATEs of all messages and do the pagination client side use search strategy only if SORT is not supported update changelog for 0.5.2 Update composerlock to https remove more message button is obsolete with infinite scroll [tx-robot] updated from transifex [tx-robot] updated from transifex [tx-robot] updated from transifex refactor message 'load' event parameters messagecontent -> foldercontent pass account/folder via constructor also use the new collection when refreshing inject messages collection Fix jscs errors sync karma require config with runtime require config open first mailbox when clicking the account's email address fix jscs error update grunt 0.5.3 version bump update/unify license headers use underscore to debounce search filters; do not re-search the same term remove obsolete folder reset event + event handler smoother transition when adding another account remove user id from alias table and js bug fix and optimization add new keyboard channel and port existing key listener allow navigation with j, k allow left/right arrow to switch messages use 'mail' instead of 'Mail' for bower to prevent warning merge conflict resolve squash and rebase commits fix AccountsControllerTest::testIndex travis js fix alias collection update adding aliases collection and bug fixes big fixes show you when mail is sent to an alias or email select current account as default in composer fix for selecting default account on composer fix grunt issues fixes and improvments remove old code that prevented selecting default account on composer ui improvment
2016-06-08 11:32:30 +03:00
},
showAccountSettings: function(accountId) {
this._navigate('accounts/' + accountId + '/settings');
var account = this.accounts.get(accountId);
if (_.isUndefined(account)) {
// Unknown account id -> redirect
Radio.ui.trigger('error:show', t('mail', 'Invalid account'));
this.default();
return;
}
Radio.ui.trigger('composer:leave');
Radio.ui.trigger('navigation:hide');
Radio.ui.trigger('accountsettings:show', account);
}
};
return RoutingController;
});