Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
24011 tejbeer 1
$(function() {
27754 amit.gupta 2
	$(document).on('click', '.send-notification', function() {
25759 tejbeer 3
 
24011 tejbeer 4
		loadNotificationPanel("main-content");
5
	});
25383 tejbeer 6
 
27755 amit.gupta 7
	$(document).on('click', '.create-notification-button',
25383 tejbeer 8
					function() {
25651 tejbeer 9
						console.log(localStorage.getItem("notifyDocument"));
25383 tejbeer 10
						var userIds = $('#fofo-users').val().concat(
11
								$('#internal-users').val());
12
						console.log("multipleUsers", userIds);
29200 manish 13
 
14
						var stateIds = $('#state-users').val();
15
 
16
						console.log("stateIds"+stateIds);
25651 tejbeer 17
 
25383 tejbeer 18
						var campaignName = $('input[name="campaignName"]')
19
								.val();
20
						var title = $('input[name="title"]').val();
21
						var message = $('input[name="message"]').val();
22
						var imageUrl = $('input[name="imageUrl"]').val();
23
						var type = $('#type').val();
24
						var expiryTime = $('#expireSat').val();
25759 tejbeer 25
 
26
						var val = $("#selectedUrl").val();
27
						console.log(val);
28
						if (val == "other") {
29
							url = $('input[name="url"]').val();
30
						} else {
31
							url = val;
32
						}
33
 
25685 tejbeer 34
						var messageType = $('#messageType').val();
35
 
25383 tejbeer 36
						$('#showImage').on('change', function() {
37
							this.value = this.checked ? true : false;
38
						}).change();
39
 
29200 manish 40
						if (campaignName === ""
25383 tejbeer 41
								&& title === "" && message === ""
25759 tejbeer 42
								&& expiryTime === "" && type === ""
43
								&& messageType === "") {
25383 tejbeer 44
							alert("Field can't be empty");
45
							return;
46
						}
29200 manish 47
						if (stateIds.length === 0 && stateIds.length === 0 ) {
48
							alert("please select the user or State");
25383 tejbeer 49
							return;
50
						}
51
						if (campaignName === "") {
52
							alert("Campaign name is required");
53
							return;
54
						}
55
						if (title === "") {
56
							alert("Title Name is required");
57
							return;
58
						}
59
						if (message === "") {
60
							alert("Message is required");
61
							return;
62
						}
63
						if (expiryTime === "") {
64
							alert("ExpiryTime is required");
65
							return;
66
						}
25759 tejbeer 67
 
25685 tejbeer 68
						if (messageType === null) {
69
							alert("message type is required");
70
							return;
71
						}
25383 tejbeer 72
						if (type === "") {
73
							alert("type is required");
74
							return;
75
						}
76
						if (type === "url") {
77
							if (url === "") {
78
								alert("url is required");
79
								return;
80
							}
81
 
82
						}
83
 
84
						var notificationData = {};
29200 manish 85
 
86
						notificationData['stateIds'] = $('#state-users').val();
87
 
25383 tejbeer 88
						notificationData['userIds'] = $('#fofo-users').val()
89
								.concat($('#internal-users').val());
90
						notificationData['campaignName'] = $(
91
								'input[name="campaignName"]').val();
92
						notificationData['title'] = $('input[name="title"]')
93
								.val();
94
						notificationData['message'] = $('#message').val();
95
						notificationData['imageUrl'] = $(
96
								'input[name="imageUrl"]').val();
97
						notificationData['type'] = $('#type').val();
25759 tejbeer 98
						notificationData['url'] = url;
25383 tejbeer 99
						notificationData['expiresat'] = startDate;
100
						notificationData['showImage'] = $(
101
								'input[name="showImage"]').val();
25651 tejbeer 102
						notificationData['documentId'] = localStorage
103
								.getItem("notifyDocument");
25683 tejbeer 104
						notificationData['messageType'] = $('#messageType')
25649 tejbeer 105
								.val();
25383 tejbeer 106
						console.log(notificationData)
107
 
108
						if (confirm("Are you sure you want to send notification!") == true) {
25759 tejbeer 109
							doPostAjaxRequestWithJsonHandler(context
110
									+ "/sendNotification", JSON
111
									.stringify(notificationData), function(
112
									response) {
113
								if (response == 'true') {
114
									alert("successfully send");
115
									loadNotificationPanel("main-content");
116
									localStorage.removeItem("notifyDocument");
117
								}
118
							});
25383 tejbeer 119
 
120
							return false;
121
						}
122
 
123
					});
124
 
24011 tejbeer 125
});
126
 
25383 tejbeer 127
function loadNotificationPanel(domId) {
25759 tejbeer 128
	localStorage.removeItem("notifyDocument");
25383 tejbeer 129
	doGetAjaxRequestHandler(context + "/sendNotificationPanel", function(
130
			response) {
24011 tejbeer 131
		$('#' + domId).html(response);
25759 tejbeer 132
		$("#url").hide();
25383 tejbeer 133
 
24011 tejbeer 134
	});
25383 tejbeer 135
 
25651 tejbeer 136
}
137
 
138
$(document)
139
		.on(
140
				'input',
141
				'#notifyDocument',
142
				function() {
143
					if (confirm('Document has been selected, Do you want to upload ?')) {
144
						var fileSelector = $('#notifyDocument')[0];
145
						if (fileSelector != undefined
146
								&& fileSelector.files[0] != undefined) {
26392 amit.gupta 147
							var url = context  + '/document-upload';
25651 tejbeer 148
 
149
							console.log(url);
150
							var file = this.files[0];
151
							doAjaxUploadRequestHandler(
152
									url,
153
									'POST',
154
									file,
155
									function(response) {
156
										console.log(response);
157
										var documentId = response.response.document_id;
158
										console.log("documentId : "
159
												+ documentId);
160
										localStorage.setItem("notifyDocument",
161
												documentId);
162
										// $('#retailerDocument').attr("documentId",
163
										// localStorage.getItem("retailerDocument"));
164
										// return
165
										// documentId;
166
									});
167
							// alert("Retailer Shop Document
168
							// is required");
169
						}
170
					} else {
171
						// Do nothing!
172
					}
25759 tejbeer 173
				});
174
 
175
function changeUrl() {
176
	var val = $("#selectedUrl").val();
177
	console.log(val);
178
	if (val == "other") {
179
		$("#url").show();
180
	} else {
181
		$("#url").hide();
182
	}
183
 
184
}