Created
September 29, 2017 13:24
-
-
Save Basster/4ec83d7118a280473b327576c5727019 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import $ from 'jquery'; | |
import _ from 'lodash'; | |
import Router from '../module/router'; | |
export class Api { | |
getComments(typeface, callback) { | |
$.getJSON(Router.generate('typeface_comments', {'slug': typeface}), callback); | |
} | |
deleteComment(typeface, id, callback) { | |
const url = Router.generate('typeface_comment_delete', {'slug': typeface, 'id': id}); | |
$.ajax({ | |
type: 'DELETE', | |
url: url, | |
dataType: 'json', | |
success: callback, | |
}, | |
); | |
} | |
addComment(typeface, comment, callback) { | |
const url = Router.generate('typeface_comment_add', {'slug': typeface}); | |
$.post(url, {comment: comment}, callback, 'json'); | |
} | |
getActivities(callback) { | |
$.getJSON(Router.generate('activities'), (response) => { | |
_.each(response.activities, (activity) => { | |
activity.profileUrl = Router.generate('user_profile', {'slug': activity.username}); | |
}); | |
callback(response); | |
}); | |
} | |
updateTypefaceObjectOrder(typeface, newOrder, callback, objects) { | |
const url = Router.generate('typeface_update_objects_order', {'slug': typeface, 'objects': objects}); | |
$.post(url, {order: newOrder}, callback, 'json'); | |
} | |
updateFontOrder(typeface, fontOrder, callback) { | |
this.updateTypefaceObjectOrder(typeface, fontOrder, callback, 'fonts'); | |
} | |
updateIllustrationOrder(typeface, illuOrder, callback) { | |
this.updateTypefaceObjectOrder(typeface, illuOrder, callback, 'illustrations'); | |
} | |
postReply(boardId, threadId, reply, callback) { | |
const url = Router.generate('post_reply', {'board_slug': boardId, 'id': threadId}); | |
$.post(url, {reply: reply}, callback, 'json'); | |
} | |
} | |
export let api = new Api(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment