Migrate `this.container` to `getOwner(this)`
This commit is contained in:
parent
24ad68e765
commit
70fb2431a1
|
@ -1,6 +1,8 @@
|
||||||
|
import { getOwner } from 'discourse-common/lib/get-owner';
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
router: function() {
|
router: function() {
|
||||||
return this.container.lookup('router:main');
|
return getOwner(this).lookup('router:main');
|
||||||
}.property(),
|
}.property(),
|
||||||
|
|
||||||
active: function() {
|
active: function() {
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
export default function deprecated(msg) {
|
||||||
|
console.warn(`DEPRECATION: ${msg}`);
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
import deprecated from 'discourse-common/lib/deprecated';
|
||||||
|
|
||||||
|
export function getOwner(obj) {
|
||||||
|
if (Ember.getOwner) {
|
||||||
|
return Ember.getOwner(obj) || Discourse.__container__;
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj.container;
|
||||||
|
}
|
||||||
|
|
||||||
|
// `this.container` is deprecated, but we can still build a container-like
|
||||||
|
// object for components to use
|
||||||
|
export function getRegister(obj) {
|
||||||
|
const owner = getOwner(obj);
|
||||||
|
const register = {
|
||||||
|
lookup: (...args) => owner.lookup(...args),
|
||||||
|
lookupFactory: (...args) => {
|
||||||
|
return owner.lookupFactory ? owner.lookupFactory(...args) : owner._lookupFactory(...args);
|
||||||
|
},
|
||||||
|
|
||||||
|
deprecateContainer(target) {
|
||||||
|
Object.defineProperty(target, 'container', {
|
||||||
|
get() {
|
||||||
|
deprecated("Use `this.register` or `getOwner` instead of `this.container`");
|
||||||
|
return register;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return register;
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
import { on, observes, default as computed } from 'ember-addons/ember-computed-decorators';
|
import { on, observes, default as computed } from 'ember-addons/ember-computed-decorators';
|
||||||
|
import { getOwner } from 'discourse-common/lib/get-owner';
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
@computed('placeholderKey')
|
@computed('placeholderKey')
|
||||||
|
@ -17,7 +18,7 @@ export default Ember.Component.extend({
|
||||||
var self = this;
|
var self = this;
|
||||||
var selectedBadges;
|
var selectedBadges;
|
||||||
|
|
||||||
var template = this.container.lookup('template:badge-selector-autocomplete.raw');
|
var template = getOwner(this).lookup('template:badge-selector-autocomplete.raw');
|
||||||
self.$('input').autocomplete({
|
self.$('input').autocomplete({
|
||||||
allowAny: false,
|
allowAny: false,
|
||||||
items: _.isArray(this.get('badgeNames')) ? this.get('badgeNames') : [this.get('badgeNames')],
|
items: _.isArray(this.get('badgeNames')) ? this.get('badgeNames') : [this.get('badgeNames')],
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { categoryBadgeHTML } from 'discourse/helpers/category-link';
|
import { categoryBadgeHTML } from 'discourse/helpers/category-link';
|
||||||
import Category from 'discourse/models/category';
|
import Category from 'discourse/models/category';
|
||||||
import { on, observes } from 'ember-addons/ember-computed-decorators';
|
import { on, observes } from 'ember-addons/ember-computed-decorators';
|
||||||
|
import { getOwner } from 'discourse-common/lib/get-owner';
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
@observes('categories')
|
@observes('categories')
|
||||||
|
@ -12,7 +13,7 @@ export default Ember.Component.extend({
|
||||||
@on('didInsertElement')
|
@on('didInsertElement')
|
||||||
_initializeAutocomplete(opts) {
|
_initializeAutocomplete(opts) {
|
||||||
const self = this,
|
const self = this,
|
||||||
template = this.container.lookup('template:category-selector-autocomplete.raw'),
|
template = getOwner(this).lookup('template:category-selector-autocomplete.raw'),
|
||||||
regexp = new RegExp(`href=['\"]${Discourse.getURL('/c/')}([^'\"]+)`);
|
regexp = new RegExp(`href=['\"]${Discourse.getURL('/c/')}([^'\"]+)`);
|
||||||
|
|
||||||
this.$('input').autocomplete({
|
this.$('input').autocomplete({
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { linkSeenTagHashtags, fetchUnseenTagHashtags } from 'discourse/lib/link-
|
||||||
import { load } from 'pretty-text/oneboxer';
|
import { load } from 'pretty-text/oneboxer';
|
||||||
import { ajax } from 'discourse/lib/ajax';
|
import { ajax } from 'discourse/lib/ajax';
|
||||||
import InputValidation from 'discourse/models/input-validation';
|
import InputValidation from 'discourse/models/input-validation';
|
||||||
|
import { getOwner } from 'discourse-common/lib/get-owner';
|
||||||
import { tinyAvatar,
|
import { tinyAvatar,
|
||||||
displayErrorForUpload,
|
displayErrorForUpload,
|
||||||
getUploadMarkdown,
|
getUploadMarkdown,
|
||||||
|
@ -62,7 +62,7 @@ export default Ember.Component.extend({
|
||||||
@on('didInsertElement')
|
@on('didInsertElement')
|
||||||
_composerEditorInit() {
|
_composerEditorInit() {
|
||||||
const topicId = this.get('topic.id');
|
const topicId = this.get('topic.id');
|
||||||
const template = this.container.lookup('template:user-selector-autocomplete.raw');
|
const template = getOwner(this).lookup('template:user-selector-autocomplete.raw');
|
||||||
const $input = this.$('.d-editor-input');
|
const $input = this.$('.d-editor-input');
|
||||||
$input.autocomplete({
|
$input.autocomplete({
|
||||||
template,
|
template,
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import computed from 'ember-addons/ember-computed-decorators';
|
import computed from 'ember-addons/ember-computed-decorators';
|
||||||
|
import { getOwner } from 'discourse-common/lib/get-owner';
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
classNameBindings: [':composer-popup', ':hidden', 'message.extraClass'],
|
classNameBindings: [':composer-popup', ':hidden', 'message.extraClass'],
|
||||||
|
|
||||||
@computed('message.templateName')
|
@computed('message.templateName')
|
||||||
defaultLayout(templateName) {
|
defaultLayout(templateName) {
|
||||||
return this.container.lookup(`template:composer/${templateName}`);
|
return getOwner(this).lookup(`template:composer/${templateName}`);
|
||||||
},
|
},
|
||||||
|
|
||||||
didInsertElement() {
|
didInsertElement() {
|
||||||
|
|
|
@ -10,6 +10,8 @@ import { cook } from 'discourse/lib/text';
|
||||||
import { translations } from 'pretty-text/emoji/data';
|
import { translations } from 'pretty-text/emoji/data';
|
||||||
import { emojiSearch } from 'pretty-text/emoji';
|
import { emojiSearch } from 'pretty-text/emoji';
|
||||||
import { emojiUrlFor } from 'discourse/lib/text';
|
import { emojiUrlFor } from 'discourse/lib/text';
|
||||||
|
import { getRegister } from 'discourse-common/lib/get-owner';
|
||||||
|
import deprecated from 'discourse-common/lib/deprecated';
|
||||||
|
|
||||||
// Our head can be a static string or a function that returns a string
|
// Our head can be a static string or a function that returns a string
|
||||||
// based on input (like for numbered lists).
|
// based on input (like for numbered lists).
|
||||||
|
@ -182,7 +184,7 @@ export function addToolbarCallback(func) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function onToolbarCreate(func) {
|
export function onToolbarCreate(func) {
|
||||||
console.warn('`onToolbarCreate` is deprecated, use the plugin api instead.');
|
deprecated('`onToolbarCreate` is deprecated, use the plugin api instead.');
|
||||||
addToolbarCallback(func);
|
addToolbarCallback(func);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -205,15 +207,18 @@ export default Ember.Component.extend({
|
||||||
this.set('ready', true);
|
this.set('ready', true);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
init() {
|
||||||
|
this._super();
|
||||||
|
this.register = getRegister(this);
|
||||||
|
},
|
||||||
|
|
||||||
didInsertElement() {
|
didInsertElement() {
|
||||||
this._super();
|
this._super();
|
||||||
|
|
||||||
const container = this.get('container'),
|
const $editorInput = this.$('.d-editor-input');
|
||||||
$editorInput = this.$('.d-editor-input');
|
|
||||||
|
|
||||||
this._applyEmojiAutocomplete(container, $editorInput);
|
|
||||||
this._applyCategoryHashtagAutocomplete(container, $editorInput);
|
|
||||||
|
|
||||||
|
this._applyEmojiAutocomplete($editorInput);
|
||||||
|
this._applyCategoryHashtagAutocomplete($editorInput);
|
||||||
|
|
||||||
Ember.run.scheduleOnce('afterRender', this, this._readyNow);
|
Ember.run.scheduleOnce('afterRender', this, this._readyNow);
|
||||||
|
|
||||||
|
@ -287,8 +292,8 @@ export default Ember.Component.extend({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_applyCategoryHashtagAutocomplete(container) {
|
_applyCategoryHashtagAutocomplete() {
|
||||||
const template = container.lookup('template:category-tag-autocomplete.raw');
|
const template = this.register.lookup('template:category-tag-autocomplete.raw');
|
||||||
const siteSettings = this.siteSettings;
|
const siteSettings = this.siteSettings;
|
||||||
|
|
||||||
this.$('.d-editor-input').autocomplete({
|
this.$('.d-editor-input').autocomplete({
|
||||||
|
@ -310,10 +315,11 @@ export default Ember.Component.extend({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_applyEmojiAutocomplete(container, $editorInput) {
|
_applyEmojiAutocomplete($editorInput) {
|
||||||
if (!this.siteSettings.enable_emoji) { return; }
|
if (!this.siteSettings.enable_emoji) { return; }
|
||||||
|
|
||||||
const template = container.lookup('template:emoji-selector-autocomplete.raw');
|
const register = this.register;
|
||||||
|
const template = this.register.lookup('template:emoji-selector-autocomplete.raw');
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
$editorInput.autocomplete({
|
$editorInput.autocomplete({
|
||||||
|
@ -329,7 +335,7 @@ export default Ember.Component.extend({
|
||||||
} else {
|
} else {
|
||||||
showSelector({
|
showSelector({
|
||||||
appendTo: self.$(),
|
appendTo: self.$(),
|
||||||
container,
|
register,
|
||||||
onSelect: title => {
|
onSelect: title => {
|
||||||
// Remove the previously type characters when a new emoji is selected from the selector.
|
// Remove the previously type characters when a new emoji is selected from the selector.
|
||||||
let selected = self._getSelected();
|
let selected = self._getSelected();
|
||||||
|
@ -614,7 +620,7 @@ export default Ember.Component.extend({
|
||||||
emoji() {
|
emoji() {
|
||||||
showSelector({
|
showSelector({
|
||||||
appendTo: this.$(),
|
appendTo: this.$(),
|
||||||
container: this.container,
|
register: this.register,
|
||||||
onSelect: title => this._addText(this._getSelected(), `:${title}:`)
|
onSelect: title => this._addText(this._getSelected(), `:${title}:`)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { on, observes, default as computed } from 'ember-addons/ember-computed-decorators';
|
import { on, observes, default as computed } from 'ember-addons/ember-computed-decorators';
|
||||||
|
import { getOwner } from 'discourse-common/lib/get-owner';
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
@computed('placeholderKey')
|
@computed('placeholderKey')
|
||||||
|
@ -18,7 +19,7 @@ export default Ember.Component.extend({
|
||||||
var selectedGroups;
|
var selectedGroups;
|
||||||
var groupNames = this.get('groupNames');
|
var groupNames = this.get('groupNames');
|
||||||
|
|
||||||
var template = this.container.lookup('template:group-selector-autocomplete.raw');
|
var template = getOwner(this).lookup('template:group-selector-autocomplete.raw');
|
||||||
self.$('input').autocomplete({
|
self.$('input').autocomplete({
|
||||||
allowAny: false,
|
allowAny: false,
|
||||||
items: _.isArray(groupNames) ? groupNames : (Ember.isEmpty(groupNames)) ? [] : [groupNames],
|
items: _.isArray(groupNames) ? groupNames : (Ember.isEmpty(groupNames)) ? [] : [groupNames],
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import deprecated from 'discourse-common/lib/deprecated';
|
||||||
|
|
||||||
export function needsSecondRowIf() {
|
export function needsSecondRowIf() {
|
||||||
Ember.warn("DEPRECATION: `needsSecondRowIf` is deprecated. Use widget hooks on `header-second-row`");
|
deprecated("`needsSecondRowIf` is deprecated. Use widget hooks on `header-second-row`");
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { keyDirty } from 'discourse/widgets/widget';
|
||||||
import { diff, patch } from 'virtual-dom';
|
import { diff, patch } from 'virtual-dom';
|
||||||
import { WidgetClickHook } from 'discourse/widgets/hooks';
|
import { WidgetClickHook } from 'discourse/widgets/hooks';
|
||||||
import { renderedKey, queryRegistry } from 'discourse/widgets/widget';
|
import { renderedKey, queryRegistry } from 'discourse/widgets/widget';
|
||||||
|
import { getRegister } from 'discourse-common/lib/get-owner';
|
||||||
|
|
||||||
const _cleanCallbacks = {};
|
const _cleanCallbacks = {};
|
||||||
export function addWidgetCleanCallback(widgetName, fn) {
|
export function addWidgetCleanCallback(widgetName, fn) {
|
||||||
|
@ -24,12 +25,15 @@ export default Ember.Component.extend({
|
||||||
|
|
||||||
(this.get('delegated') || []).forEach(m => this.set(m, m));
|
(this.get('delegated') || []).forEach(m => this.set(m, m));
|
||||||
|
|
||||||
this._widgetClass = queryRegistry(name) || this.container.lookupFactory(`widget:${name}`);
|
this.register = getRegister(this);
|
||||||
|
|
||||||
|
this._widgetClass = queryRegistry(name) || this.register.lookupFactory(`widget:${name}`);
|
||||||
|
|
||||||
if (!this._widgetClass) {
|
if (!this._widgetClass) {
|
||||||
console.error(`Error: Could not find widget: ${name}`);
|
console.error(`Error: Could not find widget: ${name}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this._childEvents = [];
|
this._childEvents = [];
|
||||||
this._connected = [];
|
this._connected = [];
|
||||||
this._dispatched = [];
|
this._dispatched = [];
|
||||||
|
@ -97,13 +101,14 @@ export default Ember.Component.extend({
|
||||||
|
|
||||||
rerenderWidget() {
|
rerenderWidget() {
|
||||||
Ember.run.cancel(this._timeout);
|
Ember.run.cancel(this._timeout);
|
||||||
|
|
||||||
if (this._rootNode) {
|
if (this._rootNode) {
|
||||||
if (!this._widgetClass) { return; }
|
if (!this._widgetClass) { return; }
|
||||||
|
|
||||||
const t0 = new Date().getTime();
|
const t0 = new Date().getTime();
|
||||||
const args = this.get('args') || this.buildArgs();
|
const args = this.get('args') || this.buildArgs();
|
||||||
const opts = { model: this.get('model') };
|
const opts = { model: this.get('model') };
|
||||||
const newTree = new this._widgetClass(args, this.container, opts);
|
const newTree = new this._widgetClass(args, this.register, opts);
|
||||||
|
|
||||||
newTree._emberView = this;
|
newTree._emberView = this;
|
||||||
const patches = diff(this._tree || this._rootNode, newTree);
|
const patches = diff(this._tree || this._rootNode, newTree);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/* You might be looking for navigation-item. */
|
/* You might be looking for navigation-item. */
|
||||||
|
|
||||||
import computed from "ember-addons/ember-computed-decorators";
|
import computed from "ember-addons/ember-computed-decorators";
|
||||||
|
import { getOwner } from 'discourse-common/lib/get-owner';
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
tagName: 'li',
|
tagName: 'li',
|
||||||
|
@ -8,7 +9,7 @@ export default Ember.Component.extend({
|
||||||
|
|
||||||
@computed()
|
@computed()
|
||||||
router() {
|
router() {
|
||||||
return this.container.lookup('router:main');
|
return getOwner(this).lookup('router:main');
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed("path")
|
@computed("path")
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import computed from 'ember-addons/ember-computed-decorators';
|
import computed from 'ember-addons/ember-computed-decorators';
|
||||||
import { bufferedRender } from 'discourse-common/lib/buffered-render';
|
import { bufferedRender } from 'discourse-common/lib/buffered-render';
|
||||||
|
import { getOwner } from 'discourse-common/lib/get-owner';
|
||||||
|
|
||||||
export function showEntrance(e) {
|
export function showEntrance(e) {
|
||||||
let target = $(e.target);
|
let target = $(e.target);
|
||||||
|
@ -11,7 +12,7 @@ export function showEntrance(e) {
|
||||||
target = target.end();
|
target = target.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.container.lookup('controller:application').send("showTopicEntrance", {topic: this.get('topic'), position: target.offset()});
|
getOwner(this).lookup('controller:application').send("showTopicEntrance", {topic: this.get('topic'), position: target.offset()});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +31,7 @@ export default Ember.Component.extend(bufferedRender({
|
||||||
},
|
},
|
||||||
|
|
||||||
buildBuffer(buffer) {
|
buildBuffer(buffer) {
|
||||||
const template = Discourse.__container__.lookup('template:list/topic-list-item.raw');
|
const template = getOwner(this).lookup('template:list/topic-list-item.raw');
|
||||||
if (template) {
|
if (template) {
|
||||||
buffer.push(template(this));
|
buffer.push(template(this));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { observes } from 'ember-addons/ember-computed-decorators';
|
import { observes } from 'ember-addons/ember-computed-decorators';
|
||||||
import TextField from 'discourse/components/text-field';
|
import TextField from 'discourse/components/text-field';
|
||||||
import userSearch from 'discourse/lib/user-search';
|
import userSearch from 'discourse/lib/user-search';
|
||||||
|
import { getOwner } from 'discourse-common/lib/get-owner';
|
||||||
|
|
||||||
export default TextField.extend({
|
export default TextField.extend({
|
||||||
@observes('usernames')
|
@observes('usernames')
|
||||||
|
@ -30,7 +31,7 @@ export default TextField.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$().val(this.get('usernames')).autocomplete({
|
this.$().val(this.get('usernames')).autocomplete({
|
||||||
template: this.container.lookup('template:user-selector-autocomplete.raw'),
|
template: getOwner(this).lookup('template:user-selector-autocomplete.raw'),
|
||||||
disabled: this.get('disabled'),
|
disabled: this.get('disabled'),
|
||||||
single: this.get('single'),
|
single: this.get('single'),
|
||||||
allowAny: this.get('allowAny'),
|
allowAny: this.get('allowAny'),
|
||||||
|
|
|
@ -6,6 +6,7 @@ import { default as computed, observes } from 'ember-addons/ember-computed-decor
|
||||||
import { relativeAge } from 'discourse/lib/formatter';
|
import { relativeAge } from 'discourse/lib/formatter';
|
||||||
import { escapeExpression } from 'discourse/lib/utilities';
|
import { escapeExpression } from 'discourse/lib/utilities';
|
||||||
import InputValidation from 'discourse/models/input-validation';
|
import InputValidation from 'discourse/models/input-validation';
|
||||||
|
import { getOwner } from 'discourse-common/lib/get-owner';
|
||||||
|
|
||||||
function loadDraft(store, opts) {
|
function loadDraft(store, opts) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
|
@ -86,7 +87,7 @@ export default Ember.Controller.extend({
|
||||||
|
|
||||||
showToolbar: Em.computed({
|
showToolbar: Em.computed({
|
||||||
get() {
|
get() {
|
||||||
const keyValueStore = this.container.lookup('key-value-store:main');
|
const keyValueStore = getOwner(this).lookup('key-value-store:main');
|
||||||
const storedVal = keyValueStore.get("toolbar-enabled");
|
const storedVal = keyValueStore.get("toolbar-enabled");
|
||||||
if (this._toolbarEnabled === undefined && storedVal === undefined) {
|
if (this._toolbarEnabled === undefined && storedVal === undefined) {
|
||||||
// iPhone 6 is 375, anything narrower and toolbar should
|
// iPhone 6 is 375, anything narrower and toolbar should
|
||||||
|
@ -97,7 +98,7 @@ export default Ember.Controller.extend({
|
||||||
return this._toolbarEnabled || storedVal === "true";
|
return this._toolbarEnabled || storedVal === "true";
|
||||||
},
|
},
|
||||||
set(key, val){
|
set(key, val){
|
||||||
const keyValueStore = this.container.lookup('key-value-store:main');
|
const keyValueStore = getOwner(this).lookup('key-value-store:main');
|
||||||
this._toolbarEnabled = val;
|
this._toolbarEnabled = val;
|
||||||
keyValueStore.set({key: "toolbar-enabled", value: val ? "true" : "false"});
|
keyValueStore.set({key: "toolbar-enabled", value: val ? "true" : "false"});
|
||||||
return val;
|
return val;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { addFlagProperty as realAddFlagProperty } from 'discourse/components/site-header';
|
import { addFlagProperty as realAddFlagProperty } from 'discourse/components/site-header';
|
||||||
|
import deprecated from 'discourse-common/lib/deprecated';
|
||||||
|
|
||||||
export function addFlagProperty(prop) {
|
export function addFlagProperty(prop) {
|
||||||
Ember.warn("importing `addFlagProperty` is deprecated. Use the PluginAPI instead");
|
deprecated("importing `addFlagProperty` is deprecated. Use the PluginAPI instead");
|
||||||
realAddFlagProperty(prop);
|
realAddFlagProperty(prop);
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,7 +151,7 @@ function render(page, offset, options) {
|
||||||
};
|
};
|
||||||
|
|
||||||
$('.emoji-modal', options.appendTo).remove();
|
$('.emoji-modal', options.appendTo).remove();
|
||||||
const template = options.container.lookup('template:emoji-toolbar.raw');
|
const template = options.register.lookup('template:emoji-toolbar.raw');
|
||||||
options.appendTo.append(template(model));
|
options.appendTo.append(template(model));
|
||||||
|
|
||||||
bindEvents(page, offset, options);
|
bindEvents(page, offset, options);
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import deprecated from 'discourse-common/lib/deprecated';
|
||||||
|
|
||||||
let mobileForced = false;
|
let mobileForced = false;
|
||||||
|
|
||||||
// An object that is responsible for logic related to mobile devices.
|
// An object that is responsible for logic related to mobile devices.
|
||||||
|
@ -67,10 +69,9 @@ export function resetMobile() {
|
||||||
mobileForced = false;
|
mobileForced = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Backwards compatibiltity, deprecated
|
|
||||||
Object.defineProperty(Discourse, 'Mobile', {
|
Object.defineProperty(Discourse, 'Mobile', {
|
||||||
get: function() {
|
get() {
|
||||||
Ember.warn("DEPRECATION: `Discourse.Mobile` is deprecated, use `this.site.mobileView` instead");
|
deprecated("`Discourse.Mobile` is deprecated, use `this.site.mobileView` instead");
|
||||||
return Mobile;
|
return Mobile;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import deprecated from 'discourse-common/lib/deprecated';
|
||||||
|
|
||||||
const PageTracker = Ember.Object.extend(Ember.Evented);
|
const PageTracker = Ember.Object.extend(Ember.Evented);
|
||||||
let _pageTracker = PageTracker.create();
|
let _pageTracker = PageTracker.create();
|
||||||
|
|
||||||
|
@ -42,7 +44,7 @@ export function onPageChange(fn) {
|
||||||
// backwards compatibility
|
// backwards compatibility
|
||||||
const BackwardsCompat = {
|
const BackwardsCompat = {
|
||||||
current() {
|
current() {
|
||||||
console.warn(`Using PageTracker.current() is deprecated. Your plugin should use the PluginAPI`);
|
deprecated(`Using PageTracker.current() is deprecated. Your plugin should use the PluginAPI`);
|
||||||
return _pageTracker;
|
return _pageTracker;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -332,7 +332,8 @@ const DiscourseURL = Ember.Object.extend({
|
||||||
|
|
||||||
const transition = router.handleURL(path);
|
const transition = router.handleURL(path);
|
||||||
transition._discourse_intercepted = true;
|
transition._discourse_intercepted = true;
|
||||||
transition.promise.then(() => jumpToElement(elementId));
|
const promise = transition.promise || transition;
|
||||||
|
promise.then(() => jumpToElement(elementId));
|
||||||
}
|
}
|
||||||
}).create();
|
}).create();
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { ajax } from 'discourse/lib/ajax';
|
import { ajax } from 'discourse/lib/ajax';
|
||||||
import RestModel from 'discourse/models/rest';
|
import RestModel from 'discourse/models/rest';
|
||||||
import ResultSet from 'discourse/models/result-set';
|
import ResultSet from 'discourse/models/result-set';
|
||||||
|
import { getRegister } from 'discourse-common/lib/get-owner';
|
||||||
|
|
||||||
let _identityMap;
|
let _identityMap;
|
||||||
|
|
||||||
|
@ -41,6 +42,11 @@ export default Ember.Object.extend({
|
||||||
_plurals: {'post-reply': 'post-replies',
|
_plurals: {'post-reply': 'post-replies',
|
||||||
'post-reply-history': 'post_reply_histories'},
|
'post-reply-history': 'post_reply_histories'},
|
||||||
|
|
||||||
|
init() {
|
||||||
|
this._super();
|
||||||
|
this.register = getRegister(this);
|
||||||
|
},
|
||||||
|
|
||||||
pluralize(thing) {
|
pluralize(thing) {
|
||||||
return this._plurals[thing] || thing + "s";
|
return this._plurals[thing] || thing + "s";
|
||||||
},
|
},
|
||||||
|
@ -196,11 +202,11 @@ export default Ember.Object.extend({
|
||||||
obj.__state = obj.id ? "created" : "new";
|
obj.__state = obj.id ? "created" : "new";
|
||||||
|
|
||||||
// TODO: Have injections be automatic
|
// TODO: Have injections be automatic
|
||||||
obj.topicTrackingState = this.container.lookup('topic-tracking-state:main');
|
obj.topicTrackingState = this.register.lookup('topic-tracking-state:main');
|
||||||
obj.keyValueStore = this.container.lookup('key-value-store:main');
|
obj.keyValueStore = this.register.lookup('key-value-store:main');
|
||||||
obj.siteSettings = this.container.lookup('site-settings:main');
|
obj.siteSettings = this.register.lookup('site-settings:main');
|
||||||
|
|
||||||
const klass = this.container.lookupFactory('model:' + type) || RestModel;
|
const klass = this.register.lookupFactory('model:' + type) || RestModel;
|
||||||
const model = klass.create(obj);
|
const model = klass.create(obj);
|
||||||
|
|
||||||
storeMap(type, obj.id, model);
|
storeMap(type, obj.id, model);
|
||||||
|
@ -208,7 +214,7 @@ export default Ember.Object.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
adapterFor(type) {
|
adapterFor(type) {
|
||||||
return this.container.lookup('adapter:' + type) || this.container.lookup('adapter:rest');
|
return this.register.lookup('adapter:' + type) || this.register.lookup('adapter:rest');
|
||||||
},
|
},
|
||||||
|
|
||||||
_lookupSubType(subType, type, id, root) {
|
_lookupSubType(subType, type, id, root) {
|
||||||
|
@ -287,7 +293,7 @@ export default Ember.Object.extend({
|
||||||
|
|
||||||
if (existing) {
|
if (existing) {
|
||||||
delete obj.id;
|
delete obj.id;
|
||||||
const klass = this.container.lookupFactory('model:' + type) || RestModel;
|
const klass = this.register.lookupFactory('model:' + type) || RestModel;
|
||||||
existing.setProperties(klass.munge(obj));
|
existing.setProperties(klass.munge(obj));
|
||||||
obj.id = id;
|
obj.id = id;
|
||||||
return existing;
|
return existing;
|
||||||
|
|
|
@ -10,7 +10,10 @@ export default {
|
||||||
// HACK to fix: https://github.com/emberjs/ember.js/issues/10310
|
// HACK to fix: https://github.com/emberjs/ember.js/issues/10310
|
||||||
const originalBuildInstance = originalBuildInstance || Ember.Application.prototype.buildInstance;
|
const originalBuildInstance = originalBuildInstance || Ember.Application.prototype.buildInstance;
|
||||||
Ember.Application.prototype.buildInstance = function() {
|
Ember.Application.prototype.buildInstance = function() {
|
||||||
this.registry = this.buildRegistry();
|
const registry = this.buildRegistry();
|
||||||
|
if (Ember.VERSION[0] === "1") {
|
||||||
|
this.registry = registry;
|
||||||
|
}
|
||||||
return originalBuildInstance.apply(this);
|
return originalBuildInstance.apply(this);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import OpenComposer from "discourse/mixins/open-composer";
|
||||||
import Category from 'discourse/models/category';
|
import Category from 'discourse/models/category';
|
||||||
import mobile from 'discourse/lib/mobile';
|
import mobile from 'discourse/lib/mobile';
|
||||||
import { findAll } from 'discourse/models/login-method';
|
import { findAll } from 'discourse/models/login-method';
|
||||||
|
import { getOwner } from 'discourse-common/lib/get-owner';
|
||||||
|
|
||||||
function unlessReadOnly(method, message) {
|
function unlessReadOnly(method, message) {
|
||||||
return function() {
|
return function() {
|
||||||
|
@ -40,7 +41,7 @@ const ApplicationRoute = Discourse.Route.extend(OpenComposer, {
|
||||||
|
|
||||||
// Ember doesn't provider a router `willTransition` event so let's make one
|
// Ember doesn't provider a router `willTransition` event so let's make one
|
||||||
willTransition() {
|
willTransition() {
|
||||||
var router = this.container.lookup('router:main');
|
var router = getOwner(this).lookup('router:main');
|
||||||
Ember.run.once(router, router.trigger, 'willTransition');
|
Ember.run.once(router, router.trigger, 'willTransition');
|
||||||
return this._super();
|
return this._super();
|
||||||
},
|
},
|
||||||
|
@ -150,7 +151,7 @@ const ApplicationRoute = Discourse.Route.extend(OpenComposer, {
|
||||||
|
|
||||||
changeBulkTemplate(w) {
|
changeBulkTemplate(w) {
|
||||||
const controllerName = w.replace('modal/', ''),
|
const controllerName = w.replace('modal/', ''),
|
||||||
factory = this.container.lookupFactory('controller:' + controllerName);
|
factory = getOwner(this).lookupFactory('controller:' + controllerName);
|
||||||
|
|
||||||
this.render(w, {into: 'modal/topic-bulk-actions', outlet: 'bulkOutlet', controller: factory ? controllerName : 'topic-bulk-actions'});
|
this.render(w, {into: 'modal/topic-bulk-actions', outlet: 'bulkOutlet', controller: factory ? controllerName : 'topic-bulk-actions'});
|
||||||
},
|
},
|
||||||
|
@ -200,7 +201,7 @@ const ApplicationRoute = Discourse.Route.extend(OpenComposer, {
|
||||||
|
|
||||||
_autoLogin(modal, modalClass, notAuto) {
|
_autoLogin(modal, modalClass, notAuto) {
|
||||||
const methods = findAll(this.siteSettings,
|
const methods = findAll(this.siteSettings,
|
||||||
this.container.lookup('capabilities:main'),
|
getOwner(this).lookup('capabilities:main'),
|
||||||
this.site.isMobileDevice);
|
this.site.isMobileDevice);
|
||||||
|
|
||||||
if (!this.siteSettings.enable_local_logins && methods.length === 1) {
|
if (!this.siteSettings.enable_local_logins && methods.length === 1) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { translateResults, getSearchKey, isValidSearchTerm } from "discourse/lib
|
||||||
import Composer from 'discourse/models/composer';
|
import Composer from 'discourse/models/composer';
|
||||||
import PreloadStore from 'preload-store';
|
import PreloadStore from 'preload-store';
|
||||||
import { getTransient, setTransient } from 'discourse/lib/page-tracker';
|
import { getTransient, setTransient } from 'discourse/lib/page-tracker';
|
||||||
|
import { getOwner } from 'discourse-common/lib/get-owner';
|
||||||
|
|
||||||
export default Discourse.Route.extend({
|
export default Discourse.Route.extend({
|
||||||
queryParams: { q: {}, expanded: false, context_id: {}, context: {}, skip_context: {} },
|
queryParams: { q: {}, expanded: false, context_id: {}, context: {}, skip_context: {} },
|
||||||
|
@ -52,7 +53,7 @@ export default Discourse.Route.extend({
|
||||||
category = match[1];
|
category = match[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.container.lookup('controller:composer').open({action: Composer.CREATE_TOPIC, draftKey: Composer.CREATE_TOPIC, topicCategory: category});
|
getOwner(this).lookup('controller:composer').open({action: Composer.CREATE_TOPIC, draftKey: Composer.CREATE_TOPIC, topicCategory: category});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,8 +56,10 @@ export default Discourse.Route.extend({
|
||||||
ignoreIfChanged: true
|
ignoreIfChanged: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).catch(function(e) {
|
}).catch(e => {
|
||||||
Ember.warn('Could not view topic', e);
|
if (!Ember.testing) {
|
||||||
|
console.log('Could not view topic', e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ export default class Connector {
|
||||||
}
|
}
|
||||||
|
|
||||||
const view = Ember.View.create({
|
const view = Ember.View.create({
|
||||||
container: widget.container,
|
container: widget.register,
|
||||||
templateName: opts.templateName,
|
templateName: opts.templateName,
|
||||||
context
|
context
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,7 +8,8 @@ class DecoratorHelper {
|
||||||
this.widget = widget;
|
this.widget = widget;
|
||||||
this.attrs = attrs;
|
this.attrs = attrs;
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.container = widget.container;
|
this.register = widget.register;
|
||||||
|
this.register.deprecateContainer(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -63,7 +63,7 @@ export default createWidget('hamburger-menu', {
|
||||||
},
|
},
|
||||||
|
|
||||||
lookupCount(type) {
|
lookupCount(type) {
|
||||||
const tts = this.container.lookup('topic-tracking-state:main');
|
const tts = this.register.lookup('topic-tracking-state:main');
|
||||||
return tts ? tts.lookupCount(type) : 0;
|
return tts ? tts.lookupCount(type) : 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -190,7 +190,7 @@ export default createWidget('header', {
|
||||||
|
|
||||||
updateHighlight() {
|
updateHighlight() {
|
||||||
if (!this.state.searchVisible) {
|
if (!this.state.searchVisible) {
|
||||||
const service = this.container.lookup('search-service:main');
|
const service = this.register.lookup('search-service:main');
|
||||||
service.set('highlightTerm', '');
|
service.set('highlightTerm', '');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -208,7 +208,7 @@ export default createWidget('header', {
|
||||||
|
|
||||||
toggleSearchMenu() {
|
toggleSearchMenu() {
|
||||||
if (this.site.mobileView) {
|
if (this.site.mobileView) {
|
||||||
const searchService = this.container.lookup('search-service:main');
|
const searchService = this.register.lookup('search-service:main');
|
||||||
const context = searchService.get('searchContext');
|
const context = searchService.get('searchContext');
|
||||||
var params = "";
|
var params = "";
|
||||||
|
|
||||||
|
@ -240,7 +240,7 @@ export default createWidget('header', {
|
||||||
|
|
||||||
state.contextEnabled = false;
|
state.contextEnabled = false;
|
||||||
|
|
||||||
const currentPath = this.container.lookup('controller:application').get('currentPath');
|
const currentPath = this.register.lookup('controller:application').get('currentPath');
|
||||||
const blacklist = [ /^discovery\.categories/ ];
|
const blacklist = [ /^discovery\.categories/ ];
|
||||||
const whitelist = [ /^topic\./ ];
|
const whitelist = [ /^topic\./ ];
|
||||||
const check = function(regex) { return !!currentPath.match(regex); };
|
const check = function(regex) { return !!currentPath.match(regex); };
|
||||||
|
@ -249,7 +249,7 @@ export default createWidget('header', {
|
||||||
// If we're viewing a topic, only intercept search if there are cloaked posts
|
// If we're viewing a topic, only intercept search if there are cloaked posts
|
||||||
if (showSearch && currentPath.match(/^topic\./)) {
|
if (showSearch && currentPath.match(/^topic\./)) {
|
||||||
showSearch = ($('.topic-post .cooked, .small-action:not(.time-gap)').length <
|
showSearch = ($('.topic-post .cooked, .small-action:not(.time-gap)').length <
|
||||||
this.container.lookup('controller:topic').get('model.postStream.stream.length'));
|
this.register.lookup('controller:topic').get('model.postStream.stream.length'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.searchVisible) {
|
if (state.searchVisible) {
|
||||||
|
|
|
@ -10,7 +10,7 @@ export default createWidget('link', {
|
||||||
href(attrs) {
|
href(attrs) {
|
||||||
const route = attrs.route;
|
const route = attrs.route;
|
||||||
if (route) {
|
if (route) {
|
||||||
const router = this.container.lookup('router:main');
|
const router = this.register.lookup('router:main');
|
||||||
if (router && router.router) {
|
if (router && router.router) {
|
||||||
const params = [route];
|
const params = [route];
|
||||||
if (attrs.model) {
|
if (attrs.model) {
|
||||||
|
|
|
@ -30,7 +30,7 @@ createWidget('search-context', {
|
||||||
tagName: 'div.search-context',
|
tagName: 'div.search-context',
|
||||||
|
|
||||||
html(attrs) {
|
html(attrs) {
|
||||||
const service = this.container.lookup('search-service:main');
|
const service = this.register.lookup('search-service:main');
|
||||||
const ctx = service.get('searchContext');
|
const ctx = service.get('searchContext');
|
||||||
|
|
||||||
const result = [];
|
const result = [];
|
||||||
|
|
|
@ -134,7 +134,7 @@ export default createWidget('search-menu', {
|
||||||
|
|
||||||
searchService() {
|
searchService() {
|
||||||
if (!this._searchService) {
|
if (!this._searchService) {
|
||||||
this._searchService = this.container.lookup('search-service:main');
|
this._searchService = this.register.lookup('search-service:main');
|
||||||
}
|
}
|
||||||
return this._searchService;
|
return this._searchService;
|
||||||
},
|
},
|
||||||
|
|
|
@ -127,12 +127,14 @@ export function createWidget(name, opts) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Widget {
|
export default class Widget {
|
||||||
constructor(attrs, container, opts) {
|
constructor(attrs, register, opts) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
this.attrs = attrs || {};
|
this.attrs = attrs || {};
|
||||||
this.mergeState = opts.state;
|
this.mergeState = opts.state;
|
||||||
this.container = container;
|
|
||||||
this.model = opts.model;
|
this.model = opts.model;
|
||||||
|
this.register = register;
|
||||||
|
|
||||||
|
register.deprecateContainer(this);
|
||||||
|
|
||||||
this.key = this.buildKey ? this.buildKey(attrs) : null;
|
this.key = this.buildKey ? this.buildKey(attrs) : null;
|
||||||
|
|
||||||
|
@ -146,13 +148,13 @@ export default class Widget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.site = container.lookup('site:main');
|
this.site = register.lookup('site:main');
|
||||||
this.siteSettings = container.lookup('site-settings:main');
|
this.siteSettings = register.lookup('site-settings:main');
|
||||||
this.currentUser = container.lookup('current-user:main');
|
this.currentUser = register.lookup('current-user:main');
|
||||||
this.capabilities = container.lookup('capabilities:main');
|
this.capabilities = register.lookup('capabilities:main');
|
||||||
this.store = container.lookup('store:main');
|
this.store = register.lookup('store:main');
|
||||||
this.appEvents = container.lookup('app-events:main');
|
this.appEvents = register.lookup('app-events:main');
|
||||||
this.keyValueStore = container.lookup('key-value-store:main');
|
this.keyValueStore = register.lookup('key-value-store:main');
|
||||||
|
|
||||||
if (this.name) {
|
if (this.name) {
|
||||||
const custom = _customSettings[this.name];
|
const custom = _customSettings[this.name];
|
||||||
|
@ -223,15 +225,15 @@ export default class Widget {
|
||||||
let WidgetClass = _registry[widgetName];
|
let WidgetClass = _registry[widgetName];
|
||||||
|
|
||||||
if (!WidgetClass) {
|
if (!WidgetClass) {
|
||||||
if (!this.container) {
|
if (!this.register) {
|
||||||
console.error("couldn't find container");
|
console.error("couldn't find register");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
WidgetClass = this.container.lookupFactory(`widget:${widgetName}`);
|
WidgetClass = this.register.lookupFactory(`widget:${widgetName}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WidgetClass) {
|
if (WidgetClass) {
|
||||||
const result = new WidgetClass(attrs, this.container, opts);
|
const result = new WidgetClass(attrs, this.register, opts);
|
||||||
result.parentWidget = this;
|
result.parentWidget = this;
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import getUrl from 'discourse-common/lib/get-url';
|
import getUrl from 'discourse-common/lib/get-url';
|
||||||
import computed from 'ember-addons/ember-computed-decorators';
|
import computed from 'ember-addons/ember-computed-decorators';
|
||||||
import { getToken } from 'wizard/lib/ajax';
|
import { getToken } from 'wizard/lib/ajax';
|
||||||
|
import { getOwner } from 'discourse-common/lib/get-owner';
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
classNames: ['wizard-image-row'],
|
classNames: ['wizard-image-row'],
|
||||||
|
@ -9,7 +10,7 @@ export default Ember.Component.extend({
|
||||||
@computed('field.id')
|
@computed('field.id')
|
||||||
previewComponent(id) {
|
previewComponent(id) {
|
||||||
const componentName = `image-preview-${Ember.String.dasherize(id)}`;
|
const componentName = `image-preview-${Ember.String.dasherize(id)}`;
|
||||||
const exists = this.container.lookup(`component:${componentName}`);
|
const exists = getOwner(this).lookup(`component:${componentName}`);
|
||||||
return exists ? componentName : 'wizard-image-preview';
|
return exists ? componentName : 'wizard-image-preview';
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue