Welcome to mirror list, hosted at ThFree Co, Russian Federation.

UsersManager.js « templates « UsersManager « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 37e205ccb56df01531f50ade95fcb6d6242c9f32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258


function getUpdateUserAJAX( row )
{
	var ajaxRequest = getStandardAjaxConf();
	toggleAjaxLoading();
	
	// prepare the API parameters to update the user
	var parameters = new Object;
	parameters.module = 'API';
	parameters.format = 'json';
 	parameters.method =  'UsersManager.updateUser';
 	parameters.userLogin = $(row).children('#userLogin').html();
 	var password =  $(row).find('input[@id=password]').val();
 	if(password != '-') parameters.password = password;
 	parameters.email = $(row).find('input[@id=email]').val();
 	parameters.alias = $(row).find('input[@id=alias]').val();
	
	ajaxRequest.data = parameters;
	
	return ajaxRequest;

}

function getDeleteUserAJAX( login )
{
	var ajaxRequest = getStandardAjaxConf();
	toggleAjaxLoading();
		
	// prepare the API parameters to update the user
	var parameters = new Object;
	parameters.module = 'API';
	parameters.format = 'json';
 	parameters.method =  'UsersManager.deleteUser';
 	parameters.userLogin = login;
	
	ajaxRequest.data = parameters;
	
	return ajaxRequest;
}

function getAddUserAJAX( row )
{
	var ajaxRequest = getStandardAjaxConf();
	toggleAjaxLoading();
	
	// prepare the API parameters to add the user
	var parameters = new Object;
	parameters.module = 'API';
	parameters.format = 'json';
 	parameters.method =  'UsersManager.addUser';
 	parameters.userLogin = $(row).find('input[@id=useradd_login]').val();
 	parameters.password =  $(row).find('input[@id=useradd_password]').val();
 	parameters.email = $(row).find('input[@id=useradd_email]').val();
 	parameters.alias = $(row).find('input[@id=useradd_alias]').val();
 	
	ajaxRequest.data = parameters;
 	
	return ajaxRequest;
}

function getIdSites()
{
	return $('#selectIdsite option:selected').val();
}

function getUpdateUserAccess(login, access, successCallback)
{
	var ajaxRequest = getStandardAjaxConf();
	
	ajaxRequest.success = successCallback;
	ajaxRequest.async = false;
	
	// prepare the API parameters to add the user
	var parameters = new Object;
	parameters.module = 'API';
	parameters.format = 'json';
 	parameters.method =  'UsersManager.setUserAccess';
 	parameters.userLogin = login;
 	parameters.access = access;
 	
 	var idSites = getIdSites();
 	if(idSites != -1)
 	{
	 	parameters.idSites = idSites;
 	}
 	
	ajaxRequest.data = parameters;
 	
	return ajaxRequest;
}

function submitOnEnter(e)
{
	var key=e.keyCode || e.which;
	if (key==13)
	{
		$(this).find('#adduser').click();
		$(this).find('#updateuser').click();
	}
}


function launchAjaxRequest(self, successCallback)
{
	//launching AJAX request
	$.ajax( getUpdateUserAccess( 
					$(self).parent().parent().find('#login').html(),//if changed change also the modal
					$(self).parent().attr('id'),
					successCallback
				) 
			);	
}

function bindUpdateAccess()
{
	$('#accessUpdated').hide();
	var self = this;
	
	// callback called when the ajax request Update the user permissions is successful
	function successCallback (response)
	{
		// if the permission couldn't be granted
		if(response.result == "error") 
		{
			ajaxShowError(response.message);
		}
		// if the permission change was successful
		else
		{
			ajaxHideError();
			
			//once successful
			$(self).parent().parent().find('.accessGranted')
				.attr("src","plugins/UsersManager/images/no-access.png" )
				.attr("class","updateAccess" )
				.click(bindUpdateAccess)
				;
			$(self)
				.attr('src',"plugins/UsersManager/images/ok.png" )
				.attr('class',"accessGranted" )
				;
			$('#accessUpdated').show();
			$('#accessUpdated').fadeOut(1500);
		}
	}
	
	var idSite = getIdSites();
	if(idSite == -1)
	{
		var target = this;       
		
		//ask confirmation
		var userLogin = $(this).parent().parent().find('#login').html();
		$('.dialog#confirm #login').text( userLogin ); // if changed here change also the launchAjaxRequest
		var question = $('.dialog#confirm').clone();
		$('#yes', question).click(function()
		{
			launchAjaxRequest(target, successCallback);	
			$.unblockUI();
		});
		
		$('#no', question).click($.unblockUI);
		$.blockUI(question, { width: '300px' });
	}
	else
	{
		launchAjaxRequest(this, successCallback);
	}
}

$(document).ready( function() {

	var alreadyEdited = new Array;
	// when click on edituser, the cells become editable
	$('.edituser')
		.click( function() {
				ajaxHideError();
				var idRow = $(this).attr('id');
				if(alreadyEdited[idRow]==1) return;
				alreadyEdited[idRow] = 1;
				$('tr#'+idRow+' .editable').each(
							// make the fields editable
							// change the EDIT button to VALID button
							function (i,n) {
								var contentBefore = $(n).html();
								var idName = $(n).attr('id');
								if(idName != 'userLogin')
								{
									var contentAfter = '<input id="'+idName+'" value="'+contentBefore+'" size="10">';
									$(n).html(contentAfter);
								}
							}
						);
						
				$(this)
					.toggle()
					.parent()
					.prepend( $('<img src="plugins/UsersManager/images/ok.png" id="updateuser">')
								.click( function(){ $.ajax( getUpdateUserAJAX( $('tr#'+idRow) ) ); } ) 
						);
				
				
				
			}
	);
	$('.editable').keypress( submitOnEnter );
	
	$('td.editable')
		.hover( function() {  
		 	 $(this).css({ cursor: "pointer"}); 
		  	},
		  	function() {  
		 	 $(this).css({ cursor: "auto"}); 
		  	}
	 	)
	 	.click( function(){ $(this).parent().find('.edituser').click(); } )
	 ;
	
	// when click on deleteuser, the we ask for confirmation and then delete the user
	$('.deleteuser').click( function() {
			ajaxHideError();
			var idRow = $(this).attr('id');
			var loginToDelete = $(this).parent().parent().find('#userLogin').html();
			if(confirm('Are you sure you want to delete the user "'+loginToDelete+'"?'))
			{
				$.ajax( getDeleteUserAJAX( loginToDelete ) );
			}
		}
	);
	
	$('#addrow').click( function() {
		ajaxHideError();
		$(this).toggle();
		
		var numberOfRows = $('table#users')[0].rows.length;
		var newRowId = numberOfRows + 1;
		var newRowId = 'row' + newRowId;
	
		$(' <tr id="'+newRowId+'">\
				<td><input id="useradd_login" value="login?" size=10></td>\
				<td><input id="useradd_password" value="password" size=10></td>\
				<td><input id="useradd_email" value="email@domain.com" size=15></td>\
				<td><input id="useradd_alias" value="alias" size=15></td>\
				<td>-</td>\
				<td><img src="plugins/UsersManager/images/ok.png" id="adduser" href="#"></td>\
	  			<td><img src="plugins/UsersManager/images/remove.png" id="cancel"></td>\
	 		</tr>')
	  			.appendTo('#users')
		;
		$('#'+newRowId).keypress( submitOnEnter );
		$('#adduser').click( function(){ $.ajax( getAddUserAJAX($('tr#'+newRowId)) ); } );
		$('#cancel').click(function() { ajaxHideError(); $(this).parents('tr').remove();  $('#addrow').toggle(); });
	
	 } );
	$('.updateAccess').click( bindUpdateAccess );
});