Resources/public/js/services/comments/manager.js   A
last analyzed

Complexity

Total Complexity 11
Complexity/F 1.22

Size

Lines of Code 43
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 11
dl 0
loc 43
rs 10
c 0
b 0
f 0
cc 0
nc 2
mnd 1
bc 10
fnc 9
bpm 1.1111
cpm 1.2222
noi 0
1
/*
2
 * This file is part of Sulu.
3
 *
4
 * (c) MASSIVE ART WebServices GmbH
5
 *
6
 * This source file is subject to the MIT license that is bundled
7
 * with this source code in the file LICENSE.
8
 */
9
10
define(['underscore', 'jquery', 'services/husky/util'], function(_, $, Util) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
11
12
    'use strict';
13
14
    var instance = null,
15
16
        getInstance = function() {
17
            if (instance === null) {
18
                instance = new CommentManager();
19
            }
20
            return instance;
21
        },
22
23
        url = _.template('/admin/api/comments<% if (typeof id !== "undefined") { %>/<%= id %><% } %>');
24
25
    /** @constructor **/
26
    function CommentManager() {
27
    }
28
29
    CommentManager.prototype = {
30
        load: function(id) {
31
            return Util.load(url({id: id}));
32
        },
33
        save: function(data) {
34
            return Util.save(url({id: data.id}), !!data.id ? 'PUT' : 'POST', data);
35
        },
36
        publish: function(id) {
37
            return Util.save(url({id: id}) + '?action=publish', 'POST');
38
        },
39
        unpublish: function(id) {
40
            return Util.save(url({id: id}) + '?action=unpublish', 'POST');
41
        },
42
        delete: function(id) {
43
            return Util.save(url({id: id}), 'DELETE');
44
        },
45
        deleteMultiple: function(ids) {
46
            return Util.save(url() + '?ids=' + ids.join(','), 'DELETE');
47
        },
48
        url: url
49
    };
50
51
    return getInstance();
52
});
53