##// END OF EJS Templates
user-groups: clear autocomplete after selection.
bart -
r4323:6d3eb74c default
parent child Browse files
Show More
@@ -1,190 +1,191 b''
1 ## -*- coding: utf-8 -*-
1 ## -*- coding: utf-8 -*-
2 <%namespace name="base" file="/base/base.mako"/>
2 <%namespace name="base" file="/base/base.mako"/>
3
3
4 <div class="panel panel-default">
4 <div class="panel panel-default">
5 <div class="panel-heading">
5 <div class="panel-heading">
6 <h3 class="panel-title">
6 <h3 class="panel-title">
7 <i class="icon-user-group" title="${_('User group')}"></i>
7 <i class="icon-user-group" title="${_('User group')}"></i>
8 ${h.link_to_group(c.user_group.users_group_name)}
8 ${h.link_to_group(c.user_group.users_group_name)}
9 - ${_('Settings')}
9 - ${_('Settings')}
10 </h3>
10 </h3>
11 </div>
11 </div>
12 <div class="panel-body">
12 <div class="panel-body">
13 ${h.secure_form(h.route_path('user_groups_update', user_group_id=c.user_group.users_group_id), id='edit_user_group', request=request)}
13 ${h.secure_form(h.route_path('user_groups_update', user_group_id=c.user_group.users_group_id), id='edit_user_group', request=request)}
14 <div class="form">
14 <div class="form">
15 <!-- fields -->
15 <!-- fields -->
16 <div class="fields">
16 <div class="fields">
17 <div class="field">
17 <div class="field">
18 <div class="label">
18 <div class="label">
19 <label for="users_group_name">${_('Group name')}:</label>
19 <label for="users_group_name">${_('Group name')}:</label>
20 </div>
20 </div>
21 <div class="input">
21 <div class="input">
22 ${h.text('users_group_name',class_='medium')}
22 ${h.text('users_group_name',class_='medium')}
23 </div>
23 </div>
24 </div>
24 </div>
25
25
26 <div class="field badged-field">
26 <div class="field badged-field">
27 <div class="label">
27 <div class="label">
28 <label for="user">${_('Owner')}:</label>
28 <label for="user">${_('Owner')}:</label>
29 </div>
29 </div>
30 <div class="input">
30 <div class="input">
31 <div class="badge-input-container">
31 <div class="badge-input-container">
32 <div class="user-badge">
32 <div class="user-badge">
33 ${base.gravatar_with_user(c.user_group.user.email, show_disabled=not c.user_group.user.active)}
33 ${base.gravatar_with_user(c.user_group.user.email, show_disabled=not c.user_group.user.active)}
34 </div>
34 </div>
35 <div class="badge-input-wrap">
35 <div class="badge-input-wrap">
36 ${h.text('user', class_="medium", autocomplete="off")}
36 ${h.text('user', class_="medium", autocomplete="off")}
37 </div>
37 </div>
38 </div>
38 </div>
39 <form:error name="user"/>
39 <form:error name="user"/>
40 <p class="help-block">${_('Change owner of this user group.')}</p>
40 <p class="help-block">${_('Change owner of this user group.')}</p>
41 </div>
41 </div>
42 </div>
42 </div>
43
43
44 <div class="field">
44 <div class="field">
45 <div class="label label-textarea">
45 <div class="label label-textarea">
46 <label for="user_group_description">${_('Description')}:</label>
46 <label for="user_group_description">${_('Description')}:</label>
47 </div>
47 </div>
48 <div class="textarea textarea-small editor">
48 <div class="textarea textarea-small editor">
49 ${h.textarea('user_group_description',cols=23,rows=5,class_="medium")}
49 ${h.textarea('user_group_description',cols=23,rows=5,class_="medium")}
50 <span class="help-block">${_('Short, optional description for this user group.')}</span>
50 <span class="help-block">${_('Short, optional description for this user group.')}</span>
51 </div>
51 </div>
52 </div>
52 </div>
53 <div class="field">
53 <div class="field">
54 <div class="label label-checkbox">
54 <div class="label label-checkbox">
55 <label for="users_group_active">${_('Active')}:</label>
55 <label for="users_group_active">${_('Active')}:</label>
56 </div>
56 </div>
57 <div class="checkboxes">
57 <div class="checkboxes">
58 ${h.checkbox('users_group_active',value=True)}
58 ${h.checkbox('users_group_active',value=True)}
59 </div>
59 </div>
60 </div>
60 </div>
61
61
62 <div class="field">
62 <div class="field">
63 <div class="label label-checkbox">
63 <div class="label label-checkbox">
64 <label for="users_group_active">${_('Add members')}:</label>
64 <label for="users_group_active">${_('Add members')}:</label>
65 </div>
65 </div>
66 <div class="input">
66 <div class="input">
67 ${h.text('user_group_add_members', placeholder="user/usergroup", class_="medium")}
67 ${h.text('user_group_add_members', placeholder="user/usergroup", class_="medium")}
68 </div>
68 </div>
69 </div>
69 </div>
70
70
71 <input type="hidden" name="__start__" value="user_group_members:sequence"/>
71 <input type="hidden" name="__start__" value="user_group_members:sequence"/>
72 <table id="group_members_placeholder" class="rctable group_members">
72 <table id="group_members_placeholder" class="rctable group_members">
73 <tr>
73 <tr>
74 <th>${_('Username')}</th>
74 <th>${_('Username')}</th>
75 <th>${_('Action')}</th>
75 <th>${_('Action')}</th>
76 </tr>
76 </tr>
77
77
78 % if c.group_members_obj:
78 % if c.group_members_obj:
79 % for user in c.group_members_obj:
79 % for user in c.group_members_obj:
80 <tr>
80 <tr>
81 <td id="member_user_${user.user_id}" class="td-author">
81 <td id="member_user_${user.user_id}" class="td-author">
82 <div class="group_member">
82 <div class="group_member">
83 ${base.gravatar(user.email, 16, user=user, tooltip=True)}
83 ${base.gravatar(user.email, 16, user=user, tooltip=True)}
84 <span class="username user">${h.link_to(h.person(user), h.route_path('user_edit',user_id=user.user_id))}</span>
84 <span class="username user">${h.link_to(h.person(user), h.route_path('user_edit',user_id=user.user_id))}</span>
85 <input type="hidden" name="__start__" value="member:mapping">
85 <input type="hidden" name="__start__" value="member:mapping">
86 <input type="hidden" name="member_user_id" value="${user.user_id}">
86 <input type="hidden" name="member_user_id" value="${user.user_id}">
87 <input type="hidden" name="type" value="existing" id="member_${user.user_id}">
87 <input type="hidden" name="type" value="existing" id="member_${user.user_id}">
88 <input type="hidden" name="__end__" value="member:mapping">
88 <input type="hidden" name="__end__" value="member:mapping">
89 </div>
89 </div>
90 </td>
90 </td>
91 <td class="">
91 <td class="">
92 <div class="usergroup_member_remove action_button" onclick="removeUserGroupMember(${user.user_id}, true)" style="visibility: visible;">
92 <div class="usergroup_member_remove action_button" onclick="removeUserGroupMember(${user.user_id}, true)" style="visibility: visible;">
93 <i class="icon-remove"></i>
93 <i class="icon-remove"></i>
94 </div>
94 </div>
95 </td>
95 </td>
96 </tr>
96 </tr>
97 % endfor
97 % endfor
98
98
99 % else:
99 % else:
100 <tr><td colspan="2">${_('No members yet')}</td></tr>
100 <tr><td colspan="2">${_('No members yet')}</td></tr>
101 % endif
101 % endif
102 </table>
102 </table>
103 <input type="hidden" name="__end__" value="user_group_members:sequence"/>
103 <input type="hidden" name="__end__" value="user_group_members:sequence"/>
104
104
105 <div class="buttons">
105 <div class="buttons">
106 ${h.submit('Save',_('Save'),class_="btn")}
106 ${h.submit('Save',_('Save'),class_="btn")}
107 </div>
107 </div>
108 </div>
108 </div>
109 </div>
109 </div>
110 ${h.end_form()}
110 ${h.end_form()}
111 </div>
111 </div>
112 </div>
112 </div>
113 <script>
113 <script>
114 $(document).ready(function(){
114 $(document).ready(function(){
115 $("#group_parent_id").select2({
115 $("#group_parent_id").select2({
116 'containerCssClass': "drop-menu",
116 'containerCssClass': "drop-menu",
117 'dropdownCssClass': "drop-menu-dropdown",
117 'dropdownCssClass': "drop-menu-dropdown",
118 'dropdownAutoWidth': true
118 'dropdownAutoWidth': true
119 });
119 });
120
120
121 removeUserGroupMember = function(userId){
121 removeUserGroupMember = function(userId){
122 $('#member_'+userId).val('remove');
122 $('#member_'+userId).val('remove');
123 $('#member_user_'+userId).addClass('to-delete');
123 $('#member_user_'+userId).addClass('to-delete');
124 };
124 };
125
125
126 $('#user_group_add_members').autocomplete({
126 $('#user_group_add_members').autocomplete({
127 serviceUrl: pyroutes.url('user_autocomplete_data'),
127 serviceUrl: pyroutes.url('user_autocomplete_data'),
128 minChars:2,
128 minChars:2,
129 maxHeight:400,
129 maxHeight:400,
130 width:300,
130 width:300,
131 deferRequestBy: 300, //miliseconds
131 deferRequestBy: 300, //miliseconds
132 showNoSuggestionNotice: true,
132 showNoSuggestionNotice: true,
133 params: { user_groups:true },
133 params: { user_groups:true },
134 formatResult: autocompleteFormatResult,
134 formatResult: autocompleteFormatResult,
135 lookupFilter: autocompleteFilterResult,
135 lookupFilter: autocompleteFilterResult,
136 onSelect: function(element, suggestion){
136 onSelect: function(element, suggestion){
137
137
138 function addMember(user, fromUserGroup) {
138 function addMember(user, fromUserGroup) {
139 var gravatar = user.icon_link;
139 var gravatar = user.icon_link;
140 var username = user.value_display;
140 var username = user.value_display;
141 var userLink = pyroutes.url('user_edit', {"user_id": user.id});
141 var userLink = pyroutes.url('user_edit', {"user_id": user.id});
142 var uid = user.id;
142 var uid = user.id;
143
143
144 if (fromUserGroup) {
144 if (fromUserGroup) {
145 username = username +" "+ _gettext('(from usergroup {0})'.format(fromUserGroup))
145 username = username +" "+ _gettext('(from usergroup {0})'.format(fromUserGroup))
146 }
146 }
147
147
148 var elem = $(
148 var elem = $(
149 ('<tr>'+
149 ('<tr>'+
150 '<td id="member_user_{6}" class="td-author td-author-new-entry">'+
150 '<td id="member_user_{6}" class="td-author td-author-new-entry">'+
151 '<div class="group_member">'+
151 '<div class="group_member">'+
152 '<img class="gravatar" src="{0}" height="16" width="16">'+
152 '<img class="gravatar" src="{0}" height="16" width="16">'+
153 '<span class="username user"><a href="{1}">{2}</a></span>'+
153 '<span class="username user"><a href="{1}">{2}</a></span>'+
154 '<input type="hidden" name="__start__" value="member:mapping">'+
154 '<input type="hidden" name="__start__" value="member:mapping">'+
155 '<input type="hidden" name="member_user_id" value="{3}">'+
155 '<input type="hidden" name="member_user_id" value="{3}">'+
156 '<input type="hidden" name="type" value="new" id="member_{4}">'+
156 '<input type="hidden" name="type" value="new" id="member_{4}">'+
157 '<input type="hidden" name="__end__" value="member:mapping">'+
157 '<input type="hidden" name="__end__" value="member:mapping">'+
158 '</div>'+
158 '</div>'+
159 '</td>'+
159 '</td>'+
160 '<td class="td-author-new-entry">'+
160 '<td class="td-author-new-entry">'+
161 '<div class="usergroup_member_remove action_button" onclick="removeUserGroupMember({5}, true)" style="visibility: visible;">'+
161 '<div class="usergroup_member_remove action_button" onclick="removeUserGroupMember({5}, true)" style="visibility: visible;">'+
162 '<i class="icon-remove"></i>'+
162 '<i class="icon-remove"></i>'+
163 '</div>'+
163 '</div>'+
164 '</td>'+
164 '</td>'+
165 '</tr>').format(gravatar, userLink, username,
165 '</tr>').format(gravatar, userLink, username,
166 uid, uid, uid, uid)
166 uid, uid, uid, uid)
167 );
167 );
168 $('#group_members_placeholder').append(elem)
168 $('#group_members_placeholder').append(elem)
169 }
169 }
170
170
171 if (suggestion.value_type == 'user_group') {
171 if (suggestion.value_type == 'user_group') {
172 $.getJSON(
172 $.getJSON(
173 pyroutes.url('user_group_members_data',
173 pyroutes.url('user_group_members_data',
174 {'user_group_id': suggestion.id}),
174 {'user_group_id': suggestion.id}),
175 function(data) {
175 function(data) {
176 $.each(data.members, function(idx, user) {
176 $.each(data.members, function(idx, user) {
177 addMember(user, suggestion.value)
177 addMember(user, suggestion.value)
178 });
178 });
179 }
179 }
180 );
180 );
181 } else if (suggestion.value_type == 'user') {
181 } else if (suggestion.value_type == 'user') {
182 addMember(suggestion, null);
182 addMember(suggestion, null);
183 }
183 }
184 $('#user_group_add_members').val('')
184 }
185 }
185 });
186 });
186
187
187
188
188 UsersAutoComplete('user', '${c.rhodecode_user.user_id}');
189 UsersAutoComplete('user', '${c.rhodecode_user.user_id}');
189 })
190 })
190 </script>
191 </script>
General Comments 0
You need to be logged in to leave comments. Login now