Skip to content

Instantly share code, notes, and snippets.

@chucknado
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chucknado/b30d153102370de4db35 to your computer and use it in GitHub Desktop.
Save chucknado/b30d153102370de4db35 to your computer and use it in GitHub Desktop.
Source code for Zendesk Apps tutorial at https://support.zendesk.com/hc/en-us/articles/203903346
(function() {
return {
requests: {
taskPost: function(new_task_data) {
return {
url: 'https://app.asana.com/api/1.0/tasks',
headers: {"Authorization": "Basic " + btoa('{api_key}' + ":")},
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(new_task_data)
};
}
},
events: {
'taskPost.done': 'notifySuccess',
'taskPost.fail': 'notifyError',
'click #add-btn': 'validateForm',
'app.activated':'showForm'
},
notifySuccess: function() {
services.notify('Successfully created a new task.');
},
notifyError: function() {
services.notify('Problem with the POST request.', 'error');
},
sendFormData: function() {
var new_task = {
data: {
assignee: "me",
workspace: this.$('#workspace').val(),
name: this.$('#name').val(),
notes: this.$('#notes').val()
}
};
this.ajax('taskPost', new_task);
this.$('#task-form')[0].reset();
services.notify('Task sent!');
},
validateForm: function(event) {
event.preventDefault();
var name = this.$('#name')[0];
if (name.value.length == 0) {
services.notify('Name can\'t be blank.', 'error');
} else { // good to go
this.sendFormData();
}
},
showForm: function() {
this.switchTo('task_form');
}
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment