Commit 430137a2 authored by enahum's avatar enahum

Merge pull request #37 from ZBoxApp/edit-domain

Domain edit with the ability to move between companies
parents b6f96f9d 06606994
...@@ -69,12 +69,16 @@ export default class CreateDomain extends React.Component { ...@@ -69,12 +69,16 @@ export default class CreateDomain extends React.Component {
handleSubmit(e) { handleSubmit(e) {
e.preventDefault(); e.preventDefault();
GlobalActions.emitStartLoading(); GlobalActions.emitStartLoading();
const elementList = document.querySelectorAll('.has-error');
Array.from(elementList).forEach((el) => el.classList.remove('has-error'));
Utils.validateInputRequired(this.refs). Utils.validateInputRequired(this.refs).
then(() => { then(() => {
const plans = Object.keys(this.state.plans); const plans = Object.keys(this.state.plans);
const zimbraDomainCOSMaxAccounts = []; const zimbraDomainCOSMaxAccounts = [];
const name = this.refs.domainName.value.trim(); const name = this.refs.domainName.value.trim();
const businessCategory = this.refs.account.value.trim(); const businessCategory = this.refs.company.value.trim();
plans.forEach((p) => { plans.forEach((p) => {
zimbraDomainCOSMaxAccounts.push(`${this.refs[`plan-${p}`].getAttribute('data-id')}:${this.refs[`plan-${p}`].value || 0}`); zimbraDomainCOSMaxAccounts.push(`${this.refs[`plan-${p}`].getAttribute('data-id')}:${this.refs[`plan-${p}`].value || 0}`);
...@@ -105,6 +109,7 @@ export default class CreateDomain extends React.Component { ...@@ -105,6 +109,7 @@ export default class CreateDomain extends React.Component {
GlobalActions.emitEndLoading(); GlobalActions.emitEndLoading();
error.refs = true; error.refs = true;
error.type = error.typeError; error.type = error.typeError;
error.node.closest('.form-group').classList.add('has-error');
return this.setState({error}); return this.setState({error});
}); });
} }
...@@ -124,11 +129,7 @@ export default class CreateDomain extends React.Component { ...@@ -124,11 +129,7 @@ export default class CreateDomain extends React.Component {
} }
let errorBar; let errorBar;
let formClass = 'simple_form form-horizontal mailbox-form';
if (error) { if (error) {
if (error.refs) {
formClass += ' has-error';
}
errorBar = ( errorBar = (
<MessageBar <MessageBar
message={error.message} message={error.message}
...@@ -187,7 +188,7 @@ export default class CreateDomain extends React.Component { ...@@ -187,7 +188,7 @@ export default class CreateDomain extends React.Component {
const form = ( const form = (
<form <form
className={formClass} className='simple_form form-horizontal mailbox-form'
onSubmit={this.handleSubmit} onSubmit={this.handleSubmit}
> >
<div className='form-group string required'> <div className='form-group string required'>
...@@ -211,15 +212,15 @@ export default class CreateDomain extends React.Component { ...@@ -211,15 +212,15 @@ export default class CreateDomain extends React.Component {
<div className='form-group string'> <div className='form-group string'>
<label className='string required col-sm-3 control-label'> <label className='string required col-sm-3 control-label'>
<abbr title='requerido'>{'*'}</abbr> <abbr title='requerido'>{'*'}</abbr>
{'Cuenta'} {'Empresa'}
</label> </label>
<div className='col-sm-8'> <div className='col-sm-8'>
<select <select
className='form-control select required' className='form-control select required'
data-required='true' data-required='true'
data-message='Debe especificar a que cuenta corresponde el dominio' data-message='Debe especificar a que empresa corresponde el dominio'
ref='account' ref='company'
defaultValue={this.state.companyId} defaultValue={this.state.companyId}
> >
{companiesOptions} {companiesOptions}
......
This diff is collapsed.
...@@ -67,52 +67,74 @@ class CompanyStoreClass { ...@@ -67,52 +67,74 @@ class CompanyStoreClass {
} }
} }
addDomainAdmins(companyId, domain) { modifyDomain(prevCompanyId, domain) {
function findDomain(company) { if (this.companies) {
const domains = company.domains; const domainCompanyId = domain.attrs.businessCategory;
let index = -1; const prevCompany = this.companies[prevCompanyId];
const newCompany = this.companies[domainCompanyId];
if (domains) {
domains.forEach((d, i) => { if (prevCompanyId !== domainCompanyId) {
if (d.id === domain.id) { if (newCompany) {
index = i; this.addDomain(newCompany.id, domain);
return false; }
}
return true; if (prevCompany) {
}); const index = findDomain(prevCompany, domain);
} prevCompany.domains.splice(index, 1);
}
return index; } else if (prevCompany) {
} const index = findDomain(prevCompany, domain);
replaceDomain(prevCompany, domain, index);
function replaceDomain(company, index) {
if (index >= 0) {
company.domains[index] = domain;
} else {
company.domains.push(domain);
} }
} }
}
addDomainAdmins(companyId, domain) {
const currentCompany = this.getCurrent(); const currentCompany = this.getCurrent();
const company = this.getCompanyById(companyId); const company = this.getCompanyById(companyId);
let index = -1; let index = -1;
if (currentCompany && currentCompany.id === companyId) { if (currentCompany && currentCompany.id === companyId) {
index = findDomain(currentCompany); index = findDomain(currentCompany, domain);
replaceDomain(currentCompany, index); replaceDomain(currentCompany, domain, index);
if (company) { if (company) {
this.companies[companyId] = currentCompany; this.companies[companyId] = currentCompany;
} }
} else if (company) { } else if (company) {
index = findDomain(company); index = findDomain(company, domain);
replaceDomain(company, index); replaceDomain(company, domain, index);
} }
} }
} }
function findDomain(company, domain) {
const domains = company.domains;
let index = -1;
if (domains) {
domains.forEach((d, i) => {
if (d.id === domain.id) {
index = i;
return false;
}
return true;
});
}
return index;
}
function replaceDomain(company, domain, index) {
if (index >= 0) {
company.domains[index] = domain;
} else {
company.domains.push(domain);
}
}
const CompanyStore = new CompanyStoreClass(); const CompanyStore = new CompanyStoreClass();
export {CompanyStore as default}; export {CompanyStore as default};
...@@ -247,6 +247,25 @@ export function createDomain(domain, success, error) { ...@@ -247,6 +247,25 @@ export function createDomain(domain, success, error) {
); );
} }
export function modifyDomain(domain, success, error) {
initZimbra().then(
(zimbra) => {
zimbra.modifyDomain(domain.id, domain.attrs, (err, data) => {
if (err) {
const e = handleError('modifyDomain', err);
return error(e);
}
return success(data);
});
},
(err) => {
const e = handleError('modifyDomain', err);
return error(e);
}
);
}
export function addDistributionList(name, attrs, success, error) { export function addDistributionList(name, attrs, success, error) {
initZimbra().then( initZimbra().then(
(zimbra) => { (zimbra) => {
......
...@@ -170,7 +170,7 @@ export function validateInputRequired(refs) { ...@@ -170,7 +170,7 @@ export function validateInputRequired(refs) {
} }
for (const ref in refs) { for (const ref in refs) {
if (refs.hasOwnProperty(ref)) { if (refs.hasOwnProperty(ref) && refs[ref].hasAttribute) {
if (refs[ref].hasAttribute('data-required') && refs[ref].getAttribute('data-required') === 'true' && refs[ref].value === '') { if (refs[ref].hasAttribute('data-required') && refs[ref].getAttribute('data-required') === 'true' && refs[ref].value === '') {
let message; let message;
if (refs[ref].getAttribute('data-message') && refs[ref].getAttribute('data-message').length > 0) { if (refs[ref].getAttribute('data-message') && refs[ref].getAttribute('data-message').length > 0) {
......
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