Proteus.addHandler("load", function() {
// パラメーター説明
// 第1パラメーター = このコードを動作させる対象スペース(「すべてのスペース」では "*" を指定)
// 第2パラメーター = セクションのID
// 第3パラメーター = ボタンのID
// 第4パラメーター = 「追加」ボタンに表示される文字
// 第5パラメーター = 既定の投稿先スペース(投稿フォームで自動選択される投稿先スペース)
// 第6パラメーター = フォーム名
// 第7パラメーター = タグ (複数指定の場合は '+:FAQ,+:todo' のように半角カンマ記号で区切る)
addButtonToSpecificSectionOnDashboard('動作テスト','discussions','btnStatus','近況を追加','動作テスト','status','+:お知らせ');
});
function addButtonToSpecificSectionOnDashboard(targetSpace,sectId,buttonId,buttonLabel,postSpace,formName,addTags) {
if (targetSpace == '*') {
var targetViewName = 'home';
} else {
var targetViewName = 'dashboard';
}
var hash = location.hash;
var viewNameArray = hash.match(/#\/(\w+).*/);
var curViewName = viewNameArray[1];
var encodedTargetSpace = encodeURIComponent(targetSpace).toLowerCase();
if (curViewName && curViewName == targetViewName) {
if (hash) {
var param = hash.split('&');
var paramArray = [];
for (i = 0; i < param.length; i++) {
var paramItem = param[i].split('=');
paramArray[paramItem[0]] = paramItem[1];
}
if ( curViewName == 'dashboard' ) {
// The proj= URL parameter should be defined in the dashboard view.
var proj = paramArray.proj.toLowerCase();
} else {
// The proj= URL parameter could not be defined.
var proj = "*";
}
if (buttonId) {
if (proj == targetSpace || proj == encodedTargetSpace) {
if ($('.sect-' + sectId + ' .sctrl .sngl:eq(1) #' + buttonId + '.proteus-custom-add-button').length) {
// Don't add the "Add" button if there is already the "Add" button.
} else {
$('.sect-' + sectId + ' .sctrl .sngl:eq(1)').append('<a id="' + buttonId + '" class="add proteus-custom-add-button" href="javascript:void(0);" rg="a#form&form=' + formName + '&default_project=' + postSpace + '&default_tags=' + addTags + '">' + buttonLabel + '</a>');
}
}
} else {
console.log('Warning: The variable buttonId is undefined or empty.')
}
}
}
}
addButtonToSpecificSectionOnDashboard('*','recenttasks','btnTask','タスクを追加','Sales','taskdialog','+:FAQ');