Test Setup Failed
Push — master ( cd1dab...2a689d )
by
unknown
03:51
created

variant-fields-view.js ➔ define   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 47
rs 9.0303
c 0
b 0
f 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A variant-fields-view.js ➔ ... ➔ BaseView.extend.initSortable 0 9 1
A variant-fields-view.js ➔ ... ➔ BaseView.extend.render 0 5 1
A variant-fields-view.js ➔ ... ➔ BaseView.extend.reindexValues 0 6 1
A variant-fields-view.js ➔ ... ➔ VariantFieldsView 0 3 1
1
define(function(require) {
2
    'use strict';
3
4
    var VariantFieldsView;
5
    var $ = require('jquery');
6
    var _ = require('underscore');
7
    var BaseView = require('oroui/js/app/views/base/view');
8
    require('jquery-ui');
9
10
    VariantFieldsView = BaseView.extend({
11
        events: {
12
            'click a.add-list-item': 'reindexValues'
13
        },
14
15
        /**
16
         * @inheritDoc
17
         */
18
        constructor: function VariantFieldsView() {
19
            VariantFieldsView.__super__.constructor.apply(this, arguments);
20
        },
21
22
        render: function() {
23
            this.initSortable();
24
            this.reindexValues();
25
            return this;
26
        },
27
28
        reindexValues: function() {
29
            var index = 1;
30
            this.$('[name$="[priority]"]').each(function() {
31
                $(this).val(index++);
32
            });
33
        },
34
35
        initSortable: function() {
36
            this.$('[data-name="field__variant-fields"]').sortable({
37
                handle: '[data-name="sortable-handle"]',
38
                tolerance: 'pointer',
39
                delay: 100,
40
                containment: 'parent',
41
                stop: _.bind(this.reindexValues, this)
42
            });
43
        }
44
    });
45
46
    return VariantFieldsView;
47
});
48