Skip to content

Instantly share code, notes, and snippets.

@kahou82
Last active August 29, 2015 14:10
Show Gist options
  • Save kahou82/86578bcc64cdf5919ec3 to your computer and use it in GitHub Desktop.
Save kahou82/86578bcc64cdf5919ec3 to your computer and use it in GitHub Desktop.
var horizon_dependencies = ['hz.conf', 'hz.utils', 'ngCookies', 'hz.table'];
dependencies = horizon_dependencies.concat(angularModuleExtension);
var horizonApp = angular.module('hz', dependencies)
.provider('unicornLauncher', function UnicornLauncherProvider() {
var useTinfoilShielding = false;
this.injectSomething = function() {
var temp = horizon.conf.spinner_options; // this provider relates on horizon.conf.spinner_options which is not initialzied during config
};
this.$get = function unicornLauncherFactory() {
return new UnicornLauncher();
};
})
.config(['$interpolateProvider', '$httpProvider', 'unicornLauncherProvider',
function ($interpolateProvider, $httpProvider, unicornLauncherProvider) {
$interpolateProvider.startSymbol('{$');
$interpolateProvider.endSymbol('$}');
$httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
$httpProvider.defaults.xsrfCookieName = 'csrftoken';
$httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
unicornLauncherProvider.injectSomething();
}])
.run(['hzConfig', 'hzUtils', '$cookieStore', '$http', '$cookies',
function (hzConfig, hzUtils, $cookieStore, $http, $cookies) {
$http.defaults.headers.post['X-CSRFToken'] = $cookies.csrftoken;
//expose the configuration for horizon legacy variable
horizon.conf = hzConfig;
horizon.utils = hzUtils;
angular.extend(horizon.cookies = {}, $cookieStore);
horizon.cookies.put = function (key, value) {
//cookies are updated at the end of current $eval, so for the horizon
//namespace we need to wrap it in a $apply function.
angular.element('body').scope().$apply(function () {
$cookieStore.put(key, value);
});
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment