//////////////////////////////////////////////////////////////////////////// // Rev: 2010.1 (P4JsApi 1.0 Example) // // NOTE: This is an example only, and should be modified to work in // a production environment! No warranty is expressed or implied. // Scripts should be tested thoroughly on a test server before // using in a production environment. // //////////////////////////////////////////////////////////////////////////// // Copyright (c) 2010, 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. //////////////////////////////////////////////////////////////////////////// Ext.onReady(function() { try { Ext.QuickTips.init(); var tools = [{ id: 'close', handler: function(e, target, panel) { panel.ownerCt.remove(panel, true); } }]; var info; var infoGrid; var column1Items = []; var column2Items = []; var column3Items = []; // This will automatically add the current server: var myServer = P4JsApi.getPort(); info = P4JsApi.p4(' -p ' + myServer + ' info'); infoGrid = getInfoGrid(info); column1Items.push({ title: myServer, layout: 'fit', tools: tools, items: infoGrid }); // If you would like to have multiple servers displayed by // default, use the following format. Note that the Column // the info window can be set using the "columnNItems.push()" // function, where N is 1, 2 or 3: /* info = P4JsApi.p4(' -p perforce:1666 info'); infoGrid = getInfoGrid(info); column2Items.push({ title: 'perforce.mycompany.com:1999', layout:'fit', tools: tools, items: infoGrid }); */ // Creates a field to input the server address: var serverInputBox = new Ext.form.TextField({ id: "serverInputBox", emptyText: "Enter Perforce server address here", width: '400', margins: '10 0 5 5' }); // The button, 'submitButton', to add additional servers: var submitButton = new Ext.Button({ text: "Add", margins: '10 0 5 5' }); // Handle the click of the submitButton: submitButton.on('click', function() { // First, check to see what's already in the columns: var serverAddr = serverInputBox.getValue(); var column1ItemsSize = Ext.getCmp('viewport').findById('column1Items').items.length; var column2ItemsSize = Ext.getCmp('viewport').findById('column2Items').items.length; var column3ItemsSize = Ext.getCmp('viewport').findById('column3Items').items.length; // Get the server info using the .p4 method: info = P4JsApi.p4(' -p ' + serverAddr + ' info'); infoGrid = getInfoGrid(info); // Create a new info window: var newItem = { title: serverAddr, layout: 'fit', tools: tools, items: infoGrid }; // Using the contents of the columns obtained earlier, determine where the first // empty "cell" is and add the new info window: if (column1ItemsSize < column2ItemsSize) { Ext.getCmp('viewport').findById('column1Items').add(newItem); } else if (column1ItemsSize == column2ItemsSize) { if (column2ItemsSize <= column3ItemsSize) { Ext.getCmp('viewport').findById('column1Items').add(newItem); } else { Ext.getCmp('viewport').findById('column3Items').add(newItem); } } else { Ext.getCmp('viewport').findById('column2Items').add(newItem); } // Refresh the viewport to display the new window: Ext.getCmp('viewport').doLayout(); }); // Viewports control the layout and look of the window. Regions are defined // As directions, where north is up and south is down, and there's always a // "center": var viewport = new Ext.Viewport({ layout: 'border', id: 'viewport', items: [{ region: 'north', layout: 'hbox', id: 'northPanel', split: true, collapsible: true, margins: '5 5 5 5', cmargins: '10 5 5 5', height: 65, minSize: 40, maxSize: 140, items: [submitButton, serverInputBox] }, { xtype: 'portal', region: 'center', margins: '0 5 5 5', items: [{ id: 'column1Items', columnWidth: .33, style: 'padding: 10px 5px 10px 5px', items: column1Items }, { id: 'column2Items', columnWidth: .33, style: 'padding: 10px 5px 10px 5px', items: column2Items }, { id: 'column3Items', columnWidth: .33, style: 'padding: 10px 5px 10px 5px', items: column3Items }] }] }); // The getInfoGrid() function takes the output from the 'p4 info' // command and formats it for the info window in the applet: function getInfoGrid(serverInfo) { var transformedData = []; for (var key in serverInfo.data[0]) { transformedData.push([key, serverInfo.data[0][key]]); } var dataStore = new Ext.data.ArrayStore({ data: transformedData, //serverInfo.data, fields: ['propertyName', 'propertyValue' ] }); var infoGridPanel = new Ext.grid.GridPanel({ store: dataStore, autoExpandColumn: 'colVal', columns: [ { header: 'Property', width: 100, sortable: true, dataIndex: 'propertyName' }, { header: 'Value ', sortable: true, dataIndex: 'propertyValue', id: 'colVal', renderer: function(value, cell) { cell.attr = ' ext:qtip="' + value + '"'; return value; } } ], enableColumnMove: false, columnLines: true, stripeRows: true, height: 270, border: false, enableColLock: false, selModel: new Ext.grid.RowSelectionModel({ singleSelect: false }) }); return infoGridPanel; } } catch(e) { alert(e); } });
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#4 | 7663 | dscheirer | Rollback //public/perforce/p4jsapi to changelist 7643 | ||
#3 | 7660 | jhalbig |
As per meeting to resolve issue with sync calls made from within async calls hanging P4V (job039138) pulling example code from Public Depot until it can be re-worked and confirmed to function correctly with pending P4JsApi changes. |
||
#2 | 7643 | jhalbig |
Cleaned up any remaining discrepancies in the code. Removed all internal references and debugging code. Cleaned up formatting, added more commenting for submit dialog code. Ready for 2010.1 Beta. |
||
#1 | 7638 | jhalbig | Initial Addition of P4JsApi samples for 2010.1 Beta |