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 = () => {};
} |