aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/public/js/controllers/homeController.js
diff options
context:
space:
mode:
authorDennis Eriksen <dennis.se@gmail.com>2013-03-20 12:43:33 +0100
committerDennis Eriksen <dennis.se@gmail.com>2013-03-20 12:43:33 +0100
commit266767e6b31d4799b218a7dc9ffd0d6f2eca92a8 (patch)
treee3e68b3acdfb276cadcc23d0028a6c1dd3bc8f21 /public/js/controllers/homeController.js
parentEdited "Sign in" button - for fun (diff)
downloadDivid-266767e6b31d4799b218a7dc9ffd0d6f2eca92a8.tar.gz
login screen
Diffstat (limited to 'public/js/controllers/homeController.js')
-rw-r--r--public/js/controllers/homeController.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/public/js/controllers/homeController.js b/public/js/controllers/homeController.js
new file mode 100644
index 0000000..9894d0e
--- /dev/null
+++ b/public/js/controllers/homeController.js
@@ -0,0 +1,67 @@
+
+function HomeController()
+{
+
+// bind event listeners to button clicks //
+ var that = this;
+
+// handle user logout //
+ $('#btn-logout').click(function(){ that.attemptLogout(); });
+
+// confirm account deletion //
+ $('#account-form-btn1').click(function(){$('.modal-confirm').modal('show')});
+
+// handle account deletion //
+ $('.modal-confirm .submit').click(function(){ that.deleteAccount(); });
+
+ this.deleteAccount = function()
+ {
+ $('.modal-confirm').modal('hide');
+ var that = this;
+ $.ajax({
+ url: '/delete',
+ type: 'POST',
+ data: { id: $('#userId').val()},
+ success: function(data){
+ that.showLockedAlert('Your account has been deleted.<br>Redirecting you back to the homepage.');
+ },
+ error: function(jqXHR){
+ console.log(jqXHR.responseText+' :: '+jqXHR.statusText);
+ }
+ });
+ }
+
+ this.attemptLogout = function()
+ {
+ var that = this;
+ $.ajax({
+ url: "/home",
+ type: "POST",
+ data: {logout : true},
+ success: function(data){
+ that.showLockedAlert('You are now logged out.<br>Redirecting you back to the homepage.');
+ },
+ error: function(jqXHR){
+ console.log(jqXHR.responseText+' :: '+jqXHR.statusText);
+ }
+ });
+ }
+
+ this.showLockedAlert = function(msg){
+ $('.modal-alert').modal({ show : false, keyboard : false, backdrop : 'static' });
+ $('.modal-alert .modal-header h3').text('Success!');
+ $('.modal-alert .modal-body p').html(msg);
+ $('.modal-alert').modal('show');
+ $('.modal-alert button').click(function(){window.location.href = '/';})
+ setTimeout(function(){window.location.href = '/';}, 3000);
+ }
+}
+
+HomeController.prototype.onUpdateSuccess = function()
+{
+ $('.modal-alert').modal({ show : false, keyboard : true, backdrop : true });
+ $('.modal-alert .modal-header h3').text('Success!');
+ $('.modal-alert .modal-body p').html('Your account has been updated.');
+ $('.modal-alert').modal('show');
+ $('.modal-alert button').off('click');
+}