Completed
Pull Request — develop (#161)
by Wachter
22:54 queued 09:56
created

main.js ➔ ... ➔ .initialize   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 33
rs 8.8571
cc 1
nc 1
nop 0
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
                            selected: this.options.selected,
75
                            locale: this.options.locale,
76
                            selectedUrl: '/admin/api/nodes/{datasource}?tree=true&language={locale}&fields=title,order,published&webspace-nodes=all',
77
                            rootUrl: '/admin/api/nodes?language={locale}&fields=title,order,published&webspace-nodes=all',
78
                            resultKey: 'nodes',
79
                            instanceName: 'internal-link',
80
                            instanceNamePrefix: '',
81
                            showStatus: true,
82
                            selectCallback: function(id, path, title, item) {
83
                                this.item = item;
84
                            }.bind(this)
85
                        }
86
                    }
87
                ]
88
            );
89
        }
90
    };
91
});
92