');
container.innerHTML = Controller.processTemplate(options.name, html, data);
let view = new app.LoadedClasses[options.className](options);
view._className = options.name.replace('.html', '');
view._controller = this;
view.el = container;
view.DOMContentLoaded(data);
container.setAttribute('sparc-id', view._sparcId);
return view;
}
loadWindow(name, options, data) {
let url = app.Router.currentRoute.realUrl;
options = options || {};
// if static, redirect to existing instance
if(options.static) {
/*
MFA:
Using stored real url instead of classname allows different instance of window based on parameter:
eg:
having route "/window/{id}", calling "/window/345" won't replace "/window/123"
Makes me wonder: shouldn't all windows be static anyway then ?
*/
//let existing = this.getViewByClass(name);
let existing = this.getViewByURL(url);
if(existing) {
this.focus(existing._sparcId, data);
return;
}
}
options.onContentLoaded = this.createWindow;
super.loadView(name, options, data).then(
view => {
this.view2url[view._sparcId] = url;
view._url = url
}
);
}
createWindow(options, data, html) {
if(!(options.className in app.LoadedClasses)){
console.error(`Missing view ${options.className} !\nLoad explicitely it from your controller, or as set it as a dependency...`);
return null;
}
let view = new app.LoadedClasses[options.className]();
view._className = options.name.replace('.html', '');
view._controller = this;
Controller._contents.push({
view: view,
type: 'window',
expanded: options.expanded || false,
visible: true,
active: false
});
let settingsMarkup = ''
if(options.withSettings){
settingsMarkup=`
`
}
let content = ui.create(`
${options.title || ''}
${settingsMarkup}
`);
if(options.expanded) content.setAttribute('expanded','');
if(options.windowStyle){
for(const k in options.windowStyle){
content.style[k] = options.windowStyle[k]
}
}
let container = content.querySelector('section');
container.innerHTML = Controller.processTemplate(options.name, html, data);
view.el = content;
// setting up window controls
let expand = content.querySelector('header button.expand');
expand.addEventListener('click', view.expand.bind(view));
let shrink = content.querySelector('header button.shrink');
shrink.addEventListener('click', view.shrink.bind(view));
let close = content.querySelector('header button.close');
close.addEventListener('click', this.onclose.bind(this));
content.addEventListener('click', this.onFocusRequest.bind(this));
content.addEventListener('expanded', this.onFocusRequest.bind(this));
content.addEventListener('shrinked', this.onFocusRequest.bind(this));
if(options.withSettings && (typeof(view.settings) == 'function')){
let settings = content.querySelector('header button.settings');
settings.addEventListener('click', view.settings.bind(view));
}
content.setAttribute('sparc-id', view._sparcId);
let parent = Controller._template.view.find('.app-workspace');
parent.appendChild(content);
this.addThesaurus(view._sparcId, options.title || 'a window')
view.DOMContentLoaded(data);
view.initWindowEvents();
this.focus(view._sparcId);
return view;
}
openDialog(view) {
let promise = new Promise(function(resolve) {
if(typeof view === 'string') {
let message = view;
view = new WindozDialogContent();
view.el = message;
}
let dialog = WindozController.createDialog(view);
function commit(result) {
WindozController.closeDialog(view._sparcId);
resolve(result);
}
function abort(result) {
WindozController.closeDialog(view._sparcId);
resolve(result);
}
view.commit = commit;
view.abort = abort;
view.buttons.forEach(function(button) {
dialog.querySelector('[eicdialog] > [eiccard] > footer').append(button.el);
});
view.DOMContentFocused();
});
return promise;
}
/**
* Used by a view that needs to change the current URL
* Typically happens when the view allows you to switch to another instance of the business-object
* handled by this controiller. Doinbg a history.replaceState in the view is not enough, because
* the controller needs to keep track of his current URL (in view2url) for changing
* the Browser URL bar when -later- changing window focus.
* @param {string} newUrl
*/
changeUrl(view, newUrl) {
history.replaceState(null, null, newUrl)
this.view2url[view._sparcId] = newUrl
view._url = newUrl
}
static createDialog(dialog, options) {
options = options || {};
let container = ui.create(`