DEV: Add a plugin API for registering a "beforeSave" on the composer
This allows plugins to perform operations before saves occur, and perhaps reject the post.
This commit is contained in:
parent
ee4369f972
commit
c5d03c30ca
|
@ -721,7 +721,9 @@ export default Ember.Controller.extend({
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
composer.set("disableDrafts", false);
|
composer.set("disableDrafts", false);
|
||||||
|
if (error) {
|
||||||
this.appEvents.one("composer:will-open", () => bootbox.alert(error));
|
this.appEvents.one("composer:will-open", () => bootbox.alert(error));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -46,7 +46,7 @@ import { queryRegistry } from "discourse/widgets/widget";
|
||||||
import Composer from "discourse/models/composer";
|
import Composer from "discourse/models/composer";
|
||||||
|
|
||||||
// If you add any methods to the API ensure you bump up this number
|
// If you add any methods to the API ensure you bump up this number
|
||||||
const PLUGIN_API_VERSION = "0.8.33";
|
const PLUGIN_API_VERSION = "0.8.34";
|
||||||
|
|
||||||
class PluginApi {
|
class PluginApi {
|
||||||
constructor(version, container) {
|
constructor(version, container) {
|
||||||
|
@ -791,7 +791,7 @@ class PluginApi {
|
||||||
*
|
*
|
||||||
* Example:
|
* Example:
|
||||||
*
|
*
|
||||||
* modifySelectKit("topic-footer-mobile-dropdown").appendContent(() => [{
|
* api.modifySelectKit("topic-footer-mobile-dropdown").appendContent(() => [{
|
||||||
* name: "discourse",
|
* name: "discourse",
|
||||||
* id: 1
|
* id: 1
|
||||||
* }])
|
* }])
|
||||||
|
@ -807,7 +807,7 @@ class PluginApi {
|
||||||
*
|
*
|
||||||
* Example:
|
* Example:
|
||||||
*
|
*
|
||||||
* addGTMPageChangedCallback( gtmData => gtmData.locale = I18n.currentLocale() )
|
* api.addGTMPageChangedCallback( gtmData => gtmData.locale = I18n.currentLocale() )
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
addGTMPageChangedCallback(fn) {
|
addGTMPageChangedCallback(fn) {
|
||||||
|
@ -821,7 +821,7 @@ class PluginApi {
|
||||||
* Example:
|
* Example:
|
||||||
*
|
*
|
||||||
* // read /discourse/lib/sharing.js.es6 for options
|
* // read /discourse/lib/sharing.js.es6 for options
|
||||||
* addSharingSource(options)
|
* api.addSharingSource(options)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
addSharingSource(options) {
|
addSharingSource(options) {
|
||||||
|
@ -837,7 +837,7 @@ class PluginApi {
|
||||||
*
|
*
|
||||||
* Example:
|
* Example:
|
||||||
*
|
*
|
||||||
* addComposerUploadHandler(["mp4", "mov"], (file, editor) => {
|
* api.addComposerUploadHandler(["mp4", "mov"], (file, editor) => {
|
||||||
* console.log("Handling upload for", file.name);
|
* console.log("Handling upload for", file.name);
|
||||||
* })
|
* })
|
||||||
*/
|
*/
|
||||||
|
@ -845,6 +845,20 @@ class PluginApi {
|
||||||
addComposerUploadHandler(extensions, method);
|
addComposerUploadHandler(extensions, method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a "beforeSave" function on the composer. This allows you to
|
||||||
|
* implement custom logic that will happen before the user makes a post.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
*
|
||||||
|
* api.composerBeforeSave(() => {
|
||||||
|
* console.log("Before saving, do something!");
|
||||||
|
* })
|
||||||
|
*/
|
||||||
|
composerBeforeSave(method) {
|
||||||
|
Composer.reopen({ beforeSave: method });
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a field to draft serializer
|
* Adds a field to draft serializer
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue