Completed
Pull Request — develop (#161)
by Wachter
15:19
created

main.js ➔ ... ➔ .startContentDatasource   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
cc 1
c 2
b 1
f 1
nc 1
nop 1
dl 0
loc 24
rs 8.9713
1
/*
2
 * This file is part of the Sulu CMS.
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
/**
11
 * Overlay to select parent page.
12
 *
13
 * @class page-tree-route/page-select
14
 * @constructor
15
 */
16
define(function() {
17
    return {
18
19
        defaults: {
20
            options: {
21
                selected: null,
22
                locale: null,
23
                selectCallback: function(item) {
0 ignored issues
show
Unused Code introduced by
The parameter item is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
24
                },
25
                cancelCallback: function() {
26
                }
27
            },
28
            translations: {
29
                overlayTitle: 'public.choose'
30
            }
31
        },
32
33
        initialize: function() {
34
            var $container = $('<div/>');
35
            var $componentContainer = $('<div/>');
36
            this.$el.append($container);
37
38
            this.sandbox.start([
39
                {
40
                    name: 'overlay@husky',
41
                    options: {
42
                        el: $container,
43
                        openOnStart: true,
44
                        removeOnClose: true,
45
                        skin: 'medium',
46
                        slides: [
47
                            {
48
                                title: this.translations.overlayTitle,
49
                                data: $componentContainer,
50
                                cssClass: 'data-source-slide',
51
                                contentSpacing: false,
52
                                okCallback: function() {
53
                                    if (this.item) {
54
                                        this.options.selectCallback(this.item);
55
                                    }
56
                                }.bind(this),
57
                                cancelCallback: function() {
58
                                    this.options.cancelCallback();
59
                                }.bind(this)
60
                            }
61
                        ]
62
                    }
63
                }
64
            ]).then(this.startContentDatasource.bind(this, $componentContainer));
65
        },
66
67
        startContentDatasource: function($componentContainer) {
68
            this.sandbox.start(
69
                [
70
                    {
71
                        name: 'content-datasource@sulucontent',
72
                        options: {
73
                            el: $componentContainer,
74
                            singleMarkable: true,
75
                            selected: this.options.selected,
76
                            locale: this.options.locale,
77
                            selectedUrl: '/admin/api/nodes/{datasource}?tree=true&language={locale}&fields=title,order,published,url&webspace-nodes=all',
78
                            rootUrl: '/admin/api/nodes?language={locale}&fields=title,order,published&webspace-nodes=all',
79
                            resultKey: 'nodes',
80
                            instanceName: 'internal-link',
81
                            instanceNamePrefix: '',
82
                            showStatus: true,
83
                            selectCallback: function(id, path, title, item) {
84
                                this.item = item;
85
                            }.bind(this)
86
                        }
87
                    }
88
                ]
89
            );
90
        }
91
    };
92
});
93