04.05.2015 Views

Perforce 2013.1 Javascript API for Visual Tools

Perforce 2013.1 Javascript API for Visual Tools

Perforce 2013.1 Javascript API for Visual Tools

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Extending P4Admin and P4V<br />

Example: A Basic Alert<br />

The following example creates an alert that tells you whether a <strong>Per<strong>for</strong>ce</strong> counter is set to<br />

an even number, an odd number, or is not set.<br />

In the central settings file, the following code specifies the JavaScript file to be executed<br />

when it is called with the alerts key:<br />

function settings(key)<br />

{<br />

if (key == "p4admin_alerts")<br />

{<br />

return ["p4:///files/depot/jsapi/alert.js"];<br />

}<br />

}<br />

settings(P4JsApi.centralSettingsKey());<br />

The alert.js file displays alert text:<br />

var alertID;<br />

function testalert()<br />

{<br />

var counter = P4JsApi.p4(’counter alerttest’);<br />

if (typeof alertID == ’undefined’)<br />

{<br />

// add a new alert that will be updated below<br />

alertID = P4JsApi.addAlert("Checking counter...");<br />

}<br />

if (counter.data[0].value==’0’)<br />

{<br />

P4JsApi.updateAlert(alertID,"Counter is unset");<br />

}<br />

else<br />

{<br />

if ((counter.data[0].value % 2) == 0)<br />

{<br />

P4JsApi.updateAlert(alertID,"Counter is even");<br />

}<br />

else<br />

{<br />

P4JsApi.updateAlert(alertID,"Counter is odd");<br />

}<br />

}<br />

}<br />

testalert();<br />

16 <strong>Per<strong>for</strong>ce</strong> <strong>2013.1</strong> JavaScript <strong>API</strong> <strong>for</strong> <strong>Visual</strong> <strong>Tools</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!