Subversion Repositories SmartDukaan

Rev

Rev 25383 | Rev 25651 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
24011 tejbeer 1
$(function() {
2
	$('.send-notification').live('click', function() {
3
		loadNotificationPanel("main-content");
4
	});
25383 tejbeer 5
 
6
	$('.create-notification-button')
7
			.live(
8
					'click',
9
					function() {
10
						var userIds = $('#fofo-users').val().concat(
11
								$('#internal-users').val());
12
						console.log("multipleUsers", userIds);
13
						var campaignName = $('input[name="campaignName"]')
14
								.val();
15
						var title = $('input[name="title"]').val();
16
						var message = $('input[name="message"]').val();
17
						var imageUrl = $('input[name="imageUrl"]').val();
18
						var type = $('#type').val();
19
						var expiryTime = $('#expireSat').val();
20
						var url = $('input[name="url"]').val();
21
						$('#showImage').on('change', function() {
22
							this.value = this.checked ? true : false;
23
						}).change();
24
 
25
						if (userIds.length === 0 && campaignName === ""
26
								&& title === "" && message === ""
27
								&& expiryTime === "" && type === "") {
28
							alert("Field can't be empty");
29
							return;
30
						}
31
						if (userIds.length === 0) {
32
							alert("please select the user");
33
							return;
34
						}
35
						if (campaignName === "") {
36
							alert("Campaign name is required");
37
							return;
38
						}
39
						if (title === "") {
40
							alert("Title Name is required");
41
							return;
42
						}
43
						if (message === "") {
44
							alert("Message is required");
45
							return;
46
						}
47
						if (expiryTime === "") {
48
							alert("ExpiryTime is required");
49
							return;
50
						}
51
						if (type === "") {
52
							alert("type is required");
53
							return;
54
						}
55
						if (type === "url") {
56
							if (url === "") {
57
								alert("url is required");
58
								return;
59
							}
60
 
61
						}
62
 
63
						var notificationData = {};
64
						notificationData['userIds'] = $('#fofo-users').val()
65
								.concat($('#internal-users').val());
66
						notificationData['campaignName'] = $(
67
								'input[name="campaignName"]').val();
68
						notificationData['title'] = $('input[name="title"]')
69
								.val();
70
						notificationData['message'] = $('#message').val();
71
						notificationData['imageUrl'] = $(
72
								'input[name="imageUrl"]').val();
73
						notificationData['type'] = $('#type').val();
74
						notificationData['url'] = $('input[name="url"]').val();
75
						notificationData['expiresat'] = startDate;
76
						notificationData['showImage'] = $(
77
								'input[name="showImage"]').val();
25649 tejbeer 78
 
79
						notificationData['annoucement'] = $('#annoucement')
80
								.val();
25383 tejbeer 81
						console.log(notificationData)
82
 
83
						if (confirm("Are you sure you want to send notification!") == true) {
84
							doPostAjaxRequestWithJsonHandler(context
85
									+ "/sendNotification", JSON
86
									.stringify(notificationData), function(
87
									response) {
88
								if (response == 'true') {
89
									alert("successfully send");
90
									loadNotificationPanel("main-content");
91
								}
92
							});
93
 
94
							return false;
95
						}
96
 
97
					});
98
 
24011 tejbeer 99
});
100
 
25383 tejbeer 101
function loadNotificationPanel(domId) {
102
	doGetAjaxRequestHandler(context + "/sendNotificationPanel", function(
103
			response) {
24011 tejbeer 104
		$('#' + domId).html(response);
25383 tejbeer 105
 
24011 tejbeer 106
	});
25383 tejbeer 107
 
24011 tejbeer 108
}