This repository has been archived on 2023-09-06. You can view files and clone it, but cannot push or open issues or pull requests.
vn-softphone/view.js

41 lines
1.1 KiB
JavaScript

module.exports = {
/**
* Attach model and render view
* @param {String} view View name
* @param {Object} response Http response
*/
render: function(view, args, response) {
let instance = require(`./views/${view}/index.js`);
if (!instance.partials)
return response.render(`${view}/index`, instance);
instance.init(args, () => {
this.getPartials(instance, args, (instance) => {
response.render(`${view}/index`, instance);
});
});
},
/**
* Attach partial models
* @param {Object} instance Main instance
* @return {Object} Merged instance
*/
getPartials: function(instance, args, cb) {
let index = 0;
for(let partial in instance.partials) {
let subInstance = require(`./views/${partial}/index.js`);
subInstance.init(args, () => {
Object.assign(instance, subInstance);
index++;
if (index == Object.keys(instance.partials).length)
cb(instance);
});
}
}
}