All files / src/methods Method.js

94.12% Statements 16/17
71.43% Branches 5/7
75% Functions 6/8
94.12% Lines 16/17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59                        30x 30x 30x 30x               30x 30x 30x           30x 30x   30x           18x         30x 30x 30x         71x 39x          
import UserView from '../userView';
import config from '../config';
import { cleanError, manageError } from '../errorManager';
 
export default class Method {
    templateInjected = false;
 
    UserViewInstance = new UserView();
 
    smartsectionObj = {};
 
    handle = (options, callbackObject) => {
        this.options = options;
        this.regexObject = options.regexObject || config.get('regexObject');
        this.callbackObject = callbackObject;
        this.init(options);
    };
 
    init = () => {
        throw new Error('class needs to implement the "init" method');
    };
 
    initUserView = () => {
        this.UserViewInstance.init(this.smartsectionObj).then((data) => {
            this.loadForm(data);
            this.callback('onTemplateLoaded', {
                data,
                templateName: this.smartsectionObj.subsection,
                injected: this.templateInjected
            });
 
            cleanError();
            this.attachEvents(data);
 
            this.callback('onEventsAttached', {
                data,
                templateName: this.smartsectionObj.subsection,
                injected: this.templateInjected
            });
        }).catch((error) => {
            manageError(error);
        });
    };
 
    loadForm = (data) => {
        Eif (this.smartsectionObj.loadForm) {
            this.UserViewInstance.populate(this.options.element, data.content);
            this.templateInjected = true;
        }
    };
 
    callback = (name, payload = {}) => {
        if (typeof this.callbackObject[name] !== 'undefined') {
            this.callbackObject[name](payload);
        }
    };
 
    attachEvents = () => {};
}