Skip to content

Commit cfb1ffe

Browse files
refactor: update ui when MailAccountWizard is shown
refs #276
1 parent 7ed305f commit cfb1ffe

File tree

2 files changed

+151
-29
lines changed

2 files changed

+151
-29
lines changed

src/app/PackageController.js

+64-19
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ Ext.define("conjoon.cn_mail.app.PackageController", {
164164
},
165165

166166
control: {
167+
"cn_mail-mailaccountwizard": {
168+
"show": "onMailAccountWizardShownOrClosed"
169+
},
167170
"cn_mail-maildesktopview": {
168171
tabchange: "onMailDesktopViewTabChange"
169172
},
@@ -233,6 +236,9 @@ Ext.define("conjoon.cn_mail.app.PackageController", {
233236
}, {
234237
ref: "toggleGridListButton",
235238
selector: "cn_navport-tbar > #cn_mail-nodeNavToggleList"
239+
}, {
240+
ref: "toggleMailFolderButton",
241+
selector: "cn_navport-tbar > #cn_mail-nodeNavToggleFolder"
236242
}, {
237243
ref: "switchReadingPaneButton",
238244
selector: "cn_navport-tbar > #cn_mail-nodeNavReadingPane"
@@ -254,6 +260,9 @@ Ext.define("conjoon.cn_mail.app.PackageController", {
254260
}, {
255261
ref: "deleteButton",
256262
selector: "cn_navport-tbar > #cn_mail-nodeNavDeleteMessage"
263+
}, {
264+
ref: "addMailAccountButton",
265+
selector: "cn_navport-tbar > #cn_mail-addMailAccountBtn"
257266
}],
258267

259268

@@ -327,9 +336,7 @@ Ext.define("conjoon.cn_mail.app.PackageController", {
327336
// we have not an inbox view. By default, disable all buttons.
328337
// they will either be re-activated instantly or once any of the
329338
// view's or editor's item/draft was loaded
330-
me.disableEmailActionButtons(true);
331-
me.disableEmailEditButtons(true);
332-
339+
me.disableMessageItemContextButtons(true);
333340

334341
if (activatedPanel.isCnMessageEditor) {
335342

@@ -418,8 +425,7 @@ Ext.define("conjoon.cn_mail.app.PackageController", {
418425
if (selection.length) {
419426
me.activateButtonsForMessageItem(selection[0]);
420427
} else {
421-
me.disableEmailActionButtons(true);
422-
me.disableEmailEditButtons(true);
428+
me.disableMessageItemContextButtons(true);
423429
}
424430
},
425431

@@ -474,8 +480,7 @@ Ext.define("conjoon.cn_mail.app.PackageController", {
474480
toggleDisabled = true;
475481

476482
if (accountSelected) {
477-
me.disableEmailActionButtons(true);
478-
me.disableEmailEditButtons(true);
483+
me.disableMessageItemContextButtons(true);
479484
}
480485
} else if (me.getMailMessageGrid().getStore().isLoading()) {
481486
toggleDisabled = true;
@@ -634,8 +639,7 @@ Ext.define("conjoon.cn_mail.app.PackageController", {
634639
me.getToggleGridListButton().setDisabled(accountSelected);
635640

636641
if (accountSelected) {
637-
me.disableEmailActionButtons(true);
638-
me.disableEmailEditButtons(true);
642+
me.disableMessageItemContextButtons(true);
639643
} else {
640644
me.activateButtonsForMessageGrid();
641645
}
@@ -657,8 +661,14 @@ Ext.define("conjoon.cn_mail.app.PackageController", {
657661
return;
658662
}
659663

660-
me.disableEmailActionButtons(true);
661-
me.disableEmailEditButtons(true);
664+
me.disableMessageItemContextButtons(true);
665+
},
666+
667+
668+
disableMessageItemContextButtons (disable) {
669+
const me = this;
670+
me.disableEmailActionButtons(disable);
671+
me.disableEmailEditButtons(disable);
662672
},
663673

664674

@@ -909,20 +919,55 @@ Ext.define("conjoon.cn_mail.app.PackageController", {
909919
/**
910920
* Callback for the node navigation's "add mail account"-button.
911921
*
912-
* @param {Ext.Button} btn
913-
*
914922
* @return {Boolean}
915923
*/
916-
onAddMailAccountBtnClick (btn) {
917-
924+
onAddMailAccountBtnClick () {
918925
const me = this;
926+
me.getMainPackageView().showMailAccountWizard();
927+
},
919928

920-
if (!me.mailAccountHandler.enabled()) {
921-
return false;
929+
930+
/**
931+
* Callback for the show/close event of the MailAccountWizard.
932+
* Will enable/disable toolbar buttons based on the visibiliyt state and the state
933+
* of available MailAccounts.
934+
*
935+
* @param {conjoon.cn_mail.view.mail.account.MailAccountWizard} wizard
936+
*/
937+
onMailAccountWizardShownOrClosed (wizard) {
938+
const
939+
me = this,
940+
btn = me.getAddMailAccountButton(),
941+
isVisible = wizard.isVisible(),
942+
activeAccount = conjoon.cn_mail.store.mail.folder.MailFolderTreeStore.getInstance().findFirstActiveMailAccount();
943+
944+
if (isVisible) {
945+
wizard.on("close", me.onMailAccountWizardShownOrClosed, me, {single: true});
922946
}
923947

924-
me.mailAccountHandler.invoke(btn);
925-
return true;
948+
if (btn) {
949+
btn.setDisabled(isVisible);
950+
}
951+
me.disableUiControlButtons(isVisible);
952+
953+
me.getCreateMessageButton().setDisabled(
954+
isVisible || !activeAccount
955+
);
956+
957+
if (isVisible) {
958+
me.disableMessageItemContextButtons(true);
959+
} else {
960+
me.activateButtonsForMessageGrid();
961+
}
962+
},
963+
964+
965+
disableUiControlButtons (disable) {
966+
const me = this;
967+
968+
me.getSwitchReadingPaneButton().setDisabled(disable);
969+
me.getToggleGridListButton().setDisabled(disable);
970+
me.getToggleMailFolderButton().setDisabled(disable);
926971
},
927972

928973

tests/src/app/PackageControllerTest.js

+87-10
Original file line numberDiff line numberDiff line change
@@ -1766,23 +1766,100 @@ StartTest(async t => {
17661766

17671767
t.it("onAddMailAccountBtnClick()", t => {
17681768

1769-
const fakeComp = {};
1769+
packageCtrl = Ext.create("conjoon.cn_mail.app.PackageController");
1770+
1771+
const FAKE_MAILDESKTOPVIEW = {
1772+
showMailAccountWizard () {
1773+
1774+
}
1775+
};
1776+
1777+
const viewSpy = t.spyOn(packageCtrl, "getMainPackageView").and.callFake(() => FAKE_MAILDESKTOPVIEW);
1778+
const wizardSpy = t.spyOn(FAKE_MAILDESKTOPVIEW, "showMailAccountWizard").and.callFake(() => {});
1779+
1780+
packageCtrl.onAddMailAccountBtnClick();
1781+
1782+
t.expect(wizardSpy.calls.count()).toBe(1);
1783+
1784+
[viewSpy, wizardSpy].map(spy => spy.remove());
1785+
});
17701786

1771-
let ENABLED = false;
1787+
1788+
t.it("onMailAccountWizardShownOrClosed()", t => {
17721789

17731790
packageCtrl = Ext.create("conjoon.cn_mail.app.PackageController");
17741791

1775-
let invokeSpy = t.spyOn(packageCtrl.mailAccountHandler, "invoke").and.callFake(() => {}),
1776-
enabledSpy = t.spyOn(packageCtrl.mailAccountHandler, "enabled").and.callFake(() => ENABLED);
1792+
t.expect(packageCtrl.getControl()["cn_navport-tbar > #cn_mail-addMailAccountBtn"].click).toBe(
1793+
"onAddMailAccountBtnClick"
1794+
);
1795+
1796+
let VISIBLE = false;
1797+
let ACTIVE_ACCOUNT = null;
1798+
let FAKE_ADDMAILACCOUNTBUTTON = {
1799+
setDisabled () {
1800+
1801+
}
1802+
};
1803+
const FAKEWIZARD = {
1804+
isVisible () {
1805+
return VISIBLE;
1806+
},
1807+
on () {
1808+
1809+
}
1810+
};
1811+
const FAKECREATEMESSAGEBUTTON = {
1812+
setDisabled () {
1813+
1814+
}
1815+
};
1816+
1817+
const store = conjoon.cn_mail.store.mail.folder.MailFolderTreeStore.getInstance();
1818+
const onSpy = t.spyOn(FAKEWIZARD, "on").and.callFake(() => {});
1819+
const findFirstActiveMailAccountSpy = t.spyOn(store, "findFirstActiveMailAccount").and.callFake(
1820+
() => ACTIVE_ACCOUNT);
1821+
const createMessageButtonSpy = t.spyOn(packageCtrl, "getCreateMessageButton").and.callFake(
1822+
() => FAKECREATEMESSAGEBUTTON);
1823+
const disableCreateMessageBtnSpy = t.spyOn(FAKECREATEMESSAGEBUTTON, "setDisabled").and.callFake(
1824+
() => {});
1825+
const contextButtonsSpy = t.spyOn(
1826+
packageCtrl, "disableMessageItemContextButtons").and.callFake(() => {});
1827+
const uiButtonSpy = t.spyOn(packageCtrl, "disableUiControlButtons").and.callFake(() => {});
1828+
const messageGridButtonsSpy = t.spyOn(packageCtrl, "activateButtonsForMessageGrid").and.callFake(
1829+
() => {});
1830+
const getAddMailAccountButtonSpy = t.spyOn(packageCtrl, "getAddMailAccountButton").and.callFake(
1831+
() => FAKE_ADDMAILACCOUNTBUTTON
1832+
);
1833+
const disableAddMailAccountButtonSpy = t.spyOn(
1834+
FAKE_ADDMAILACCOUNTBUTTON, "setDisabled").and.callFake(() => {});
1835+
1836+
[false, true].map(isVisible => {
1837+
VISIBLE = isVisible;
1838+
packageCtrl.onMailAccountWizardShownOrClosed(FAKEWIZARD);
1839+
1840+
t.expect(uiButtonSpy.calls.mostRecent().args[0]).toBe(VISIBLE);
1841+
1842+
t.expect(disableAddMailAccountButtonSpy.calls.mostRecent().args[0]).toBe(VISIBLE);
1843+
1844+
if (VISIBLE) {
1845+
t.expect(onSpy.calls.mostRecent().args).toEqual([
1846+
"close", packageCtrl.onMailAccountWizardShownOrClosed, packageCtrl, {single: true}
1847+
]);
1848+
1849+
t.expect(contextButtonsSpy.calls.mostRecent().args[0]).toBe(true);
1850+
} else {
1851+
t.expect(messageGridButtonsSpy.calls.count()).toBe(1);
1852+
}
1853+
t.expect(disableCreateMessageBtnSpy.calls.mostRecent().args[0]).toBe(VISIBLE || !ACTIVE_ACCOUNT);
1854+
});
17771855

1778-
t.expect(packageCtrl.onAddMailAccountBtnClick()).toBe(false);
17791856

1780-
ENABLED = true;
1781-
t.expect(packageCtrl.onAddMailAccountBtnClick(fakeComp)).toBe(true);
1782-
t.expect(invokeSpy.calls.count()).toBe(1);
1783-
t.expect(invokeSpy.calls.mostRecent().args[0]).toBe(fakeComp);
1857+
[
1858+
onSpy, findFirstActiveMailAccountSpy, createMessageButtonSpy, disableCreateMessageBtnSpy,
1859+
contextButtonsSpy,uiButtonSpy, messageGridButtonsSpy, getAddMailAccountButtonSpy,
1860+
disableAddMailAccountButtonSpy
1861+
].map(spy => spy.remove());
17841862

1785-
[invokeSpy, enabledSpy].map(spy => spy.remove());
17861863
});
17871864

17881865

0 commit comments

Comments
 (0)