Commit 703e1d44 authored by Juorder Gonzalez's avatar Juorder Gonzalez Committed by GitHub

Merge pull request #223 from ZBoxApp/issues_beta_v1

add functions to edit preferences about domain, set size of attachmen…
parents bdc78891 8700407c
module.exports = {"main":{"js":"/976919bundle.js"}}
\ No newline at end of file
module.exports = {"main":{"js":"/454009bundle.js"}}
\ No newline at end of file
......@@ -37,7 +37,6 @@ export default class DistributionLists extends React.Component {
this.onCancelOwner = this.onCancelOwner.bind(this);
this.onExportMembers = this.onExportMembers.bind(this);
this.onExportAllowers = this.onExportAllowers.bind(this);
this.makeRequest = this.makeRequest.bind(this);
this.domain = null;
this.isGlobalAdmin = UserStore.isGlobalAdmin();
......@@ -63,54 +62,6 @@ export default class DistributionLists extends React.Component {
Utils.exportAsCSV(data, 'allowers', title, true);
}
makeRequest(response, dl, resolve, store) {
const keys = Object.keys(response).sort();
const item = keys[0];
const res = store || {};
const action = item.match(/(remove|add)/gi);
if (action) {
var element = response[item];
if (element && element.length) {
const pop = element.pop();
const target = typeof pop === 'object' ? pop.name || pop.id : pop;
const label = action[0] === 'remove' ? 'eliminar' : 'agregar';
return dl[item](target, (er, success) => {
if (success) {
if (res.completed) {
res.completed.push({
action: label,
target
});
} else {
res.completed = [{
action: label,
target
}];
}
const api = success.api ? success : dl;
return this.makeRequest(response, api, resolve, res);
}
er.action = label;
er.target = target;
if (res.error) {
res.error.push(er);
} else {
res.error = [er];
}
return this.makeRequest(response, dl, resolve, res);
});
} else {
Reflect.deleteProperty(response, item);
return this.makeRequest(response, dl, resolve, res);
}
}
res.data = dl;
return resolve(res);
}
getDistributionLists() {
const domain = this.isStoreEnabled ? DomainStore.getCurrent() : null;
const id = this.props.params.id;
......@@ -175,7 +126,7 @@ export default class DistributionLists extends React.Component {
onSubmitActions(response) {
return new Promise((resolve) => {
return this.makeRequest(response, this.state.distributionsList, resolve);
return Utils.makeRequest(response, this.state.distributionsList, resolve);
}).then((data) => {
const errors = [];
if (data.error) {
......
......@@ -4,6 +4,7 @@
import $ from 'jquery';
import React from 'react';
import {browserHistory} from 'react-router';
import Promise from 'bluebird';
import MessageBar from '../message_bar.jsx';
import PageInfo from '../page_info.jsx';
......@@ -19,6 +20,7 @@ import AntiSpamComponent from './antispam.jsx';
import ZonaDNS from './domain_admin_dns.jsx';
import EventStore from '../../stores/event_store.jsx';
import UserStore from '../../stores/user_store.jsx';
import bytesConvertor from 'bytes';
import DomainStore from '../../stores/domain_store.jsx';
......@@ -36,8 +38,12 @@ export default class DomainDetails extends React.Component {
this.getDomain = this.getDomain.bind(this);
this.showMessage = this.showMessage.bind(this);
this.handleClickOnTab = this.handleClickOnTab.bind(this);
this.isGlobalAdmin = UserStore.isGlobalAdmin();
this.slideLimitDomainAttach = this.slideLimitDomainAttach.bind(this);
this.handleUpdatePreferences = this.handleUpdatePreferences.bind(this);
this.isGlobalAdmin = UserStore.isGlobalAdmin();
this.DomainAttachmentLimit = window.manager_config.maxAttachmentLimit;
this.sizeOfAttatch = this.DomainAttachmentLimit.min;
this.state = {};
}
......@@ -46,6 +52,58 @@ export default class DomainDetails extends React.Component {
browserHistory.push(`${path}?tab=${tab}`);
}
slideLimitDomainAttach(e) {
const bytes = parseInt(e.target.value, 10);
this.sizeOfAttatch = bytes;
const sizeOfAttatch = bytesConvertor(bytes);
this.refs.outputBytes.value = sizeOfAttatch;
this.refs.amavisMessageSizeLimit.value = this.sizeOfAttatch;
}
handleUpdatePreferences(e) {
e.preventDefault();
const domain = {
id: this.state.domain.id,
attrs: {
amavisMessageSizeLimit: this.refs.amavisMessageSizeLimit.value
}
};
GlobalActions.emitStartLoading();
new Promise((resolve, reject) => {
Client.modifyDomain(
domain,
(data) => {
resolve(data);
},
(error) => {
reject(error);
}
);
}).then((success) => {
/*if (this.isStoreEnabled) {
//logic
}*/
this.setState({
domain: success
});
GlobalActions.emitMessage({
message: 'Se han guardado sus preferencias con éxtio.',
typeError: Constants.MessageType.SUCCESS
});
}).catch((error) => {
GlobalActions.emitMessage({
message: error.message,
typeError: Constants.MessageType.ERROR
});
}).finally(() => {
GlobalActions.emitEndLoading();
});
}
showMessage(attrs) {
this.setState({
error: {
......@@ -62,6 +120,8 @@ export default class DomainDetails extends React.Component {
if (domain && domain.id === this.props.params.id) {
states.domain = domain;
this.sizeOfAttatch = domain.attrs.amavisMessageSizeLimit || this.DomainAttachmentLimit.min;
GlobalActions.emitEndLoading();
this.setState(states);
......@@ -90,6 +150,8 @@ export default class DomainDetails extends React.Component {
}
states.domain = data;
this.sizeOfAttatch = data.attrs.amavisMessageSizeLimit || this.DomainAttachmentLimit.min;
Client.getZone(data.name, (zone) => {
states.zone = this.isStoreEnabled ? DomainStore.setZoneDNS(zone) : zone;
......@@ -182,22 +244,80 @@ export default class DomainDetails extends React.Component {
/>
);
const tabTareasMasivas = (
<div>
<ul className='list-inline'>
<li>
<ToggleModalButton
role='button'
className=''
dialogType={MultipleTaskModal}
dialogProps={{
const sizOfArratchment = this.sizeOfAttatch && typeof this.sizeOfAttatch === 'number' ? bytesConvertor(this.sizeOfAttatch, 10) : bytesConvertor(parseInt(this.sizeOfAttatch, 10));
const tabPreferencesBtns = [
<ToggleModalButton
role='button'
className='btn btn-info'
dialogType={MultipleTaskModal}
dialogProps={{
data: domain
}}
key='change-passwd-import'
>
{'Mensaje fuera de Oficina'}
</ToggleModalButton>
</li>
key='change-passwd-import'
>
{'Mensaje fuera de Oficina'}
</ToggleModalButton>,
<div
key='range-max-attachment'
className='row'
>
<div className='col-xs-6'>
<div className='input-group'>
<div className='input-group-addon'>Tamaño Adjunto</div>
<input
type='text'
className='form-control'
ref='outputBytes'
readOnly='readOnly'
value={sizOfArratchment}
/>
<input
type='hidden'
ref='amavisMessageSizeLimit'
value={this.sizeOfAttatch}
/>
</div>
</div>
<div className='col-xs-6'>
<input
type='range'
className='range-size'
placeholder='Amount'
max={this.DomainAttachmentLimit.max}
min={this.DomainAttachmentLimit.min}
onChange={this.slideLimitDomainAttach}
step={this.DomainAttachmentLimit.step}
defaultValue={this.sizeOfAttatch}
/>
</div>
</div>
];
const listsBtns = tabPreferencesBtns.map((btn, i) => {
return (
<li
key={`preference-${i}`}
className='list-group-item'
>
{btn}
</li>
);
});
const tabPreferences = (
<div>
<div className='text-right'>
<button
className='btn btn-info'
onClick={this.handleUpdatePreferences}
>
Guardar Preferencias
</button>
</div>
<ul className='list-group clearfix set-margin-up'>
{listsBtns}
</ul>
</div>
);
......@@ -218,21 +338,21 @@ export default class DomainDetails extends React.Component {
/>
);
tabNames = ['Administradores', 'AntiSpam', 'Listas De Distribución', 'Tareas Masivas', 'Zona DNS'];
tabNames = ['Administradores', 'AntiSpam', 'Listas De Distribución', 'Preferencias', 'Zona DNS'];
tabs = {
administradores: tabAdmin,
antispam: tabAntiSpam,
listas_de_distribución: tabDistribution,
tareas_masivas: tabTareasMasivas,
preferencias: tabPreferences,
zona_dns: zonaDNS
};
if (!this.isGlobalAdmin) {
tabNames = ['Administradores', 'Listas De Distribución', 'Tareas Masivas', 'Zona DNS'];
tabNames = ['Administradores', 'Listas De Distribución', 'Preferencias', 'Zona DNS'];
tabs = {
administradores: tabAdmin,
listas_de_distribución: tabDistribution,
tareas_masivas: tabTareasMasivas,
preferencias: tabPreferences,
zona_dns: zonaDNS
};
}
......
......@@ -13,6 +13,7 @@ import * as Utils from '../../utils/utils.jsx';
import EventStore from '../../stores/event_store.jsx';
import MailboxStore from '../../stores/mailbox_store.jsx';
import DomainStore from '../../stores/domain_store.jsx';
import ZimbraStore from '../../stores/zimbra_store.jsx';
import Constants from '../../utils/constants.jsx';
......@@ -22,6 +23,7 @@ export default class CreateMailBox extends React.Component {
constructor(props) {
super(props);
this.isStoreEnabled = window.manager_config.enableStores;
this.handleSubmit = this.handleSubmit.bind(this);
this.getAllDomains = this.getAllDomains.bind(this);
this.showMessage = this.showMessage.bind(this);
......@@ -29,6 +31,7 @@ export default class CreateMailBox extends React.Component {
this.controllerDataList = this.controllerDataList.bind(this);
this.handlePasswd = this.handlePasswd.bind(this);
this.getEnableAccountsFromDomain = this.getEnableAccountsFromDomain.bind(this);
this.cos = Utils.getEnabledPlansByCos(ZimbraStore.getAllCos());
this.reset = null;
this.cacheDomain = null;
......@@ -36,7 +39,6 @@ export default class CreateMailBox extends React.Component {
this.state = {
zimbraCOSId: ''
};
this.s = true;
}
handlePasswd(e) {
......@@ -89,12 +91,12 @@ export default class CreateMailBox extends React.Component {
return domainName.includes(value) && domainName.length === value.length;
});
if (thatDomainExists && thatDomainExists.name === this.cacheDomain) {
if (thatDomainExists && this.cacheDomain && thatDomainExists.name === this.cacheDomain.name) {
return null;
}
if (thatDomainExists) {
this.cacheDomain = value;
this.cacheDomain = thatDomainExists;
const maxCosAccounts = Utils.parseMaxCOSAccounts(thatDomainExists.attrs.zimbraDomainCOSMaxAccounts);
this.setState({
loadingEnableAccounts: true,
......@@ -236,7 +238,11 @@ export default class CreateMailBox extends React.Component {
document.getElementById('createAccount').reset();
this.reset.toggleOptions();
MailboxStore.setMailbox(data);
if (this.isStoreEnabled) {
const domainId = this.props.params.domainId || this.cacheDomain.id || null;
MailboxStore.setMailbox(data);
MailboxStore.setMailboxByDomain(domainId, data);
}
if (shouldEnableArchive) {
data.enableArchiving(plan, (err) => {
......@@ -249,11 +255,6 @@ export default class CreateMailBox extends React.Component {
} else {
return Utils.handleLink(event, `/mailboxes/${data.id}`, this.props.location);
}
/*GlobalActions.emitMessage({
message: 'Se ha creado su cuenta con éxito.',
typeError: messageType.SUCCESS
});*/
},
(error) => {
GlobalActions.emitMessage({
......@@ -281,48 +282,29 @@ export default class CreateMailBox extends React.Component {
}
getAllDomains() {
const promises = [];
const max = 200;
const doms = new Promise((resolve, reject) => {
new Promise((resolve, reject) => {
Client.getAllDomains(
{
limit: max
},
(data) => {
const rightsDomains = data.domain.filter((domain) => {
return !domain.isAliasDomain && !domain.name.match('archive');
});
data.domain = rightsDomains;
resolve(data);
},
(error) => {
reject(error);
}
);
});
const cos = new Promise((resolve, reject) => {
Client.getAllCos((success) => {
resolve(success);
}, (error) => {
reject(error);
});
});
promises.push(doms, cos);
Promise.all(promises).then((success) => {
const response = {};
success.map((pos) => {
if (Array.isArray(pos)) {
const arrPlans = Utils.getEnabledPlansByCos(pos);
response.plans = arrPlans;
} else {
response.domains = pos;
}
return true;
});
}).then((domains) => {
const rightsDomains = Utils.getDomainsCleaned(domains.domain);
domains.domain = rightsDomains;
domains.total = rightsDomains.length;
const response = {
plans: this.cos,
domains
};
if (this.props.params.id) {
let defaultDomain = null;
......@@ -349,15 +331,12 @@ export default class CreateMailBox extends React.Component {
if (response.currentDomain) {
this.getEnableAccountsFromDomain(null, response.currentDomain);
}
GlobalActions.emitEndLoading();
Utils.toggleStatusButtons('.action-save', false);
}, (error) => {
GlobalActions.emitMessage({
error: error.message,
typeError: error.type
});
}).finally(() => {
GlobalActions.emitEndLoading();
Utils.toggleStatusButtons('.action-save', false);
});
......@@ -368,19 +347,7 @@ export default class CreateMailBox extends React.Component {
Utils.toggleStatusButtons('.action-save', true);
$('#sidebar-mailboxes').addClass('active');
this.getAllDomains();
GlobalActions.emitEndLoading();
this.addBlurListeneronInput();
/*console.log(this.s);
setTimeout(() => {
console.log('setTimeout', this.s);
if (this.s) {
console.log('set state');
this.setState({
flag: true
})
}
}, 10000);*/
}
componentWillUnmount() {
......@@ -389,7 +356,6 @@ export default class CreateMailBox extends React.Component {
this.cacheDomain = null;
const parent = document.getElementById('add-mailbox');
parent.removeEventListener('focusout', null);
this.s = false;
}
controllerDataList(controller) {
......@@ -432,32 +398,6 @@ export default class CreateMailBox extends React.Component {
counterPlans--;
}
});
/*if (accounts.length > 0) {
const response = accounts.map((account) => {
return (
<li
key={`${account.plan}-status`}
>
<span className={`${account.classCss} tag-status`}>
{Utils.titleCase(account.plan)}
<span>
{`Usadas: ${account.used} | Disponibles: ${account.enabled}`}
</span>
</span>
</li>
);
});
enableAccounts = (
<div className='row'>
<div className='col-xs-12 text-center'>
<ul className='list-inline'>
{response}
</ul>
</div>
</div>
);
}*/
}
if (this.state.domains) {
......@@ -553,60 +493,6 @@ export default class CreateMailBox extends React.Component {
}
});
/*for (let plan in plans) {
if (plans.hasOwnProperty(plan)) {
let isDisabled = null;
let classCss = null;
let info = null;
if (this.state.enabledAccounts) {
this.state.enabledAccounts.forEach((p) => {
if (plans[plan] === p.cosId) {
isDisabled = p.enabled < 1 ? true : null;
classCss = p.classCss;
info = (
<div>
<span>
Usadas: {p.used}
</span>
<span> - </span>
<span className={p.enabled <= 0 ? 'text-danger' : 'text-success'}>
Libres: {p.enabled}
</span>
</div>
);
}
});
}
const disabledCss = isDisabled ? 'disabled' : '';
const item = (
<label
className={`radio radio-info radio-inline pretty-input ${disabledCss}`}
key={plan}
>
<div className='pretty-radio'>
<input
type='radio'
className='pretty'
name='mailbox'
onChange={() => {
this.handleRadioChanged(plans[plan]);
}}
disabled={isDisabled}
/>
<span></span>
</div>
<span className={`${classCss} status-plan`}>
{Utils.titleCase(plan)}
</span>
{info}
</label>
);
checkboxes.push(item);
}
}*/
form = (
<form
className='simple_form form-horizontal mailbox-form'
......
......@@ -35,6 +35,7 @@ export default class EditMailBox extends React.Component {
this.showMessage = this.showMessage.bind(this);
this.handleRenameAccount = this.handleRenameAccount.bind(this);
this.editUrlFromParams = this.props.params.domain_id ? `/domains/${this.props.params.domain_id}/mailboxes/` : '/mailboxes/';
this.domainId = null;
this.state = {
zimbraCOSId: ''
......@@ -92,7 +93,6 @@ export default class EditMailBox extends React.Component {
MailboxStore.removeAccount(account);
}
response.text = 'Será redireccionado a Casillas.';
this.editUrlFromParams = this.props.params.domain_id ? `/domains/${this.props.params.domain_id}/mailboxes/` : '/mailboxes/';
return sweetAlert(
response,
() => {
......@@ -271,10 +271,10 @@ export default class EditMailBox extends React.Component {
);
}).then((account) => {
if (this.isStoreEnabled) {
MailboxStore.changeAccount(account);
MailboxStore.updateMailbox(account.id, account, this.domainId);
}
console.log('disable', shouldDisabledArchiving, 'enable', shouldEnableArchiving); //eslint-disable-line no-console
console.log(account); //eslint-disable-line no-console
if (shouldDisabledArchiving && !shouldEnableArchiving) {
account.disableArchiving((err) => {
......@@ -381,8 +381,8 @@ export default class EditMailBox extends React.Component {
{
limit: max
},
(domain) => {
return resolve(domain);
(data) => {
return resolve(data);
},
(error) => {
return reject(error);
......@@ -394,11 +394,14 @@ export default class EditMailBox extends React.Component {
Promise.all(promises).then((result) => {
const account = result.shift();
const domains = Utils.getDomainsCleaned(result.shift().domain);
this.domainId = Utils.findDomaindIdFromAccount(account, domains);
this.setState({
data: account,
zimbraCOSId: account.attrs.zimbraCOSId,
domains: result.shift().domain,
domains,
cos
});
......
......@@ -61,6 +61,7 @@ export default class Mailboxes extends React.Component {
this.optionStatus = Constants.status;
this.optionPlans = window.manager_config.plans;
this.domainName = null;
this.createUrlFromParams = this.props.params.domain_id ? `/domains/${this.props.params.domain_id}/mailboxes/new` : '/mailboxes/new';
this.state = {
page,
......@@ -579,7 +580,7 @@ export default class Mailboxes extends React.Component {
{
props: {
className: 'btn btn-success',
onClick: (e) => Utils.handleLink(e, '/mailboxes/new')
onClick: (e) => Utils.handleLink(e, this.createUrlFromParams)
},
label: '+ Nueva Casilla'
}
......
......@@ -69,23 +69,26 @@ export default class MailboxDetails extends React.Component {
}
onRemoveAlias(alias) {
MailboxStore.removeAlias(alias);
const allAlias = this.state.alias.filter((item) => {
return alias !== item;
});
const items = MailboxStore.getAlias();
allAlias.sort(Utils.sortByNames);
this.setState({
alias: items,
alias: allAlias,
error: false
});
}
onCancelAlias(arrAlias) {
MailboxStore.refreshAlias(arrAlias);
const {alias} = this.state;
const items = MailboxStore.getAlias();
alias.push(...arrAlias);
alias.sort(Utils.sortByNames);
this.setState({
alias: items,
alias,
error: false
});
}
......@@ -116,6 +119,8 @@ export default class MailboxDetails extends React.Component {
}
}
items.sort(Utils.sortByNames);
mailbox.viewMailPath(global.window.manager_config.webmailLifetime, (error, res) => {
if (res) {
return this.setState({
......@@ -154,106 +159,42 @@ export default class MailboxDetails extends React.Component {
}
onAliasSubmit(response) {
if (response.refresh) {
MailboxStore.refreshAlias(response.refresh);
}
this.multipleActions(response, this.state.data).then((result) => {
const limit = result.length;
return new Promise((resolve) => {
return Utils.makeRequest(response, this.state.data, resolve, false);
}).then((data) => {
const errors = [];
for (let index = 0; index < limit; index++) {
const res = result[index];
if (result[index].error) {
const action = (res.action === 'remove') ? 'eliminar' : 'agregar';
const {alias} = this.state;
if (data.error) {
data.error.forEach((err) => {
errors.push({
error: `Hubo un error al ${action} el alias: ${res.item}, debido a ${res.error.extra.reason}`,
error: `Hubo un error al ${err.action} ${err.target}, debido a : ${err.extra.reason}`,
type: MessageTypes.ERROR
});
}
if (res.isCompleted && res.action === 'add') {
MailboxStore.setAlias(res.item);
}
});
}
if (errors.length !== limit) {
if (data.completed) {
errors.push({
error: 'Se han guardado los datos éxitosamente.',
type: MessageTypes.SUCCESS
});
data.completed.forEach((obj) => {
alias.push(obj.target);
});
alias.sort(Utils.sortByNames);
}
this.setState({
error: errors,
alias: MailboxStore.getAlias()
return this.setState({
error: errors.length > 0 ? errors : null,
alias
});
}).finally(() => {
response.reset();
});
}
multipleActions(response, account) {
const promises = [];
for (const key in response) {
if (response.hasOwnProperty(key) && key === 'add') {
const array = response[key];
const limit = array.length;
for (let index = 0; index < limit; index++) {
const res = {};
const promesa = new Promise((resolve) => {
account.addAccountAlias(array[index], (error) => {
if (error) {
res.isCompleted = false;
res.item = response[key][index];
res.action = key;
res.error = error;
} else {
res.isCompleted = true;
res.item = response[key][index];
res.action = key;
}
return resolve(res);
});
});
promises.push(promesa);
}
}
if (response.hasOwnProperty(key) && key === 'remove') {
const array = response[key];
const limit = array.length;
for (let index = 0; index < limit; index++) {
const res = {};
const promesa = new Promise((resolve) => {
account.removeAccountAlias(array[index], (error) => {
if (error) {
res.isCompleted = false;
res.item = response[key][index];
res.action = key;
res.error = error;
} else {
res.isCompleted = true;
res.item = response[key][index];
res.action = key;
}
return resolve(res);
});
});
promises.push(promesa);
}
}
}
return Promise.all(promises);
}
render() {
let generalData;
let statsData;
......@@ -373,6 +314,7 @@ export default class MailboxDetails extends React.Component {
onApplyChanges={(response) => {
this.onAliasSubmit(response);
}}
nameFunc={'AccountAlias'}
/>
);
......
......@@ -200,11 +200,10 @@ export default class PanelActions extends React.Component {
componentWillReceiveProps(nextProps) {
this.pagination.setArray(nextProps.data);
this.pagination.reset();
const states = {};
states['items' + this.props.name] = nextProps.data;
states['items' + this.props.name] = this.pagination.reset();
states['pagination' + this.props.name] = this.pagination.getResults();
this.setState(states);
......@@ -276,8 +275,8 @@ export default class PanelActions extends React.Component {
response.reset = this.reset;
response.target = this.props.nameFunc;
/*this.refs.savebutton.setAttribute('disabled', 'disabled');
this.refs.savebutton.innerHTML = 'Aplicando Cambios...';*/
this.refs.savebutton.setAttribute('disabled', 'disabled');
this.refs.savebutton.innerHTML = 'Aplicando Cambios...';
if (this.forAdd.length > 0) {
response['add' + Utils.titleCase(this.props.nameFunc)] = this.forAdd;
......@@ -287,10 +286,6 @@ export default class PanelActions extends React.Component {
response['remove' + Utils.titleCase(this.props.nameFunc)] = this.forRemove;
}
/*if (this.refresh.length > 0) {
response.refresh = this.refresh;
}*/
this.props.onApplyChanges(response);
}
......
......@@ -11,6 +11,11 @@
"token": "otto",
"inmutable": ["mx", "soa", "ns", "spf"]
},
"maxAttachmentLimit": {
"max": 52428800,
"min": 1048576,
"step": 1048576
},
"maxResultOnRequestZimbra": 3000,
"autoincrementOnFailRequestZimbra": 500,
"plans": {
......@@ -82,7 +87,8 @@
"businessCategory": true,
"zimbraCreateTimestamp": true,
"zimbraDomainType": true,
"zimbraMailCatchAllForwardingAddress": true
"zimbraMailCatchAllForwardingAddress": true,
"amavisMessageSizeLimit": true
}
},
"search": {
......
......@@ -21,6 +21,7 @@ $border-rad: 1px;
$color-navy-blue: #34495e;
$color-violet: #9b59b6;
$color-blue: #3498db;
$color-blue-light: #8cc9f2;
$color-green: #62cb31;
$color-yellow: #ffb606;
$color-orange: #e67e22;
......
......@@ -3,6 +3,7 @@
import EventEmitter from 'events';
import Constants from '../utils/constants.jsx';
import * as Utils from '../utils/utils.jsx';
const eventTypes = Constants.EventTypes;
......@@ -24,7 +25,6 @@ class MailboxStoreClass extends EventEmitter {
setMailboxesByDomain(id, mailboxes) {
if (mailboxes) {
this.mailboxesByDomain[id] = mailboxes;
//console.log('setMailboxesByDomain', this.mailboxesByDomain);
return true;
}
......@@ -58,31 +58,22 @@ class MailboxStoreClass extends EventEmitter {
setMailbox(mailbox) {
if (mailboxesArray) {
const currentTotal = mailboxesArray.account.push(mailbox);
if (currentTotal > mailboxesArray.total) {
mailboxesArray.total = currentTotal;
}
mailboxesArray.account.push(mailbox);
mailboxesArray.total++;
mailboxesArray.account.sort(Utils.sortByNames);
}
}
hasThisPage(page) {
if (page && this.currentPage[page]) {
return this.currentPage[page];
setMailboxByDomain(domainId, mailbox) {
if (!domainId) {
return null;
}
return false;
}
setCurrentPage(page) {
this.currentPage[page] = true;
}
getMailboxByPage(page) {
if (page && this.currentPage[page]) {
return this.currentPage[page];
if (this.mailboxesByDomain && this.mailboxesByDomain[domainId]) {
this.mailboxesByDomain[domainId].account.push(mailbox);
this.mailboxesByDomain[domainId].total++;
this.mailboxesByDomain[domainId].account.sort(Utils.sortByNames);
}
return false;
}
setCurrent(account) {
......@@ -103,17 +94,19 @@ class MailboxStoreClass extends EventEmitter {
if (index > -1) {
accounts[index] = newMailbox;
accounts.sort(Utils.sortByNames);
}
}
if (domainId && this.mailboxesByDomain[domainId]) {
const accountsFromDomain = this.mailboxesByDomain.account;
const accountsFromDomain = this.mailboxesByDomain[domainId].account;
const indexOfMailbox = accountsFromDomain.findIndex((mailbox) => {
return mailbox.id === mailboxId;
});
if (indexOfMailbox > -1) {
accountsFromDomain[indexOfMailbox] = newMailbox;
accountsFromDomain.sort(Utils.sortByNames);
}
}
......
......@@ -692,3 +692,86 @@ export function parseMaxCOSAccounts(maxCosAccounts) {
return response;
}
export function getDomainsCleaned(domains) {
const rightsDomains = domains.filter((domain) => {
return !domain.isAliasDomain && !domain.name.match('archive');
});
return rightsDomains;
}
export function findDomaindIdFromAccount(account, domains) {
const name = account === 'object' ? account.domain : account;
const rightsDomains = domains.filter((domain) => {
return name === domain.name;
});
const domainReturned = rightsDomains.length === 1 ? rightsDomains.pop() : null;
return domainReturned ? domainReturned.id : null;
}
export function sortByNames(a, b) {
const name1 = typeof a === 'object' ? a.name || a.domain : a;
const name2 = typeof b === 'object' ? b.name || b.domain : b;
if (name1 < name2) {
return -1;
}
if (name1 > name2) {
return 1;
}
return 0;
}
export function makeRequest(response, dl, resolve, returnAPI, store) {
const APIReturn = returnAPI || true;
const keys = Object.keys(response).sort();
const item = keys[0];
const res = store || {};
const action = item.match(/(remove|add)/gi);
if (action) {
var element = response[item];
if (element && element.length) {
const pop = element.pop();
const target = typeof pop === 'object' ? pop.name || pop.id : pop;
const label = action[0] === 'remove' ? 'eliminar' : 'agregar';
return dl[item](target, (er, success) => {
if (success) {
if (res.completed) {
res.completed.push({
action: label,
target
});
} else {
res.completed = [{
action: label,
target
}];
}
const api = success.api && APIReturn ? success : dl;
return this.makeRequest(response, api, resolve, APIReturn, res);
}
er.action = label;
er.target = target;
if (res.error) {
res.error.push(er);
} else {
res.error = [er];
}
return this.makeRequest(response, dl, resolve, APIReturn, res);
});
} else {
Reflect.deleteProperty(response, item);
return this.makeRequest(response, dl, resolve, APIReturn, res);
}
}
res.data = dl;
return resolve(res);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment