Skip to content

Instantly share code, notes, and snippets.

@LucaLanziani
Last active December 16, 2015 10:19
Show Gist options
  • Save LucaLanziani/5419248 to your computer and use it in GitHub Desktop.
Save LucaLanziani/5419248 to your computer and use it in GitHub Desktop.
AngularApp
.run(["$rootScope", function ($rootScope) {
$rootScope.log_http_response = function (what, callback) {
return function (data, status, headers, config) {
console.log(what, data, status, headers, config);
(callback || angular.noop)(data, status, headers, config);
};
};
$rootScope.message = function () {
var args = Array.prototype.slice.call(arguments);
var message_type = 1;
if (args.length > 1) {
if (angular.isNumber(args[0]) && (args[0] >= 100)) {
var type = args.shift();
message_type = (Math.floor(type/100));
}
}
this.$emit("message", message_type, args.join(" "));
};
}]);
<div ng-controller="MessagesCtrl">
<div ng-include="'partials/messages.html'"></div>
</div>
.notifications {
position: fixed;
z-index: 20;
top: 10px;
right: 10px;
}
<div class="notifications">
<div ng-show="loading">
<div ng-include="'partials/spinner_small.html'"></div>
</div>
</div>
<div class="notifications">
<div ng-repeat="message in messages" class="alert fade {{message.type}}" bs-alert>
{{message.text}}
</div>
</div>
(function () {
/*jshint laxcomma:true, asi:true */
'use strict';
var CONTROLLER_NAME = "MessagesCtrl";
function controller($scope, $timeout, loading) {
$scope.messages = [];
var messages_type = ["alert-info",
"alert-success",
"",
"alert-error",
"alert-error"];
$scope.list_template="partials/spinner.html";
$scope.$on("message",function (event, type, message) {
$scope.messages.push({type: messages_type[type-1], text: message});
$timeout(function () {
$scope.messages.shift();
}, 5000);
});
$scope.$watch(function() { return loading.isLoading(); },
function(value) { $scope.loading = value;});
}
controller.$inject = ['$scope', '$timeout', 'loading'];
angular
.module("AngularApp")
.controller(CONTROLLER_NAME, controller);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment