diff options
Diffstat (limited to 'src/main.js')
-rw-r--r-- | src/main.js | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/src/main.js b/src/main.js new file mode 100644 index 0000000..e0fe8eb --- /dev/null +++ b/src/main.js @@ -0,0 +1,102 @@ +var ExtensionManager = require('./src/extension_manager.js'); +var extension_manager = new ExtensionManager(); +var profile = tizen.systeminfo.getCapability('http://tizen.org/feature/profile'); + +var activate = function(extension) { + console.log('activate : ' + extension.name); + extension.activate = true; + extension_manager.activate(extension.name); + if (extension.type.toUpperCase() === 'API') { + extension_manager.build(true); + extension_manager.generateJsFromAPIs(); + } + extension_manager.saveJsonDB(); +} +var deactivate = function(extension) { + console.log('deactivate : ' + extension.name); + extension.activate = false; + extension_manager.deactivate(extension.name); + if (extension.type.toUpperCase() === 'API') { + extension_manager.build(true); + extension_manager.generateJsFromAPIs(); + } + extension_manager.saveJsonDB(); +} + +var extDiv = document.getElementById('extDiv'); + +var uninstallExtension = function(extension) { + console.log('uninstall ' + extension.name); + extension_manager.uninstallExtension(extension); +} + +var refreshAllList = function() { + refreshExtensionsList(); +} + +var refreshExtensionsList = function() { + extDiv.innerText = ""; + + var table = document.createElement('table'); + if (profile === 'WEARABLE') + table.style.width = "70%"; + var tr = document.createElement('tr'); + var td_1 = document.createElement('td'); + var td_2 = document.createElement('td'); + tr.appendChild(td_1); + tr.appendChild(td_2); + td_1.textContent = 'EXTENSIONS lists'; + table.appendChild(tr); + + extension_manager.loadJsonDB(); + + for (i in extension_manager.extensions_list_) { + var extension = extension_manager.extensions_list_[i]; + tr = document.createElement('tr'); + td_1 = document.createElement('td'); + td_2 = document.createElement('td'); + tr.appendChild(td_1); + tr.appendChild(td_2); + var div = document.createElement('div'); + var contents = '<b>' + extension.name + '</b>'; + var button = document.createElement('a'); + if (extension.type.toUpperCase() === 'INSTALLER') { + button.setAttribute('class', 'button dark_grey'); + button.textContent = 'INSTALLED'; + } else { + button.setAttribute('class', 'button black'); + var btnContent = 'Off'; + if (!extension.activate) btnContent = 'On'; + button.textContent = btnContent; + button.extension = extension; + button.onclick = function(ev) { + if (this.textContent == 'On') { + activate(this.extension); + this.textContent = 'Off'; + } else { + deactivate(this.extension); + this.textContent = 'On'; + } + }; + } + // delete button + var button2 = document.createElement('a'); + button2.setAttribute('class', 'button dsgnmoo'); + button2.textContent = 'X'; + button2.extension = extension; + button2.onclick = function(ev) { + uninstallExtension(this.extension) + setTimeout(function(){ + refreshAllList(); + }, 1000); + } + + td_1.innerHTML = contents; + td_2.appendChild(button); + td_2.appendChild(button2); + table.appendChild(tr); + } + extDiv.appendChild(table); +} + +refreshExtensionsList(); |