Преглед на файлове

#324 Improve: Enable ON/OFF switch of attaching a title header
* Enabled attaching title header to new page draft, and that ON/OFF setting too

Tatsuya Ise преди 8 години
родител
ревизия
c8a1985a6a

+ 2 - 2
lib/form/admin/customfeatures.js

@@ -5,7 +5,7 @@ var form = require('express-form')
 
 module.exports = form(
   field('settingForm[customize:isEnabledTimeline]').trim().toBooleanStrict(),
-  field('settingForm[customize:isSavedStatesOfTabChanges]').trim().toBooleanStrict()
-  // field('settingForm[customize:isEnabledAttachTitleHeader]').trim().toBooleanStrict()
+  field('settingForm[customize:isSavedStatesOfTabChanges]').trim().toBooleanStrict(),
+  field('settingForm[customize:isEnabledAttachTitleHeader]').trim().toBooleanStrict()
 );
 

+ 4 - 1
lib/locales/en-US/translation.json

@@ -306,7 +306,10 @@
     "reflect_change": "You need to reload the page to reflect the change.",
     "ctrl_space": "Ctrl+Space to Autocomplete",
     "Custom script": "Custom script",
-    "write_java": "You can write Javascript that is applied to whole system."
+    "write_java": "You can write Javascript that is applied to whole system.",
+    "attach_title_header": "Attach title header",
+    "attach_title_header_desc": "Attach the page path to new page first line when you create new page.(ON is Crowi default)",
+    "by_invalidating_title_header": "By invalidating, you can create the page cleanly.(OFF is GROWI standard)"
   },
 
   "user_management": {

+ 4 - 2
lib/locales/ja/translation.json

@@ -326,8 +326,10 @@
     "reflect_change": "変更の反映はページの更新が必要です。",
     "ctrl_space": "Ctrl+Space でコード補完",
     "Custom script": "カスタムスクリプト",
-    "write_java": "システム全体に適用されるJavaScriptを記述できます。"
-
+    "write_java": "システム全体に適用されるJavaScriptを記述できます。",
+    "attach_title_header": "タイトルヘッダの挿入",
+    "attach_title_header_desc": "新規作成したページの1行目にページのパスをタイトルヘッダとして挿入します。(Crowi の規定値はON)",
+    "by_invalidating_title_header": "無効化することで、まっさらな状態からページを作成することができます。(GROWI の標準はOFF)"
   },
 
   "user_management": {

+ 8 - 7
lib/models/config.js

@@ -32,7 +32,7 @@ module.exports = function(crowi) {
     config['customize:behavior'] = 'growi';
     config['customize:layout'] = 'growi';
     config['customize:isSavedStatesOfTabChanges'] = false;
-    // config['customize:isEnabledAttachTitleHeader'] = false;
+    config['customize:isEnabledAttachTitleHeader'] = false;
 
     return config;
   }
@@ -92,7 +92,7 @@ module.exports = function(crowi) {
       'customize:layout' : 'crowi',
       'customize:isEnabledTimeline' : true,
       'customize:isSavedStatesOfTabChanges' : true,
-      // 'customize:isEnabledAttachTitleHeader' : true,
+      'customize:isEnabledAttachTitleHeader' : true,
     };
   }
 
@@ -424,11 +424,11 @@ module.exports = function(crowi) {
     return getValueForCrowiNS(config, key);
   };
 
-  // configSchema.statics.isEnabledAttachTitleHeader = function(config)
-  // {
-  //   const key = 'customize:isEnabledAttachTitleHeader';
-  //   return getValueForCrowiNS(config, key);
-  // };
+  configSchema.statics.isEnabledAttachTitleHeader = function(config)
+  {
+    const key = 'customize:isEnabledAttachTitleHeader';
+    return getValueForCrowiNS(config, key);
+  };
 
   configSchema.statics.fileUploadEnabled = function(config)
   {
@@ -510,6 +510,7 @@ module.exports = function(crowi) {
       layoutType: Config.layoutType(config),
       isEnabledLineBreaks: Config.isEnabledLinebreaks(config),
       isSavedStatesOfTabChanges: Config.isSavedStatesOfTabChanges(config),
+      isEnabledAttachTitleHeader: Config.isEnabledAttachTitleHeader(config),
       env: {
         PLANTUML_URI: env.PLANTUML_URI || null,
         MATHJAX: env.MATHJAX || null,

+ 4 - 4
lib/util/swigFunctions.js

@@ -171,10 +171,10 @@ module.exports = function(crowi, app, req, locals) {
     return Config.isUploadable(config);
   };
 
-  // locals.isEnabledAttachTitleHeader = function() {
-  //   var config = crowi.getConfig()
-  //   return Config.isEnabledAttachTitleHeader(config);
-  // };
+  locals.isEnabledAttachTitleHeader = function() {
+    var config = crowi.getConfig()
+    return Config.isEnabledAttachTitleHeader(config);
+  };
 
   locals.parentPath = function(path) {
     if (path == '/') {

+ 0 - 1
lib/views/_form.html

@@ -17,7 +17,6 @@
 <form action="/_/edit" id="page-form" method="post" class="{% if isUploadable() %}uploadable{% endif %} page-form">
 
   <div id="page-editor">{% if pageForm.body %}{{ pageForm.body }}{% endif %}</div>
-  <!-- <div id="page-editor">{% if pageForm.body %}{{ pageForm.body }}{% elseif isEnabledAttachTitleHeader() %}# {{ path|path2name }}{% endif %}</div> -->
 
   <input type="hidden" id="form-body" name="pageForm[body]" value="{% if pageForm.body %}{{ pageForm.body }}{% endif %}">
   <input type="hidden" name="pageForm[path]" value="{{ path }}">

+ 9 - 13
lib/views/admin/customize.html

@@ -243,29 +243,25 @@
             </p>
           </div>
         </div>
-<!--
+
         <div class="form-group">
-          <label for="settingForm[customize:isEnabledAttachTitleHeader]" class="col-xs-3 control-label">{{ t("customize_page.tab_switch") }}</label>
+          <label for="settingForm[customize:isEnabledAttachTitleHeader]" class="col-xs-3 control-label">{{ t("customize_page.attach_title_header") }}</label>
           <div class="col-xs-9">
             <div class="btn-group btn-toggle" data-toggle="buttons">
-              <label class="btn btn-default btn-rounded btn-outline {% if settingForm['customize:isEnabledAttachTitleHeader'] %}active{% endif %}"
-                data-active-class="primary">
-                <input name="settingForm[customize:isEnabledAttachTitleHeader]" value="true" type="radio" {% if true===s ettingForm[
-                  'customize:isEnabledAttachTitleHeader'] %}checked{% endif %}> ON
+              <label class="btn btn-default btn-rounded btn-outline {% if settingForm['customize:isEnabledAttachTitleHeader'] %}active{% endif %}" data-active-class="primary">
+                <input name="settingForm[customize:isEnabledAttachTitleHeader]" value="true" type="radio" {% if true===settingForm['customize:isEnabledAttachTitleHeader'] %}checked{% endif %}> ON
               </label>
-              <label class="btn btn-default btn-rounded btn-outline {% if !settingForm['customize:isEnabledAttachTitleHeader'] %}active{% endif %}"
-                data-active-class="default">
-                <input name="settingForm[customize:isEnabledAttachTitleHeader]" value="false" type="radio" {% if !settingForm[
-                  'customize:isEnabledAttachTitleHeader'] %}checked{% endif %}> OFF
+              <label class="btn btn-default btn-rounded btn-outline {% if !settingForm['customize:isEnabledAttachTitleHeader'] %}active{% endif %}" data-active-class="default">
+                <input name="settingForm[customize:isEnabledAttachTitleHeader]" value="false" type="radio" {% if !settingForm['customize:isEnabledAttachTitleHeader'] %}checked{% endif %}> OFF
               </label>
             </div>
 
             <p class="help-block">
-              {{ t("customize_page.save_edit") }}
-              <br> {{ t("customize_page.by_invalidating") }}
+              {{ t("customize_page.attach_title_header_desc") }}<br>
+              {{ t("customize_page.by_invalidating_title_header") }}
             </p>
           </div>
-        </div> -->
+        </div>
 
         <div class="form-group">
           <div class="col-xs-offset-3 col-xs-6">

+ 5 - 0
resource/js/util/Crowi.js

@@ -147,6 +147,11 @@ export default class Crowi {
     if (this.draft && this.draft[path]) {
       return this.draft[path];
     }
+    if (this.config.isEnabledAttachTitleHeader) {
+      var pathdraft = "# " + path;
+      this.saveDraft(path, pathdraft);
+      return this.draft[path];
+    }
 
     return null;
   }