(sorry for the lag) and thanks again for your assistance
so… lets post the prompt class and some relevant code
prompt.html
<template>
<div class="modal fade" tabindex="-1" role="dialog" element.ref="modalElement">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">${title}</h4>
</div>
<div class="modal-body">
<p>${message}</p>
</div>
<div class="modal-footer">
<button repeat.for="button of buttons" type="button"
class="btn btn-${$first ? 'primary' : 'default'}"
click.delegate="submit(button)">
${button}
</button>
</div>
</div>
</div>
</div>
</template>
prompt.js
export class Prompt {
modalElement: Element = null;
submit(button) {
$(this.modalElement).modal('hide');
this.resolve(button);
}
show(title, message, buttons) {
this.title = title;
this.message = message;
this.buttons = buttons;
let modal = $(this.modalElement);
modal.modal({ show: true, backdrop: 'static' });
modal.on('hide.bs.modal', () => {
modal.off('hide.bs.modal');
});
modal.find('button:first').focus();
return new Promise(r => this.resolve = r);
}
}
app.html
<template>
<require from="./resources/prompt"></require>
<prompt view-model.ref="prompt"></prompt>
...
<router-view></router-view>
</template>
app.ts
import { Prompt } from './resources/prompt';
@autoinject
export class App {
public prompt: Prompt;
constructor(...)
{
...
}
bind() {
this.container.registerInstance(Prompt, this.prompt);
}
}
Usage (ie foo.ts)
canDeactivate() {
if (!this.hasChanges) {
return Promise.resolve(true);
}
return this.prompt.show('Navigate', 'You have unsaved changes. Do you want to save them?', ['Save', 'Discard', 'Cancel'])
.then(button => {
if (button === 'Save') {
return this.submit().then(() => true);
}
return button === 'Discard';
});
}
Notice we pass in with Prompt.Show all the parameters for the Dialog and Choices. Since you can only have one modal at a time it’s sort of a singleton. Note the Bind() in app.ts which is suspicious…
Again, just don’t understand why the browser Refresh of a subpage would be different then routing click-by-click to the same point with something defined in the app.js
Also note: jDanyow initially helped me with this project and I believe this was working for many initial version of Aurelia… (Who tests refresh in a spa… )
I’ve reached out to him for help, but he’s crazy busy
Thanks again,
Mike