horizon/openstack_dashboard/static/app/app.module.js
Diana Whitten c219a3efc6 Horizon Spinner/Loader should inherit from theme
The Horizon spinner was using a spinner generated and animated
entirely out of JavaScript. Since CSS3 provides animates and we have
access to icon fonts, doing everything with JavaScript is not
necessary and actually taxing on the browser. Plus, all of the
spinner options were being passed in and around with JavaScript,
including the colors.  This makes it supremely difficult to use the
theme to style the spinner.

The new spinner is just defined by a handful of templates now. There
are two clientside templates to support Legacy Horizon, and one
template in the Angular to support spinners going forward.  Legacy
Horizon had two forms of spinners, so it was broken up. Angular as
not yet made use of the inline spinner, but should follow the same
markup when it is made.

There are two types of spinners, inline spinners (those shown when a
dynamic tab content is loading) and modal spinners (various other
places).  These are consistent with each other for the 'default'
experience, but their experience can be entirely customized separate
from each other.  'material' has been augmented with loaders defined
within their design spec to show the power of this new feature.

horizon.templates.js was augmented with this refactor to support only
having to compile one tempalte at a time (instead of all of them) and
caching that template so that all of them can be recompiled later.
Also, horizon.loader.js was added to house template compilation code
that was repeated in several locations.

To test overwriting page modal spinner and inline-modal spinner
examples, please follow the instructions in _loading_inline_exmaple.html,
_loading_modal_example.html under
openstack_dashboard/themes/material/templates/horizon/client_side

Change-Id: I92bc786160e070d30691eeabd4f2a50d6e2bb395
Partially-implements: blueprint horizon-theme-css-reorg
Partially-Implements: blueprint bootstrap-html-standards
Closes-bug: #1570485
2017-04-21 11:15:52 -07:00

158 lines
3.9 KiB
JavaScript

/*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*global horizonPlugInModules*/
(function () {
'use strict';
/**
* Library modules - modules defined in third-party libraries, including
* angular's extensions.
*/
var libraryModules = [
'gettext',
'lrDragNDrop',
'ngCookies',
'ngSanitize',
'schemaForm',
'smart-table',
'ui.bootstrap'
];
/**
* Horizon's built-in modules, including modules from `framework` components
* and modules from `openstack_dashboard` application core components.
*/
var horizonBuiltInModules = [
'horizon.app.core',
'horizon.app.resources',
'horizon.app.tech-debt',
'horizon.auth',
'horizon.framework'
];
/**
* @ngdoc overview
* @name horizon.app
* @description
*
* # horizon.app
*
* Horizon's application level module depends on modules from three
* sources:
*
* 1) Library modules.
* 2) Horizon's built-in modules.
* 3) Horizon's plug-in modules.
*/
angular
.module('horizon.app', ['ngRoute']
.concat(libraryModules)
.concat(horizonBuiltInModules)
.concat(horizonPlugInModules)
)
.config(configHorizon)
.run(updateHorizon);
configHorizon.$inject = [
'$locationProvider',
'$routeProvider'
];
/**
* Configure the Horizon Angular Application.
* This sets up the $locationProvider Service to use HTML5 Mode and
* the Hash Prefix to use when it is not supported.
*
* It also sets the default Angular route which will apply if
* a link is clicked that doesn't match any current Angular route.
*
*/
function configHorizon($locationProvider, $routeProvider) {
if (angular.element('base').length === 1) {
$locationProvider.html5Mode(true).hashPrefix('!');
$routeProvider
.otherwise({
template: '',
controller: 'RedirectController'
});
}
}
updateHorizon.$inject = [
'gettextCatalog',
'horizon.framework.util.tech-debt.helper-functions',
'horizon.framework.widgets.toast.service',
'$cookieStore',
'$http',
'$cookies',
'$route'
];
function updateHorizon(
gettextCatalog,
hzUtils,
toastService,
$cookieStore,
$http,
$cookies,
$route
) {
$http.defaults.headers.post['X-CSRFToken'] = $cookies.csrftoken;
// expose the legacy utils module
horizon.utils = hzUtils;
horizon.toast = toastService;
if (angular.version.major === 1 && angular.version.minor < 4) {
horizon.cookies = angular.extend({}, $cookieStore, {
getObject: $cookieStore.get,
put: put,
putObject: put,
getRaw: getRaw
});
} else {
horizon.cookies = $cookies;
}
// rewire the angular-gettext catalog to use django catalog
gettextCatalog.setCurrentLanguage(horizon.languageCode);
gettextCatalog.setStrings(horizon.languageCode, django.catalog);
// because of angular startup, and our use of ng-include with
// embedded ng-view, we need to re-kick ngRoute after everything's
// resolved
$route.reload();
/*
* cookies are updated at the end of current $eval, so for the horizon
* namespace we need to wrap it in a $apply function.
*/
function put(key, value) {
angular.element('body').scope().$apply(function () {
$cookieStore.put(key, value);
});
}
function getRaw(key) {
return $cookies[key];
}
}
}());