#use Mojo::Base 'Mojolicious::Controller';
use Mojo::Util qw(dumper);
use Mojo::JSON qw(decode_json encode_json);
+use Newslash::Util::TextFormatter;
sub get {
my $c = shift;
$message = "invalid author";
}
$params->{uid} = $user->{uid};
- $params->{article} = $item->{introtext};
- $params->{commentstatus} = $item->{commentstatus};
+ $params->{article} = $item->{introtext} || $item->{intro_text};
+ $params->{commentstatus} = $item->{comment_status};
$params->{action} = $data->{action} || 'preview';
$params->{posttype} = $item->{posttype};
$params->{tid} = $item->{tid};
# TODO: can select topics
#$params->{topics_chosen} = { 49 => 10, }; # tid => weight
+ # parse tags
+ #$params->{tid} = 49; #mainpage
+ my $tags_string = $item->{tags_string};
+ my @tags = split(/\s+/, $tags_string);
+ my $topic = $c->model('topics')->get_primary_topic_from_tags(\@tags) || {};
+ $params->{tid} = $topic->{tid} || 49;
+ $params->{tags_string} = $tags_string;
+
#$extra_params->{createheaders} = $c->req->headers->to_string;
+
if (length($message) > 0) {
$c->render(json => { err => 1, message => $message });
$c->rendered(400);
}
if ($data->{action} eq 'preview') {
- $item->{introtext} = $util->clean_html($allowed, $params->{article});
+ if ($item->{formatter} eq 'legacy') {
+ $item->{introtext} = Newslash::Util::TextFormatter::strip_by_mode($params->{article},
+ $params->{posttype},
+ allowed_tags => $allowed);
+ }
+ else {
+ $item->{introtext} = $util->clean_html($allowed, $params->{article});
+ }
+ $item->{intro_text} = $item->{intro_text};
$item->{title} = $params->{description};
+ $item->{topic} = $topic;
$c->render(json => {item => $item});
return;
}
// only editor's property will be send when preview/post
editor: {
title: "",
- introtext: "",
- bodytext: "",
- createtime: "",
+ intro_text: "",
+ body_text: "",
+ create_time: "",
author: "",
dept: "",
- commentstatus: "enabled",
+ comment_status: "enabled",
submissioncopy: 0,
url: "",
email: "",
createdUrl: "",
currentTopics: [],
- enableAutoPreview: "1",
+ enableAutoPreview: 1,
mode: "",
primaryTopicIconURL: "",
var props = {
item: {
type: Object,
- default: function () {return new Contents();},
+ default: function () {return new Content();},
},
showEditor: {
- type: [Boolean, Number],
+ type: [Boolean, Number, String],
default: false,
},
csrfToken: String,
* watch
*/
var watch = {
- 'editor.introtext': watchIntrotext,
- 'editor.bodytext': watchBodytext,
+ 'editor.intro_text': watchIntrotext,
+ 'editor.body_text': watchBodytext,
'editor.title': watchTitle,
'editor.url': watchURL,
- 'editor.createtime': watchCreatetime,
+ 'editor.create_time': watchCreatetime,
'editor.author': watchAuthor,
'editor.dept': watchDept,
'editor.tags_string': updateTopics,
};
function watchIntrotext(val, oldVal) {
- this.item.introtext = (val.length > 0) ? quoteHtml(val) : "";
+ this.item.intro_text = (val.length > 0) ? quoteHtml(val) : "";
};
function watchBodytext(val, oldVal) {
- this.item.bodytext = (val.length > 0) ? quoteHtml(val) : "";
+ this.item.body_text = (val.length > 0) ? quoteHtml(val) : "";
};
function watchTitle(val, oldVal) {
(resp) => { // success
this.message = "";
this.previewTitle = resp.item.title;
- this.previewIntro = resp.item.introtext;
+ this.previewIntro = resp.item.intro_text;
this.item.primary_topic = resp.item.topic;
this.updatePrimaryTopicIconURL();
(response) => { // success
this.message = "";
this.previewTitle = response.body.item.title;
- this.previewIntro = response.body.item.introtext;
+ this.previewIntro = response.body.item.intro_text;
this.item.primary_topic = response.body.item.topic;
this.item.url = response.body.item.url;
this.updatePrimaryTopicIconURL();
}
function startEdit() {
- _initEditor(this);
+ _startEdit(this);
}
function cancelEdit() {
* created and related private functions
*/
function created() {
- _loadItem(this);
if (this.showEditor) {
- _initEditor(this);
+ _startEdit(this);
}
this.updatePrimaryTopicIconURL();
}
- function _loadItem(vm) {
- if (!page) { return; }
+ function _loadItem(vm, callback) {
+ if (!page) { return callback(); }
if (page.contentType == "journal") {
newslash.getJournal(page.id).then(
for (k in resp.journal) {
vm.item[k] = resp.journal[k];
}
+ callback();
},
(resp) => {
statusBar.error(resp.message);
}
);
+ return 0;
}
+ return callback();
+ }
+
+ function _startEdit(vm) {
+ _loadItem(vm, () => { _initEditor(vm); });
}
function _initEditor(vm) {
if (page.type == 'journal' && page.id) {
vm.cancelable = 1;
vm.editor.title = vm.item.title;
- vm.editor.introtext = vm.item.article;
+ vm.editor.intro_text = vm.item.article;
vm.editor.tags_string = vm.item.tags_string || "";
- vm.editor.commentstatus = vm.item.commentstatus;
+ vm.editor.comment_status = vm.item.comment_status;
vm.editor.formatter = vm.item.formatter;
vm.editor.posttype = vm.item.posttype;
vm.editor.id = vm.item.id;
vm.$newslash.getSubmissionByID(vm.item.submission_id,
(resp) => { // succeed
vm.editor.title = resp.body.item.title;
- vm.editor.introtext = resp.body.item.drafttext;
+ vm.editor.intro_text = resp.body.item.drafttext;
},
(resp) => { //failed
vm.message = resp.body.message;
});
}
+ // check formatter
+ if (vm.editor.formatter == "legacy") {
+ vm.enableAutoPreview = 0;
+ }
vm.mode = "editing";
}
<p class="form-group">
<label for="post-introtext">本文:</label>
- <textarea id="post-introtext" name="introtext" class="form-control" v-model="editor.introtext" placeholder="本文をここに記述してください" ></textarea>
+ <textarea id="post-introtext" name="introtext" class="form-control" v-model="editor.intro_text" placeholder="本文をここに記述してください" ></textarea>
</p>
<p class="form-group" v-if="item.content_type == 'story'">
<label for="post-bodytext">続きの本文:</label>
- <textarea id="post-bodytext" name="bodytext" class="form-control" v-model="editor.bodytext" placeholder="続きの本文をここに記述してください" ></textarea>
+ <textarea id="post-bodytext" name="bodytext" class="form-control" v-model="editor.body_text" placeholder="続きの本文をここに記述してください" ></textarea>
</p>
<p class="form-group" v-if="item.content_type == 'submission'">
<div class="form-inline" v-if="item.content_type == 'story' || item.content_type == 'journal'">
<p class="form-group">
<label for="post-commentstatus">コメント設定:</label>
- <select id="post-commentstatus" class="form-control" name="commentstatus" v-model="editor.commentstatus">
+ <select id="post-commentstatus" class="form-control" name="comment_status" v-model="editor.comment_status">
<option value="disabled">コメント無効</option>
<option value="enabled"[% IF !x_template %] selected="selected"[% END %]>コメント有効</option>
<option value="friends_fof_only">トモダチとそのトモダチ</option>
<div class="checkbox" v-if="mode == 'editing'">
<label>
- <input type="checkbox" id="auto-preview-enable" v-model="enableAutoPreview" />
+ <input type="checkbox" id="auto-preview-enable" v-model="enableAutoPreview" :disabled="editor.formatter == 'legacy'"/>
自動プレビューを有効にする
</label>
+ <div class="alert alert-info" v-if="editor.formatter != 'modern'">
+ このフォーマットでは自動プレビューを利用できません
+ </div>
</div>
</div>