-
Notifications
You must be signed in to change notification settings - Fork 0
/
trello.js
61 lines (52 loc) · 1.21 KB
/
trello.js
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
var getCardCost = function (cardName) {
var re = /\((\d+)\)$/;
var cost = re.exec(cardName);
if (cost) {
return parseInt(cost[1]);
}
return 0;
};
var getCardPid = function (cardName) {
var re = /(P\d+)/;
var pid = re.exec(cardName);
if (pid) return pid[1];
};
var cleanCardName = function (cardName) {
cardName = cardName.replace(/\s*\(\d+\)$/, '');
cardName = cardName.replace(/(\s*-)?\s*P\d+\s*(-\s*)?/, '');
return cardName;
};
var getSprint = function (card, list) {
var re = /Sprint\s+(\d+)/;
var sprint = re.exec(list.name);
if (sprint) {
return sprint[1];
}
return list.name;
};
var trelloAuth = function() {
var self=this;
self.authenticated = ko.observable(false);
self.user = ko.observable();
self.onAuthorize = function() {
Trello.get("member/me", function (member) {
self.user(member.username);
});
self.authenticated(Trello.authorized());
};
self.login = function () {
Trello.authorize({
type: "popup",
success: self.onAuthorize
});
};
self.logout = function() {
self.authenticated(false);
Trello.deauthorize();
};
self.onLogin = function (event) {
self.authenticated.subscribe(function (authenticated) {
if (self.authenticated) event();
});
};
};