Subversion Repositories SmartDukaan

Rev

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