Subversion Repositories SmartDukaan

Rev

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