Просмотр исходного кода

Merge pull request #56 from weseek/feat/save-with-ctrl-s

save with Ctrl+S
Yuki Takei 9 лет назад
Родитель
Сommit
4545459412
4 измененных файлов с 60 добавлено и 13 удалено
  1. 1 0
      package.json
  2. 3 0
      resource/css/crowi.scss
  3. 51 0
      resource/js/legacy/crowi-form.js
  4. 5 13
      yarn.lock

+ 1 - 0
package.json

@@ -117,6 +117,7 @@
     "socket.io-client": "~1.7.0",
     "style-loader": "^0.16.1",
     "swig": "~1.4.0",
+    "toastr": "^2.1.2",
     "uglifycss": "^0.0.25",
     "webpack": "~2.3.1",
     "webpack-dll-bundles-plugin": "^1.0.0-beta.5",

+ 3 - 0
resource/css/crowi.scss

@@ -11,6 +11,9 @@ $bootstrap-sass-asset-helper: true;
 @import '~react-bootstrap-typeahead/css/Token';
 @import '~react-bootstrap-typeahead/css/Typeahead';
 
+// import toastr styles
+@import '~toastr/build/toastr';
+
 // crowi component
 @import 'admin';
 @import 'attachments';

+ 51 - 0
resource/js/legacy/crowi-form.js

@@ -13,6 +13,7 @@
   require('bootstrap-sass');
   require('inline-attachment/src/inline-attachment');
   require('./thirdparty-js/jquery.selection');
+  const toastr = require('toastr');
 
   // show/hide
   function FetchPagesUpdatePostAndInsert(path) {
@@ -363,6 +364,53 @@ $(function() {
     }
   };
 
+  /**
+   * event handler when 'Ctrl-S' pressed
+   */
+  var handleSKey = function(event) {
+    if (!event.ctrlKey) {
+      return;
+    }
+
+    event.preventDefault();
+
+    let data = {
+      page_id: pageId,
+      body: $('#form-body').val(),
+    }
+
+    crowi.apiPost('/pages.update', data)
+      .then((res) => {
+        let page = res.page;
+        toastr.success(undefined, 'Saved successful', {
+          closeButton: true,
+          progressBar: true,
+          newestOnTop: false,
+          showDuration: "100",
+          hideDuration: "100",
+          timeOut: "1200",
+          extendedTimeOut: "150",
+        });
+
+        // update currentRevision input
+        $('#page-form [name="pageForm[currentRevision]"]').val(page.revision._id);
+
+        // TODO update $('#revision-body-content')
+      })
+      .catch((error) => {
+        console.error(error);
+        toastr.error(error.message, 'Error occured on saveing', {
+          closeButton: true,
+          progressBar: true,
+          newestOnTop: false,
+          showDuration: "100",
+          hideDuration: "100",
+          timeOut: "3000",
+        });
+      });
+
+  }
+
   // markdown helper inspired by 'esarea'.
   // see: https://github.com/fukayatsu/esarea
   $('textarea#form-body').on('keydown', function(event) {
@@ -379,6 +427,9 @@ $(function() {
       case 32:
         handleSpaceKey(event);
         break;
+      case 83:
+        handleSKey(event);
+        break;
       default:
     }
   });

+ 5 - 13
yarn.lock

@@ -4890,7 +4890,7 @@ readable-stream@1.1.x, readable-stream@~1.1.9:
     isarray "0.0.1"
     string_decoder "~0.10.x"
 
-readable-stream@2.2.7:
+readable-stream@2.2.7, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.5, readable-stream@^2.0.6, readable-stream@^2.1.4, readable-stream@^2.2.2, readable-stream@^2.2.6:
   version "2.2.7"
   resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.2.7.tgz#07057acbe2467b22042d36f98c5ad507054e95b1"
   dependencies:
@@ -4902,18 +4902,6 @@ readable-stream@2.2.7:
     string_decoder "~1.0.0"
     util-deprecate "~1.0.1"
 
-readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.5, readable-stream@^2.0.6, readable-stream@^2.1.4, readable-stream@^2.2.2, readable-stream@^2.2.6:
-  version "2.2.9"
-  resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.2.9.tgz#cf78ec6f4a6d1eb43d26488cac97f042e74b7fc8"
-  dependencies:
-    buffer-shims "~1.0.0"
-    core-util-is "~1.0.0"
-    inherits "~2.0.1"
-    isarray "~1.0.0"
-    process-nextick-args "~1.0.6"
-    string_decoder "~1.0.0"
-    util-deprecate "~1.0.1"
-
 readable-stream@~2.0.5:
   version "2.0.6"
   resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.0.6.tgz#8f90341e68a53ccc928788dacfcd11b36eb9b78e"
@@ -5752,6 +5740,10 @@ to-fast-properties@^1.0.1:
   version "1.0.3"
   resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47"
 
+toastr@^2.1.2:
+  version "2.1.2"
+  resolved "https://registry.yarnpkg.com/toastr/-/toastr-2.1.2.tgz#fd69066ae7578a5b3357725fc9c7c335e9b681df"
+
 tough-cookie@~2.3.0:
   version "2.3.2"
   resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.2.tgz#f081f76e4c85720e6c37a5faced737150d84072a"