OSDN Git Service

js: clean up article editor related codes
authorhylom <hylom@users.sourceforge.jp>
Fri, 24 Aug 2018 12:33:21 +0000 (21:33 +0900)
committerhylom <hylom@users.sourceforge.jp>
Fri, 24 Aug 2018 12:33:21 +0000 (21:33 +0900)
src/newslash_web/public/js/article-item2.js
src/newslash_web/public/js/vue-newslash.js

index 123fad7..4908ada 100644 (file)
@@ -140,7 +140,7 @@ articleItem.init = function init () {
   function showPreview(event) {
     var type = this.item.content_type;
     if (!type) {
-      console.log("no content_type!");
+      console.warn("no content_type!");
       return;
     }
     var postData = _preparePostData(this, "preview");
@@ -192,10 +192,11 @@ articleItem.init = function init () {
     var postData = _preparePostData(this, "post");
     var type = this.item.content_type;
     if (!type) {
-      console.log("no content_type!");
+      console.warn("no content_type!");
       return;
     }
 
+    // journal post
     if (type == "journal") {
       postData.csrf_token = this.csrfToken;
       newslash.postJournal(postData).then(
@@ -208,9 +209,9 @@ articleItem.init = function init () {
           // check if new post
           if (!postData.id) {
             this.createdUrl = url;
-            this.message = "post_success";
             this.item.subid = id;
           }
+          this.message = "";
           this.mode = "posted";
         },
         (resp) => { // fail
@@ -221,28 +222,28 @@ articleItem.init = function init () {
       return;
     }
 
+    // submission post
     this.$newslash.post(type, postData, {csrfToken: this.csrfToken},
-      (response) => { // success
-        this.message = "";
-        var id = response.body.id;
-        var type = response.body.type;
-        var url = '/' + type + '/' + id;
-
-        // check if new post
-        if (!postData.id) {
-          this.createdUrl = url;
-          this.message = "post_success";
-          this.item.subid = id;
-        }
-
-        this.mode = "posted";
-      },
-      (response) => { // fail
-        this.message = response.body.message;
-        this.mode = "preview";
-      }
-    );
-
+                        (response) => { // success
+                          this.message = "";
+                          var 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;
+                          }
+                          this.message = "";
+                          this.mode = "posted";
+                        },
+                        (response) => { // fail
+                          this.message = response.body.message;
+                          this.mode = "preview";
+                        }
+                       );
+    
   }
 
   function _preparePostData(vm, action) {
@@ -269,7 +270,7 @@ articleItem.init = function init () {
   }
 
   function quoteHtml(html) {
-    return nsUtil.quoteHtml(html, editorConfig.allowed_tags);
+    return nsUtil.quoteHtml(html, siteConfig.editorConfig.allowed_tags);
   }
 
   function quoteTitle(html) {
@@ -432,7 +433,7 @@ articleItem.init = function init () {
 articleItem.run = function (params) {
   params = params || {};
   if (!params.el) {
-    console.log('error in articleItem.run(): no element given');
+    console.error('error in articleItem.run(): no element given');
     return;
   }
   this.vm = new Vue({el: params.el});
@@ -441,11 +442,11 @@ articleItem.run = function (params) {
 articleItem.addTrigger = function addTrigger (selector, params) {
   params = params || {};
   if (!params.el) {
-    console.log('error in articleItem.addTrigger(): no element given');
+    console.error('error in articleItem.addTrigger(): no element given');
     return;
   }
   if (!selector) {
-    console.log('error in articleItem.addTrigger(): no selector given');
+    console.error('error in articleItem.addTrigger(): no selector given');
     return;
   }
   $(selector).on('click', function (e) {
index ec49402..97ac529 100644 (file)
@@ -18,8 +18,8 @@ VueNewslash.prototype.postUrlOf = {
 
 VueNewslash.prototype.executeCaptcha = function executeCaptcha(onSuccess, onFail) {
   if (typeof grecaptcha === 'undefined' || !grecaptcha) {
-    console.log("$newslash.executeCaptcha: no grecaptcha!");
-    onFail({});
+    console.warn("$newslash.executeCaptcha: no grecaptcha!");
+    onFail({message: "no_grecaptcha"});
     return;
   }
 
@@ -33,7 +33,7 @@ VueNewslash.prototype.executeCaptcha = function executeCaptcha(onSuccess, onFail
       onSuccess(token);
     } else {
       if (statusBar) { statusBar.error("captcha_error"); }
-      onFail({});
+      onFail({resp: "captcha_error"});
     }
   };
   grecaptcha.reset();
@@ -44,8 +44,8 @@ VueNewslash.prototype.executeCaptcha = function executeCaptcha(onSuccess, onFail
 VueNewslash.prototype.post = function post(type, data, options, onSuccess, onFail) {
   var url = this.postUrlOf[type];
   if (!url) {
-    console.log("$newslash.post: invalid type");
-    onFail({});
+    console.error("$newslash.post: invalid type");
+    onFail({message:"invalid_type"});
     return;
   }
 
@@ -69,11 +69,11 @@ VueNewslash.prototype.post = function post(type, data, options, onSuccess, onFai
         _doPost(this.vm, url, data, csrfToken, 0, onSuccess, onFail);
       },
       (resp) => {
+        console.error("$newslash.post: captcha check failed.");
         onFail(resp);
       });
     return;
   }
-
   _doPost(this.vm, url, data, csrfToken, 0, onSuccess, onFail);
 
   function _doPost(vm, url, data, newToken, retry, onSuccess, onFail, lastResp) {
@@ -170,7 +170,7 @@ VueNewslash.init();
  */
 function recaptchaDone(token) {
   if (!VueNewslash.currentRecaptchaCallback) {
-    console.log("recapcha: no VueNewslash.currentRecaptchaCallback!");
+    console.warn("recapcha: no VueNewslash.currentRecaptchaCallback!");
     return;
   }
   VueNewslash.currentRecaptchaCallback(token);