ここではInputManJSを利用して設定済みのレポートテンプレートを挿入することで簡単にレポート作成することや、課題に対するコメントを投稿するサンプルを確認することができます。
import "@grapecity/inputman.richtexteditor/CSS/gc.inputman.richtexteditor.css";
import "@grapecity/inputman/CSS/gc.inputman-js.css";
import { InputMan } from "@grapecity/inputman.richtexteditor";
import * as GcCommon from "@grapecity/inputman";
GcCommon.InputMan.appearanceStyle = GcCommon.InputMan.AppearanceStyle.Modern;
var gcTextBox = new GcCommon.InputMan.GcTextBox(
document.getElementById("topic"),
{
width: 700,
showHelpButton: true,
helpContent: "ここに課題の要約を入力してください",
}
);
var reportCategory = new GcCommon.InputMan.GcComboBox(
document.getElementById("reportCategory"),
{
items: ["バグ報告", "仕様変更報告"],
isEditable: false,
}
);
var gcRichTextEditor = new InputMan.GcRichTextEditor(
document.getElementById("gcRichTextEditor"),
{
watermarkText:
"テンプレート挿入より報告書のフォーマットを設定してから編集を行ってください...",
height: 280,
width: 700,
plugins: [InputMan.GcRichTextEditorPluginItem.All],
baseUrl:
window.location.origin +
"/inputmanjs/demos/lib/purejs/node_modules/@grapecity/inputman.richtexteditor/JS",
menubar: [
InputMan.GcRichTextEditorMenuBarItem.Insert,
InputMan.GcRichTextEditorMenuBarItem.Edit,
],
toolbar: [
InputMan.GcRichTextEditorToolbarItem.Print,
InputMan.GcRichTextEditorToolbarItem.Template,
InputMan.GcRichTextEditorToolbarItem.WordCount,
InputMan.GcRichTextEditorToolbarItem.FullScreen,
InputMan.GcRichTextEditorToolbarItem.Preview,
],
plugins: [InputMan.GcRichTextEditorPluginItem.All],
contextmenu: [InputMan.GcRichTextEditorMenuItem.Template],
templates: "src/template.json",
}
);
var inlineEditor = new InputMan.GcRichTextEditor(
document.getElementById("inline"),
{
watermarkText: "課題に対するコメントを入力してください...",
menubar: null,
plugins: [InputMan.GcRichTextEditorPluginItem.All],
baseUrl:
window.location.origin +
"/inputmanjs/demos/lib/purejs/node_modules/@grapecity/inputman.richtexteditor/JS",
toolbar: [
InputMan.GcRichTextEditorToolbarItem.Redo,
InputMan.GcRichTextEditorToolbarItem.Undo,
InputMan.GcRichTextEditorToolbarItem.BackColor,
InputMan.GcRichTextEditorToolbarItem.ForeColor,
InputMan.GcRichTextEditorToolbarItem.FontFamily,
InputMan.GcRichTextEditorToolbarItem.BulList,
InputMan.GcRichTextEditorToolbarItem.NumList,
InputMan.GcRichTextEditorToolbarItem.Remove,
InputMan.GcRichTextEditorToolbarItem.Copy,
InputMan.GcRichTextEditorToolbarItem.Cut,
InputMan.GcRichTextEditorToolbarItem.Paste,
],
inline: true,
setup: (inlineEditor) => {
inlineEditor.addContextToolbar("textselection", {
items: [
InputMan.GcRichTextEditorToolbarItem.ForeColor,
InputMan.GcRichTextEditorToolbarItem.FontFamily,
InputMan.GcRichTextEditorToolbarItem.Bold,
InputMan.GcRichTextEditorToolbarItem.Italic,
InputMan.GcRichTextEditorToolbarItem.SeperateLine,
InputMan.GcRichTextEditorToolbarItem.BlockQuote,
],
predicate: (node) => inlineEditor.getSelection(),
position: "selection",
});
},
}
);
reportCategory.addEventListener(
GcCommon.InputMan.GcComboBoxEvent.SelectedChanged,
(e) => {
if (e.selectedIndex === 0) {
gcRichTextEditor.execCommand(InputMan.GcRichTextEditorCommand.Template);
} else {
gcRichTextEditor.execCommand(
InputMan.GcRichTextEditorCommand.InsertTemplate,
"<p>以下のホームページのデザインを変更します。</p><p><a href='https://demo.mescius.jp/inputmanjs/docs/how_to'>製品ヘルプ-製品紹介</a></p>"
);
}
}
);
document.getElementById("commitComment").addEventListener("click", () => {
const element = document.getElementById("content");
const addelement = document.createElement("p");
const date = new Date();
if (inlineEditor.getContent("text").trim().length > 0) {
addelement.innerHTML =
date.toLocaleString("ja-JP") + ": " + inlineEditor.getContent("html");
element.insertBefore(addelement, element.firstChild);
} else {
alert("コメントを入力してください");
}
});
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>実用例 - 課題報告フォーム</title>
<!-- SystemJS -->
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('./src/app');
</script>
</head>
<body>
<h2>課題報告</h2>
<div class="editArea">
<div class="contents">
<label for="topic">トピック</label><br />
<input class="title" id="topic" />
</div>
<br />
<div class="contents">
<label for="reportCategory">レポート種類</label><br />
<select id="reportCategory"></select>
</div>
<br />
<div class="contents">
<div>
<label for="gcRichTextEditor">課題内容</label><br />
<textarea id="gcRichTextEditor"></textarea>
</div>
</div>
<br />
</div>
<br />
<div class="comment">
<div class="editArea">
<label for="comment">コメント</label><br />
<div id="inline"></div>
<br />
</div>
<div class="btn">
<button id="commitComment">コメントを投稿</button>
</div>
<div class="displayArea">
<div id="content"></div>
</div>
</div>
</body>
</html>
.title .gcim {
width: 450px;
border-width: 1px;
}
body {
width: 700px;
height: 100%;
background-color: #eaf4fc;
position: static !important;
}
#inline {
width: 700px;
height: 100px;
border-width: 0.5px;
background-color: white;
overflow: auto;
}
#inline .gcim__richtexteditor-content-body .gcim__richtexteditor-edit-focus {
width: 700px;
height: 500px;
}
label {
font-weight: bold;
color: #007bbb;
}
.gcim__richtexteditor .gcim__richtexteditor-editor-header .gcim__richtexteditor-toolbar-overlord {
background-color: #007bbb;
}
.gcim__richtexteditor-editor-container {
width: 700px;
}
button {
height: 40px;
width: 120px;
font-weight: bold;
font-size: small;
border: 2px solid #83ccd2;
background: #83ccd2;
color: #fff;
border-radius: 5px;
}
button:hover {
border: 2px solid#84b9cb;
background-color: #84b9cb;
}
.displayArea {
color: #38a1db;
font-size: 14px;
font-family: 'メイリオ', serif;
}
#content{
background-color:#f5f5f5;
}
[gcim-control-appearance="modern"] .title .gcim {
width: 450px;
border-width: 1px;
}
body {
width: 700px;
height: 100%;
background-color: #eaf4fc;
position: static !important;
}
[gcim-control-appearance="modern"] #inline {
width: 700px;
height: 100px;
border-width: 0.5px;
background-color: white;
overflow: auto;
}
[gcim-control-appearance="modern"] #inline .gcim__richtexteditor-content-body .gcim__richtexteditor-edit-focus {
width: 700px;
height: 500px;
}
[gcim-control-appearance="modern"] label {
font-weight: bold;
color: #007bbb;
}
[gcim-control-appearance="modern"] .gcim__richtexteditor .gcim__richtexteditor-editor-header .gcim__richtexteditor-toolbar-overlord {
background-color: #007bbb;
}
[gcim-control-appearance="modern"] .gcim__richtexteditor-editor-container {
width: 700px;
}
button {
height: 40px;
width: 120px;
font-weight: bold;
font-size: small;
border: 2px solid #83ccd2;
background: #83ccd2;
color: #fff;
border-radius: 5px;
}
button:hover {
border: 2px solid#84b9cb;
background-color: #84b9cb;
}
[gcim-control-appearance="modern"] .displayArea {
color: #38a1db;
font-size: 14px;
font-family: 'メイリオ', serif;
}
[gcim-control-appearance="modern"] #content {
background-color: #f5f5f5;
}
System.config({
transpiler: 'plugin-babel',
babelOptions: {
es2015: true
},
meta: {
'*.css': { loader: 'css' }
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
'@grapecity/inputman': 'npm:@grapecity/inputman/index.js',
'@grapecity/inputman/CSS': 'npm:@grapecity/inputman/CSS',
'@grapecity/inputman.richtexteditor': 'npm:@grapecity/inputman.richtexteditor/index.js',
'@grapecity/inputman.richtexteditor/CSS': 'npm:@grapecity/inputman.richtexteditor/CSS',
'css': 'npm:systemjs-plugin-css/css.js',
'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js',
'systemjs-babel-build': 'npm:systemjs-plugin-babel/systemjs-babel-browser.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
src: {
defaultExtension: 'js'
},
"node_modules": {
defaultExtension: 'js'
},
}
});