UNPKG

landers.angular

Version:

landers.angular

69 lines (60 loc) 2.35 kB
;angular.module('Landers.angular') .provider('GNotify', function(){ var provider = this; provider.config = { startTop: 60, // templateUrl: '', position: 'right', duration: 10000 }; provider.setConfig = function(opts) { angular.extend(provider.config, opts || {}); } provider.events = []; provider.classes = ['notify-box', 'text-left', 'alert']; this.$get = ['$rootScope', 'notify', function($rootScope, notify) { var setConfig = function(opts){ var config = angular.extend({}, provider.config, opts || {}); notify.config(config); }; return { show: function(rspn, opts){ if (!rspn.message) return; setConfig(opts); var classes = provider.classes.slice(0); classes.push('p15 pt20'); if (!rspn.response_code) { if (rspn.success) { classes.push('cg-notify-success'); } else { classes.push('cg-notify-danger'); } } else { switch(rspn.response_code) { case 'success': classes.push('cg-notify-success'); break; case 'error': classes.push('cg-notify-danger'); break; case 'info': classes.push('cg-notify-info'); break; } } notify({ classes: classes.join(' '), message: rspn.message }); }, startlisten: function(){ var _this = this; provider.events.map(function(event){ $rootScope.$on(event, function($event, rspn){ _this.show(rspn); }); }) } }; }]; });