Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Bug 1156502 - update l10n string and refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
EragonJ authored and rvandermeulen committed Apr 24, 2015
1 parent f06ea5c commit 89f0b40
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 43 deletions.
75 changes: 33 additions & 42 deletions apps/settings/js/panels/wifi_manage_certificates/panel.js
Expand Up @@ -20,53 +20,47 @@ define(function(require) {
panel.querySelector('.importCertificate');
elements.deleteCertificateBtn =
panel.querySelector('.deleteCertificate');

elements.deleteCertificateBtn.onclick =
this._deleteCertificate.bind(this);
},
onBeforeShow: function(panel) {
this._scan();
},
_scan: function() {
var self = this;
var list = elements.certificateList;
this._cleanup();

var certRequest = wifiManager.getImportedCerts();
certRequest.onsuccess = function() {
var certList = certRequest.result;
wifiManager.getImportedCerts().then((result) => {
var certList = result;
// save the imported server certificates
var certificateList = certList.ServerCert;

// display certificate list
if (certificateList.length) {
for (var i = 0; i < certificateList.length; i++) {
list.appendChild(
self._newCertificateItem(certificateList[i]));
this._newCertificateItem(certificateList[i]));
}

// add event listener for update toggle delete/import cert. buttons
var toggleBtnsWhenClicked = function() {
var option = self._isItemSelected();
self._toggleDeleteCertificateBtn(option);
self._toggleImportCertificateBtn(!option);
var toggleBtnsWhenClicked = () => {
var option = this._isItemSelected();
this._toggleDeleteCertificateBtn(option);
this._toggleImportCertificateBtn(!option);
};

var inputItems = list.querySelectorAll('input');
for (var j = 0; j < inputItems.length; j++) {
inputItems[j].onchange = toggleBtnsWhenClicked;
}
} else {
// display "no certificate" message
// while no any imported certificate
// show "no certificates" message
list.appendChild(
WifiUtils.newExplanationItem('noCertificate'));
WifiUtils.newExplanationItem('noImportedCertificates'));
}
};

certRequest.onerror = function() {
}, () => {
console.warn('getImportedCerts failed');
};
});

this._toggleDeleteCertificateBtn(false);
this._toggleImportCertificateBtn(true);
Expand All @@ -79,43 +73,40 @@ define(function(require) {
}
},
_deleteCertificate: function() {
var self = this;
var countItemDeleted = 0;
var checkedInputList =
elements.certificateList.querySelectorAll(
'input[type=checkbox]:checked');

var scanWhenDeleteFinish = function(totalLength) {
return function() {
if (++countItemDeleted == totalLength) {
// refresh certificate list
countItemDeleted = 0;
self._scan();
}
};
var scanWhenDeleteFinish = (totalLength) => {
if (++countItemDeleted == totalLength) {
// refresh certificate list
countItemDeleted = 0;
this._scan();
}
};

var scanWhenDeleteError = function(totalLength) {
return function() {
if (++countItemDeleted == totalLength) {
// refresh certificate list
countItemDeleted = 0;
self._scan();
}
// Pop out alert message for certificate deletion failed
var dialog = elements.deleteCertificateFailedDialog;
dialog.hidden = false;
dialog.onsubmit = function confirm() {
dialog.hidden = true;
};
var scanWhenDeleteError = (totalLength) => {
if (++countItemDeleted == totalLength) {
// refresh certificate list
countItemDeleted = 0;
this._scan();
}
// Pop out alert message for certificate deletion failed
var dialog = elements.deleteCertificateFailedDialog;
dialog.hidden = false;
dialog.onsubmit = () => {
dialog.hidden = true;
};
};

for (var i = 0; i < checkedInputList.length; i++) {
var nickname = checkedInputList[i].name;
var certRequest = wifiManager.deleteCert(nickname);
certRequest.onsuccess = scanWhenDeleteFinish(checkedInputList.length);
certRequest.onerror = scanWhenDeleteError(checkedInputList.length);
wifiManager.deleteCert(nickname).then(() => {
scanWhenDeleteFinish(checkedInputList.length);
}, () => {
scanWhenDeleteError(checkedInputList.length);
});
}
},
_isItemSelected: function() {
Expand Down
2 changes: 1 addition & 1 deletion apps/settings/locales/settings.en-US.properties
Expand Up @@ -118,7 +118,7 @@ noNetworksFound=No networks found
noKnownNetworks=No known networks
edit=Edit
certificateList=Certificate List
noCertificate=No imported certificate
noImportedCertificates=No certificates imported
deleteCertificate=Delete certificate
importCertificate=Import certificate
selectCertificateFile=Select certificate file
Expand Down

0 comments on commit 89f0b40

Please sign in to comment.