Passed
Push — master ( 57e849...66e16b )
by Michael
02:16
created

NodeForm.js ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 1
c 0
b 0
f 0
cc 1
nop 1
rs 10
1
class NodeForm {
2
    /**
3
     * @param {string} formID id of the respective form element
4
     *
5
     * @return {void}
6
     */
7
    constructor(formID) {
8
        this.$form = jQuery(`#${formID}`);
9
        this.$form.find('[name="cancel-button"]').on('click', this.hide.bind(this));
10
    }
11
12
    /**
13
     * Show this form in a jQueryUI dialog
14
     *
15
     * @return {void}
16
     */
17
    show() {
18
        this.$form.dialog({
19
            title: this.name,
20
            width: 600,
21
        });
22
    }
23
24
    /**
25
     * Hide this form/dialog
26
     *
27
     * @return {void}
28
     */
29
    hide() {
30
        jQuery(this.$form).dialog('close');
31
    }
32
33
    /**
34
     * Bind a callback to an event on the form
35
     *
36
     * @param {string} eventName name of the event, can contain namespaces (e.g. click.myPlugin )
37
     * @param {function} callback the handler function to be attached to the event
38
     *
39
     * @return {void}
40
     */
41
    on(eventName, callback) {
42
        this.$form.on(eventName, callback);
43
    }
44
45
    /**
46
     * Remove a handler from an event
47
     *
48
     * @param {string} eventName name of the event, can contain namespaces (e.g. click.myPlugin )
49
     *
50
     * @return {void}
51
     */
52
    off(eventName) {
53
        this.$form.off(eventName);
54
    }
55
}
56
57
export default NodeForm;
58