1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 function showMessage(msg) { 6 var area = $('message-area'); 7 var entry = document.createElement('div'); 8 entry.textContent = msg; 9 area.appendChild(entry); 10 window.setTimeout(function() { 11 area.removeChild(entry); 12 }, 3000); 13 } 14 15 function getShowMessageCallback(message) { 16 return function() { 17 var error = chrome.runtime.lastError; 18 if (error) { 19 showMessage(message + ': ' + error.message); 20 } else { 21 showMessage(message + ': Success!'); 22 } 23 }; 24 } 25 26 function onPageLoad() { 27 var networkConfig = $('network-config'); 28 network.config.NetworkConfig.decorate(networkConfig); 29 30 $('save').onclick = function() { 31 chrome.networkingPrivate.setProperties( 32 networkConfig.networkId, 33 networkConfig.userSettings, 34 getShowMessageCallback('Set properties of ' + networkConfig.networkId)); 35 }; 36 37 $('connect').onclick = function() { 38 chrome.networkingPrivate.startConnect( 39 networkConfig.networkId, 40 getShowMessageCallback( 41 'Requested connect to ' + networkConfig.networkId)); 42 }; 43 44 $('disconnect').onclick = function() { 45 chrome.networkingPrivate.startDisconnect( 46 networkConfig.networkId, 47 getShowMessageCallback( 48 'Requested disconnect from ' + networkConfig.networkId)); 49 }; 50 } 51 52 document.addEventListener('DOMContentLoaded', onPageLoad); 53