mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Expose Composer.serializeOnUpdate
in client side plugin api.
Also expose `Composer.serializeOnCreate` as well.
This commit is contained in:
parent
fdea969f14
commit
a1a798ac7d
@ -55,7 +55,7 @@ import { on } from "@ember/object/evented";
|
|||||||
import KeyboardShortcuts from "discourse/lib/keyboard-shortcuts";
|
import KeyboardShortcuts from "discourse/lib/keyboard-shortcuts";
|
||||||
|
|
||||||
// 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.43";
|
const PLUGIN_API_VERSION = "0.9.0";
|
||||||
|
|
||||||
class PluginApi {
|
class PluginApi {
|
||||||
constructor(version, container) {
|
constructor(version, container) {
|
||||||
@ -956,6 +956,36 @@ class PluginApi {
|
|||||||
Composer.serializeToDraft(fieldName, property);
|
Composer.serializeToDraft(fieldName, property);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a field to composer create serializer
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
*
|
||||||
|
* api.serializeOnCreate('key_set_in_model', 'field_name_in_payload');
|
||||||
|
*
|
||||||
|
* to keep both of them same
|
||||||
|
* api.serializeOnCreate('field_name');
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
serializeOnCreate(fieldName, property) {
|
||||||
|
Composer.serializeOnCreate(fieldName, property);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a field to composer update serializer
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
*
|
||||||
|
* api.serializeOnUpdate('key_set_in_model', 'field_name_in_payload');
|
||||||
|
*
|
||||||
|
* to keep both of them same
|
||||||
|
* api.serializeOnUpdate('field_name');
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
serializeOnUpdate(fieldName, property) {
|
||||||
|
Composer.serializeOnUpdate(fieldName, property);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a criteria that can be used as default topic order on category
|
* Registers a criteria that can be used as default topic order on category
|
||||||
* pages.
|
* pages.
|
||||||
|
@ -61,6 +61,11 @@ const CLOSED = "closed",
|
|||||||
no_bump: "noBump",
|
no_bump: "noBump",
|
||||||
draft_key: "draftKey"
|
draft_key: "draftKey"
|
||||||
},
|
},
|
||||||
|
_update_serializer = {
|
||||||
|
raw: "reply",
|
||||||
|
topic_id: "topic.id",
|
||||||
|
raw_old: "rawOld"
|
||||||
|
},
|
||||||
_edit_topic_serializer = {
|
_edit_topic_serializer = {
|
||||||
title: "topic.title",
|
title: "topic.title",
|
||||||
categoryId: "topic.category.id",
|
categoryId: "topic.category.id",
|
||||||
@ -851,6 +856,11 @@ const Composer = RestModel.extend({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@discourseComputed("editConflict", "originalText")
|
||||||
|
rawOld(editConflict, originalText) {
|
||||||
|
return editConflict ? null : originalText;
|
||||||
|
},
|
||||||
|
|
||||||
editPost(opts) {
|
editPost(opts) {
|
||||||
const post = this.post;
|
const post = this.post;
|
||||||
const oldCooked = post.cooked;
|
const oldCooked = post.cooked;
|
||||||
@ -885,14 +895,12 @@ const Composer = RestModel.extend({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const props = {
|
const props = {
|
||||||
topic_id: this.topic.id,
|
|
||||||
raw: this.reply,
|
|
||||||
raw_old: this.editConflict ? null : this.originalText,
|
|
||||||
edit_reason: opts.editReason,
|
edit_reason: opts.editReason,
|
||||||
image_sizes: opts.imageSizes,
|
image_sizes: opts.imageSizes,
|
||||||
cooked: this.getCookedHtml()
|
cooked: this.getCookedHtml()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.serialize(_update_serializer, props);
|
||||||
this.set("composeState", SAVING);
|
this.set("composeState", SAVING);
|
||||||
|
|
||||||
const rollback = throwAjaxError(error => {
|
const rollback = throwAjaxError(error => {
|
||||||
@ -1225,6 +1233,17 @@ Composer.reopenClass({
|
|||||||
return Object.keys(_create_serializer);
|
return Object.keys(_create_serializer);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
serializeOnUpdate(fieldName, property) {
|
||||||
|
if (!property) {
|
||||||
|
property = fieldName;
|
||||||
|
}
|
||||||
|
_update_serializer[fieldName] = property;
|
||||||
|
},
|
||||||
|
|
||||||
|
serializedFieldsForUpdate() {
|
||||||
|
return Object.keys(_update_serializer);
|
||||||
|
},
|
||||||
|
|
||||||
serializeToDraft(fieldName, property) {
|
serializeToDraft(fieldName, property) {
|
||||||
if (!property) {
|
if (!property) {
|
||||||
property = fieldName;
|
property = fieldName;
|
||||||
|
Loading…
Reference in New Issue
Block a user