Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to specify labels for cards #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 55 additions & 3 deletions trello_bookmarklet.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}

/* This is run after we've connected to Trello and selected a list */
var run = function(Trello, idList) {
var run = function(Trello, idList, labels) {
var name;
// Default description is the URL of the page we're looking at
var desc = location.href;
Expand Down Expand Up @@ -90,7 +90,8 @@
if(name) {
Trello.post("lists/" + idList + "/cards", {
name: name,
desc: desc
desc: desc,
labels: labels
}, function(card){
// Display a little notification in the upper-left corner with a link to the card
// that was just created
Expand Down Expand Up @@ -215,6 +216,8 @@
// The ids of values we keep in localStorage
var appKeyName = "trelloAppKey";
var idListName = "trelloIdList";
var idBoardName = "trelloIdBoard";
var labelsName = "trelloLabels";

waterfall([
// Load jQuery
Expand Down Expand Up @@ -295,7 +298,56 @@
function(idList, next) {
if(idList) {
store(idListName, idList);
next(Trello, idList);

var idBoard = store(idBoardName) || window[idBoardName];
if(idBoard && idBoard.length == 24) {
next(idList, idBoard);
} else {
Trello.get('lists/' + idList + '/idBoard', {}, function (data) {
idBoard = data._value;
store(idBoardName, idBoard);

next(idList, idBoard);
});
}
}
},
// Select any labels to apply to cards
function(idList, idBoard, next) {
var labels = store(labelsName) || window[labelsName];
if(labels) {
next(idList, labels);
} else {
Trello.get("boards/" + idBoard + "/labels", { fields: "name,color" }, function(labels){
$prompt = overlayPrompt('What labels should be applied to cards from this page?<hr><div class="labels" style="height:300px;overflow-y:scroll"></div>', false, function(){
labelList = $prompt.find("input:checked");

var labels = [];
labelList.each(function() {
labels[labels.length] = $(this).val();
});

labels = labels.join(',');

next(idList, labels);
});

$.each(labels, function(ix, label) {
var $div = $("<div>").appendTo($prompt.find('.labels'));
idLabel = label.id;
$("<input type='checkbox'>").attr('id', idLabel).attr("value", label.color).attr("name", "idLabel").appendTo($div);

color = label.color.charAt(0).toUpperCase() + label.color.slice(1);
$("<label>").text(color + " - " + label.name).attr("for", idLabel).appendTo($div);
});
});
}
},
// Store the labels for later
function(idList, labels, next) {
if(labels) {
store(labelsName, labels);
next(Trello, idList, labels);
}
},
// Run the user portion
Expand Down