OSDN Git Service

fix to work journal and submission editing
authorhylom <hylom@users.sourceforge.jp>
Thu, 16 Nov 2017 17:53:16 +0000 (02:53 +0900)
committerhylom <hylom@users.sourceforge.jp>
Thu, 16 Nov 2017 17:53:16 +0000 (02:53 +0900)
src/newslash_web/css/main/form.less
src/newslash_web/lib/Newslash/Web/Controller/API/Journal.pm
src/newslash_web/lib/Newslash/Web/Controller/API/Submission.pm
src/newslash_web/public/js/article-item2.js
src/newslash_web/templates/common/article/article.html.tt2
src/newslash_web/templates/common/article/editor.html.tt2

index f17974f..d1edab4 100644 (file)
@@ -6,7 +6,7 @@
 }
 
 textarea.form-control {
-    height: 8em;
+    height: 18em;
 }
 
 input[type="datetime-local"].form-control {
index e9d6a84..1e5dd55 100644 (file)
@@ -3,6 +3,7 @@ use Mojo::Base 'Newslash::Web::Controller';
 #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;
@@ -76,8 +77,8 @@ sub post {
         $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};
@@ -94,8 +95,17 @@ sub post {
     # 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);
@@ -103,8 +113,17 @@ sub post {
     }
 
     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;
     }
index 928d5ec..98259d8 100644 (file)
@@ -90,8 +90,8 @@ sub post {
     my $message = "";
 
     # check body
-    if ($item->{introtext}) {
-        my $text = $item->{introtext};
+    if ($item->{introtext} || $item->{intro_text}) {
+        my $text = $item->{introtext} || $item->{intro_text};
         $text =~ s/\s+\z//m;
         $params->{introtext} = $util->clean_html($allowed, $text);
         $params->{introtext} =~ s/\s+\z//m;
index b583c10..727e1e7 100644 (file)
@@ -8,12 +8,12 @@ articleItem.init = function init () {
       // 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: "",
@@ -29,7 +29,7 @@ articleItem.init = function init () {
       createdUrl: "",
       currentTopics: [],
       
-      enableAutoPreview: "1",
+      enableAutoPreview: 1,
       mode: "",
 
       primaryTopicIconURL: "",
@@ -41,10 +41,10 @@ articleItem.init = function init () {
   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,
@@ -54,22 +54,22 @@ articleItem.init = function init () {
    * 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) {
@@ -150,7 +150,7 @@ articleItem.init = function init () {
         (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();
 
@@ -172,7 +172,7 @@ articleItem.init = function init () {
       (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();
@@ -277,7 +277,7 @@ articleItem.init = function init () {
   }
 
   function startEdit() {
-    _initEditor(this);
+    _startEdit(this);
   }
 
   function cancelEdit() {
@@ -313,15 +313,14 @@ articleItem.init = function init () {
    * 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(
@@ -329,12 +328,19 @@ articleItem.init = function init () {
           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) {
@@ -366,9 +372,9 @@ articleItem.init = function init () {
     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;
@@ -394,13 +400,17 @@ articleItem.init = function init () {
       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";
   }
 
index 0f1ade2..a50abb3 100644 (file)
@@ -72,12 +72,12 @@ IF item.content_type == 'poll'; url = "/poll/" _ item.id _ "/"; END;
     [%- END -%]
   </div>
 
-  [%- IF item.introtext || x_template -%]
-  <div class="body contents-text" v-html="item.introtext">[% item.introtext %]</div>
+  [%- IF item.intro_text || x_template -%]
+  <div class="body contents-text" v-html="item.intro_text">[% item.intro_text %]</div>
   [%- END -%]
 
-  [% IF item.content_type != "journal" && item.bodytext && !hide_bodytext %]
-  <div class="body contents-text" v-html="item.bodytext">[% item.bodytext %]</div>
+  [% IF item.content_type != "journal" && item.body_text && !hide_bodytext %]
+  <div class="body contents-text" v-html="item.body_text">[% item.body_text %]</div>
   [% END %]
 
   [%- IF x_template -%]
index 0446f32..c99ef6e 100644 (file)
    
     <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>