arrow-admin
Version:
Arrow Admin Website
122 lines (114 loc) • 4.47 kB
JavaScript
define(['jquery', 'toc'], function ($, TOC) {
return function (src, enablePartialLoads, callback) {
if (!callback) {
callback = enablePartialLoads;
enablePartialLoads = false;
}
var isCMS = src === 'cms';
var loadingHTML = '<div id="loader"><i class="icon-spin5 animate-spin"></i> Loading...</div>';
$('#mainContent').html(loadingHTML).load(src, loaded);
if (enablePartialLoads) {
$('#nav-secondary').on('click', 'a', function (evt) {
var href = $(this).attr('href'),
page = isCMS ? src : href.replace('.html?', '/');
history.pushState({href: href}, '', href);
if (!isCMS) { TOC.reRenderMenu(); }
$('#mainContent').html(loadingHTML).load(page, loaded);
evt.preventDefault();
});
window.onpopstate = function () {
var href = window.location.pathname.split('/').pop() + (window.location.search || ''),
page = isCMS ? src : (window.location.search ? href.replace('.html?', '/') : href.split('.')[0]);
if (!isCMS) { TOC.reRenderMenu(); }
$('#mainContent').html(loadingHTML).load(page, loaded);
};
}
function loaded(response, status, xhr) {
var content = $('#mainContent'),
body = $('body');
if (status === 'error') {
body.addClass('error-tpl');
content.removeClass('panel content');
var html = [];
html.push('<section class="text-center center-block">');
if (xhr.status === 404) {
html.push('<h1><i class="icon-404_link"></i>404</h1>');
html.push('<hr>');
html.push('<p class="txt-spaced txt-16 txt-medgray">The resource you requested cannot be not found.</p>');
html.push('<hr>');
html.push('<p class="txt-left txt-14 txt-medgray">');
html.push('Check your URL. It could be that the URL was entered incorrectly or, when you pasted the URL into your browser, it was malformed.');
}
else {
html.push('<h1>' + xhr.status + '</h1>');
html.push('<hr>');
html.push('<p class="txt-spaced txt-16 txt-medgray">' + xhr.statusText + '</p>');
html.push('<hr>');
html.push('<p class="txt-left txt-14 txt-medgray">');
}
html.push('It could also be that we have gotten something wrong and have an issue.');
html.push('If you are still having problems with the URL, you can reach us at <a href="mailto:support@axway.com">support@axway.com</a>, and we will be glad to see what we can do to assist.');
html.push('</p>');
html.push('<hr> ');
html.push('<ul class="mg-top-l list-unstyled txt-spaced">');
html.push('<li><a class="txt-14" href="/">Dashboard</a></li>');
html.push('<li><a class="txt-14" href="http://status.appcelerator.com">Status</a></li>');
html.push('<li><a class="txt-14" href="https://support.axway.com/">Support</a></li>');
html.push('</ul>');
html.push('</section>');
content.html(html.join('\n'));
}
else {
body.removeClass('error-tpl');
content.addClass('panel content');
// join together blockquote and code as one big block
$('blockquote.unformat + pre.highlight').prev().addClass('noborder');
$('blockquote.unformat + pre.highlight div.toolbar').each(function () {
var el = $(this).parent('pre.highlight').prev('blockquote.unformat');
// move it to the blockquote
el.append($(this));
});
body.trigger('contentloaded');
var cookies = {};
document.cookie.split(';').forEach(function (cookie) {
var keyValue = cookie.split('=');
cookies[keyValue[0].trim()] = keyValue[1].trim();
});
if (src === 'cms' && !CONFIG.devmode && !cookies.sessionsecret) {
$('#sessionSecretModal').modal({
backdrop: 'static',
keyboard: false,
show: true
}).on('hidden.bs.modal', function (e) {
if (callback) {
callback();
}
});
$('#sessionSecretForm').submit(function (evt) {
evt.preventDefault();
$('#sessionSecretButton').button('loading');
var secret = $('#sessionSecret').val();
document.cookie = 'sessionsecret=' + secret;
$.get('isloggedin', function (isLoggedIn) {
$('#sessionSecretButton').button('reset');
if (isLoggedIn) {
$('#sessionSecretModal').modal('hide');
/*if (callback) {
callback();
}*/
}
else {
alert('Invalid session secret entered. Please try again.');
document.cookie = 'sessionsecret=';
}
});
return false;
});
}
else if (callback) {
callback();
}
}
}
};
});