Last active
December 16, 2015 10:19
-
-
Save LucaLanziani/5419248 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(" ")); | |
}; | |
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div ng-controller="MessagesCtrl"> | |
<div ng-include="'partials/messages.html'"></div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.notifications { | |
position: fixed; | |
z-index: 20; | |
top: 10px; | |
right: 10px; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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