Commit 2b316059 authored by Elias Nahum's avatar Elias Nahum Committed by Juorder Antonio

add store functionality to companies, and show or hide if user is global admin or no.

parent 1cb0e59a
module.exports = {"main":{"js":"/263980bundle.js"}}
\ No newline at end of file
module.exports = {"main":{"js":"/699779bundle.js"}}
\ No newline at end of file
......@@ -11,6 +11,8 @@ import Panel from '../panel.jsx';
import CompaniesStore from '../../stores/company_store.jsx';
import ZimbraStore from '../../stores/zimbra_store.jsx';
import UserStore from '../../stores/user_store.jsx';
import DomainStore from '../../stores/domain_store.jsx';
import * as Client from '../../utils/client.jsx';
import * as Utils from '../../utils/utils.jsx';
......@@ -30,6 +32,8 @@ export default class Companies extends React.Component {
this.getDomains = this.getDomains.bind(this);
this.getPlans = this.getPlans.bind(this);
this.gotoCompany = this.gotoCompany.bind(this);
this.isGlobalAdmin = UserStore.isGlobalAdmin();
}
gotoCompany(e, company) {
......@@ -47,29 +51,65 @@ export default class Companies extends React.Component {
return GlobalActions.emitEndLoading();
}
return Client.getAllCompanies().then((data) => {
const domains = data.map((company) => {
return self.getDomains(company);
});
const mydomain = UserStore.getCurrentUser().name.split('@').pop();
return Promise.all(domains).then((comps) => {
CompaniesStore.setCompanies(comps);
if (this.isGlobalAdmin) {
return Client.getAllCompanies().then((data) => {
const domains = data.map((company) => {
return self.getDomains(company);
});
self.setState({
companies: comps
return Promise.all(domains).then((comps) => {
CompaniesStore.setCompanies(comps);
self.setState({
companies: comps
});
}).
catch((error) => {
self.setState({error: {
message: error,
type: messageTypes.ERROR
}});
});
}).
catch((error) => {
}).catch((error) => {
self.setState({error});
}).finally(() => {
GlobalActions.emitEndLoading();
});
}
if (DomainStore.getDomains()) {
const domain = DomainStore.getDomainByName(mydomain);
Client.getCompany(domain.attrs.businessCategory, (company) => {
CompaniesStore.setCompanies(company);
}, (error) => {
self.setState({error: {
message: error,
type: messageTypes.ERROR
}});
});
}).catch((error) => {
self.setState({error});
}).finally(() => {
GlobalActions.emitEndLoading();
});
} else {
Client.getDomain(mydomain, (dom) => {
Client.getCompany(dom.attrs.businessCategory, (company) => {
self.setState({
companies: company
});
}, (error) => {
self.setState({error: {
message: error,
type: messageTypes.ERROR
}});
});
}, (error) => {
self.setState({
error,
type: messageTypes.ERROR
});
});
}
return GlobalActions.emitEndLoading();
}
getDomains(company) {
......
......@@ -7,6 +7,8 @@ import DNSZoneForm from './multiform/dns_form.jsx';
import DomainStore from '../../stores/domain_store.jsx';
import EventStore from '../../stores/event_store.jsx';
import MessageBar from '../message_bar.jsx';
import UserStore from '../../stores/user_store.jsx';
import * as GlobalActions from '../../action_creators/global_actions.jsx';
export default class CreateDomain extends React.Component {
constructor(props) {
......@@ -15,6 +17,7 @@ export default class CreateDomain extends React.Component {
this.getNextStep = this.getNextStep.bind(this);
this.showMessage = this.showMessage.bind(this);
this.isGlobalAdmin = UserStore.isGlobalAdmin();
this.multiform = window.manager_config.multiFormDomain;
let total = 1;
......@@ -30,7 +33,8 @@ export default class CreateDomain extends React.Component {
this.state = {
step: 1,
total
total,
isGlobalAdmin: this.isGlobalAdmin
};
}
......@@ -56,6 +60,7 @@ export default class CreateDomain extends React.Component {
componentDidMount() {
DomainStore.addNextStepListener(this.getNextStep);
EventStore.addMessageListener(this.showMessage);
GlobalActions.emitEndLoading();
}
componentWillUnmount() {
......@@ -73,76 +78,97 @@ export default class CreateDomain extends React.Component {
width: `${width}%`
};
let error = null;
let actions = null;
if (this.state.isGlobalAdmin) {
if (this.state.error) {
error = (
<MessageBar
message={this.state.error}
type={this.state.type}
autoclose={true}
/>
);
}
if (this.state.error) {
error = (
<MessageBar
message={this.state.error}
type={this.state.type}
autoclose={true}
/>
);
}
let step = this.state.step;
let step = this.state.step;
if (!this.multiform.hasMailCleaner && step > 1) {
++step;
}
if (!this.multiform.hasMailCleaner && step > 1) {
++step;
}
switch (step) {
case 1:
form = (
<CreateDomainForm
params={this.props.params}
state={this.state}
/>
);
titleForm = 'Creación de Dominio';
break;
case 2:
form = <MailCleanerForm state={this.state}/>;
titleForm = 'Asignación del Dominio al MailCleaner';
break;
case 3:
form = <DNSZoneForm state={this.state}/>;
titleForm = 'Asignación de la Zona DNS';
break;
}
switch (step) {
case 1:
form = (
<CreateDomainForm
params={this.props.params}
state={this.state}
/>
);
titleForm = 'Creación de Dominio';
break;
case 2:
form = <MailCleanerForm state={this.state}/>;
titleForm = 'Asignación del Dominio al MailCleaner';
break;
case 3:
form = <DNSZoneForm state={this.state}/>;
titleForm = 'Asignación de la Zona DNS';
break;
}
//onClick: (e) => Utils.handleLink(e, backUrl)
const actions = [
{
label: 'Cancelar',
props: {
className: 'btn btn-default btn-xs'
//onClick: (e) => Utils.handleLink(e, backUrl)
actions = [
{
label: 'Cancelar',
props: {
className: 'btn btn-default btn-xs'
}
}
}
];
if (this.state.total > 1) {
progressForm = (
<div className='progress'>
<div
className={'progress-bar progress-bar-info progress-bar-striped active text-center step'}
style={progressSize}
>
<span className='progress-text'>{`${titleForm} - ${progress}`}</span>
];
if (this.state.total > 1) {
progressForm = (
<div className='progress'>
<div
className={'progress-bar progress-bar-info progress-bar-striped active text-center step'}
style={progressSize}
>
<span className='progress-text'>{`${titleForm} - ${progress}`}</span>
</div>
</div>
);
}
}
if (!this.state.isGlobalAdmin) {
form = (
<div className='text-center'>
<h4>
{'Lo sentimos pero usted no tiene permiso para crear dominios.'}
</h4>
</div>
);
}
return (
<Panel
title={'Agregar Dominio'}
classHeader={'forum-box'}
btnsHeader={actions}
>
{error}
{progressForm}
{form}
</Panel>
<div>
<div className='content animate-panel'>
<div className='row'>
<div className='col-md-12 panel-with-tabs'>
<Panel
title={'Agregar Dominio'}
classHeader={'forum-box'}
btnsHeader={actions}
>
{error}
{progressForm}
{form}
</Panel>
</div>
</div>
</div>
</div>
);
}
}
......
......@@ -33,8 +33,10 @@ export default class SearchView extends React.Component {
loading: true
});
Client.search({
maxResults: window.manager_config.maxResultOnRequestZimbra,
query: `(|(mail=*${query}*)(cn=*${query}*)(sn=*${query}*)(gn=*${query}*)(displayName=*${query}*)(zimbraMailDeliveryAddress=*${query}*)(zimbraDomainName=*${query}*)(uid=*${query}*)(zimbraMailAlias=*${query}*)(uid=*${query}*)(zimbraDomainName=*${query}*)(cn=*${query}*))`,
types: 'accounts,distributionlists,domains'
types: 'accounts,distributionlists,domains',
attrs: 'objectClass'
}, (success) => {
const result = [];
......@@ -55,7 +57,8 @@ export default class SearchView extends React.Component {
return this.setState({
result,
loading: false
loading: false,
notfound: false
});
}, (error) => {
console.log(error); //eslint-disable-line no-console
......@@ -131,6 +134,7 @@ export default class SearchView extends React.Component {
<tr
key={id}
className={'mailbox-row'}
onClick={(e) => Utils.handleLink(e, url)}
>
<td className={'mailbox-name'}>
{tipo}
......@@ -166,7 +170,7 @@ export default class SearchView extends React.Component {
id='index-domains'
cellPadding='1'
cellSpacing='1'
className='table table-condensed table-striped vertical-align index-mailbox-table'
className='table table-condensed table-striped vertical-align index-mailbox-table table-search'
>
<thead>
<tr>
......
.margin-left {
margin-left: 5px;
}
.table-search {
.mailbox-row {
transition: background-color .5s;
&:hover {
background-color: $color-background;
cursor: pointer;
}
}
}
......@@ -18,6 +18,7 @@ class DomainStoreClass extends EventEmitter {
resetThisStore() {
this.current = null;
this.domains = null;
this.distributionListOwners = null;
this.distributionListMembers = null;
this.zoneDNS = null;
......@@ -39,6 +40,24 @@ class DomainStoreClass extends EventEmitter {
return null;
}
getDomainByName(name) {
if (this.domains) {
const data = this.domains.domain;
if (data) {
let length = data.length;
for (;length-- > 0;) {
if (data[length].name === name) {
return data[length];
}
}
}
}
return null;
}
getCurrent() {
return this.current;
}
......
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