Created
June 3, 2015 05:34
-
-
Save ajoyoommen/98da763cc1379fbae363 to your computer and use it in GitHub Desktop.
Ionic PushPlugin project
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
var exapp = angular.module('exapp', | |
['ionic', | |
'ui.select2', | |
'exapp.controllers', | |
'exapp.services']); | |
exapp.run(function($ionicPlatform, $state, Notifications, geo) { | |
$ionicPlatform.ready(function() { | |
if (window.cordova && window.plugins.backgroundGeoLocation) { | |
geo(); | |
} | |
try{ | |
var pushNotification = window.plugins.pushNotification; | |
} catch (ex){ | |
} | |
var successfn = function(result){ | |
// window.alert("S: " + result); | |
}; | |
var errorfn = function(result){ | |
// window.alert("E: " + result); | |
}; | |
window.onCB = function(e){ | |
switch (e.event){ | |
case 'registered': | |
if (e.regid.length > 0){ | |
localStorage.setItem('registration_id', e.regid); | |
} | |
break; | |
case 'message': | |
if (e.foreground){ | |
navigator.notification.beep(1); | |
} | |
$state.go('app.notifications'); | |
break; | |
} | |
}; | |
try{ | |
pushNotification.register( | |
successfn, | |
errorfn, | |
{ | |
"senderID": "191919191919191", | |
"ecb" : "window.onCB" | |
} | |
); | |
} catch(e){ | |
} | |
}); | |
}); | |
// States | |
exapp.config(function($stateProvider, $urlRouterProvider) { | |
$stateProvider | |
.state('app', { | |
url: "/app", | |
abstract: true, | |
templateUrl: "templates/menu.html", | |
controller: 'AppCtrl' | |
}) | |
.state('app.profile', { | |
url: "/profile", | |
views: { | |
'menuContent': { | |
templateUrl: "templates/profile.html", | |
controller: "ProfileCtrl" | |
} | |
} | |
}) | |
.state('app.notifications', { | |
url: "/notifications", | |
views: { | |
'menuContent': { | |
templateUrl: "templates/notifications.html", | |
controller: "NotificationCtrl" | |
} | |
} | |
}) | |
.state('app.form_new', { | |
url: "/form/new/:formId", | |
views: { | |
'menuContent' :{ | |
templateUrl: "templates/form_new.html", | |
controller: 'FormNewCtrl' | |
} | |
} | |
}) | |
.state('app.form_records', { | |
url: "/form/records/:formId", | |
views: { | |
'menuContent' :{ | |
templateUrl: "templates/form_records.html", | |
controller: 'FormRecordsCtrl' | |
} | |
} | |
}) | |
.state('app.form_record', { | |
url: "/form/record/:formId/:recordId", | |
views: { | |
'menuContent' :{ | |
templateUrl: "templates/form_record.html", | |
controller: 'FormRecordCtrl' | |
} | |
} | |
}) | |
.state('app.unsynced_records', { | |
url: "/unsynced", | |
views: { | |
'menuContent' :{ | |
templateUrl: "templates/unsynced_records.html", | |
controller: 'UnsyncedRecordsCtrl' | |
} | |
} | |
}) | |
.state('app.unsynced_record', { | |
url: "/unsynced/edit/:formId/:recordId", | |
views: { | |
'menuContent' :{ | |
templateUrl: "templates/unsynced_record.html", | |
controller: 'UnsyncedRecordCtrl' | |
} | |
} | |
}) | |
.state('app.login', { | |
url: "/login", | |
views: { | |
'menuContent' :{ | |
templateUrl: "templates/login.html", | |
controller: 'AuthCtrl' | |
} | |
} | |
}); | |
// if none of the above states are matched, use this as the fallback | |
$urlRouterProvider.otherwise('/app/profile'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment