<!--// //******************************************************************************* // //Copyright (c) 2009, Perforce Software, Inc. All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //******************************************************************************* // //Author: Stephen Moon // //Date: September 3,2010 //Program: Dynamically generates an user list for the given environment. // It is meant to be an example. It does not check for all outlier // cases. //******************************************************************************* --> <html> <head> <title>List each user with its user spec</title> <script type="text/javascript"> function getUsers() { var users = P4JsApi.p4("users"); var headerArray; var table = document.getElementById('users'); headerArray = buildTableHeader(); var row = document.createElement("tr"); row.innerHTML = headerArray[8]; table.appendChild(row); for(var i=0; i < users.size; i++) { var row = document.createElement("tr"); row.innerHTML = buildTableRow(users.data[i].FullName,headerArray); table.appendChild(row); } } function buildTableHeader() { var headerArray = new Array(); var htmlStr; var header = P4JsApi.p4("spec -o user"); for(var j=0; j < 8; j++) { eval("header.data[0].Fields" + j).match(/^\d+\s(\w+)\s.*$/); if(j == 0) { htmlStr = "<td>" + P4JsApi.encodeForHTML(RegExp.$1) + "</td>"; } else { htmlStr = htmlStr + "<td>" + P4JsApi.encodeForHTML(RegExp.$1) + "</td>"; } headerArray[j] = RegExp.$1; } headerArray[8] = htmlStr; return headerArray; } function buildTableRow(eachUser,headerArray) { var htmlStr; var user = P4JsApi.p4("user -o " + eachUser); for(var j=0; j < 8; j++) { for(k in user.data[0]) { if(j == 0 && headerArray[j] === k) { htmlStr = "<td>" + P4JsApi.encodeForHTML(user.data[0][k]) + "</td>"; } else if(headerArray[j] === k) { htmlStr = htmlStr + "<td>" + P4JsApi.encodeForHTML(user.data[0][k]) + "</td>"; } } } return htmlStr; } </script> <meta http-equiv="refresh" content="30"> </head> <body onLoad="getUsers();"> <table id=users border=1 width="50%"> </table> </body> </html>
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 7765 | Stephen Moon |
P4JsApi script which dynamically creates a header form p4 spec -o user output and list userspec as table data. Needs more refining |