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

refs #276: Enable to select highlight.js style
WIP
can save custom highlight

大谷 東彦 8 лет назад
Родитель
Сommit
0c537d610e

+ 9 - 0
lib/form/admin/customhighlight.js

@@ -0,0 +1,9 @@
+'use strict';
+
+var form = require('express-form')
+  , field = form.field
+  ;
+
+module.exports = form(
+  field('settingForm[customize:highlight]')
+);

+ 1 - 0
lib/form/index.js

@@ -26,6 +26,7 @@ module.exports = {
     custombehavior: require('./admin/custombehavior'),
     customlayout: require('./admin/customlayout'),
     customfeatures: require('./admin/customfeatures'),
+    customhighlight: require('./admin/customhighlight'),
     userInvite: require('./admin/userInvite'),
     slackIwhSetting: require('./admin/slackIwhSetting'),
     slackSetting: require('./admin/slackSetting'),

+ 7 - 0
lib/models/config.js

@@ -85,6 +85,7 @@ module.exports = function(crowi) {
       'customize:css' : '',
       'customize:script' : '',
       'customize:header' : '',
+      'customize:layout' : 'github',
       'customize:behavior' : 'crowi',
       'customize:layout' : 'crowi',
       'customize:isEnabledTimeline' : true,
@@ -370,6 +371,12 @@ module.exports = function(crowi) {
     return getValueForCrowiNS(config, key);
   }
 
+  configSchema.statics.highlightType = function(config)
+  {
+    const key = 'customize:highlight';
+    return getValueForCrowiNS(config, key);
+  }
+
   configSchema.statics.isEnabledTimeline = function(config)
   {
     const key = 'customize:isEnabledTimeline';

+ 1 - 0
lib/routes/index.js

@@ -77,6 +77,7 @@ module.exports = function(crowi, app) {
   app.post('/_api/admin/customize/behavior' , loginRequired(crowi, app) , middleware.adminRequired() , csrf, form.admin.custombehavior, admin.api.customizeSetting);
   app.post('/_api/admin/customize/layout'   , loginRequired(crowi, app) , middleware.adminRequired() , csrf, form.admin.customlayout, admin.api.customizeSetting);
   app.post('/_api/admin/customize/features' , loginRequired(crowi, app) , middleware.adminRequired() , csrf, form.admin.customfeatures, admin.api.customizeSetting);
+  app.post('/_api/admin/customize/highlight' , loginRequired(crowi, app) , middleware.adminRequired() , csrf, form.admin.customhighlight, admin.api.customizeSetting);
 
   // search admin
   app.get('/admin/search'              , loginRequired(crowi, app) , middleware.adminRequired() , admin.search.index);

+ 4 - 2
lib/views/admin/customize.html

@@ -149,7 +149,7 @@
           <div class="form-group">
             <div class="col-xs-3">
               <select class="form-control" id="number" name="number">
-                <option value="github" selected="selected">Github</option>
+                <option value="github">Github</option>
                 <option value="atom-one-dark">Atom One Dark</option>
                 <option value="atom-one-light">Atom One Light</option>
               </select>
@@ -358,7 +358,7 @@ window.addEventListener('load', (event) => {
   </div>
 
   <script>
-    $('#cutomcssSettingForm, #cutomscriptSettingForm, #cutomlayoutSettingForm, #cutombehaviorSettingForm, #customfeaturesSettingForm, #cutomheaderSettingForm').each(function() {
+    $('#cutomcssSettingForm, #cutomscriptSettingForm, #cutomlayoutSettingForm, #cutombehaviorSettingForm, #customfeaturesSettingForm, #cutomheaderSettingForm, #cutomhighlightSettingForm').each(function() {
       $(this).submit(function()
       {
         function showMessage(formId, msg, status) {
@@ -405,6 +405,8 @@ window.addEventListener('load', (event) => {
         return false;
       });
     });
+    // TODO 保存した highlight の値を selector に復元する
+    $('#cutomhighlightSettingForm select').val('github')
 
   </script>