Commit e46e475c authored by Juorder Antonio's avatar Juorder Antonio

update mailbox when add, remove alias and get domaind id when it doesnt exists

parent 703e1d44
1465787195
\ No newline at end of file
1466524663
\ No newline at end of file
module.exports = {"main":{"js":"/454009bundle.js"}}
\ No newline at end of file
module.exports = {"main":{"js":"/838029bundle.js"}}
\ No newline at end of file
......@@ -82,10 +82,6 @@ export default class DomainDetails extends React.Component {
}
);
}).then((success) => {
/*if (this.isStoreEnabled) {
//logic
}*/
this.setState({
domain: success
});
......
......@@ -5,6 +5,7 @@ import * as Client from '../../utils/client.jsx';
import * as Utils from '../../utils/utils.jsx';
import * as GlobalActions from '../../action_creators/global_actions.jsx';
import ZimbraStore from '../../stores/zimbra_store.jsx';
import MailboxStore from '../../stores/mailbox_store.jsx';
export default class BlockGeneralInfoMailbox extends React.Component {
constructor(props) {
......@@ -27,6 +28,7 @@ export default class BlockGeneralInfoMailbox extends React.Component {
const domain = Utils.getDomainFromString(this.data.name);
Client.getDomain(domain, (data) => {
MailboxStore.emitDomainId(data.id);
this.setState({
hasDomain: true,
domainData: data
......
......@@ -37,6 +37,7 @@ export default class MailboxDetails extends React.Component {
this.showMessage = this.showMessage.bind(this);
this.onRemoveAlias = this.onRemoveAlias.bind(this);
this.onCancelAlias = this.onCancelAlias.bind(this);
this.setDomainId = this.setDomainId.bind(this);
this.domain_id = this.props.params.domain_id || null;
this.mailboxId = this.props.params.id || null;
......@@ -47,6 +48,12 @@ export default class MailboxDetails extends React.Component {
this.state = {};
}
setDomainId(domainId) {
if (!this.domain_id) {
this.domain_id = domainId;
}
}
handleEdit(e, path, location) {
Utils.handleLink(e, path, location);
}
......@@ -117,9 +124,9 @@ export default class MailboxDetails extends React.Component {
if (!Array.isArray(items)) {
items = [items];
}
}
items.sort(Utils.sortByNames);
items.sort(Utils.sortByNames);
}
mailbox.viewMailPath(global.window.manager_config.webmailLifetime, (error, res) => {
if (res) {
......@@ -149,12 +156,14 @@ export default class MailboxDetails extends React.Component {
componentDidMount() {
EventStore.addMessageListener(this.showMessage);
MailboxStore.addListenerSendDomainId(this.setDomainId);
$('#sidebar-mailboxes').addClass('active');
this.getMailbox(this.mailboxId);
}
componentWillUnmount() {
EventStore.removeMessageListener(this.showMessage);
MailboxStore.removeListenerSendDomainId(this.setDomainId);
$('#sidebar-mailboxes').removeClass('active');
}
......@@ -164,6 +173,7 @@ export default class MailboxDetails extends React.Component {
}).then((data) => {
const errors = [];
const {alias} = this.state;
const mailbox = this.state.data;
if (data.error) {
data.error.forEach((err) => {
......@@ -181,11 +191,19 @@ export default class MailboxDetails extends React.Component {
});
data.completed.forEach((obj) => {
alias.push(obj.target);
if (obj.isNew) {
alias.push(obj.target);
}
});
alias.sort(Utils.sortByNames);
}
if (this.isStoreEnabled) {
mailbox.attrs.zimbraMailAlias = alias;
MailboxStore.updateMailbox(this.mailboxId, mailbox, this.domain_id);
}
return this.setState({
error: errors.length > 0 ? errors : null,
alias
......
......@@ -256,6 +256,20 @@ class MailboxStoreClass extends EventEmitter {
this.removeListener(eventTypes.MAILBOX_ADD_MASSIVE_EVENT, callback);
}
// emit domainId to the parent component
emitDomainId(params) {
this.emit(eventTypes.SEND_DOMAINID_EVENT, params);
}
addListenerSendDomainId(params) {
this.on(eventTypes.SEND_DOMAINID_EVENT, params);
}
removeListenerSendDomainId(params) {
this.removeListener(eventTypes.SEND_DOMAINID_EVENT, params);
}
}
const MailboxStore = new MailboxStoreClass();
......
......@@ -33,7 +33,8 @@ export default {
NEW_TOAST_EVENT: null,
MAILBOX_ADD_MASSIVE_EVENT: null,
NEXT_STEP_EVENT: null,
ZONE_DNS_CHANGE_EVENT: null
ZONE_DNS_CHANGE_EVENT: null,
SEND_DOMAINID_EVENT: null
}),
MessageType: keyMirror({
......
......@@ -739,17 +739,20 @@ export function makeRequest(response, dl, resolve, returnAPI, store) {
const pop = element.pop();
const target = typeof pop === 'object' ? pop.name || pop.id : pop;
const label = action[0] === 'remove' ? 'eliminar' : 'agregar';
const isNew = action[0] === 'remove' ? 0 : 1;
return dl[item](target, (er, success) => {
if (success) {
if (res.completed) {
res.completed.push({
action: label,
target
target,
isNew
});
} else {
res.completed = [{
action: label,
target
target,
isNew
}];
}
const api = success.api && APIReturn ? success : dl;
......
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