-
Notifications
You must be signed in to change notification settings - Fork 1
/
planbox_api_sandbox.html
492 lines (433 loc) · 13.5 KB
/
planbox_api_sandbox.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8;" http-equiv="Content-Type">
<title>Planbox API Sandbox</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js" type="text/javascript"></script>
</head>
<style>
* {
margin: 0;
padding: 0;}
html {
overflow-y:scroll;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
min-height:100%;}
body {
line-height: 1;}
ul {
list-style: none;}
input, textarea {
font-family: 'Verdana', Tahoma, Arial, 'Sans serif';}
.fr {float:right;}
.fl {float:left;}
.clear {clear:both;}
.error {color:#990000;}
.ok {color:#009900;}
#header {
background-color:#F0F0F0;}
#header a.logo {
display:block;}
#header div.sandbox {
font-size:30px;
font-weight:bold;
color:#999;
padding:10px 0 0 20px;}
#header a.help {
margin:20px;}
#header div.login_logout {
padding:15px;}
#message {
min-height:20px;
text-align:center;
padding:5px 0;}
#buttons {
padding:15px;}
#buttons button,
#buttons label {
margin-right:5px;}
#content {
border-top:1px solid #DDD;
min-height:400px;}
#content table {
width:100%;
font-size:12px;
font-weight:normal;
text-align:left;
border-bottom:1px solid #F0F0F0;
background-color:white;}
#content table th {
background-color:#F0F0F0;
font-weight:bold;
padding:5px;}
#content table td {
border-bottom:1px solid #F0F0F0;
padding:5px;}
#footer {
border-top:1px solid #F0F0F0;
padding:15px;}
#footer span.copyright {
color:#999;}
</style>
<script type="text/javascript">
// General properties and helper functions
window.Planbox = {
// Url to Planbox. You can use https if you like.
base_url: 'http://www.planbox.com/',
// This object will contain the logged user
logged_resource: {},
// Call the Planbox API
api: function(fname, args, onsuccess, onerror) {
var url = Planbox.base_url+'api/'+fname+'?callback=?';
args = args || {};
return $.getJSON(url, args, function(data) {
if (data && data.code == 'ok') {
if (onsuccess) onsuccess(data.content);
} else if (data && data.code == 'error') {
if (onerror) onerror(data.content);
} else {
if (onerror) onerror('Cannot reach Planbox');
}
}, 'json');
},
// Helper function to create a table from an array
// Returns the newly created TABLE element
// Also sets ZeroClipboard's data
table: function(header, data) {
var table = $('<table cellspacing="0" cellpadding="2" border="0">');
var tr = $('<tr>').appendTo(table);
for (var c=0; c<header.length; c++)
$('<th>'+header[c]+'</th>').appendTo(tr);
for (var r=0; r<data.length; r++) {
tr = $('<tr>').appendTo(table);
for (var c=0; c<data[r].length; c++)
$('<td>'+data[r][c]+'</td>').appendTo(tr);
}
return table;
},
// Constructs a URL to reach the Work page in Planbox
// and show the appropriate object
url: function(product_id, project_id, story_id) {
var url = 'http';
if (Planbox.logged_resource.https) url += 's';
url += '://www.planbox.com/nik';
if (product_id) {
url += '#{product_id:'+product_id;
if (project_id)
url += ',project_id:'+project_id;
if (story_id)
url += ',story_id:'+story_id
url += '}';
}
return url;
}
};
// Script to login/logout and load the logged resource object
$(document).ready(function() {
var message = $('#message');
var buttons = $('#buttons>button');
var content = $('#content');
// Login & logout
var login = $('#header div.login_logout .login');
var logout = $('#header div.login_logout .logout');
var login_button = $('#header div.login_logout button.login');
var login_email = $('#header div.login_logout input[name=email]');
var login_password = $('#header div.login_logout input[name=password]');
var logged_welcome = $('#header div.login_logout label.welcome');
var logout_button = $('#header div.login_logout a.logout');
var clear = $('#buttons button.clear');
// Helper function to login
var _login = function(e) {
login_button.attr('disabled', 'disabled');
message.removeClass('error').addClass('ok').text('Please wait...');
Planbox.api('login', {email:login_email.val(), password:login_password.val()},
function(result) {
message.addClass('ok').text(result);
Planbox.api('get_logged_resource', {},
function(obj) {
Planbox.logged_resource = obj;
logged_welcome.text("Welcome "+Planbox.logged_resource.name);
logout.show();
login.hide();
message.removeClass('ok error').empty();
login_button.removeAttr('disabled');
},
function(error) {
message.removeClass('ok').addClass('error').text(error);
login_button.removeAttr('disabled');
}
);
},
function(error) {
login_button.removeAttr('disabled');
message.removeClass('ok').addClass('error').text(error);
}
);
return false;
};
// Helper function to logout
var _logout = function(e) {
message.removeClass('error').addClass('ok').text('Please wait...');
Planbox.api('logout', {},
function() {
logout.hide();
login.show();
message.removeClass('ok error').empty();
Planbox.logged_resource = {};
clear.click();
},
function(error) {
message.removeClass('ok').addClass('error').text(error);
}
);
return false;
};
// Bind our elements to trigger correct functions
login_button.bind('click', _login);
login_password.bind('keydown', function(e) {
if (e.keyCode == 13) return _login(arguments);
return true;
});
logout_button.bind('click', _logout);
// Start by loading the logged user
logout.hide();
message.removeClass('error').addClass('ok').text('Please wait...');
Planbox.api('get_logged_resource', {},
function(obj) {
Planbox.logged_resource = obj;
logged_welcome.text("Welcome "+Planbox.logged_resource.name);
logout.show();
login.hide();
message.removeClass('ok error').empty();
},
function(error) {
message.removeClass('ok error').empty();
}
);
// Clear table
clear.click(function(e) {
content.empty();
var table = Planbox.table(['NO DATA LOADED'], ['']);
table.appendTo(content);
table.find('th').css({
textAlign:'center',
fontStyle:'italic',
fontWeight:'normal'
});
});
// Start everything by showing an empty table
clear.click();
});
</script>
<script type="text/javascript">
// Your custom scripts go here
$(document).ready(function() {
var buttons = $('#buttons>button');
var message = $('#message');
var content = $('#content');
// My products
var my_products = $('#buttons button.my_products');
my_products.click(function(e) {
content.empty();
message.removeClass('error').addClass('ok').text('Please wait...');
buttons.attr('disabled', 'disabled');
// Load products
Planbox.api('get_products', {},
function(obj) {
var products = obj;
var product_ids = [];
var product_id2name = {};
for (var i=0; i<products.length; i++) {
var product = products[i];
product_id2name[product.id] = product.name;
product_ids.push(product.id);
}
buttons.removeAttr('disabled');
message
.removeClass('error')
.addClass('ok')
.text(products.length+' products loaded');
// Build arrays
var header = ['id', 'name', 'permission'];
var data = [];
for (var i=0; i<products.length; i++) {
var product = products[i];
var row = [];
row.push('<a href="'+Planbox.url(product.id)+'" target="_blank">'+product.id+'</a>');
row.push(product.name);
row.push(product.permission);
data.push(row);
}
// Create table and show it
var table = Planbox.table(header, data);
table.appendTo(content);
},
function(error) {
buttons.removeAttr('disabled');
message.removeClass('ok').addClass('error').text(error);
}
);
return false;
});
// My projects across all products
var my_projects = $('#buttons button.my_projects');
my_projects.click(function(e) {
content.empty();
message.removeClass('error').addClass('ok').text('Please wait...');
buttons.attr('disabled', 'disabled');
// Load products
Planbox.api('get_products', {},
function(obj) {
var products = obj;
var product_ids = [];
var product_id2name = {};
for (var i=0; i<products.length; i++) {
var product = products[i];
product_id2name[product.id] = product.name;
product_ids.push(product.id);
}
message
.removeClass('error')
.addClass('ok')
.text(products.length+' products loaded. Now loading projects...');
// Load stories for these products where the logged
// user is involved
Planbox.api('get_projects', {
product_id: product_ids
},
function(obj) {
var projects = obj;
buttons.removeAttr('disabled');
message
.removeClass('error')
.addClass('ok')
.text(projects.length+' projects loaded across '+products.length+' products');
// Build arrays
var header = ['id', 'product', 'name', 'alias'];
var data = [];
for (var i=0; i<projects.length; i++) {
var project = projects[i];
var row = [];
row.push('<a href="'+Planbox.url(project.product_id, project.id)+'" target="_blank">'+project.id+'</a>');
row.push(product_id2name[project.product_id]);
row.push(project.name);
row.push(project.alias);
data.push(row);
}
// Create table and show it
var table = Planbox.table(header, data);
table.appendTo(content);
},
function(error) {
buttons.removeAttr('disabled');
message.removeClass('ok').addClass('error').text(error);
}
);
},
function(error) {
buttons.removeAttr('disabled');
message.removeClass('ok').addClass('error').text(error);
}
);
return false;
});
// My stories across all products
var my_stories = $('#buttons button.my_stories');
my_stories.click(function(e) {
content.empty();
message.removeClass('error').addClass('ok').text('Please wait...');
buttons.attr('disabled', 'disabled');
// Load products
Planbox.api('get_products', {},
function(obj) {
var products = obj;
var product_ids = [];
var product_id2name = {};
for (var i=0; i<products.length; i++) {
var product = products[i];
product_id2name[product.id] = product.name;
product_ids.push(product.id);
}
message
.removeClass('error')
.addClass('ok')
.text(products.length+' products loaded. Now loading stories...');
// Load stories for these products where the logged
// user is involved
Planbox.api('get_stories', {
product_id: product_ids,
timeframe: 'current',
resource_id: Planbox.logged_resource.id
},
function(obj) {
var stories = obj;
buttons.removeAttr('disabled');
message
.removeClass('error')
.addClass('ok')
.text(stories.length+' stories loaded across '+products.length+' products');
// Build arrays
var header = ['id', 'product', 'name', 'status'];
var data = [];
for (var i=0; i<stories.length; i++) {
var story = stories[i];
var row = [];
row.push('<a href="'+Planbox.url(story.product_id, null, story.id)+'" target="_blank">'+story.id+'</a>');
row.push(product_id2name[story.product_id]);
row.push(story.name);
row.push(story.status);
data.push(row);
}
// Create table and show it
var table = Planbox.table(header, data);
table.appendTo(content);
},
function(error) {
buttons.removeAttr('disabled');
message.removeClass('ok').addClass('error').text(error);
}
);
},
function(error) {
buttons.removeAttr('disabled');
message.removeClass('ok').addClass('error').text(error);
}
);
return false;
});
});
</script>
<body>
<div id="header">
<a class="fl logo" href="http://www.planbox.com" target="_blank">
<img src="http://www.planbox.com/img/logo_small.png" alt="Planbox" />
</a>
<div class="fl sandbox">API Sanbox</div>
<a class="fl help" href="http://www.planbox.com/api" target="_blank">Help</a>
<div class="login_logout fr">
<label class="login">Login</label>
<input class="login" type="text" id="email" name="email" />
<input class="login" type="password" id="password" name="password" />
<button class="login">Submit</button>
<label class="logout welcome">Welcome </label>
<a href="#" class="logout">Logout</a>
</div>
<div class="clear"></div>
</div>
<div id="message"></div>
<div id="buttons">
<button class="my_products" title="Load my products">My Products</button>
<button class="my_projects" title="Load my projects across all products">My Projects</button>
<button class="my_stories" title="Load my stories across all products">My Stories</button>
<label> | </label>
<button class="clear" title="Clear table">Clear</button>
<div class="clear"></div>
</div>
<div id="content"></div>
<div id="footer">
<a class="fl" href="http://www.planbox.com/api">http://www.planbox.com/api</a>
<span class="fr copyright">© Planbox 2009-2012</span>
<div class="clear"</div>
</div>
<body>
</html>