Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
crowiプラグインのサンプル
function get_data() {
source = document.getElementById("form-body").innerHTML.split("\n");
for(i in source) {
// データは改行を含まないとする
if(~source[i].indexOf("{")){
return JSON.parse(source[i]);
}
}
}
function save_data(json) {
source = document.getElementById("form-body").innerHTML.split("\n");
text = "";
for(i in source) {
if(~source[i].indexOf("{")){
text += JSON.stringify(json).replace(/"/g,'"');
} else {
text += source[i];
}
text += "\n";
}
document.getElementById("form-body").innerHTML = text;
document.getElementById("edit-form-submit").click();
}
function crowi_plugin_test(plugin_data) {
ret = "<h1>プラグインのテスト</h1>\n";
heads = plugin_data["head"];
ret += "<form name='plugin_test'><table>\n<tr>\n<td></td>";
for(i=0;i<heads.length;i++) {
ret += "<td>" + heads[i] + "</td>\n";
}
ret += "</tr>\n";
members = plugin_data["member"];
for(i=0;i<members.length;i++) {
ret += "<tr><td>" + members[i] + "</td>\n";
for(j=0;j<heads.length;j++) {
if(plugin_data["result"][members[i]] === undefined) {
ret += "<td></td>";
continue;
}
if(plugin_data["result"][members[i]][j] === undefined
|| plugin_data["result"][members[i]][j] == 0) {
ret += "<td></td>";
} else if(plugin_data["result"][members[i]][j] === 1) {
ret += "<td>o</td>";
} else if(plugin_data["result"][members[i]][j] === 2) {
ret += "<td>x</td>";
} else {
ret += "<td>?</td>";
}
}
ret += "</tr>\n"
}
pulldown = plugin_data["pulldown"];
if(pulldown === undefined) {
pulldown = ["","o","x","?"];
}
ret += "<tr><td><input type='text' name='new_member_name'></td>\n"
for(i=0;i<heads.length;i++) {
ret += "<td><select name='"+heads[i]+"'>"
for(j=0;j<pulldown.length;j++) {
ret += "<option value='"+ j + "'>" + pulldown[j] + "</option>\n";
}
ret += "</td>"
}
ret += "</select></tr></table><input type='button' class='btn' onClick='plugintest_onClick();' value='button!!'></form>";
//save_data(plugin_data);
return ret;
}
function get_formdata(json) {
dom = document.getElementsByName("plugin_test")[0];
json["member"].push(dom.new_member_name.value);
json["result"][json["member"]] = [];
console.log(json["member"]);
for(i=0;i<json["head"].length;i++) {
json["result"][json["member"]][i] = ((dom[json["head"]] === undefined) ? 0 : dom[json["head"][i]].options);
}
console.log(json);
return json;
}
function plugintest_onClick() {
json = get_data();
save_data(get_formdata(json));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.