Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function(name, opts) {
opts = opts || {};
const container = Discourse.__container__;
// We use the container here because modals are like singletons
// in Discourse. Only one can be shown with a particular state.
const route = container.lookup("route:application");
const modalController = route.controllerFor("modal");
modalController.set("modalClass", opts.modalClass);
const controllerName = opts.admin ? `modals/${name}` : name;
modalController.set("name", controllerName);
let controller = container.lookup("controller:" + controllerName);
const templateName = opts.templateName || dasherize(name);
const renderArgs = { into: "modal", outlet: "modalBody" };
if (controller) {
renderArgs.controller = controllerName;
} else {
// use a basic controller
renderArgs.controller = "basic-modal-body";
controller = container.lookup(`controller:${renderArgs.controller}`);
}
if (opts.addModalBodyView) {
renderArgs.view = "modal-body";
}
const modalName = `modal/${templateName}`;
const fullName = opts.admin ? `admin/templates/${modalName}` : modalName;
import {dasherize} from '@ember/string';
// we use data attributes rather than classes even though they can be slower
// because in many instances our draggable/droppable element's classes attribute
// could be dynamically generated which could remove our DnD classes when changed
export const CONTAINER_DATA_ATTR = 'koenigDndContainer';
export const CONTAINER_SELECTOR = `[data-${dasherize(CONTAINER_DATA_ATTR)}]`;
export const DRAGGABLE_DATA_ATTR = 'koenigDndDraggable';
export const DRAGGABLE_SELECTOR = `[data-${dasherize(DRAGGABLE_DATA_ATTR)}]`;
export const DROPPABLE_DATA_ATTR = 'koenigDndDroppable';
export const DROPPABLE_SELECTOR = `[data-${dasherize(DROPPABLE_DATA_ATTR)}]`;
export const DRAG_DISABLED_DATA_ATTR = 'koenigDndDisabled';
export const DRAG_DISABLED_SELECTOR = `[data-${dasherize(DRAG_DISABLED_DATA_ATTR)}]`;
export const DROP_INDICATOR_ID = 'koenig-drag-drop-indicator';
export const DROP_INDICATOR_ZINDEX = 10000;
export const GHOST_CONTAINER_ID = 'koenig-drag-drop-ghost-container';
export const GHOST_ZINDEX = DROP_INDICATOR_ZINDEX + 1;
import {dasherize} from '@ember/string';
// we use data attributes rather than classes even though they can be slower
// because in many instances our draggable/droppable element's classes attribute
// could be dynamically generated which could remove our DnD classes when changed
export const CONTAINER_DATA_ATTR = 'koenigDndContainer';
export const CONTAINER_SELECTOR = `[data-${dasherize(CONTAINER_DATA_ATTR)}]`;
export const DRAGGABLE_DATA_ATTR = 'koenigDndDraggable';
export const DRAGGABLE_SELECTOR = `[data-${dasherize(DRAGGABLE_DATA_ATTR)}]`;
export const DROPPABLE_DATA_ATTR = 'koenigDndDroppable';
export const DROPPABLE_SELECTOR = `[data-${dasherize(DROPPABLE_DATA_ATTR)}]`;
export const DRAG_DISABLED_DATA_ATTR = 'koenigDndDisabled';
export const DRAG_DISABLED_SELECTOR = `[data-${dasherize(DRAG_DISABLED_DATA_ATTR)}]`;
export const DROP_INDICATOR_ID = 'koenig-drag-drop-indicator';
export const DROP_INDICATOR_ZINDEX = 10000;
export const GHOST_CONTAINER_ID = 'koenig-drag-drop-ghost-container';
export const GHOST_ZINDEX = DROP_INDICATOR_ZINDEX + 1;
async didUpdateArguments() {
for (let key of this.validArgs) {
let prevValue = this.prev[key];
let value = this.args.named[key];
this.prev[key] = value; // update previous value
if (prevValue !== value) {
let className = dasherize(key);
if (value) {
this.addClass(className);
await this.transition('add', className);
if (this.args.named.didTransitionIn) {
this.args.named.didTransitionIn(className);
}
} else {
await this.transition('remove', className);
if (this.args.named.didTransitionOut) {
this.args.named.didTransitionOut(className);
}
}
}
export const examples = definitions.map(example => {
return assign({}, example, {
slug: dasherize(example.title)
});
})
get fieldEditor() {
return `fields/${dasherize(this.sanitizedType)}-editor`;
}
selectSearchResult({ communityDistricts }, { geometry }) {
const foundDistrict = lookupCommunityDistrict([communityDistricts, geometry]);
this.transitionToRoute('show-geography', { queryParams: { 'community-districts': [dasherize(foundDistrict)] } });
}
}
get fieldEditor() {
return `fields/${dasherize(this.sanitizedType)}-editor`;
}
get isolatedComponentName() {
return `cards/${dasherize(this.componentName)}/isolated`;
}
}
_lookupAdapter(adapterName) {
assert('Could not find integration without a name', adapterName);
const owner = getOwner(this);
const dasherizedAdapterName = dasherize(adapterName);
const localAdapter = owner.lookup(`ember-cli-analytics@integration:${dasherizedAdapterName}`);
const adapter = owner.lookup(`integration:${dasherizedAdapterName}`);
return adapter ? adapter : localAdapter;
}
});