Subversion Repositories SmartDukaan

Rev

Rev 25651 | Rev 25684 | 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() {
25651 tejbeer 10
						console.log(localStorage.getItem("notifyDocument"));
25383 tejbeer 11
						var userIds = $('#fofo-users').val().concat(
12
								$('#internal-users').val());
13
						console.log("multipleUsers", userIds);
25651 tejbeer 14
 
25383 tejbeer 15
						var campaignName = $('input[name="campaignName"]')
16
								.val();
17
						var title = $('input[name="title"]').val();
18
						var message = $('input[name="message"]').val();
19
						var imageUrl = $('input[name="imageUrl"]').val();
20
						var type = $('#type').val();
21
						var expiryTime = $('#expireSat').val();
22
						var url = $('input[name="url"]').val();
23
						$('#showImage').on('change', function() {
24
							this.value = this.checked ? true : false;
25
						}).change();
26
 
27
						if (userIds.length === 0 && campaignName === ""
28
								&& title === "" && message === ""
29
								&& expiryTime === "" && type === "") {
30
							alert("Field can't be empty");
31
							return;
32
						}
33
						if (userIds.length === 0) {
34
							alert("please select the user");
35
							return;
36
						}
37
						if (campaignName === "") {
38
							alert("Campaign name is required");
39
							return;
40
						}
41
						if (title === "") {
42
							alert("Title Name is required");
43
							return;
44
						}
45
						if (message === "") {
46
							alert("Message is required");
47
							return;
48
						}
49
						if (expiryTime === "") {
50
							alert("ExpiryTime is required");
51
							return;
52
						}
53
						if (type === "") {
54
							alert("type is required");
55
							return;
56
						}
57
						if (type === "url") {
58
							if (url === "") {
59
								alert("url is required");
60
								return;
61
							}
62
 
63
						}
64
 
65
						var notificationData = {};
66
						notificationData['userIds'] = $('#fofo-users').val()
67
								.concat($('#internal-users').val());
68
						notificationData['campaignName'] = $(
69
								'input[name="campaignName"]').val();
70
						notificationData['title'] = $('input[name="title"]')
71
								.val();
72
						notificationData['message'] = $('#message').val();
73
						notificationData['imageUrl'] = $(
74
								'input[name="imageUrl"]').val();
75
						notificationData['type'] = $('#type').val();
76
						notificationData['url'] = $('input[name="url"]').val();
77
						notificationData['expiresat'] = startDate;
78
						notificationData['showImage'] = $(
79
								'input[name="showImage"]').val();
25651 tejbeer 80
						notificationData['documentId'] = localStorage
81
								.getItem("notifyDocument");
25683 tejbeer 82
						notificationData['messageType'] = $('#messageType')
25649 tejbeer 83
								.val();
25383 tejbeer 84
						console.log(notificationData)
85
 
86
						if (confirm("Are you sure you want to send notification!") == true) {
87
							doPostAjaxRequestWithJsonHandler(context
88
									+ "/sendNotification", JSON
89
									.stringify(notificationData), function(
90
									response) {
91
								if (response == 'true') {
92
									alert("successfully send");
93
									loadNotificationPanel("main-content");
94
								}
95
							});
96
 
97
							return false;
98
						}
99
 
100
					});
101
 
24011 tejbeer 102
});
103
 
25383 tejbeer 104
function loadNotificationPanel(domId) {
105
	doGetAjaxRequestHandler(context + "/sendNotificationPanel", function(
106
			response) {
24011 tejbeer 107
		$('#' + domId).html(response);
25383 tejbeer 108
 
24011 tejbeer 109
	});
25383 tejbeer 110
 
25651 tejbeer 111
}
112
 
113
$(document)
114
		.on(
115
				'input',
116
				'#notifyDocument',
117
				function() {
118
					if (confirm('Document has been selected, Do you want to upload ?')) {
119
						var fileSelector = $('#notifyDocument')[0];
120
						if (fileSelector != undefined
121
								&& fileSelector.files[0] != undefined) {
122
							var url = webApiScheme + '://' + webApiHost + ':'
123
									+ webApiPort + webApiRoot
124
									+ '/document-upload';
125
 
126
							console.log(url);
127
							var file = this.files[0];
128
							doAjaxUploadRequestHandler(
129
									url,
130
									'POST',
131
									file,
132
									function(response) {
133
										console.log(response);
134
										var documentId = response.response.document_id;
135
										console.log("documentId : "
136
												+ documentId);
137
										localStorage.setItem("notifyDocument",
138
												documentId);
139
										// $('#retailerDocument').attr("documentId",
140
										// localStorage.getItem("retailerDocument"));
141
										// return
142
										// documentId;
143
									});
144
							// alert("Retailer Shop Document
145
							// is required");
146
						}
147
					} else {
148
						// Do nothing!
149
					}
150
				});