Last active
August 29, 2015 14:18
-
-
Save tkc49/08f859c675ce8ac8f463 to your computer and use it in GitHub Desktop.
kintoneのレコード一覧画面、レコード詳細画面から他のアプリへページ遷移できるセレクトボックスメニューです。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
"use strict"; | |
var subdomain = ""; | |
// レコード一覧画面イベント | |
kintone.events.on('app.record.index.show',createAppSelectBox); | |
// レコード詳細画面イベント | |
kintone.events.on('app.record.detail.show',createAppSelectBox); | |
function createAppSelectBox(){ | |
var select; | |
kintone.api('/k/v1/apps', 'GET', {}, | |
// データ取得 | |
function ( resp ) { | |
select = document.createElement("select"); | |
var option = document.createElement("option"); | |
option.value = "メニュー"; | |
var text = document.createTextNode('メニュー'); | |
option.appendChild(text); | |
select.appendChild(option); | |
for( var i = 0; i < resp['apps'].length; i++ ){ | |
var option = document.createElement("option"); | |
option.value = resp['apps'][i]['appId']; | |
var text = document.createTextNode(resp['apps'][i]['name']); | |
option.appendChild(text); | |
select.appendChild(option); | |
} | |
var recordElement = kintone.app.record.getHeaderMenuSpaceElement(); | |
if( recordElement ){ | |
recordElement.appendChild( select ); | |
} | |
var listElement = kintone.app.getHeaderMenuSpaceElement(); | |
if( listElement ){ | |
listElement.appendChild( select ); | |
} | |
select.onchange = check; | |
}, | |
// エラー処理 | |
function (resp) { | |
var errmsg = 'An error occurred while getting records.'; | |
if (resp.message !== undefined) { | |
errmsg += '\n' + resp.message; | |
alert(errmsg); | |
} | |
} | |
); | |
function check(){ | |
var selectValue = select.value; | |
if(selectValue != "メニュー"){ | |
location.href = "https://" + subdomain + ".cybozu.com/k/"+selectValue; | |
} | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment