表現はさておきSharePointのほうの解説をします。
- SiteData.asmxのGetSiteでサイトURLを引っ張ってきます。
- GetSiteで引っ張ってきたサイトヒエラルキーのUserGroup.asmxでGetGroupCollectionFromWebを使います。これでそのサイトのグループ一覧を得ます。
- 最後に2.で引っ張ったグループUserGroup.asmxのGetUserCollectionFromGroupに与えて所属するユーザを引っ張ります。
- ExtJSのgridでレンダリングするという流れです。
<link rel="stylesheet" type="text/css" href="<yourSitePath>/ext/resources/css/ext-all.css" />
<script type="text/javascript" src="<yourSitePath>/ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="<yourSitePath>/ext/ext-all.js"></script>
<script type="text/javascript">
_spBodyOnLoadFunctionNames.push( "getSiteUrlList" );
function getHttpReq(){
return window.XMLHttpRequest ? new XMLHttpRequest() : ( function() {
try { return new ActiveXObject( "Msxml2.XMLHTTP" ); }
catch( e ) { return new ActiveXObject( "Microsoft.XMLHTTP" ); }
}());
}
function getSiteUrlList() {
var httpInst = getHttpReq();
var renderItem = '';
httpInst.open( "POST", "/_vti_bin/SiteData.asmx", false );
httpInst.setRequestHeader( 'Content-Type','text/xml; charset=utf-8' );
httpInst.setRequestHeader( 'SOAPAction','http://schemas.microsoft.com/sharepoint/soap/GetSite' );
var postBody = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetSite xmlns="http://schemas.microsoft.com/sharepoint/soap/" /></soap:Body></soap:Envelope>';
httpInst.onreadystatechange = function ()
{
if ( httpInst.readyState == 4 ){
var xmlData = httpInst.responseXML;
var urlList = xmlData.getElementsByTagName( "Url" );
var listSize = urlList.length;
var tempStr = '';
for( idx = 0; idx < listSize; idx++ ){
tempStr = tempStr + '<option value="' + urlList[ idx ].childNodes[ 0 ].nodeValue + '">' + urlList[ idx ].childNodes[ 0 ].nodeValue + '</option>';
}
renderItem = '<select id="choseSite" onchange="getSiteGroup()"><option value="">▼サイトを選んでください</option>' + tempStr + '</select>';
}
}
httpInst.send( postBody );
document.getElementById( 'siteUrlList' ).innerHTML = renderItem;
}
function getSiteGroup() {
if( document.getElementById( 'choseSite' ).value == "" ){
document.getElementById( 'groupList' ).innerHTML = "";
exit();
}
var httpInst = getHttpReq();
var renderItem = "";
httpInst.open( "POST", document.getElementById( 'choseSite' ).value + "/_vti_bin/UserGroup.asmx", false );
httpInst.setRequestHeader( 'Content-Type','text/xml; charset=utf-8' );
httpInst.setRequestHeader( 'SOAPAction','http://schemas.microsoft.com/sharepoint/soap/directory/GetGroupCollectionFromWeb' );
var postBody = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetGroupCollectionFromWeb xmlns="http://schemas.microsoft.com/sharepoint/soap/directory/" /></soap:Body></soap:Envelope>';
httpInst.onreadystatechange = function()
{
if ( httpInst.readyState == 4 ){
xmlDoc = new ActiveXObject( "Microsoft.XMLDOM" );
xmlDoc.async = false;
xmlDoc.loadXML( httpInst.responseText );
rowsItem = xmlDoc.selectNodes( '/soap:Envelope/soap:Body/GetGroupCollectionFromWebResponse/GetGroupCollectionFromWebResult/GetGroupCollectionFromWeb/Groups/Group' );
var tempStr = "";
for( idx = 0; idx < rowsItem.length; idx++ ){
tempStr = tempStr + '<option value="' + rowsItem[ idx ].getAttribute( "Name" ) + '">' + rowsItem[ idx ].getAttribute( "Name" ) + '</option>';
}
renderItem = '<select id="choseGroup" onchange="getGroupUser()"><option value="">▼グループを選んでください</option>' + tempStr + '</select>';
}
}
httpInst.send( postBody );
document.getElementById( 'groupList' ).innerHTML = renderItem;
}
function getGroupUser() {
document.getElementById( 'groupUserList' ).innerHTML = "";
if( document.getElementById( 'choseGroup' ).value == "" ){
document.getElementById( 'groupUserList' ).innerHTML = "";
return;
}
var httpInst = getHttpReq();
var renderItem = document.getElementById( 'choseGroup' ).value;
var dataAry = new Array();
httpInst.open( "POST", document.getElementById( 'choseSite' ).value + "/_vti_bin/UserGroup.asmx", false );
httpInst.setRequestHeader( 'Content-Type','text/xml; charset=utf-8' );
httpInst.setRequestHeader( 'SOAPAction','http://schemas.microsoft.com/sharepoint/soap/directory/GetUserCollectionFromGroup' );
var postBody = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetUserCollectionFromGroup xmlns="http://schemas.microsoft.com/sharepoint/soap/directory/"><groupName>' + renderItem + '</groupName></GetUserCollectionFromGroup></soap:Body></soap:Envelope>';
httpInst.onreadystatechange = function()
{
if ( httpInst.readyState == 4 ){
xmlDoc = new ActiveXObject( "Microsoft.XMLDOM" );
xmlDoc.async = false;
xmlDoc.loadXML( httpInst.responseText );
rowsItem = xmlDoc.selectNodes( '/soap:Envelope/soap:Body/GetUserCollectionFromGroupResponse/GetUserCollectionFromGroupResult/GetUserCollectionFromGroup/Users/User' );
var copytext = renderItem + "\n名前\tメール\tアカウント\n";
for( idx = 0; idx < rowsItem.length; idx++ ){
var fieldDataList = new Array();
var nameValue = "";
var emailValue = "";
var loginNameValue = "";
fieldDataList.push( ( nameValue = rowsItem[ idx ].getAttribute( "Name" ) ) );
fieldDataList.push( ( emailValue = rowsItem[ idx ].getAttribute( "Email" ) ) );
fieldDataList.push( ( loginNameValue = rowsItem[ idx ].getAttribute( "LoginName" ) ) );
dataAry.push( fieldDataList );
copytext = copytext + nameValue + "\t"+ emailValue + "\t" + loginNameValue + "\n";
}
document.getElementById( 'cparea' ).value = copytext;
Ext.onReady( function(){
var reader = new Ext.data.ArrayReader( {}, [
{ name: "Name" },
{ name: "Email" },
{ name: "LoginName" }
]);
var store = new Ext.data.Store({
reader: reader,
data: dataAry
});
var grid = new Ext.grid.GridPanel({
store: store,
columns: [
{ header: "名前", width: 120, sortable: true, dataIndex: "Name" },
{ header: "メール", width: 240, sortable: true, dataIndex: "Email" },
{ header: "アカウント", width: 180, sortable: true, dataIndex: "LoginName" }
],
width: 600,
height: 400,
stripeRows: true,
title:renderItem,
viewConfig: { forceFit:true },
frame:true,
collapsible: true,
animCollapse: true
});
grid.render( 'groupUserList' );
grid.getSelectionModel().selectFirstRow();
});
}
}
httpInst.send( postBody );
}
function CopyText( arg ){
var obj = document.all && document.all( arg ) || document.getElementById && document.getElementById( arg );
if ( obj.value ) {
var doc = document.body.createTextRange();
doc.moveToElementText( obj );
doc.execCommand( "copy" );
alert( 'クリップボードにコピーしました。' );
} else {
alert( 'コピーするデータがありません。' );
}
}
</script>
<table><tr><td>サイトURLを選んでください</td><td>
<div id="siteUrlList"><img src="<yourSitePath>/ext/resources/images/default/shared/blue-loading.gif">loading...</div></td></tr>
<tr><td>サイトに属するグループを選んでください</td><td>
<div id="groupList"><select><option value="">▼グループを選んでください</option></select></div></td></tr>
<tr><td>出力ユーザをコピーします。</td><td><input type="button" name="Copy" value="コピー" onClick='CopyText("cparea")'></td></tr>
</table>
<div id="groupUserList"></div>
<textarea style="display:none" name="cparea"></textarea>



