Completed
Push — master ( fb754a...2a3626 )
by Antonio
03:49
created

clone.js ➔ ... ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
'use strict';
2
3
/**
4
 * Clone product extension
5
 */
6
define([
7
    'jquery',
8
    'pim/form',
9
    'underscore',
10
    'oro/translator',
11
    'backbone',
12
    'pim/form-builder',
13
    'flagbit/template/product/clone-button',
14
    ],
15
    function (
16
        $,
17
        BaseForm,
18
        _,
19
        __,
20
        Backbone,
21
        FormBuilder,
22
        template
23
    ) {
24
        return BaseForm.extend({
25
            template: _.template(template),
26
27
            initialize(config) {
28
                this.config = config.config;
29
                BaseForm.prototype.initialize.apply(this, arguments);
30
            },
31
32
            openModal() {
33
                return FormBuilder.build(this.config.formName).then(modal => {
34
35
                    const rootModel = this.getRoot().model;
36
                    var productType, codeToClone;
37
                    if (rootModel.has('identifier')) {
38
                        productType = 'product';
39
                        codeToClone = rootModel.get('identifier')
40
                    } else {
41
                        productType = 'model';
42
                        codeToClone = rootModel.get('code')
43
                    }
44
45
                    const initialModalState = {
46
                        parent: rootModel.get('parent'),
47
                        values: {},
48
                        code_to_clone: codeToClone,
49
                        type: productType
50
                    };
51
                    modal.setData(initialModalState);
52
                    modal.open();
53
                });
54
            },
55
56
            /**
57
             * {@inheritdoc}
58
             */
59
            getIdentifier: function () {
60
                return this.getFormData().meta.id;
61
            },
62
63
            /**
64
             * {@inheritdoc}
65
             */
66
            render: function () {
67
                if (!this.getFormData().meta) {
68
                    return;
0 ignored issues
show
Comprehensibility Best Practice introduced by
Are you sure this return statement is not missing an argument? If this is intended, consider adding an explicit undefined like return undefined;.
Loading history...
69
                }
70
71
                this.$el.html(this.template());
72
73
                $('.clone-product-button').on('click', () => {
74
                    this.openModal();
75
                });
76
                return this;
77
            }
78
        });
79
});
80