mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 15:25:35 +08:00
REFACTOR: Remove Discourse
constant from showModal
This commit is contained in:
parent
98e5e1cd53
commit
02e8d84e30
|
@ -1,13 +1,17 @@
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import { dasherize } from "@ember/string";
|
import { dasherize } from "@ember/string";
|
||||||
|
|
||||||
|
let _container;
|
||||||
|
export function setModalContainer(container) {
|
||||||
|
_container = container;
|
||||||
|
}
|
||||||
|
|
||||||
export default function(name, opts) {
|
export default function(name, opts) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
const container = Discourse.__container__;
|
|
||||||
|
|
||||||
// We use the container here because modals are like singletons
|
// We use the container here because modals are like singletons
|
||||||
// in Discourse. Only one can be shown with a particular state.
|
// in Discourse. Only one can be shown with a particular state.
|
||||||
const route = container.lookup("route:application");
|
const route = _container.lookup("route:application");
|
||||||
const modalController = route.controllerFor("modal");
|
const modalController = route.controllerFor("modal");
|
||||||
|
|
||||||
modalController.set(
|
modalController.set(
|
||||||
|
@ -18,7 +22,7 @@ export default function(name, opts) {
|
||||||
const controllerName = opts.admin ? `modals/${name}` : name;
|
const controllerName = opts.admin ? `modals/${name}` : name;
|
||||||
modalController.set("name", controllerName);
|
modalController.set("name", controllerName);
|
||||||
|
|
||||||
let controller = container.lookup("controller:" + controllerName);
|
let controller = _container.lookup("controller:" + controllerName);
|
||||||
const templateName = opts.templateName || dasherize(name);
|
const templateName = opts.templateName || dasherize(name);
|
||||||
|
|
||||||
const renderArgs = { into: "modal", outlet: "modalBody" };
|
const renderArgs = { into: "modal", outlet: "modalBody" };
|
||||||
|
@ -27,7 +31,7 @@ export default function(name, opts) {
|
||||||
} else {
|
} else {
|
||||||
// use a basic controller
|
// use a basic controller
|
||||||
renderArgs.controller = "basic-modal-body";
|
renderArgs.controller = "basic-modal-body";
|
||||||
controller = container.lookup(`controller:${renderArgs.controller}`);
|
controller = _container.lookup(`controller:${renderArgs.controller}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.addModalBodyView) {
|
if (opts.addModalBodyView) {
|
||||||
|
|
|
@ -13,6 +13,7 @@ import deprecated from "discourse-common/lib/deprecated";
|
||||||
import { setIconList } from "discourse-common/lib/icon-library";
|
import { setIconList } from "discourse-common/lib/icon-library";
|
||||||
import { setPluginContainer } from "discourse/lib/plugin-api";
|
import { setPluginContainer } from "discourse/lib/plugin-api";
|
||||||
import { setURLContainer } from "discourse/lib/url";
|
import { setURLContainer } from "discourse/lib/url";
|
||||||
|
import { setModalContainer } from "discourse/lib/show-modal";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "discourse-bootstrap",
|
name: "discourse-bootstrap",
|
||||||
|
@ -21,6 +22,7 @@ export default {
|
||||||
initialize(container, app) {
|
initialize(container, app) {
|
||||||
setPluginContainer(container);
|
setPluginContainer(container);
|
||||||
setURLContainer(container);
|
setURLContainer(container);
|
||||||
|
setModalContainer(container);
|
||||||
|
|
||||||
// Our test environment has its own bootstrap code
|
// Our test environment has its own bootstrap code
|
||||||
if (isTesting()) {
|
if (isTesting()) {
|
||||||
|
|
|
@ -29,6 +29,7 @@ import { currentSettings, mergeSettings } from "helpers/site-settings";
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwner } from "discourse-common/lib/get-owner";
|
||||||
import { setTopicList } from "discourse/lib/topic-list-tracker";
|
import { setTopicList } from "discourse/lib/topic-list-tracker";
|
||||||
import { setURLContainer } from "discourse/lib/url";
|
import { setURLContainer } from "discourse/lib/url";
|
||||||
|
import { setModalContainer } from "discourse/lib/show-modal";
|
||||||
|
|
||||||
export function currentUser() {
|
export function currentUser() {
|
||||||
return User.create(sessionFixtures["/session/current.json"].current_user);
|
return User.create(sessionFixtures["/session/current.json"].current_user);
|
||||||
|
@ -176,6 +177,7 @@ export function acceptance(name, options) {
|
||||||
this.container = getOwner(this);
|
this.container = getOwner(this);
|
||||||
setPluginContainer(this.container);
|
setPluginContainer(this.container);
|
||||||
setURLContainer(this.container);
|
setURLContainer(this.container);
|
||||||
|
setModalContainer(this.container);
|
||||||
if (options.beforeEach) {
|
if (options.beforeEach) {
|
||||||
options.beforeEach.call(this);
|
options.beforeEach.call(this);
|
||||||
}
|
}
|
||||||
|
@ -205,6 +207,7 @@ export function acceptance(name, options) {
|
||||||
setTopicList(null);
|
setTopicList(null);
|
||||||
_clearSnapshots();
|
_clearSnapshots();
|
||||||
setURLContainer(null);
|
setURLContainer(null);
|
||||||
|
setModalContainer(null);
|
||||||
Discourse._runInitializer(
|
Discourse._runInitializer(
|
||||||
"instanceInitializers",
|
"instanceInitializers",
|
||||||
(initName, initializer) => {
|
(initName, initializer) => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user