strolch-maven-archetypes/li.strolch.mvn.archetype.we.../src/main/resources/archetype-resources/src/main/webapp/app/src/behaviors/c-app-behavior.html

199 lines
7.1 KiB
HTML

<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="./c-component-behavior.html">
<script>
CustomAppBehaviorImpl = {
properties: {
notifications: {
type: Array,
value: []
},
},
onClearSearchTerm: function () {
this.$$("#debouncedInput").onClearTapped();
},
_updatePageTitle: function (pageName) {
if (pageName === "${appName}" || pageName === "${appName}")
document.title = pageName;
else
document.title = "${appName}: " + (this.localize == null ? pageName : this.localize(pageName));
},
onLogOut: function () {
this.$$("#pages").logout();
sessionStorage.clear();
Strolch.clearStorageData();
this.deleteCookie("strolch.authorization");
window.location.reload();
},
reloadPage: function (pageName) {
this._updatePageTitle(pageName);
this.debounce('page-reload-' + pageName, function () {
var page = this.$$('#' + pageName);
if (page && page.reload) {
console.log('Reloading ' + pageName);
page.reload();
}
switch (pageName) {
case 'login' :
case 'inspector' :
case 'control' :
case 'operations-log' :
case 'jobs' :
case 'sessions' :
case 'users' :
case 'roles' :
case 'i18n-editor' :
case 'reports' :
this.set('toolbarConfig', {
pageTitle: pageName,
backButton: true,
hasSearchTerm: false
});
break;
default:
if (page != null && page.toolbarConfig != null) {
this.set('toolbarConfig', page.toolbarConfig);
}
}
}, 100);
},
onShowToast: function (e) {
if (this.$.toast.opened) {
this.$.toast.close();
this.async(function () {
this.toastText = e.detail.text;
this.$.toast.open();
}, 100);
} else {
this.toastText = e.detail.text;
this.$.toast.open();
}
},
onShowDialog: function (e) {
var dlgTitle;
if (e.detail.title != null)
dlgTitle = e.detail.title;
else
dlgTitle = e.detail.isError ? 'errorOccurred' : 'info';
var dlgText;
if (e.detail.text)
dlgText = e.detail.text;
else if (e.detail.message)
dlgText = e.detail.message;
else
dlgText = JSON.stringify(e.detail);
this._showDialog(dlgTitle, dlgText);
},
onShowNotification: function (e) {
console.log("Showing notification " + e.detail.id);
this.push("notifications", e.detail);
},
onClearNotification: function (e) {
console.log("Clearing notification " + e.detail.id);
for (var i = 0; i < this.notifications.length; i++) {
if (this.notifications[i].id === e.detail.id) {
this.splice("notifications", i, 1);
break;
}
}
},
onServerNotAvailable: function (event) {
clearInterval(this.checkForNewVersionInterval);
this.showInfo({
translate: true,
okLbl: 'reconnect',
title: 'serverNotAvailable',
line1: 'serverNotAvailableMsg',
cancelable: false,
callback: function (confirmed) {
if (confirmed)
this.reconnect();
}.bind(this)
});
},
onSessionInvalid: function (e) {
console.log(this.routeTail);
if (this.routeTail.prefix !== '/login') {
this.showInfo({
translate: true,
title: 'sessionInvalid',
line1: 'sessionInvalidConfirmNavToLogin',
cancelable: false,
callback: function (confirmed) {
if (!confirmed) return;
this.deleteCookie('strolch.authorization');
this.set("authTokenValid", false);
}.bind(this)
});
}
},
onPrivilegeDenied: function (e) {
if (this.authTokenValid) {
if (e.detail && e.detail.detail && e.detail.detail.request //
&& e.detail.detail.request.response //
&& e.detail.detail.request.response.i18n) {
this.showInfo({
title: 'privilegeDenied',
i18n: e.detail.detail.request.response.i18n,
translate: true
});
} else if (e.detail && e.detail.detail && e.detail.detail.request //
&& e.detail.detail.request.response //
&& e.detail.detail.request.response.exceptionMsg) {
this.showInfo({
title: 'privilegeDenied',
line1: e.detail.detail.request.response.exceptionMsg,
line2: this.requestEventToUrl(e),
translate: true
});
} else {
this.showInfo({
title: 'privilegeDenied',
line1: 'privilegeDeniedText',
line2: this.requestEventToUrl(e),
translate: true
});
}
} else {
console.warn("Privilege denied to URL " + this.requestEventToUrl(e));
this.requestErrorToMsg(e);
}
},
_showDialog: function (dlgTitle, dlgText, dlgReason) {
if (this.localize) {
var data = {
title: this.localize(dlgTitle),
line1: this.localize(dlgText)
};
if (dlgReason)
data.line1 += ": " + dlgReason;
this.$.infoDlg.open(data);
} else {
this.debounce('show-dlg', function () {
var data = {
title: this.localize(dlgTitle),
line1: this.localize(dlgText)
};
if (dlgReason)
data.line1 += ": " + dlgReason;
this.$.infoDlg.open(data);
}.bind(this), 250);
}
},
};
CustomAppBehavior = [CustomComponentBehavior, CustomAppBehaviorImpl];
</script>