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"}} module.exports = {"main":{"js":"/454009bundle.js"}}
\ No newline at end of file \ No newline at end of file
...@@ -37,7 +37,6 @@ export default class DistributionLists extends React.Component { ...@@ -37,7 +37,6 @@ export default class DistributionLists extends React.Component {
this.onCancelOwner = this.onCancelOwner.bind(this); this.onCancelOwner = this.onCancelOwner.bind(this);
this.onExportMembers = this.onExportMembers.bind(this); this.onExportMembers = this.onExportMembers.bind(this);
this.onExportAllowers = this.onExportAllowers.bind(this); this.onExportAllowers = this.onExportAllowers.bind(this);
this.makeRequest = this.makeRequest.bind(this);
this.domain = null; this.domain = null;
this.isGlobalAdmin = UserStore.isGlobalAdmin(); this.isGlobalAdmin = UserStore.isGlobalAdmin();
...@@ -63,54 +62,6 @@ export default class DistributionLists extends React.Component { ...@@ -63,54 +62,6 @@ export default class DistributionLists extends React.Component {
Utils.exportAsCSV(data, 'allowers', title, true); 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() { getDistributionLists() {
const domain = this.isStoreEnabled ? DomainStore.getCurrent() : null; const domain = this.isStoreEnabled ? DomainStore.getCurrent() : null;
const id = this.props.params.id; const id = this.props.params.id;
...@@ -175,7 +126,7 @@ export default class DistributionLists extends React.Component { ...@@ -175,7 +126,7 @@ export default class DistributionLists extends React.Component {
onSubmitActions(response) { onSubmitActions(response) {
return new Promise((resolve) => { return new Promise((resolve) => {
return this.makeRequest(response, this.state.distributionsList, resolve); return Utils.makeRequest(response, this.state.distributionsList, resolve);
}).then((data) => { }).then((data) => {
const errors = []; const errors = [];
if (data.error) { if (data.error) {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import $ from 'jquery'; import $ from 'jquery';
import React from 'react'; import React from 'react';
import {browserHistory} from 'react-router'; import {browserHistory} from 'react-router';
import Promise from 'bluebird';
import MessageBar from '../message_bar.jsx'; import MessageBar from '../message_bar.jsx';
import PageInfo from '../page_info.jsx'; import PageInfo from '../page_info.jsx';
...@@ -19,6 +20,7 @@ import AntiSpamComponent from './antispam.jsx'; ...@@ -19,6 +20,7 @@ import AntiSpamComponent from './antispam.jsx';
import ZonaDNS from './domain_admin_dns.jsx'; import ZonaDNS from './domain_admin_dns.jsx';
import EventStore from '../../stores/event_store.jsx'; import EventStore from '../../stores/event_store.jsx';
import UserStore from '../../stores/user_store.jsx'; import UserStore from '../../stores/user_store.jsx';
import bytesConvertor from 'bytes';
import DomainStore from '../../stores/domain_store.jsx'; import DomainStore from '../../stores/domain_store.jsx';
...@@ -36,8 +38,12 @@ export default class DomainDetails extends React.Component { ...@@ -36,8 +38,12 @@ export default class DomainDetails extends React.Component {
this.getDomain = this.getDomain.bind(this); this.getDomain = this.getDomain.bind(this);
this.showMessage = this.showMessage.bind(this); this.showMessage = this.showMessage.bind(this);
this.handleClickOnTab = this.handleClickOnTab.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 = {}; this.state = {};
} }
...@@ -46,6 +52,58 @@ export default class DomainDetails extends React.Component { ...@@ -46,6 +52,58 @@ export default class DomainDetails extends React.Component {
browserHistory.push(`${path}?tab=${tab}`); 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) { showMessage(attrs) {
this.setState({ this.setState({
error: { error: {
...@@ -62,6 +120,8 @@ export default class DomainDetails extends React.Component { ...@@ -62,6 +120,8 @@ export default class DomainDetails extends React.Component {
if (domain && domain.id === this.props.params.id) { if (domain && domain.id === this.props.params.id) {
states.domain = domain; states.domain = domain;
this.sizeOfAttatch = domain.attrs.amavisMessageSizeLimit || this.DomainAttachmentLimit.min;
GlobalActions.emitEndLoading(); GlobalActions.emitEndLoading();
this.setState(states); this.setState(states);
...@@ -90,6 +150,8 @@ export default class DomainDetails extends React.Component { ...@@ -90,6 +150,8 @@ export default class DomainDetails extends React.Component {
} }
states.domain = data; states.domain = data;
this.sizeOfAttatch = data.attrs.amavisMessageSizeLimit || this.DomainAttachmentLimit.min;
Client.getZone(data.name, (zone) => { Client.getZone(data.name, (zone) => {
states.zone = this.isStoreEnabled ? DomainStore.setZoneDNS(zone) : zone; states.zone = this.isStoreEnabled ? DomainStore.setZoneDNS(zone) : zone;
...@@ -182,13 +244,12 @@ export default class DomainDetails extends React.Component { ...@@ -182,13 +244,12 @@ export default class DomainDetails extends React.Component {
/> />
); );
const tabTareasMasivas = ( const sizOfArratchment = this.sizeOfAttatch && typeof this.sizeOfAttatch === 'number' ? bytesConvertor(this.sizeOfAttatch, 10) : bytesConvertor(parseInt(this.sizeOfAttatch, 10));
<div>
<ul className='list-inline'> const tabPreferencesBtns = [
<li>
<ToggleModalButton <ToggleModalButton
role='button' role='button'
className='' className='btn btn-info'
dialogType={MultipleTaskModal} dialogType={MultipleTaskModal}
dialogProps={{ dialogProps={{
data: domain data: domain
...@@ -196,8 +257,67 @@ export default class DomainDetails extends React.Component { ...@@ -196,8 +257,67 @@ export default class DomainDetails extends React.Component {
key='change-passwd-import' key='change-passwd-import'
> >
{'Mensaje fuera de Oficina'} {'Mensaje fuera de Oficina'}
</ToggleModalButton> </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> </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> </ul>
</div> </div>
); );
...@@ -218,21 +338,21 @@ export default class DomainDetails extends React.Component { ...@@ -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 = { tabs = {
administradores: tabAdmin, administradores: tabAdmin,
antispam: tabAntiSpam, antispam: tabAntiSpam,
listas_de_distribución: tabDistribution, listas_de_distribución: tabDistribution,
tareas_masivas: tabTareasMasivas, preferencias: tabPreferences,
zona_dns: zonaDNS zona_dns: zonaDNS
}; };
if (!this.isGlobalAdmin) { if (!this.isGlobalAdmin) {
tabNames = ['Administradores', 'Listas De Distribución', 'Tareas Masivas', 'Zona DNS']; tabNames = ['Administradores', 'Listas De Distribución', 'Preferencias', 'Zona DNS'];
tabs = { tabs = {
administradores: tabAdmin, administradores: tabAdmin,
listas_de_distribución: tabDistribution, listas_de_distribución: tabDistribution,
tareas_masivas: tabTareasMasivas, preferencias: tabPreferences,
zona_dns: zonaDNS zona_dns: zonaDNS
}; };
} }
......
...@@ -13,6 +13,7 @@ import * as Utils from '../../utils/utils.jsx'; ...@@ -13,6 +13,7 @@ import * as Utils from '../../utils/utils.jsx';
import EventStore from '../../stores/event_store.jsx'; import EventStore from '../../stores/event_store.jsx';
import MailboxStore from '../../stores/mailbox_store.jsx'; import MailboxStore from '../../stores/mailbox_store.jsx';
import DomainStore from '../../stores/domain_store.jsx'; import DomainStore from '../../stores/domain_store.jsx';
import ZimbraStore from '../../stores/zimbra_store.jsx';
import Constants from '../../utils/constants.jsx'; import Constants from '../../utils/constants.jsx';
...@@ -22,6 +23,7 @@ export default class CreateMailBox extends React.Component { ...@@ -22,6 +23,7 @@ export default class CreateMailBox extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.isStoreEnabled = window.manager_config.enableStores;
this.handleSubmit = this.handleSubmit.bind(this); this.handleSubmit = this.handleSubmit.bind(this);
this.getAllDomains = this.getAllDomains.bind(this); this.getAllDomains = this.getAllDomains.bind(this);
this.showMessage = this.showMessage.bind(this); this.showMessage = this.showMessage.bind(this);
...@@ -29,6 +31,7 @@ export default class CreateMailBox extends React.Component { ...@@ -29,6 +31,7 @@ export default class CreateMailBox extends React.Component {
this.controllerDataList = this.controllerDataList.bind(this); this.controllerDataList = this.controllerDataList.bind(this);
this.handlePasswd = this.handlePasswd.bind(this); this.handlePasswd = this.handlePasswd.bind(this);
this.getEnableAccountsFromDomain = this.getEnableAccountsFromDomain.bind(this); this.getEnableAccountsFromDomain = this.getEnableAccountsFromDomain.bind(this);
this.cos = Utils.getEnabledPlansByCos(ZimbraStore.getAllCos());
this.reset = null; this.reset = null;
this.cacheDomain = null; this.cacheDomain = null;
...@@ -36,7 +39,6 @@ export default class CreateMailBox extends React.Component { ...@@ -36,7 +39,6 @@ export default class CreateMailBox extends React.Component {
this.state = { this.state = {
zimbraCOSId: '' zimbraCOSId: ''
}; };
this.s = true;
} }
handlePasswd(e) { handlePasswd(e) {
...@@ -89,12 +91,12 @@ export default class CreateMailBox extends React.Component { ...@@ -89,12 +91,12 @@ export default class CreateMailBox extends React.Component {
return domainName.includes(value) && domainName.length === value.length; 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; return null;
} }
if (thatDomainExists) { if (thatDomainExists) {
this.cacheDomain = value; this.cacheDomain = thatDomainExists;
const maxCosAccounts = Utils.parseMaxCOSAccounts(thatDomainExists.attrs.zimbraDomainCOSMaxAccounts); const maxCosAccounts = Utils.parseMaxCOSAccounts(thatDomainExists.attrs.zimbraDomainCOSMaxAccounts);
this.setState({ this.setState({
loadingEnableAccounts: true, loadingEnableAccounts: true,
...@@ -236,7 +238,11 @@ export default class CreateMailBox extends React.Component { ...@@ -236,7 +238,11 @@ export default class CreateMailBox extends React.Component {
document.getElementById('createAccount').reset(); document.getElementById('createAccount').reset();
this.reset.toggleOptions(); this.reset.toggleOptions();
if (this.isStoreEnabled) {
const domainId = this.props.params.domainId || this.cacheDomain.id || null;
MailboxStore.setMailbox(data); MailboxStore.setMailbox(data);
MailboxStore.setMailboxByDomain(domainId, data);
}
if (shouldEnableArchive) { if (shouldEnableArchive) {
data.enableArchiving(plan, (err) => { data.enableArchiving(plan, (err) => {
...@@ -249,11 +255,6 @@ export default class CreateMailBox extends React.Component { ...@@ -249,11 +255,6 @@ export default class CreateMailBox extends React.Component {
} else { } else {
return Utils.handleLink(event, `/mailboxes/${data.id}`, this.props.location); return Utils.handleLink(event, `/mailboxes/${data.id}`, this.props.location);
} }
/*GlobalActions.emitMessage({
message: 'Se ha creado su cuenta con éxito.',
typeError: messageType.SUCCESS
});*/
}, },
(error) => { (error) => {
GlobalActions.emitMessage({ GlobalActions.emitMessage({
...@@ -281,48 +282,29 @@ export default class CreateMailBox extends React.Component { ...@@ -281,48 +282,29 @@ export default class CreateMailBox extends React.Component {
} }
getAllDomains() { getAllDomains() {
const promises = [];
const max = 200; const max = 200;
const doms = new Promise((resolve, reject) => { new Promise((resolve, reject) => {
Client.getAllDomains( Client.getAllDomains(
{ {
limit: max limit: max
}, },
(data) => { (data) => {
const rightsDomains = data.domain.filter((domain) => {
return !domain.isAliasDomain && !domain.name.match('archive');
});
data.domain = rightsDomains;
resolve(data); resolve(data);
}, },
(error) => { (error) => {
reject(error); reject(error);
} }
); );
}); }).then((domains) => {
const rightsDomains = Utils.getDomainsCleaned(domains.domain);
const cos = new Promise((resolve, reject) => { domains.domain = rightsDomains;
Client.getAllCos((success) => { domains.total = rightsDomains.length;
resolve(success);
}, (error) => { const response = {
reject(error); plans: this.cos,
}); domains
}); };
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;
});
if (this.props.params.id) { if (this.props.params.id) {
let defaultDomain = null; let defaultDomain = null;
...@@ -349,15 +331,12 @@ export default class CreateMailBox extends React.Component { ...@@ -349,15 +331,12 @@ export default class CreateMailBox extends React.Component {
if (response.currentDomain) { if (response.currentDomain) {
this.getEnableAccountsFromDomain(null, response.currentDomain); this.getEnableAccountsFromDomain(null, response.currentDomain);
} }
GlobalActions.emitEndLoading();
Utils.toggleStatusButtons('.action-save', false);
}, (error) => { }, (error) => {
GlobalActions.emitMessage({ GlobalActions.emitMessage({
error: error.message, error: error.message,
typeError: error.type typeError: error.type
}); });
}).finally(() => {
GlobalActions.emitEndLoading(); GlobalActions.emitEndLoading();
Utils.toggleStatusButtons('.action-save', false); Utils.toggleStatusButtons('.action-save', false);
}); });
...@@ -368,19 +347,7 @@ export default class CreateMailBox extends React.Component { ...@@ -368,19 +347,7 @@ export default class CreateMailBox extends React.Component {
Utils.toggleStatusButtons('.action-save', true); Utils.toggleStatusButtons('.action-save', true);
$('#sidebar-mailboxes').addClass('active'); $('#sidebar-mailboxes').addClass('active');
this.getAllDomains(); this.getAllDomains();
GlobalActions.emitEndLoading();
this.addBlurListeneronInput(); 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() { componentWillUnmount() {
...@@ -389,7 +356,6 @@ export default class CreateMailBox extends React.Component { ...@@ -389,7 +356,6 @@ export default class CreateMailBox extends React.Component {
this.cacheDomain = null; this.cacheDomain = null;
const parent = document.getElementById('add-mailbox'); const parent = document.getElementById('add-mailbox');
parent.removeEventListener('focusout', null); parent.removeEventListener('focusout', null);
this.s = false;
} }
controllerDataList(controller) { controllerDataList(controller) {
...@@ -432,32 +398,6 @@ export default class CreateMailBox extends React.Component { ...@@ -432,32 +398,6 @@ export default class CreateMailBox extends React.Component {
counterPlans--; 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) { if (this.state.domains) {
...@@ -553,60 +493,6 @@ export default class CreateMailBox extends React.Component { ...@@ -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 = (
<form <form
className='simple_form form-horizontal mailbox-form' className='simple_form form-horizontal mailbox-form'
......
...@@ -35,6 +35,7 @@ export default class EditMailBox extends React.Component { ...@@ -35,6 +35,7 @@ export default class EditMailBox extends React.Component {
this.showMessage = this.showMessage.bind(this); this.showMessage = this.showMessage.bind(this);
this.handleRenameAccount = this.handleRenameAccount.bind(this); this.handleRenameAccount = this.handleRenameAccount.bind(this);
this.editUrlFromParams = this.props.params.domain_id ? `/domains/${this.props.params.domain_id}/mailboxes/` : '/mailboxes/'; this.editUrlFromParams = this.props.params.domain_id ? `/domains/${this.props.params.domain_id}/mailboxes/` : '/mailboxes/';
this.domainId = null;
this.state = { this.state = {
zimbraCOSId: '' zimbraCOSId: ''
...@@ -92,7 +93,6 @@ export default class EditMailBox extends React.Component { ...@@ -92,7 +93,6 @@ export default class EditMailBox extends React.Component {
MailboxStore.removeAccount(account); MailboxStore.removeAccount(account);
} }
response.text = 'Será redireccionado a Casillas.'; response.text = 'Será redireccionado a Casillas.';
this.editUrlFromParams = this.props.params.domain_id ? `/domains/${this.props.params.domain_id}/mailboxes/` : '/mailboxes/';
return sweetAlert( return sweetAlert(
response, response,
() => { () => {
...@@ -271,10 +271,10 @@ export default class EditMailBox extends React.Component { ...@@ -271,10 +271,10 @@ export default class EditMailBox extends React.Component {
); );
}).then((account) => { }).then((account) => {
if (this.isStoreEnabled) { 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) { if (shouldDisabledArchiving && !shouldEnableArchiving) {
account.disableArchiving((err) => { account.disableArchiving((err) => {
...@@ -381,8 +381,8 @@ export default class EditMailBox extends React.Component { ...@@ -381,8 +381,8 @@ export default class EditMailBox extends React.Component {
{ {
limit: max limit: max
}, },
(domain) => { (data) => {
return resolve(domain); return resolve(data);
}, },
(error) => { (error) => {
return reject(error); return reject(error);
...@@ -394,11 +394,14 @@ export default class EditMailBox extends React.Component { ...@@ -394,11 +394,14 @@ export default class EditMailBox extends React.Component {
Promise.all(promises).then((result) => { Promise.all(promises).then((result) => {
const account = result.shift(); const account = result.shift();
const domains = Utils.getDomainsCleaned(result.shift().domain);
this.domainId = Utils.findDomaindIdFromAccount(account, domains);
this.setState({ this.setState({
data: account, data: account,
zimbraCOSId: account.attrs.zimbraCOSId, zimbraCOSId: account.attrs.zimbraCOSId,
domains: result.shift().domain, domains,
cos cos
}); });
......
...@@ -61,6 +61,7 @@ export default class Mailboxes extends React.Component { ...@@ -61,6 +61,7 @@ export default class Mailboxes extends React.Component {
this.optionStatus = Constants.status; this.optionStatus = Constants.status;
this.optionPlans = window.manager_config.plans; this.optionPlans = window.manager_config.plans;
this.domainName = null; this.domainName = null;
this.createUrlFromParams = this.props.params.domain_id ? `/domains/${this.props.params.domain_id}/mailboxes/new` : '/mailboxes/new';
this.state = { this.state = {
page, page,
...@@ -579,7 +580,7 @@ export default class Mailboxes extends React.Component { ...@@ -579,7 +580,7 @@ export default class Mailboxes extends React.Component {
{ {
props: { props: {
className: 'btn btn-success', className: 'btn btn-success',
onClick: (e) => Utils.handleLink(e, '/mailboxes/new') onClick: (e) => Utils.handleLink(e, this.createUrlFromParams)
}, },
label: '+ Nueva Casilla' label: '+ Nueva Casilla'
} }
......
...@@ -69,23 +69,26 @@ export default class MailboxDetails extends React.Component { ...@@ -69,23 +69,26 @@ export default class MailboxDetails extends React.Component {
} }
onRemoveAlias(alias) { 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({ this.setState({
alias: items, alias: allAlias,
error: false error: false
}); });
} }
onCancelAlias(arrAlias) { onCancelAlias(arrAlias) {
MailboxStore.refreshAlias(arrAlias); const {alias} = this.state;
const items = MailboxStore.getAlias(); alias.push(...arrAlias);
alias.sort(Utils.sortByNames);
this.setState({ this.setState({
alias: items, alias,
error: false error: false
}); });
} }
...@@ -116,6 +119,8 @@ export default class MailboxDetails extends React.Component { ...@@ -116,6 +119,8 @@ export default class MailboxDetails extends React.Component {
} }
} }
items.sort(Utils.sortByNames);
mailbox.viewMailPath(global.window.manager_config.webmailLifetime, (error, res) => { mailbox.viewMailPath(global.window.manager_config.webmailLifetime, (error, res) => {
if (res) { if (res) {
return this.setState({ return this.setState({
...@@ -154,104 +159,40 @@ export default class MailboxDetails extends React.Component { ...@@ -154,104 +159,40 @@ export default class MailboxDetails extends React.Component {
} }
onAliasSubmit(response) { onAliasSubmit(response) {
if (response.refresh) { return new Promise((resolve) => {
MailboxStore.refreshAlias(response.refresh); return Utils.makeRequest(response, this.state.data, resolve, false);
} }).then((data) => {
this.multipleActions(response, this.state.data).then((result) => {
const limit = result.length;
const errors = []; const errors = [];
for (let index = 0; index < limit; index++) { const {alias} = this.state;
const res = result[index];
if (result[index].error) { if (data.error) {
const action = (res.action === 'remove') ? 'eliminar' : 'agregar'; data.error.forEach((err) => {
errors.push({ 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 type: MessageTypes.ERROR
}); });
});
} }
if (res.isCompleted && res.action === 'add') { if (data.completed) {
MailboxStore.setAlias(res.item);
}
}
if (errors.length !== limit) {
errors.push({ errors.push({
error: 'Se han guardado los datos éxitosamente.', error: 'Se han guardado los datos éxitosamente.',
type: MessageTypes.SUCCESS type: MessageTypes.SUCCESS
}); });
}
this.setState({
error: errors,
alias: MailboxStore.getAlias()
});
response.reset();
});
}
multipleActions(response, account) { data.completed.forEach((obj) => {
const promises = []; alias.push(obj.target);
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);
});
}); });
alias.sort(Utils.sortByNames);
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); return this.setState({
error: errors.length > 0 ? errors : null,
alias
}); });
}).finally(() => {
response.reset();
}); });
promises.push(promesa);
}
}
}
return Promise.all(promises);
} }
render() { render() {
...@@ -373,6 +314,7 @@ export default class MailboxDetails extends React.Component { ...@@ -373,6 +314,7 @@ export default class MailboxDetails extends React.Component {
onApplyChanges={(response) => { onApplyChanges={(response) => {
this.onAliasSubmit(response); this.onAliasSubmit(response);
}} }}
nameFunc={'AccountAlias'}
/> />
); );
......
...@@ -200,11 +200,10 @@ export default class PanelActions extends React.Component { ...@@ -200,11 +200,10 @@ export default class PanelActions extends React.Component {
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
this.pagination.setArray(nextProps.data); this.pagination.setArray(nextProps.data);
this.pagination.reset();
const states = {}; 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(); states['pagination' + this.props.name] = this.pagination.getResults();
this.setState(states); this.setState(states);
...@@ -276,8 +275,8 @@ export default class PanelActions extends React.Component { ...@@ -276,8 +275,8 @@ export default class PanelActions extends React.Component {
response.reset = this.reset; response.reset = this.reset;
response.target = this.props.nameFunc; response.target = this.props.nameFunc;
/*this.refs.savebutton.setAttribute('disabled', 'disabled'); this.refs.savebutton.setAttribute('disabled', 'disabled');
this.refs.savebutton.innerHTML = 'Aplicando Cambios...';*/ this.refs.savebutton.innerHTML = 'Aplicando Cambios...';
if (this.forAdd.length > 0) { if (this.forAdd.length > 0) {
response['add' + Utils.titleCase(this.props.nameFunc)] = this.forAdd; response['add' + Utils.titleCase(this.props.nameFunc)] = this.forAdd;
...@@ -287,10 +286,6 @@ export default class PanelActions extends React.Component { ...@@ -287,10 +286,6 @@ export default class PanelActions extends React.Component {
response['remove' + Utils.titleCase(this.props.nameFunc)] = this.forRemove; response['remove' + Utils.titleCase(this.props.nameFunc)] = this.forRemove;
} }
/*if (this.refresh.length > 0) {
response.refresh = this.refresh;
}*/
this.props.onApplyChanges(response); this.props.onApplyChanges(response);
} }
......
...@@ -11,6 +11,11 @@ ...@@ -11,6 +11,11 @@
"token": "otto", "token": "otto",
"inmutable": ["mx", "soa", "ns", "spf"] "inmutable": ["mx", "soa", "ns", "spf"]
}, },
"maxAttachmentLimit": {
"max": 52428800,
"min": 1048576,
"step": 1048576
},
"maxResultOnRequestZimbra": 3000, "maxResultOnRequestZimbra": 3000,
"autoincrementOnFailRequestZimbra": 500, "autoincrementOnFailRequestZimbra": 500,
"plans": { "plans": {
...@@ -82,7 +87,8 @@ ...@@ -82,7 +87,8 @@
"businessCategory": true, "businessCategory": true,
"zimbraCreateTimestamp": true, "zimbraCreateTimestamp": true,
"zimbraDomainType": true, "zimbraDomainType": true,
"zimbraMailCatchAllForwardingAddress": true "zimbraMailCatchAllForwardingAddress": true,
"amavisMessageSizeLimit": true
} }
}, },
"search": { "search": {
......
...@@ -21,6 +21,7 @@ $border-rad: 1px; ...@@ -21,6 +21,7 @@ $border-rad: 1px;
$color-navy-blue: #34495e; $color-navy-blue: #34495e;
$color-violet: #9b59b6; $color-violet: #9b59b6;
$color-blue: #3498db; $color-blue: #3498db;
$color-blue-light: #8cc9f2;
$color-green: #62cb31; $color-green: #62cb31;
$color-yellow: #ffb606; $color-yellow: #ffb606;
$color-orange: #e67e22; $color-orange: #e67e22;
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
import EventEmitter from 'events'; import EventEmitter from 'events';
import Constants from '../utils/constants.jsx'; import Constants from '../utils/constants.jsx';
import * as Utils from '../utils/utils.jsx';
const eventTypes = Constants.EventTypes; const eventTypes = Constants.EventTypes;
...@@ -24,7 +25,6 @@ class MailboxStoreClass extends EventEmitter { ...@@ -24,7 +25,6 @@ class MailboxStoreClass extends EventEmitter {
setMailboxesByDomain(id, mailboxes) { setMailboxesByDomain(id, mailboxes) {
if (mailboxes) { if (mailboxes) {
this.mailboxesByDomain[id] = mailboxes; this.mailboxesByDomain[id] = mailboxes;
//console.log('setMailboxesByDomain', this.mailboxesByDomain);
return true; return true;
} }
...@@ -58,31 +58,22 @@ class MailboxStoreClass extends EventEmitter { ...@@ -58,31 +58,22 @@ class MailboxStoreClass extends EventEmitter {
setMailbox(mailbox) { setMailbox(mailbox) {
if (mailboxesArray) { if (mailboxesArray) {
const currentTotal = mailboxesArray.account.push(mailbox); mailboxesArray.account.push(mailbox);
if (currentTotal > mailboxesArray.total) { mailboxesArray.total++;
mailboxesArray.total = currentTotal; mailboxesArray.account.sort(Utils.sortByNames);
} }
} }
}
hasThisPage(page) {
if (page && this.currentPage[page]) {
return this.currentPage[page];
}
return false;
}
setCurrentPage(page) { setMailboxByDomain(domainId, mailbox) {
this.currentPage[page] = true; if (!domainId) {
return null;
} }
getMailboxByPage(page) { if (this.mailboxesByDomain && this.mailboxesByDomain[domainId]) {
if (page && this.currentPage[page]) { this.mailboxesByDomain[domainId].account.push(mailbox);
return this.currentPage[page]; this.mailboxesByDomain[domainId].total++;
this.mailboxesByDomain[domainId].account.sort(Utils.sortByNames);
} }
return false;
} }
setCurrent(account) { setCurrent(account) {
...@@ -103,17 +94,19 @@ class MailboxStoreClass extends EventEmitter { ...@@ -103,17 +94,19 @@ class MailboxStoreClass extends EventEmitter {
if (index > -1) { if (index > -1) {
accounts[index] = newMailbox; accounts[index] = newMailbox;
accounts.sort(Utils.sortByNames);
} }
} }
if (domainId && this.mailboxesByDomain[domainId]) { if (domainId && this.mailboxesByDomain[domainId]) {
const accountsFromDomain = this.mailboxesByDomain.account; const accountsFromDomain = this.mailboxesByDomain[domainId].account;
const indexOfMailbox = accountsFromDomain.findIndex((mailbox) => { const indexOfMailbox = accountsFromDomain.findIndex((mailbox) => {
return mailbox.id === mailboxId; return mailbox.id === mailboxId;
}); });
if (indexOfMailbox > -1) { if (indexOfMailbox > -1) {
accountsFromDomain[indexOfMailbox] = newMailbox; accountsFromDomain[indexOfMailbox] = newMailbox;
accountsFromDomain.sort(Utils.sortByNames);
} }
} }
......
...@@ -692,3 +692,86 @@ export function parseMaxCOSAccounts(maxCosAccounts) { ...@@ -692,3 +692,86 @@ export function parseMaxCOSAccounts(maxCosAccounts) {
return response; 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