aboutsummaryrefslogtreecommitdiff
path: root/src/web/js/actions/RightPanelActions.js
blob: 838690d18677093e7e71e0548b10c4fdc64d9d53 (plain)
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
var jquery = require('jquery');
var JarrDispatcher = require('../dispatcher/JarrDispatcher');
var ActionTypes = require('../constants/JarrConstants');
var MenuActions = require('../actions/MenuActions');

var RightPanelActions = {
    loadArticle: function(article_id, was_read_before) {
        jquery.getJSON('/getart/' + article_id,
            function(payload) {
                JarrDispatcher.dispatch({
                    type: ActionTypes.LOAD_ARTICLE,
                    article: payload,
                    was_read_before: was_read_before,
                });
            }
        );
    },
    _apiReq: function(meth, id, obj_type, data, success_callback) {
        var args = {type: meth, contentType: 'application/json',
                    url: "api/v2.0/" + obj_type + "/" + id}
        if(data) {args.data = JSON.stringify(data);}
        if(success_callback) {args.success = success_callback;}
        jquery.ajax(args);
    },
    putObj: function(id, obj_type, fields) {
        this._apiReq('PUT', id, obj_type, fields, MenuActions.reload);
    },
    delObj: function(id, obj_type, fields) {
        this._apiReq('DELETE', id, obj_type, null, MenuActions.reload);
    },
};

module.exports = RightPanelActions;
bgstack15