-/* post.js */
-var post = {};
var editor = {};
-var viewModel;
-
-var allowed_tags = {
- "a": ["href"],
- "blockquote": [],
- "i": [],
- "strong": [],
-};
-
-post.quote_html = function _post_quote_html(html) {
- const escaped = eh.escape(allowed_tags, html);
- const quoted = eh.blank_line_to_paragraph(escaped);
- const parsed = $.parseHTML(quoted, null);
- const result = [];
- parsed.forEach((i) => {
- i.normalize();
- result.push(i.outerHTML);
- });
- return result.join('\n');
-};
-
-post.quote_title = function _post_quote_title(html) {
- const escaped = '<div>' + eh.escape({}, html) + '</div>';
- const parsed = $.parseHTML(escaped, null);
- const result = [];
- parsed.forEach((i) => {
- i.normalize();
- const t = i.innerHTML || i.wholeText;
- result.push(t);
- });
- return result.join('');
-};
-
-var editor = {
- title: "",
- createtime: "",
- author: "anonymous coward",
- dept: "",
- introtext: "",
- bodytext: "",
- add_related: "",
- url: "",
- mediaurl: "",
- mediatype: "",
- email: "",
- commentstatus: "enabled",
- display: 1,
- submissioncopy: 0,
-
- show_form: true,
- show_submit: false,
- preview_introtext: "",
- preview_bodytext: "",
- preview_title: "",
- message: "",
- action: "preview",
-};
-
-var computed = {
- introtext_raw: function () {
- if (this.preview_introtext.length > 0) {
- return this.preview_introtext;
- } else {
- return post.quote_html(this.introtext);
- }
- },
- bodytext_raw: function () {
- if (this.preview_bodytext.length > 0) {
- return this.preview_bodytext;
- } else {
- return post.quote_html(this.bodytext);
- }
- },
- title_raw: function () {
- if (this.preview_title.length > 0) {
- return this.preview_title;
- } else {
- return post.quote_title(this.title);
- }
- },
- author_name: function () {
- if (this.author.length > 0) {
- return this.author;
- } else {
- return authors[this.uid];
- }
+var vm;
+
+editor.run = function run(params) {
+ var data = {
+ item: {
+ title: "",
+ createtime: "",
+ author: "anonymous coward",
+ dept: "",
+ introtext: "",
+ bodytext: "",
+ add_related: "",
+ url: "",
+ mediaurl: "",
+ mediatype: "",
+ email: "",
+ commentstatus: "enabled",
+ display: 1,
+ submissioncopy: 0,
+ content_type: '',
+ editing: true,
+ },
}
-};
-var methods = {
- show_preview: function (event) {
- this.action = "preview";
- this.message = "";
- this.$http.post(this.postUrl, this.$data).then(
- (response) => { // success
- this.message = "";
- this.preview_title = response.body.title;
- this.preview_introtext = response.body.introtext;
- this.show_form = false;
- this.show_submit = true;
- },
- (response) => { // fail
- if (response.body.message) {
- this.message = response.body.message;
- }
- }
- );
- },
- post_submission: function (event) {
- this.action = "post";
- this.message = "";
- this.$http.post(this.postUrl, this.$data).then(
- (response) => { // success
- this.message = "";
- const id = response.body.id;
- const type = response.body.type;
- const url = '/' + type + '/' + id;
- this.message = "投稿しました。URL:"
- + "<a href='" + url + "'>" + url + "</a>";
- this.show_form = false;
- this.show_submit = false;
- },
- (response) => { // fail
- if (response.body.message) {
- this.message = response.body.message;
- }
- }
- );
- },
- leave_preview: function (event) {
- this.preview_title = "";
- this.preview_introtext = "";
- this.preview_bodytext = "";
- this.show_form = true;
- this.show_submit = false;
- },
-};
+ const user = params.user || {};
+ data.item.author = user.nickname;
+ data.item.content_type = params.type;
-editor.run = function run (params) {
- if (params.type == 'submission') {
- editor.postUrl = '/api/v1/submission';
- } else if (params.type == 'story') {
- editor.postUrl = '/api/v1/story';
- } else if (params.type == 'journal') {
- editor.postUrl = '/api/v1/journal';
- }
- if (params.author) {
- editor.author = params.author;
- }
- viewModel = new Vue({el: params.el,
- data: editor,
- computed: computed,
- methods: methods});
+ vm = new Vue({el: params.el,
+ data: data,
+ });
};