Subversion Repositories SmartDukaan

Rev

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