latest updates
[namibia] / public / templates / page / unsubscribenewsletter.js
1 var template_unsubscribenewsletter = function( static )
2 {
3         this.static = static;
4         this.elements = {};
5         this.construct = function()
6         {
7                 $('body').removeClass("black");
8                 $('body').removeClass("black");
9                 App.Util.updateCheckboxStyles($('#frmUnsubLogin'));
10                 $('#email').val(App.Util.getCookie('UserEmail', ''));
11                 $('#frmUnsubLogin').validate({
12                         rules: {
13                                 email: {
14                                         email: true,
15                                         required: true
16                                 },
17                                 pin: {
18                                         minlength: 3,
19                                         required: true
20                                 },
21                                 mpin: {
22                                         minlength: 3,
23                                         required: true
24                                 }
25                         },
26                         submitHandler: function( form ) {
27                                 App.API.getTask(
28                                                 'login', 'User', 'Profile.Login', null,
29                                                 {}, function() {
30                                                         var data = {
31                                                                 "Login":{
32                                                                     "email"      : $('#email').val(),
33                                                                     "pin"        : $('#pin').val()
34                                                           }};
35                                                         App.API.execTask(
36                                                                 'login', data, {},
37                                                                 function(response) {
38                                                                         $('#login-fail').popover('hide');
39                                                                         _w.unsubUserId = response.Data.id;
40                                                                         App.API.getTask(
41                                                                                 'UnsubscribeUser:' + _w.unsubUserId, 'User', 'Profile.Unsubscribe', _w.unsubUserId,
42                                                                                 {'id':_w.unsubUserId}, function()
43                                                                                 {
44                                                                                         var data = {Profile:{subscribeNewsletter:false}};
45                                                                                         App.API.execTask(
46                                                                                                 'UnsubscribeUser:' + _w.unsubUserId, data, {},
47                                                                                                 function()
48                                                                                                 {
49                                                                                                         $('#unsubTitle').hide();
50                                                                                                         $('#theLoginBox').hide();
51                                                                                                         $('#unsubSuccessTitle').show();
52                                                                                                         App.API.getTask(
53                                                                                                                 'logout:', 'User', 'Profile.Logout', null,
54                                                                                                                 {}, function() {}, function() {}
55                                                                                                         );
56                                                                                                 }, _w.taskExecError
57                                                                                         );
58                                                                                 }, _w.taskContractError
59                                                                         );
60                                                                 }, function (data) {
61                                                                         $('#login-fail').attr('data-content', data.StatusReason);
62                                                                         $('#login-fail').popover('show');
63                                                                 }
64                                                         );
65                                                 }, _w.taskContractError
66                                 );
67                         }
68                 });
69         };
70         this.destruct = function()
71         {
72                 //alert('Hi there, removing bindings, etc');
73         };
74 };