Completed
Pull Request — develop (#161)
by Wachter
14:20
created

main.js ➔ ... ➔ .defaults.options.selectCallback   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 2
rs 10
cc 1
nc 1
nop 1
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
            this.id = this.options.selected;
35
36
            var $container = $('<div/>');
37
            var $componentContainer = $('<div/>');
38
            this.$el.append($container);
39
40
            this.sandbox.start([
41
                {
42
                    name: 'overlay@husky',
43
                    options: {
44
                        el: $container,
45
                        openOnStart: true,
46
                        removeOnClose: true,
47
                        skin: 'medium',
48
                        instanceName: 'page-select',
49
                        slides: [
50
                            {
51
                                title: this.translations.overlayTitle,
52
                                data: $componentContainer,
53
                                cssClass: 'data-source-slide',
54
                                contentSpacing: false,
55
                                okCallback: function() {
56
                                    if (this.item) {
57
                                        this.options.selectCallback(this.item);
58
                                    }
59
                                }.bind(this),
60
                                cancelCallback: function() {
61
                                    this.options.cancelCallback();
62
                                }.bind(this)
63
                            }
64
                        ]
65
                    }
66
                }
67
            ]).then(this.startContentDatasource.bind(this, $componentContainer));
68
        },
69
70
        startContentDatasource: function($componentContainer) {
71
            this.sandbox.start(
72
                [
73
                    {
74
                        name: 'content-datasource@sulucontent',
75
                        options: {
76
                            el: $componentContainer,
77
                            singleMarkable: true,
78
                            selected: this.options.selected,
79
                            locale: this.options.locale,
80
                            selectedUrl: '/admin/api/nodes/{datasource}?tree=true&language={locale}&fields=title,order,published,url&webspace-nodes=all',
81
                            rootUrl: '/admin/api/nodes?language={locale}&fields=title,order,published&webspace-nodes=all',
82
                            resultKey: 'nodes',
83
                            instanceName: 'internal-link',
84
                            instanceNamePrefix: '',
85
                            showStatus: true,
86
                            selectCallback: function(id, path, title, item) {
87
                                if (this.id === id) {
88
                                    return this.setItem(null, null);
89
                                }
90
91
                                this.setItem(item, id);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
92
                            }.bind(this)
93
                        }
94
                    }
95
                ]
96
            );
97
        },
98
99
        setItem: function(item, id) {
100
            this.item = item;
101
            this.id = id;
102
103
            var action = 'activate';
104
            if (!item) {
105
                action = 'deactivate';
106
            }
107
108
            this.sandbox.emit('husky.overlay.page-select.okbutton.' + action);
109
        }
110
    };
111
});
112