Commit 28415fc5 authored by Juorder Gonzalez's avatar Juorder Gonzalez Committed by GitHub

Merge pull request #216 from ZBoxApp/issues_beta_v1

fix the wat on we identify archive account, throw regexp store in jso…
parents e2674fe9 7668dd06
module.exports = {"main":{"js":"/275274bundle.js"}}
\ No newline at end of file
module.exports = {"main":{"js":"/280485bundle.js"}}
\ No newline at end of file
......@@ -94,6 +94,7 @@ export default class EditDomain extends React.Component {
const businessCategory = this.refs.company.value.trim();
const description = this.refs.description.value.trim();
const zimbraNotes = this.refs.notes.value.trim();
const zimbraDomainMaxAccounts = this.refs.mailboxLimit.value;
const plans = this.state.plans;
const plansKeys = Object.keys(plans);
const zimbraDomainCOSMaxAccounts = [];
......@@ -108,7 +109,8 @@ export default class EditDomain extends React.Component {
businessCategory,
description,
zimbraNotes,
zimbraDomainCOSMaxAccounts
zimbraDomainCOSMaxAccounts,
zimbraDomainMaxAccounts
}
};
......
......@@ -33,7 +33,9 @@ export default class CreateMailBox extends React.Component {
this.reset = null;
this.cacheDomain = null;
this.state = {};
this.state = {
zimbraCOSId: ''
};
this.s = true;
}
......@@ -96,8 +98,10 @@ export default class CreateMailBox extends React.Component {
const maxCosAccounts = Utils.parseMaxCOSAccounts(thatDomainExists.attrs.zimbraDomainCOSMaxAccounts);
this.setState({
loadingEnableAccounts: true,
error: false
error: false,
zimbraCOSId: ''
});
return Client.batchCountAccount([thatDomainExists.name],
(s) => {
const usedAccounts = s.pop();
......@@ -175,6 +179,9 @@ export default class CreateMailBox extends React.Component {
const domain = document.querySelector('input[list=\'domain\']');
const passwd = this.refs.passwd.value;
const maskPasswd = document.getElementById('password');
let shouldEnableArchive = false;
const plans = this.state.plans;
let plan = null;
if (domain.value === '') {
GlobalActions.emitMessage({
......@@ -206,11 +213,20 @@ export default class CreateMailBox extends React.Component {
sn: this.refs.sn.value,
displayName: `${this.refs.givenName.value} ${this.refs.sn.value}`,
description: this.refs.description.value,
zimbraCOSId: this.refs.zimbraCOSId.value,
zimbraCOSId: this.state.zimbraCOSId,
zimbraAccountStatus: this.refs.zimbraAccountStatus.value,
zimbraIsDelegatedAdminAccount: this.refs.zimbraIsDelegatedAdminAccount.checked.toString().toUpperCase()
};
const keysPlans = Object.keys(this.state.plans);
keysPlans.forEach((p) => {
if (plans[p] === this.state.zimbraCOSId) {
plan = p;
shouldEnableArchive = window.manager_config.plans[p].archiving;
}
});
Client.createAccount(
email,
passwd,
......@@ -222,7 +238,17 @@ export default class CreateMailBox extends React.Component {
MailboxStore.setMailbox(data);
return Utils.handleLink(event, `/mailboxes/${data.id}`, this.props.location);
if (shouldEnableArchive) {
data.enableArchiving(plan, (err) => {
if (err) {
return err;
}
return Utils.handleLink(event, `/mailboxes/${data.id}`, this.props.location);
});
} else {
return Utils.handleLink(event, `/mailboxes/${data.id}`, this.props.location);
}
/*GlobalActions.emitMessage({
message: 'Se ha creado su cuenta con éxito.',
......@@ -249,7 +275,9 @@ export default class CreateMailBox extends React.Component {
}
handleRadioChanged(val) {
this.refs.zimbraCOSId.value = val;
this.setState({
zimbraCOSId: val
});
}
getAllDomains() {
......@@ -364,15 +392,12 @@ export default class CreateMailBox extends React.Component {
this.s = false;
}
shouldComponentUpdate() {
return true;
}
controllerDataList(controller) {
this.reset = controller;
}
render() {
const {zimbraCOSId} = this.state;
let message;
let domains = [];
let form = null;
......@@ -458,7 +483,77 @@ export default class CreateMailBox extends React.Component {
return null;
});
for (let plan in plans) {
const keyPlans = Object.keys(plans);
keyPlans.forEach((plan) => {
if (plans[plan]) {
let isDisabled = null;
let classCss = null;
let info = null;
let hasPlan = false;
if (this.state.enabledAccounts) {
this.state.enabledAccounts.forEach((p) => {
if (plans[plan] === p.cosId) {
hasPlan = true;
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>
);
}
});
}
if (this.state.enabledAccounts && !hasPlan && null) {
isDisabled = true;
info = (
<div>
<span className='text-danger'>
Este plan no esta contratado
</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);
}
});
/*for (let plan in plans) {
if (plans.hasOwnProperty(plan)) {
let isDisabled = null;
let classCss = null;
......@@ -510,7 +605,7 @@ export default class CreateMailBox extends React.Component {
);
checkboxes.push(item);
}
}
}*/
form = (
<form
......@@ -646,6 +741,7 @@ export default class CreateMailBox extends React.Component {
type='hidden'
ref='zimbraCOSId'
data-required='true'
value={zimbraCOSId}
data-message='El plan de su casilla es requerido, por favor verificar.'
/>
</div>
......@@ -686,14 +782,20 @@ export default class CreateMailBox extends React.Component {
<div className='form-group'>
<div className='col-sm-8 col-sm-offset-3'>
{counterPlans > 0 && (
/*{counterPlans > 0 && (
<input
type='submit'
name='commit'
value='Guardar'
className='btn btn-primary action-save'
/>
)}
)}*/
<input
type='submit'
name='commit'
value='Guardar'
className='btn btn-primary action-save'
/>
<Button
btnAttrs={
{
......
......@@ -8,14 +8,16 @@ import Button from '../button.jsx';
import MessageBar from '../message_bar.jsx';
import Panel from '../panel.jsx';
import DataList from 'react-datalist';
import UserStore from '../../stores/user_store.jsx';
import Promise from 'bluebird';
import MailboxStore from '../../stores/mailbox_store.jsx';
import * as Client from '../../utils/client.jsx';
import * as GlobalActions from '../../action_creators/global_actions.jsx';
import * as Utils from '../../utils/utils.jsx';
import UserStore from '../../stores/user_store.jsx';
import EventStore from '../../stores/event_store.jsx';
import MailboxStore from '../../stores/mailbox_store.jsx';
import ZimbraStore from '../../stores/zimbra_store.jsx';
import Constants from '../../utils/constants.jsx';
......@@ -25,6 +27,7 @@ export default class EditMailBox extends React.Component {
constructor(props) {
super(props);
this.isStoreEnabled = window.manager_config.enableStores;
this.handleEdit = this.handleEdit.bind(this);
this.handleRadioChanged = this.handleRadioChanged.bind(this);
this.getMailbox = this.getMailbox.bind(this);
......@@ -33,7 +36,9 @@ export default class EditMailBox extends React.Component {
this.handleRenameAccount = this.handleRenameAccount.bind(this);
this.editUrlFromParams = this.props.params.domain_id ? `/domains/${this.props.params.domain_id}/mailboxes/` : '/mailboxes/';
this.state = {};
this.state = {
zimbraCOSId: ''
};
}
showMessage(attrs) {
......@@ -44,7 +49,9 @@ export default class EditMailBox extends React.Component {
}
handleRadioChanged(val) {
this.refs.zimbraCOSId.value = val;
this.setState({
zimbraCOSId: val
});
}
removeAccount() {
......@@ -81,7 +88,9 @@ export default class EditMailBox extends React.Component {
}
);
}).then(() => {
MailboxStore.removeAccount(account);
if (this.isStoreEnabled) {
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(
......@@ -157,7 +166,7 @@ export default class EditMailBox extends React.Component {
}
handleRenameAccount(email) {
const account = MailboxStore.getCurrent();
const account = this.isStoreEnabled ? MailboxStore.getCurrent() : null;
if (account) {
const oldName = this.refs.rename.innerHTML;
......@@ -179,14 +188,14 @@ export default class EditMailBox extends React.Component {
});
}
let newAccount = MailboxStore.changeAccount(success);
let newAccount = this.isStoreEnabled ? MailboxStore.changeAccount(success) : null;
if (!newAccount) {
newAccount = success;
}
this.setState({
data: newAccount
data: newAccount || success
});
this.refs.rename.innerHTML = 'Renombrar';
......@@ -216,7 +225,12 @@ export default class EditMailBox extends React.Component {
handleEdit(e) {
e.preventDefault();
Utils.toggleStatusButtons('.action-button', true);
let shouldEnableArchiving = false;
let shouldDisabledArchiving = false;
const plans = this.state.cos;
const mailbox = this.state.data.attrs;
let p;
//Utils.toggleStatusButtons('.action-button', true);
Utils.validateInputRequired(this.refs).then(() => {
// fill new attrs
......@@ -229,6 +243,19 @@ export default class EditMailBox extends React.Component {
displayName: `${this.refs.givenName.value} ${this.refs.sn.value}`
};
const keysPlans = Object.keys(this.state.cos);
const plansConfig = window.manager_config.plans;
keysPlans.forEach((plan) => {
if (plans[plan] === attrs.zimbraCOSId && plansConfig[plan].archiving) {
shouldEnableArchiving = !shouldEnableArchiving;
p = plan;
}
});
if (mailbox.zimbraCOSId !== attrs.zimbraCOSId && mailbox.zimbraArchiveEnabled === 'TRUE') {
shouldDisabledArchiving = !shouldDisabledArchiving;
}
GlobalActions.emitStartLoading();
return new Promise((resolve, reject) => {
......@@ -243,9 +270,31 @@ export default class EditMailBox extends React.Component {
}
);
}).then((account) => {
MailboxStore.changeAccount(account);
if (this.isStoreEnabled) {
MailboxStore.changeAccount(account);
}
if (shouldDisabledArchiving && !shouldEnableArchiving) {
account.disableArchiving((err) => {
if (err) {
return err;
}
Utils.handleLink(e, `/mailboxes/${this.props.params.id}`, this.props.location);
return Utils.handleLink(e, `/mailboxes/${this.props.params.id}`, this.props.location);
});
}
if (shouldEnableArchiving && !shouldDisabledArchiving && mailbox.zimbraArchiveEnabled === 'FALSE') {
account.enableArchiving(p, (err) => {
if (err) {
return err;
}
return Utils.handleLink(e, `/mailboxes/${this.props.params.id}`, this.props.location);
});
}
return Utils.handleLink(e, `/mailboxes/${this.props.params.id}`, this.props.location);
}).catch((error) => {
GlobalActions.emitMessage({
message: error.message,
......@@ -271,8 +320,10 @@ export default class EditMailBox extends React.Component {
let data = null;
const max = 200;
Utils.toggleStatusButtons('.action-save', true);
const cos = Utils.getEnabledPlansByCos(ZimbraStore.getAllCos());
const hasMailboxes = this.isStoreEnabled ? MailboxStore.hasMailboxes() : null;
if (MailboxStore.hasMailboxes()) {
if (hasMailboxes) {
data = MailboxStore.getMailboxById(id);
const domains = new Promise((resolve, reject) => {
......@@ -289,22 +340,17 @@ export default class EditMailBox extends React.Component {
);
});
const cos = new Promise((resolve, reject) => {
Client.getAllCos((success) => {
resolve(success);
}, (error) => {
reject(error);
});
});
promises.push(domains, cos);
promises.push(domains);
Promise.all(promises).then((result) => {
MailboxStore.setCurrent(data);
if (this.isStoreEnabled) {
MailboxStore.setCurrent(data);
}
this.setState({
data,
zimbraCOSId: data.attrs.zimbraCOSId,
domains: result.shift().domain,
cos: Utils.getEnabledPlansByCos(result.shift())
cos
});
Utils.toggleStatusButtons('.action-save', false);
}).catch((error) => {
......@@ -342,27 +388,22 @@ export default class EditMailBox extends React.Component {
);
});
const cos = new Promise((resolve, reject) => {
Client.getAllCos((success) => {
resolve(success);
}, (error) => {
reject(error);
});
});
promises.push(mailbox, doms, cos);
promises.push(mailbox, doms);
Promise.all(promises).then((result) => {
const account = result.shift();
this.setState({
data: account,
zimbraCOSId: account.attrs.zimbraCOSId,
domains: result.shift().domain,
cos: Utils.getEnabledPlansByCos(result.shift())
cos
});
Utils.toggleStatusButtons('.action-save', false);
MailboxStore.setCurrent(account);
if (this.isStoreEnabled) {
MailboxStore.setCurrent(account);
}
}).catch((error) => {
GlobalActions.emitMessage({
message: error.message,
......@@ -391,7 +432,6 @@ export default class EditMailBox extends React.Component {
this.refs.givenName.value = attrs.givenName || '';
this.refs.sn.value = attrs.sn;
this.refs.description.value = attrs.description || '';
this.refs.zimbraCOSId.value = attrs.zimbraCOSId || '';
this.refs.zimbraAccountStatus.value = attrs.zimbraAccountStatus;
}
......@@ -404,6 +444,7 @@ export default class EditMailBox extends React.Component {
const domains = [];
let currentDomain = '';
const cosElements = [];
const {zimbraCOSId} = this.state;
let datalist = (
<input
type='text'
......@@ -487,7 +528,7 @@ export default class EditMailBox extends React.Component {
/>
<span></span>
</div>
{cosName}
{Utils.titleCase(cosName)}
</label>
);
cosElements.push(checkbox);
......@@ -626,6 +667,7 @@ export default class EditMailBox extends React.Component {
<input
type='hidden'
ref='zimbraCOSId'
value={zimbraCOSId}
data-required='true'
data-message='El plan de su cuenta es requerido, por favor verificar.'
/>
......
......@@ -64,7 +64,7 @@ export default class BlockGeneralInfoMailbox extends React.Component {
let AdminStatus = null;
const description = attrs.description;
const mailhost = attrs.zimbraMailHost;
const archive = attrs.zimbraArchiveAccount;
const archive = data.archiveEnabled ? attrs.zimbraArchiveAccount : data.archiveEnabled;
const isAdminDelegated = attrs.zimbraIsDelegatedAdminAccount === 'TRUE';
if (isAdminDelegated) {
statusCos += ' margin-left';
......
......@@ -36,6 +36,8 @@ export default class Mailboxes extends React.Component {
super(props);
this.isStoreEnabled = window.manager_config.enableStores;
this.archivingConfig = window.manager_config.plans.archiving;
this.regexp = new RegExp(this.archivingConfig.regexp, 'gi');
this.showMessage = this.showMessage.bind(this);
this.refreshAllAccounts = this.refreshAllAccounts.bind(this);
this.handleChangeFilter = this.handleChangeFilter.bind(this);
......@@ -365,7 +367,7 @@ export default class Mailboxes extends React.Component {
}
if (!tipo) {
tipo = row.archiveEnabled ? 'Archiving' : 'Desconocido';
tipo = row.name.match(this.regexp) ? 'Archiving' : 'Desconocido';
}
displayName = attrs.displayName || `${attrs.givenName || attrs.cn} ${attrs.sn}`;
......
......@@ -37,7 +37,8 @@
"archiving": {
"statusCos": "btn-warning",
"label": "Archiving",
"isEnabledToEdit": false
"isEnabledToEdit": false,
"regexp": ".archive$"
}
},
"multiFormDomain": {
......
......@@ -690,5 +690,5 @@ export function parseMaxCOSAccounts(maxCosAccounts) {
return response;
}
return arrCos;
return response;
}
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