Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add toast messages #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 42 additions & 10 deletions clients/ionic/bestoon/www/js/controllers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
angular.module('starter.controllers', ['ionic'])
.controller('ConfigCtrl', function($scope, $http, $state, $ionicHistory, ) {
.controller('ConfigCtrl', function($scope, $http, $state, $ionicHistory, $ionicLoading) {
$scope.loggedin = false;
$scope.tabTitle = 'ورود';
token = storage.getItem('token');
Expand Down Expand Up @@ -28,11 +28,14 @@ angular.module('starter.controllers', ['ionic'])
} else {
// request was fine, but error on username / password
// TODO: toast message about failed login
$ionicLoading.show({ template: 'در ورود مشکلی پیش آمده است. لطفا نام کاربری و کلمه عبور را چک کنید', noBackdrop: true, duration: 2200 });

}
})
.error(function() {
$scope.message = 'erorr logging in' //TODO: show some error to user
console.log('error on login request')
$ionicLoading.show({ template: $scope.message, noBackdrop: true, duration: 2200 });
})
}

Expand All @@ -55,10 +58,12 @@ angular.module('starter.controllers', ['ionic'])
$scope.news = JSON.parse(data);
}).error(function() {
$scope.message = 'erorr reading news' //TODO: show some error to user console.log('error on request')
$ionicLoading.show({ template: $scope.message, noBackdrop: true, duration: 2200 });

})
})
})
.controller('DashCtrl', function($scope, $http, $state) {
.controller('DashCtrl', function($scope, $http, $state,$ionicLoading) {
$scope.$on('$ionicView.enter', function(e) {
if (!token) {
back_to_login_page($scope, $state);
Expand All @@ -74,11 +79,13 @@ angular.module('starter.controllers', ['ionic'])
.error(function() {
$scope.message = 'erorr reading from bestoon stats' //TODO: show some error to user
console.log('error on request')
$ionicLoading.show({ template: $scope.message, noBackdrop: true, duration: 2200 });

})
});
})

.controller('ExpenseCtrl', function($scope, $http, $state, $ionicModal) {
.controller('ExpenseCtrl', function($scope, $http, $state, $ionicModal,$ionicLoading) {
// With the new view caching in Ionic, Controllers are only called
// when they are recreated or on app start, instead of every page change.
// To listen for when this page is active (for example, to refresh data),
Expand All @@ -89,7 +96,7 @@ angular.module('starter.controllers', ['ionic'])

$ionicModal.fromTemplateUrl('expense-edit-modal.html', {
scope: $scope,
animation: 'slide-in-left',//'slide-left-right', 'slide-in-up', 'slide-right-left'
animation: 'slide-in-left',//'slide-left-right', 'slide-in-up', 'slide-right-left'
}).then(function(modal) {
$scope.modal = modal;
});
Expand All @@ -107,18 +114,22 @@ angular.module('starter.controllers', ['ionic'])
.success(function(data) {

// show a TOAST
$scope.message = 'اطلاعات ذخیره شد'
$ionicLoading.show({ template: $scope.message, noBackdrop: true, duration: 2200 });
$scope.modal.hide();
// update the expenses part, containing the new one
$http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
$http.post(bestoonURL + '/q/expenses/', 'token='+token).success(function(data) {
$scope.expenses = JSON.parse(data);
}).error(function() {
$scope.message = 'erorr reading previous expenses' //TODO: show some error to user console.log('error on request')
})
$ionicLoading.show({ template: $scope.message, noBackdrop: true, duration: 2200 });
})
})
.error(function() {
$scope.message = 'خطا در ذخیره اطلاعات. بعدا دوباره تلاش کنید' //TODO: show some error to user
console.log('error while submitting expense')
$ionicLoading.show({ template: $scope.message, noBackdrop: true, duration: 2200 });
})
};
$scope.closeModal = function() {
Expand Down Expand Up @@ -146,6 +157,8 @@ angular.module('starter.controllers', ['ionic'])
$scope.expenses = JSON.parse(data);
}).error(function() {
$scope.message = 'erorr reading previous expenses' //TODO: show some error to user console.log('error on request')
$ionicLoading.show({ template: $scope.message, noBackdrop: true, duration: 2200 });

})
})

Expand Down Expand Up @@ -174,25 +187,31 @@ angular.module('starter.controllers', ['ionic'])
.success(function(data) {
$scope.text = '';
$scope.amount = '';

// show a TOAST

$scope.message = 'اطلاعات ذخیره شد'
$ionicLoading.show({ template: $scope.message, noBackdrop: true, duration: 2200 });
// update the expenses part, containing the new one
$http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
$http.post(bestoonURL + '/q/expenses/', 'token='+token).success(function(data) {
$scope.expenses = JSON.parse(data);
}).error(function() {
$scope.message = 'erorr reading previous expenses' //TODO: show some error to user console.log('error on request')
$ionicLoading.show({ template: $scope.message, noBackdrop: true, duration: 2200 });

})
})
.error(function() {
$scope.message = 'خطا در ذخیره اطلاعات. بعدا دوباره تلاش کنید' //TODO: show some error to user
console.log('error while submitting expense')
$ionicLoading.show({ template: $scope.message, noBackdrop: true, duration: 2200 });

})
}

})

.controller('ExpenseDetailCtrl', function($scope, $stateParams, $state, Expense) {
.controller('ExpenseDetailCtrl', function($scope, $stateParams, $state, Expense,$ionicLoading) {
$scope.$on('$ionicView.enter', function(e) {
if (!token) {
back_to_login_page($scope, $state);
Expand All @@ -202,11 +221,11 @@ angular.module('starter.controllers', ['ionic'])
$scope.expense = Expense.get($stateParams.expenseId);
})

.controller('IncomeCtrl', function($scope, $http, $state, $ionicModal) {
.controller('IncomeCtrl', function($scope, $http, $state, $ionicModal,$ionicLoading) {

$ionicModal.fromTemplateUrl('income-edit-modal.html', {
scope: $scope,
animation: 'slide-in-left',//'slide-left-right', 'slide-in-up', 'slide-right-left'
animation: 'slide-in-left',//'slide-left-right', 'slide-in-up', 'slide-right-left'
}).then(function(modal) {
$scope.modal = modal;
});
Expand All @@ -224,18 +243,24 @@ angular.module('starter.controllers', ['ionic'])
.success(function(data) {

// show a TOAST
$scope.message = 'اطلاعات ذخیره شد'
$ionicLoading.show({ template: $scope.message, noBackdrop: true, duration: 2200 });
$scope.modal.hide();
// update the expenses part, containing the new one
$http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
$http.post(bestoonURL + '/q/incomes/', 'token='+token).success(function(data) {
$scope.incomes = JSON.parse(data);
}).error(function() {
$scope.message = 'erorr reading previous incomes' //TODO: show some error to user console.log('error on request')
$ionicLoading.show({ template: $scope.message, noBackdrop: true, duration: 2200 });

})
})
.error(function() {
$scope.message = 'خطا در ذخیره اطلاعات. بعدا دوباره تلاش کنید' //TODO: show some error to user
console.log('error while submitting expense')
$ionicLoading.show({ template: $scope.message, noBackdrop: true, duration: 2200 });

})
};
$scope.closeModal = function() {
Expand Down Expand Up @@ -280,6 +305,8 @@ angular.module('starter.controllers', ['ionic'])
$scope.incomes = JSON.parse(data);
}).error(function() {
$scope.message = 'erorr reading previous incomes' //TODO: show some error to user console.log('error on request')
$ionicLoading.show({ template: $scope.message, noBackdrop: true, duration: 2200 });

})
})

Expand All @@ -293,18 +320,23 @@ angular.module('starter.controllers', ['ionic'])
$scope.text = '';
$scope.amount = '';
// show a TOAST

$scope.message = 'اطلاعات ذخیره شد'
$ionicLoading.show({ template: $scope.message, noBackdrop: true, duration: 2200 });
// update the incomes part, containing the new one
$http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
$http.post(bestoonURL + '/q/incomes/', 'token='+token).success(function(data) {
$scope.incomes = JSON.parse(data);
}).error(function() {
$scope.message = 'erorr reading previous incomes' //TODO: show some error to user console.log('error on request')
$ionicLoading.show({ template: $scope.message, noBackdrop: true, duration: 2200 });

})
})
.error(function() {
$scope.message = 'خطا در ذخیره اطلاعات. بعدا دوباره تلاش کنید' //TODO: show some error to user
console.log('error while submitting income')
$ionicLoading.show({ template: $scope.message, noBackdrop: true, duration: 2200 });

})
}
})
Expand Down