« SharePointのライブラリをExtJSのgridウィジェットで表現してみました | メイン | 肉まんを皮からつくったよ。 »



SharePointとExtJSでSharePointグループを一覧で表現してみたよ

SharePointとExtJSでSharePointグループを一覧で表現してみたよをはてなブックマークに追加 SharePointとExtJSでSharePointグループを一覧で表現してみたよをdel.icio.usに追加  Yahoo!ブックマークに登録 SharePointとExtJSでSharePointグループを一覧で表現してみたよをGoogle Bookmarksに追加 SharePointとExtJSでSharePointグループを一覧で表現してみたよをtwitterにポスト
sharePointGroup.PNG 任意のサイトのSharePointグループを引っこ抜いてリスト表示して、クリップボードにも挿入しちゃうスクリプトを組みました。ExtJSで表現する上ではサイトヒエラルキーと、所属するグループをExt.treeで表現するのがいいかなと思いましたが、gridで表現しました。そのうちtreeでもポストしたいと思います。

表現はさておきSharePointのほうの解説をします。
  1. SiteData.asmxのGetSiteでサイトURLを引っ張ってきます。
  2. GetSiteで引っ張ってきたサイトヒエラルキーのUserGroup.asmxでGetGroupCollectionFromWebを使います。これでそのサイトのグループ一覧を得ます。
  3. 最後に2.で引っ張ったグループUserGroup.asmxのGetUserCollectionFromGroupに与えて所属するユーザを引っ張ります。
  4. 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>

★このコンテンツに目的の情報はありませんでしたか?


[ 最近のエントリーとその関連エントリー ]


[ スポンサードリンク ]

トラックバック

このエントリーのトラックバックURL:
http://mojalog.com/cgi/mt/mt-tb.cgi/254

コメントを投稿

ツリータイプ・カテゴリー

open all | close all

リファラから検索


サイト内検索