Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
23783 ashik.ali 1
$(function() {
27754 amit.gupta 2
	$(document).on('click', ".create-api", function() {
23783 ashik.ali 3
		loadCreateApi("main-content");
4
	});
5
 
27754 amit.gupta 6
	$(document).on('click', ".create-api-button", function() {
23783 ashik.ali 7
		var name = $('#apiName').val();
8
		var uri = $('#uri').val();
9
		var method = $('#api-methods option:selected').val();
10
		createApi("main-content", name, uri, method);
11
	});
12
 
27754 amit.gupta 13
	$(document).on('click', ".edit-api", function() {
23783 ashik.ali 14
		loadEditApi("main-content");
15
	});
16
 
27754 amit.gupta 17
	$(document).on('change', '#apis-for-edit', function(){
23783 ashik.ali 18
		var apiText = $('#apis-for-edit option:selected').text();
19
		var apiTexts = apiText.split('[');
20
		var name = apiTexts[0].trim();
21
		var uri = apiTexts[1].substring(0, apiTexts[1].length - 1);
22
		var method = apiTexts[2].substring(0, apiTexts[2].length - 1);
23
		$('#apiName').val(name);
24
		$('#uri').val(uri);
25
		$('#api-methods').val(method);
26
		//$('#apiName').val(roleName);
27
	});
28
 
27754 amit.gupta 29
	$(document).on('click', ".edit-api-button", function() {
23783 ashik.ali 30
		var apiId = $('#apis-for-edit').val();
31
		var apiName = $('#apiName').val();
32
		var uri = $('#uri').val();
33
		var method = $('#api-methods option:selected').text();
34
		editApi("main-content", apiId, apiName, uri, method);
35
	});
36
 
27754 amit.gupta 37
	$(document).on('click', ".delete-api", function() {
23783 ashik.ali 38
		loadDeleteApi("main-content");
39
	});
40
 
27754 amit.gupta 41
	$(document).on('click', ".delete-api-button", function() {
23783 ashik.ali 42
		var apiId = $('#apis-for-delete').val();
43
		deleteApi("main-content", apiId);
44
	});
45
 
27754 amit.gupta 46
	$(document).on('click', ".create-role", function() {
23783 ashik.ali 47
		loadCreateRole("main-content");
48
	});
49
 
27754 amit.gupta 50
	$(document).on('click', ".create-role-button", function() {
23783 ashik.ali 51
		var roleName = $('#roleName').val();
52
		createRole("main-content", roleName);
53
	});
54
 
27754 amit.gupta 55
	$(document).on('click', ".create-duplicate-role", function() {
23783 ashik.ali 56
		loadCreateDuplicateRole("main-content");
57
	});
58
 
27754 amit.gupta 59
	$(document).on('change', '#roles-for-duplicate', function(){
23783 ashik.ali 60
		var roleName = $('#roles-for-duplicate option:selected').text();
61
		$('#roleName').val(roleName+"2");
62
	});
63
 
27754 amit.gupta 64
	$(document).on('click', ".create-duplicate-role-button", function() {
23783 ashik.ali 65
		console.log("create duplicate role button clicked");
66
		var roleId = $('#roles-for-duplicate').val();
67
		var roleName = $('#roleName').val();
68
		createDuplicateRole("main-content", roleId, roleName); 
69
	});
70
 
27754 amit.gupta 71
	$(document).on('click', ".delete-role", function() {
23783 ashik.ali 72
		loadDeleteRole("main-content");
73
	});
74
 
27754 amit.gupta 75
	$(document).on('click', ".delete-role-button", function() {
23783 ashik.ali 76
		var roleId = $('#roles-for-delete').val();
77
		deleteRole("main-content", roleId);
78
	});
79
 
27754 amit.gupta 80
	$(document).on('click', ".rename-role", function() {
23783 ashik.ali 81
		loadRenameRole("main-content");
82
	});
83
 
27754 amit.gupta 84
	$(document).on('change', '#roles-for-rename', function(){
23783 ashik.ali 85
		var roleName = $('#roles-for-rename option:selected').text();
86
		$('#roleName').val(roleName);
87
	});
88
 
27754 amit.gupta 89
	$(document).on('click', ".rename-role-button", function() {
23783 ashik.ali 90
		var roleId = $('#roles-for-rename').val();
91
		var roleName = $('#roleName').val();
92
		renameRole("main-content", roleId, roleName);
93
	});
94
 
27754 amit.gupta 95
	$(document).on('click', ".add-remove-api", function() {
23783 ashik.ali 96
		loadAddRemoveApi("main-content");
97
	});
98
 
27754 amit.gupta 99
	$(document).on('click', ".add-remove-role", function() {
23783 ashik.ali 100
		loadAddRemoveRole("main-content");
101
	});
102
 
27754 amit.gupta 103
	$(document).on('change', '#api-roles', function(){
23783 ashik.ali 104
		//$('#tag-listing-brand-value').text($(this).text());
105
		loadApisByRoleId("apis-container", $(this).val());
106
	});
107
 
27754 amit.gupta 108
	$(document).on('click', ".add-remove-api-button", function() {
23783 ashik.ali 109
		var roleId = $('#api-roles').val();
110
		var roleName = $('#api-roles option:selected').text();
111
		var apiIds = $('#apis').val();
112
		addRemoveApis("main-content", roleId, apiIds);
113
		//$('#api-roles option:selected').text(roleName);
114
	});
115
 
27754 amit.gupta 116
	$(document).on('click', ".add-remove-role-button", function() {
23783 ashik.ali 117
		var emailIdOrMobileNumber = $('#emailIdOrMobileNumber').val();
118
		var roleIds = $('#roles').val();
119
		addRemoveRoles("main-content", emailIdOrMobileNumber, roleIds);
120
	});
121
 
122
});
123
 
124
function getRolesByEmailIdOrMobileNumber(){
125
	var emailIdOrMobileNumber = $('#emailIdOrMobileNumber').val();
126
	console.log("emailIdOrMobileNumber = "+emailIdOrMobileNumber);
127
	if(emailIdOrMobileNumber != ""){
128
		loadRolesByEmailIdOrMobileNumber("roles-container", emailIdOrMobileNumber);
129
	}
130
}
131
 
132
function loadCreateApi(domId){
133
	doGetAjaxRequestHandler(context+"/createApi", function(response){
134
		$('#' + domId).html(response);
135
	});
136
}
137
 
138
function loadEditApi(domId){
139
	doGetAjaxRequestHandler(context+"/editApi", function(response){
140
		$('#' + domId).html(response);
141
	});
142
}
143
 
144
function loadDeleteApi(domId){
145
	doGetAjaxRequestHandler(context+"/deleteApi", function(response){
146
		$('#' + domId).html(response);
147
	});
148
}
149
 
150
function loadCreateRole(domId){
151
	doGetAjaxRequestHandler(context+"/createRole", function(response){
152
		$('#' + domId).html(response);
153
	});
154
}
155
 
156
function loadCreateDuplicateRole(domId){
157
	doGetAjaxRequestHandler(context+"/createDuplicateRole", function(response){
158
		$('#' + domId).html(response);
159
	});
160
}
161
 
162
function loadDeleteRole(domId){
163
	doGetAjaxRequestHandler(context+"/deleteRole", function(response){
164
		$('#' + domId).html(response);
165
	});
166
}
167
 
168
function loadRenameRole(domId){
169
	doGetAjaxRequestHandler(context+"/renameRole", function(response){
170
		$('#' + domId).html(response);
171
	});
172
}
173
 
174
function loadAddRemoveApi(domId){
175
	doGetAjaxRequestHandler(context+"/addRemoveApi", function(response){
176
		$('#' + domId).html(response);
177
	});
178
}
179
 
180
function loadAddRemoveRole(domId){
181
	doGetAjaxRequestHandler(context+"/addRemoveRole", function(response){
182
		$('#' + domId).html(response);
183
	});
184
}
185
 
186
function loadApisByRoleId(domId, roleId){
187
	doGetAjaxRequestHandler(context+"/roleApis?roleId="+roleId, function(response){
188
		$('#' + domId).html(response);
189
		configureRoleApisDropDown();
190
	});
191
}
192
 
193
function loadRolesByEmailIdOrMobileNumber(domId, emailIdOrMobileNumber){
194
	doGetAjaxRequestHandler(context+"/userRoles?emailIdOrMobileNumber="+emailIdOrMobileNumber, function(response){
195
		$('#' + domId).html(response);
196
		configureUserRolesDropDown();
197
	});
198
}
199
 
200
function configureApisForEditDropDown(){
201
	$(document).ready(function() {
202
        $('#apis-for-edit').multiselect({
203
        		multiple:false,
204
	        	includeSelectAllOption: true,
205
	        	maxHeight: 200,
206
	        	buttonWidth: '380px',
207
	        	numberDisplayed: 1,
208
	        	nonSelectedText: 'Apis',
209
	        	nSelectedText: ' - Apis Selected',
210
	        	allSelectedText: 'All Apis Selected',
211
	        	enableFiltering: true
212
        });
213
    });
214
}
215
 
216
function configureApisForDeleteDropDown(){
217
	$(document).ready(function() {
218
        $('#apis-for-delete').multiselect({
219
        		multiple:false,
220
	        	includeSelectAllOption: true,
221
	        	maxHeight: 200,
222
	        	buttonWidth: '800px',
223
	        	numberDisplayed: 1,
224
	        	nonSelectedText: 'Apis',
225
	        	nSelectedText: ' - Apis Selected',
226
	        	allSelectedText: 'All Apis Selected',
227
	        	enableFiltering: true
228
        });
229
    });
230
}
231
 
232
function configureUserRolesDropDown(){
233
	$(document).ready(function() {
234
        $('#roles').multiselect({
235
	        	includeSelectAllOption: true,
236
	        	maxHeight: 200,
237
	        	buttonWidth: '280px',
238
	        	numberDisplayed: 1,
239
	        	nonSelectedText: 'Roles',
240
	        	nSelectedText: ' - Roles Selected',
241
	        	allSelectedText: 'All Roles Selected',
242
	        	enableFiltering: true
243
        });
244
    });
245
}
246
 
247
function configureRoleApisDropDown(){
248
	$(document).ready(function() {
249
        $('#apis').multiselect({
250
	        	includeSelectAllOption: true,
251
	        	maxHeight: 200,
252
	        	buttonWidth: '800px',
253
	        	numberDisplayed: 1,
254
	        	nonSelectedText: 'Apis',
255
	        	nSelectedText: ' - Apis Selected',
256
	        	allSelectedText: 'All Apis Selected',
257
	        	enableFiltering: true
258
        });
259
    });
260
}
261
 
262
function createApi(domId, name, uri, method){
263
	if(name == ""){
264
		alert("Api name is required");
265
		return;
266
	}
267
	if(uri == ""){
268
		alert("Api uri is required");
269
		return;
270
	}
271
	if(method == ""){
272
		alert("Please choose api method");
273
		return;
274
	}
275
	var params = {
276
			"name":name,
277
			"uri":uri,
278
			"method":method
279
		}
280
	if(confirm("Are you sure you want to create Api!") == true){
281
		doPostAjaxRequestWithParamsHandler(context+"/createApi", params, function(response){
282
			$('#' + domId).html(response);
283
		});
284
	}
285
}
286
 
287
function editApi(domId, apiId, name, uri, method){
288
	if(confirm("Are you sure you want to update api!") == true){
289
		doPutAjaxRequestHandler(context+"/editApi?apiId="+apiId+"&name="+name+"&uri="+uri+"&method="+method, function(response){
290
			$('#' + domId).html(response);
291
		});
292
	}
293
}
294
 
295
function deleteApi(domId, apiId){
296
	if(confirm("Are you sure you want to delete api!") == true){
297
		doDeleteAjaxRequestHandler(context+"/deleteApi?apiId="+apiId, function(response){
298
			$('#' + domId).html(response);
299
		});
300
	}
301
}
302
 
303
function createRole(domId, name){
304
	var params = {
305
			"name":name
306
		}
307
	if(confirm("Are you sure you want to create Role!") == true){
308
		doPostAjaxRequestWithParamsHandler(context+"/createRole", params, function(response){
309
			$('#' + domId).html(response);
310
		});
311
	}
312
}
313
 
314
function createDuplicateRole(domId, roleId, name){
315
	var params = {
316
			"roleId":roleId,
317
			"name":name
318
		}
319
	if(confirm("Are you sure you want to create duplicate role!") == true){
320
		doPostAjaxRequestWithParamsHandler(context+"/createDuplicateRole", params, function(response){
321
			$('#' + domId).html(response);
322
		});
323
	}
324
}
325
 
326
function deleteRole(domId, roleId){
327
	if(confirm("Are you sure you want to delete role!") == true){
328
		doDeleteAjaxRequestHandler(context+"/deleteRole?roleId="+roleId, function(response){
329
			$('#' + domId).html(response);
330
		});
331
	}
332
}
333
 
334
function renameRole(domId, roleId, name){
335
	if(confirm("Are you sure you want to rename role!") == true){
336
		doPutAjaxRequestHandler(context+"/renameRole?roleId="+roleId+"&name="+name, function(response){
337
			$('#' + domId).html(response);
338
		});
339
	}
340
}
341
 
342
function addRemoveApis(domId, roleId, apiIds){
343
	if(confirm("Are you sure you want to add or remove apis!") == true){
344
		doPostAjaxRequestWithJsonHandler(context+"/addRemoveApis?roleId="+roleId, JSON.stringify(apiIds), function(response){
345
			$('#' + domId).html(response);
346
			$('#api-roles').val(roleId);
347
			$('#api-roles').change();
348
		});
349
	}
350
}
351
 
352
function addRemoveRoles(domId, emailIdOrMobileNumber, roleIds){
353
	if(confirm("Are you sure you want to add or remove roles!") == true){
354
		doPostAjaxRequestWithJsonHandler(context+"/addRemoveRoles?emailIdOrMobileNumber="+emailIdOrMobileNumber, JSON.stringify(roleIds), function(response){
355
			$('#' + domId).html(response);
356
			$('#emailIdOrMobileNumber').val(emailIdOrMobileNumber);
357
			getRolesByEmailIdOrMobileNumber();
358
		});
359
	}
360
}
361