- "action": "function install(url, autoStart, async) { \n var importedSystem = null,\n system = {},\n systemId = '',\n callbackLoad = null,\n xhr = null,\n result = '',\n channel = $component.get('channel');\n \n if (typeof url === 'object') {\n importedSystem = url;\n } else {\n if (url.indexOf('{') === 0) {\n importedSystem = JSON.parse(url);\n }\n }\n \n if (importedSystem) {\n systemId = this.require('db').system(importedSystem); \n if (systemId) {\n system = this.require(systemId);\n \n system.status('installed'); \n channel.$systemInstalled(systemId);\n system.status('resolved');\n channel.$systemResolved(systemId);\n \n if (autoStart) {\n system.status('starting');\n system.main(); // deprecated\n system.start();\n channel.$systemStarted(systemId);\n system.status('active');\n }\n \n result = systemId;\n }\n } else { \n if (typeof global !== 'undefined') {\n if (url.indexOf('.json') !== -1) {\n system = global.require(global.process.env.PWD + '/' + url);\n } else {\n system = global.require(url);\n }\n systemId = this.require('db').system(system);\n system = this.require(systemId);\n \n system.status('installed'); \n channel.$systemInstalled(systemId);\n if (!system.master()) {\n system.status('resolved');\n channel.$systemResolved(systemId);\n }\n if (autoStart) {\n if (system.master()) {\n system.status('resolved');\n channel.$systemResolved(systemId);\n }\n system.status('starting');\n if (this.require(systemId).main) {\n this.require(systemId).main();\n }\n if (this.require(systemId).start) {\n this.require(systemId).start();\n }\n channel.$systemStarted(systemId);\n system.status('active');\n }\n \n result = systemId;\n } else {\n xhr = new XMLHttpRequest();\n callbackLoad = function callbackLoad(system) {\n var sysId = $db.system(system),\n sys = $component.get(sysId),\n channel = $component.get('channel');\n \n sys.status('installed'); \n channel.$systemInstalled(sysId);\n if (!sys.master()) {\n sys.status('resolved');\n channel.$systemResolved(sysId);\n }\n if (sys && autoStart) {\n if (sys.master()) {\n sys.status('resolved');\n channel.$systemResolved(sysId);\n }\n sys.status('starting');\n if (sys.main) {\n sys.main(); // deprecated\n }\n if (sys.start) {\n sys.start();\n }\n channel.$systemStarted(sysId);\n sys.status('active');\n } \n \n result = sysId;\n };\n \n if (async) {\n xhr.open('GET', url, true);\n xhr.onreadystatechange = function () {\n if (xhr.readyState === 4) {\n if (xhr.status === 200) {\n callbackLoad(JSON.parse(xhr.response));\n }\n }\n };\n xhr.send(null);\n } else {\n xhr.open('GET', url, false);\n xhr.send(null);\n if (xhr.status === 200) {\n callbackLoad(JSON.parse(xhr.response));\n }\n }\n }\n }\n return result;\n}",
0 commit comments