$message = "invalid_createtime";
}
else {
+ # convert localtime to GMT
+ if ($user && $user->{config}->{ui}->{offset_sec}) {
+ my $offset_sec = $user->{config}->{ui}->{offset_sec} || 0;
+ if ($offset_sec) {
+ $dt->subtract(seconds => $offset_sec);
+ }
+ }
$params->{time} = DateTime::Format::MySQL->format_datetime($dt);
}
if ($item->{stoid}) {
# update story
$params->{stoid} = $item->{stoid};
- my $rs = $stories->update(user => $user, %$params);
- $stoid = $rs ? $item->{stoid} : 0;
- $sid = $rs ? $item->{sid} : 0;
+ ($sid, $stoid) = $stories->update(user => $user, %$params);
}
else {
# create story
}
# post succeeded, return result
- $c->render(json => {type => "story", id => $stoid, sid => $sid});
+ $c->render(json => {type => "story", id => $stoid, sid => $sid, url_id => $sid});
$c->event_que->emit("story", "post", $user->{uid}, $stoid);
$c->stats->add_event_counter("story_create");
return;
my $authors = $users->select(author => 1);
my $sub_id = $c->param('subid');
+ my $stoid = $c->param('stoid');
my $source = {};
+ my $page = {};
- if ($sub_id) {
+ if ($stoid) {
+ my $story = $c->model('stories')->select(stoid => $stoid);
+ if ($story) {
+ $source->{type} = "story";
+ $source->{id} = $stoid;
+ $source->{item} = $story;
+ $page->{type} = "story";
+ $page->{stoid} = $stoid;
+ }
+ }
+ elsif ($sub_id) {
my $sub = $c->model('submissions')->select(submission_id => $sub_id);
if ($sub) {
$source->{type} = "submission";
}
}
- $c->render(authors => $authors, source => $source);
+ $c->render(authors => $authors, source => $source, page => $page);
}
this.$newslash.post(type, postData, {csrfToken: this.csrfToken},
(response) => { // success
this.message = "";
- var id = response.body.id;
+ var id = response.body.url_id || response.body.id;
var type = response.body.type;
var url = '/' + type + '/' + id;
// check if new post
if (!postData.id) {
this.createdUrl = url;
- this.item.subid = id;
+ if (page.type == "submission") {
+ this.item.subid = id;
+ }
+ this.editor.id = response.body.id;
}
this.message = "";
this.mode = "posted";
postData.item[k] = vm.editor[k];
});
+ // prepare ID
+ if (vm.editor.id) {
+ if (page.type == "story") {
+ postData.item.stoid = vm.editor.id;
+ }
+ }
+
return postData;
}
c.item.content_type = "story";
c.$newslash.getStoryByID(page.stoid,
- (resp) => { // succeed
- for (k in resp.body.item) {
- c.editor.item[k] = resp.body.item[k];
+ (resp) => {
+ // succeed
+ var item = resp.body.item;
+ for (var k in c.editor) {
+ if (item[k] !== undefined) {
+ c.editor[k] = item[k];
+ }
+ }
+ // convert tags to tags_string
+ if (item.tags) {
+ var tagnames = item.tags.map(tag => tag.tagname);
+ c.editor.tags_string = tagnames.join(" ");
}
+ // TODO: related stories
+ // convert public to display
+ c.editor.display = (item.public == "yes");
+ c.editor.createtime = nsUtil.formatToLocalISOString(nsUtil.decodeMySQLDateTime(item.create_time));
+ c.editor.id = item.stoid;
},
(resp) => { //failed
c.message = resp.body.message;
});
}
-
+
// submission to story mode
if (c.item.submission_id) {
c.$newslash.getSubmissionByID(c.item.submission_id,
<script>
editor.run({ type: 'story',
el: '#story-editor',
- [% IF source.id %] submissionID: [% source.id %], [% END %]
+ [%- IF source.type == "submission" %] submissionID: [% source.id %], [% END %]
+ [%- IF source.type == "story" %] storyID: [% source.id %], [% END %]
});
</script>
</button>
[%- END -%]
[%- IF x_template || item.content_type == 'story' && user.is_admin || user.editor -%]
- <a href="/story/edit?stoid=[% item. stoid %]">[編集]</a>
+ <a href="/admin/story/edit?stoid=[% item. stoid %]">[編集]</a>
[%- END -%]
[%- IF item.content_type == 'submission' && (user.author || x_template) -%]
- [<a href="/admin/story/edit?subid=[% item.submission_id %]">accept</a>]
+ [<a href="/admin/story/edit?subid=[% item.submission_id %]">[accept]</a>]
[%- END -%]
</div>
<div class="content-editor-wrap">
<div class="alert alert-info post-done" v-if="mode == 'posted'">
投稿を行いました。URL:<A :href="createdUrl" v-text="createdUrl"></a>
+ <span v-if="item.content_type == 'story'"><a href="#" @click="leavePreview">[再編集]</a></span>
</div>
<div class="alert alert-info post-error-message" v-show="message">
<div v-if="message == 'duplicated_post'">エラー:すでに同じ内容が投稿されています</div>