@ -1,5 +1,23 @@ |
|||||
angular.module('app.main', ['pascalprecht.translate']) |
angular.module('app.main', ['pascalprecht.translate']) |
||||
|
|
||||
.controller('MainCtrl', function($scope, $stateParams, $translate, $filter) { |
|
||||
|
|
||||
}); |
|
||||
|
.controller('MainCtrl', function($scope, $stateParams, $translate, $filter, |
||||
|
$ionicLoading, $http) { |
||||
|
if (localStorage.getItem("cim_app_userdata")) { |
||||
|
$scope.storageuser = JSON.parse(localStorage.getItem("cim_app_userdata")); |
||||
|
console.log($scope.storageuser); |
||||
|
} |
||||
|
//get the num of pendent notifications each time
|
||||
|
$http.get(urlapi + 'numnotifications') |
||||
|
.then(function(data) { |
||||
|
$scope.storageuser.notifications = data.data; |
||||
|
console.log(data.data); |
||||
|
localStorage.setItem("cim_app_storageuser", JSON.stringify($scope.storageuser)); |
||||
|
}, function(data) { |
||||
|
console.log('data error'); |
||||
|
$ionicLoading.show({ |
||||
|
template: 'Error connecting server', |
||||
|
noBackdrop: true, |
||||
|
duration: 2000 |
||||
|
}); |
||||
|
}); |
||||
|
}); |
@ -1,25 +1,52 @@ |
|||||
angular.module('app.notifications', ['pascalprecht.translate']) |
angular.module('app.notifications', ['pascalprecht.translate']) |
||||
|
|
||||
.controller('NotificationsCtrl', function($scope, $http, $ionicLoading, |
|
||||
$stateParams, $translate, $filter) { |
|
||||
$scope.notifications=[]; |
|
||||
$scope.doRefresh = function(){ |
|
||||
$http.get(urlapi + 'notifications') |
|
||||
.then(function(data){ |
|
||||
console.log(data); // for browser console
|
|
||||
$scope.storageuser = JSON.parse(localStorage.getItem("cim_app_userdata")); |
|
||||
$scope.storageuser.notifications = data.data; |
|
||||
localStorage.setItem("cim_app_userdata", JSON.stringify($scope.storageuser)); |
|
||||
|
.controller('NotificationsCtrl', function($scope, $http, $ionicLoading, |
||||
|
$stateParams, $translate, $filter) { |
||||
|
$scope.notifications = []; |
||||
|
$scope.doRefresh = function() { |
||||
|
//first, if already have notifications, set to viewed
|
||||
|
if(localStorage.getItem("cim_app_notifications")!=undefined){ |
||||
|
//console.log(localStorage.getItem("cim_app_notifications"));
|
||||
|
$scope.notifications = JSON.parse(localStorage.getItem("cim_app_notifications")); |
||||
|
for(var i=0; i<$scope.notifications.length; i++){ |
||||
|
$scope.notifications[i].state = "viewed"; |
||||
|
} |
||||
|
localStorage.setItem("cim_app_notifications", JSON.stringify($scope.notifications)); |
||||
|
} |
||||
|
$http.get(urlapi + 'notifications') |
||||
|
.then(function(data) { |
||||
|
//console.log(data); // for browser console
|
||||
|
/*$scope.storageuser = JSON.parse(localStorage.getItem("cim_app_userdata")); |
||||
|
$scope.storageuser.notifications = []; |
||||
|
console.log($scope.storageuser.notifications.length); |
||||
|
localStorage.setItem("cim_app_userdata", JSON.stringify($scope.storageuser));*/ |
||||
|
|
||||
$scope.notifications = data.data; // for UI
|
|
||||
$scope.$broadcast('scroll.refreshComplete');//refresher stop
|
|
||||
|
//get the storage notifications
|
||||
|
if (localStorage.getItem("cim_app_notifications")) { |
||||
|
$scope.notifications = JSON.parse(localStorage.getItem("cim_app_notifications")); |
||||
|
$scope.notifications = $scope.notifications.concat(data.data); // for UI
|
||||
|
} else { |
||||
|
$scope.notifications = data.data; |
||||
|
} |
||||
|
//store the notifications
|
||||
|
localStorage.setItem("cim_app_notifications", JSON.stringify($scope.notifications)); |
||||
|
|
||||
}, function(data){ |
|
||||
console.log('data error'); |
|
||||
$scope.$broadcast('scroll.refreshComplete');//refresher stop
|
|
||||
$ionicLoading.show({ template: 'Error connecting server', noBackdrop: true, duration: 2000 }); |
|
||||
|
//now clean the notification number that is showed in the menu and main page, from the storageuser.notifications
|
||||
|
/*$scope.storageuser = JSON.parse(localStorage.getItem("cim_app_userdata")); |
||||
|
$scope.storageuser.pendentnotifications = []; |
||||
|
localStorage.setItem("cim_app_userdata", JSON.stringify($scope.storageuser));*/ |
||||
|
$scope.$broadcast('scroll.refreshComplete'); //refresher stop
|
||||
|
|
||||
|
}, function(data) { |
||||
|
console.log('data error'); |
||||
|
$scope.$broadcast('scroll.refreshComplete'); //refresher stop
|
||||
|
$ionicLoading.show({ |
||||
|
template: 'Error connecting server', |
||||
|
noBackdrop: true, |
||||
|
duration: 2000 |
||||
|
}); |
||||
|
|
||||
}); |
}); |
||||
}; |
}; |
||||
$scope.doRefresh(); |
$scope.doRefresh(); |
||||
}); |
|
||||
|
}); |