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

Commit

Permalink
Bug 1164354 - migrate app install manager to use smart-modal-dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
john-hu committed Jun 1, 2015
1 parent 27d847f commit 871b075
Show file tree
Hide file tree
Showing 7 changed files with 475 additions and 432 deletions.
69 changes: 3 additions & 66 deletions tv_apps/smart-system/index.html
Expand Up @@ -215,6 +215,7 @@

<!-- App Install -->
<link rel="stylesheet" type="text/css" href="style/app_install_manager/app_install_manager.css">
<script defer src="js/app_install_dialogs.js"></script>
<script defer src="js/app_install_manager.js"></script>

<!-- Notifications -->
Expand Down Expand Up @@ -580,59 +581,8 @@ <h2 id="permission-message"></h2>
-->
</div>

<form id="app-install-dialog" class='app-install-dialog generic-dialog'
data-type="confirm" role="dialog"
data-z-index-level="app-install-dialog">
<section>
<h1 id="app-install-message"></h1>
<menu data-items="2">
<smart-button id="app-install-cancel-button" data-l10n-id="cancel" type="circle-text">Cancel</smart-button>
<smart-button id="app-install-install-button" class="recommend primary" data-l10n-id="install" type="circle-text">Install</smart-button>
</menu>
</section>
</form>

<form id="app-install-cancel-dialog" class='app-install-dialog generic-dialog'
data-type="confirm" role="dialog"
data-z-index-level="app-install-dialog">
<section>
<h1 data-l10n-id="cancelling-will-not-refund">Cancelling will not refund a purchase. Refunds for paid content are provided by the original seller.</h1>
<h1 data-l10n-id="apps-can-be-installed-later">Apps can be installed later from the original installation source.</h1>
<h1 data-l10n-id="are-you-sure-you-want-to-cancel">Are you sure you want to cancel this install?</h1>
<menu data-items="2">
<smart-button id="app-install-confirm-cancel-button" type="circle-text" data-l10n-id="cancel-install-button">Cancel Install</smart-button>
<smart-button id="app-install-resume-button" type="circle-text" data-l10n-id="resume">Resume</smart-button>
</menu>
</section>
</form>

<form id="app-uninstall-dialog" class='app-uninstall-dialog generic-dialog'
data-type="confirm" role="dialog"
data-z-index-level="app-install-dialog">
<section>
<h1 id="app-uninstall-message"></h1>
<menu data-items="2">
<smart-button id="app-uninstall-cancel-button" data-l10n-id="cancel" type="circle-text">Cancel</smart-button>
<smart-button id="app-uninstall-confirm-button" class="danger" data-l10n-id="delete" type="circle-text">delete</smart-button>
</menu>
</section>
</form>

<form id="app-download-cancel-dialog" class='app-install-dialog generic-dialog'
data-type="confirm" role="dialog"
data-z-index-level="app-install-dialog">
<section>
<h1></h1>
<p data-l10n-id="app-download-can-be-restarted">The download can
be restarted later.</p>
<menu data-items="2">
<button id="app-download-stop-button" class="danger confirm"
data-l10n-id="app-download-stop-button">Stop Download</button>
<button id="app-download-continue-button" class="cancel"
type="reset" data-l10n-id="continue">Continue</button>
</menu>
</section>
</form>
<div id="app-install-dialogs" data-z-index-level="app-install-dialog">
</div>

<form id="updates-download-dialog" data-type="confirm" role="dialog"
data-z-index-level="updates-download-dialog" data-nowifi="false"
Expand All @@ -655,19 +605,6 @@ <h1>
</menu>
</form>

<form id="setup-installed-app-dialog" class='setup-installed-app-dialog'
data-type="confirm" role="dialog"
data-z-index-level="setup-installed-app-dialog">
<section>
<h1 id="setup-app-name"></h1>
<p id="setup-app-description"></p>
<menu data-items="2">
<button id="setup-cancel-button" type="button" data-l10n-id="later">Later</button>
<button id="setup-confirm-button" class="recommend" type="button" data-l10n-id="setup">Setup</button>
</menu>
</section>
</form>

<form id="ime-layout-dialog" class="ime-layout-dialog"
data-type="confirm" role="dialog"
data-z-index-level="ime-layout-dialog">
Expand Down
279 changes: 279 additions & 0 deletions tv_apps/smart-system/js/app_install_dialogs.js
@@ -0,0 +1,279 @@
/* global SmartModalDialog, Promise, focusManager */
(function(exports) {
'use strict';

function AppInstallDialogs(containerElement) {
this.containerElement = containerElement;
}

var TYPES = Object.freeze({
'InstallDialog': 'install',
'InstallCancelDialog': 'installcancel',
'UninstallDialog': 'uninstall',
'DownloadCancelDialog': 'downloadcancel',
'SetupAppDialog': 'setupapp'
});

AppInstallDialogs.TYPES = TYPES;

var proto = AppInstallDialogs.prototype;

proto.start = function aid_start() {
this.containerElement.addEventListener('modal-dialog-closed', this);
this.containerElement.addEventListener('modal-dialog-will-open', this);
this._visibleDialogs = [];
this._dialogs = [];
};

proto.stop = function aid_stop() {
this.containerElement.removeEventListener('modal-dialog-closed', this);
this.containerElement.removeEventListener('modal-dialog-will-open', this);
this._visibleDialogs = [];
this.dialogs.forEach(function(dialog) {
if (dialog.isOpened) {
dialog.close();
}
});
this._dialogs = [];

this._installDialog = null;
this._installCancelDialog = null;
this._uninstallDialog = null;
this._setupAppDialog = null;

this.containerElement.innerHTML = '';
};

// install dialog
proto._renderInstallDialog = function aid__renderInstallDialog() {
if (this._installDialog) {
return;
}
this._installDialog = new SmartModalDialog(this.containerElement);
this._installDialog.element.classList.add('app-install-dialog');
this._dialogs.push(this._installDialog);
};

proto._showInstallDialog = function aid__showInstallDialog(options) {
return new Promise(function(resolve, reject) {
this._renderInstallDialog();
this._installDialog.open({
'onCancel': reject,
'message': {
'textL10nId': {
'id': 'install-app',
'args': {'name': options.manifest.name }
}
},
'buttonSettings': [
{
'textL10nId': 'cancel',
'onClick': reject
}, {
'textL10nId': 'install',
'onClick': resolve,
'defaultFocus': true,
'class': 'primary'
}
]
});

}.bind(this));
};
// end of install dialog

// install cancel dialog
proto._renderInstallCancelDialog = function aid__renderInstallDialog() {
if (this._installCancelDialog) {
return;
}
this._installCancelDialog = new SmartModalDialog(this.containerElement);
this._installCancelDialog.element.classList.add(
'app-install-cancel-dialog');
this._dialogs.push(this._installCancelDialog);
};

proto._showInstallCancelDialog = function aid__showInstallDialog(options) {
return new Promise(function(resolve, reject) {
this._renderInstallCancelDialog();
var message = document.createElement('div');
var lines = [ document.createElement('h1'),
document.createElement('h1'),
document.createElement('h1') ];
lines[0].setAttribute('data-l10n-id', 'cancelling-will-not-refund');
lines[1].setAttribute('data-l10n-id', 'apps-can-be-installed-later');
lines[2].setAttribute('data-l10n-id', 'are-you-sure-you-want-to-cancel');
lines.forEach(message.appendChild.bind(message));

this._installCancelDialog.open({
'onCancel': reject,
'customElementSettings': {
'element': message
},
'buttonSettings': [
{
'textL10nId': 'cancel-install-button',
'onClick': resolve,
'defaultFocus': true
}, {
'textL10nId': 'resume',
'onClick': reject
}
]
});
}.bind(this));
};
// end of install cancel dialog

// uninstall dialog
proto._renderUninstallDialog = function aid__renderUninstallDialog() {
if (this._uninstallDialog) {
return;
}
this._uninstallDialog = new SmartModalDialog(this.containerElement);
this._uninstallDialog.element.classList.add('app-uninstall-dialog');
this._dialogs.push(this._uninstallDialog);
};

proto._showUninstallDialog = function aid__showUninstallDialog(options) {
return new Promise(function(resolve, reject) {
this._renderUninstallDialog();
var message = options.unrecoverable ? 'unrecoverable-error-body' : {
'id': 'delete-body',
'args': {'name': options.manifest.name }
};

var buttons = options.unrecoverable ? [{
'textL10nId': 'delete',
'onClick': resolve,
'class': 'danger'
}] : [
{
'textL10nId': 'cancel',
'onClick': reject,
'defaultFocus': true
}, {
'textL10nId': 'delete',
'onClick': resolve,
'class': 'danger'
}
];
if (options.unrecoverable) {
this._uninstallDialog.element.classList.add('unrecoverable');
} else {
this._uninstallDialog.element.classList.remove('unrecoverable');
}

this._uninstallDialog.open({
'onCancel': reject,
'message': {
'textL10nId': message
},
'buttonSettings': buttons
});
}.bind(this));
};
// end of uninstall dialog

// setup installed app dialog
proto._renderSetupAppDialog = function aid__renderUninstallDialog() {
if (this._setupAppDialog) {
return;
}
this._setupAppDialog = new SmartModalDialog(this.containerElement);
this._setupAppDialog.element.classList.add('setup-app-dialog');
this._dialogs.push(this._setupAppDialog);
};

proto._showSetupAppDialog = function aid__showUninstallDialog(options) {
return new Promise(function(resolve, reject) {
this._renderSetupAppDialog();

var message = document.createElement('div');
var lines = [ document.createElement('h1'),
document.createElement('p')];
navigator.mozL10n.setAttributes(lines[0], 'app-install-success',
{ 'appName': options.manifest.name });
lines[1].textContent = options.manifest.description;
lines.forEach(message.appendChild.bind(message));
this._setupAppDialog.open({
'onCancel': reject,
'customElementSettings': {
'element': message
},
'buttonSettings': [
{
'textL10nId': 'later',
'onClick': reject,
'defaultFocus': true
}, {
'textL10nId': 'setup',
'onClick': resolve,
'class': 'primary'
}
]
});
}.bind(this));
};
// end of uninstall dialog

proto.show = function aid_show(type, options) {
switch(type) {
case TYPES.InstallDialog:
return this._showInstallDialog(options);
case TYPES.InstallCancelDialog:
return this._showInstallCancelDialog(options);
case TYPES.UninstallDialog:
return this._showUninstallDialog(options);
case TYPES.DownloadCancelDialog:
// do nothing because we don't have such UI to trigger it.
return Promise.resolve();
case TYPES.SetupAppDialog:
return this._showSetupAppDialog(options);
default:
return Promise.reject();
}
};

proto.handleEvent = function aid_handleEvent(evt) {
switch(evt.type) {
case 'modal-dialog-will-open':
this._visibleDialogs.push(evt.detail);
focusManager.focus();
break;
case 'modal-dialog-closed':
var idx = this._visibleDialogs.indexOf(evt.detail);
if (idx > -1) {
this._visibleDialogs.splice(idx, 1);
}
focusManager.focus();
break;
}
};

proto.focus = function aid_focus() {
var topMost = this.getTopMostDialogElement();
if (topMost) {
document.activeElement.blur();
topMost.focus();
}
};

proto.getTopMostDialogElement = function aid_getTopMostDialogElement() {
return (this._visibleDialogs.length > 0) ?
this._visibleDialogs[this._visibleDialogs.length - 1].element : null;
};

proto.hasVisibleDialog = function aid_hasVisibleDialog() {
return this._visibleDialogs.length > 0;
};

proto.hideAll = function aid_hideAll() {
this._visibleDialogs.forEach(function(dialog) {
dialog.close();
});
};

exports.AppInstallDialogs = AppInstallDialogs;

})(window);

0 comments on commit 871b075

Please sign in to comment.