Subversion Repositories SmartDukaan

Rev

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