Show More
The requested changes are too big and content was truncated. Show full diff
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
@@ -1,188 +1,190 b'' | |||||
1 | <div class="panel panel-default"> |
|
1 | <div class="panel panel-default"> | |
2 | <div class="panel-heading"> |
|
2 | <div class="panel-heading"> | |
3 | <h3 class="panel-title">${_('Authentication Tokens')}</h3> |
|
3 | <h3 class="panel-title">${_('Authentication Tokens')}</h3> | |
4 | </div> |
|
4 | </div> | |
5 | <div class="panel-body"> |
|
5 | <div class="panel-body"> | |
6 | <div class="apikeys_wrap"> |
|
6 | <div class="apikeys_wrap"> | |
7 | <p> |
|
7 | <p> | |
8 | ${_('Each token can have a role. Token with a role can be used only in given context, ' |
|
8 | ${_('Authentication tokens can be used to interact with the API, or VCS-over-http. ' | |
|
9 | 'Each token can have a role. Token with a role can be used only in given context, ' | |||
9 | 'e.g. VCS tokens can be used together with the authtoken auth plugin for git/hg/svn operations only.')} |
|
10 | 'e.g. VCS tokens can be used together with the authtoken auth plugin for git/hg/svn operations only.')} | |
10 | </p> |
|
11 | </p> | |
11 | <table class="rctable auth_tokens"> |
|
12 | <table class="rctable auth_tokens"> | |
12 | <tr> |
|
13 | <tr> | |
13 | <th>${_('Token')}</th> |
|
14 | <th>${_('Token')}</th> | |
14 | <th>${_('Scope')}</th> |
|
|||
15 | <th>${_('Description')}</th> |
|
15 | <th>${_('Description')}</th> | |
16 | <th>${_('Role')}</th> |
|
16 | <th>${_('Role')}</th> | |
|
17 | <th>${_('Repository Scope')}</th> | |||
17 | <th>${_('Expiration')}</th> |
|
18 | <th>${_('Expiration')}</th> | |
18 | <th>${_('Action')}</th> |
|
19 | <th>${_('Action')}</th> | |
19 | </tr> |
|
20 | </tr> | |
20 | %if c.user_auth_tokens: |
|
21 | %if c.user_auth_tokens: | |
21 | %for auth_token in c.user_auth_tokens: |
|
22 | %for auth_token in c.user_auth_tokens: | |
22 | <tr class="${'expired' if auth_token.expired else ''}"> |
|
23 | <tr class="${('expired' if auth_token.expired else '')}"> | |
23 | <td class="truncate-wrap td-authtoken"> |
|
24 | <td class="truncate-wrap td-authtoken"> | |
24 | <div class="user_auth_tokens truncate autoexpand"> |
|
25 | <div class="user_auth_tokens truncate autoexpand"> | |
25 | <code>${auth_token.api_key}</code> |
|
26 | <code>${auth_token.api_key}</code> | |
26 | </div> |
|
27 | </div> | |
27 | </td> |
|
28 | </td> | |
28 | <td class="td">${auth_token.scope_humanized}</td> |
|
|||
29 | <td class="td-wrap">${auth_token.description}</td> |
|
29 | <td class="td-wrap">${auth_token.description}</td> | |
30 | <td class="td-tags"> |
|
30 | <td class="td-tags"> | |
31 | <span class="tag disabled">${auth_token.role_humanized}</span> |
|
31 | <span class="tag disabled">${auth_token.role_humanized}</span> | |
32 | </td> |
|
32 | </td> | |
|
33 | <td class="td">${auth_token.scope_humanized}</td> | |||
33 | <td class="td-exp"> |
|
34 | <td class="td-exp"> | |
34 | %if auth_token.expires == -1: |
|
35 | %if auth_token.expires == -1: | |
35 | ${_('never')} |
|
36 | ${_('never')} | |
36 | %else: |
|
37 | %else: | |
37 | %if auth_token.expired: |
|
38 | %if auth_token.expired: | |
38 | <span style="text-decoration: line-through">${h.age_component(h.time_to_utcdatetime(auth_token.expires))}</span> |
|
39 | <span style="text-decoration: line-through">${h.age_component(h.time_to_utcdatetime(auth_token.expires))}</span> | |
39 | %else: |
|
40 | %else: | |
40 | ${h.age_component(h.time_to_utcdatetime(auth_token.expires))} |
|
41 | ${h.age_component(h.time_to_utcdatetime(auth_token.expires))} | |
41 | %endif |
|
42 | %endif | |
42 | %endif |
|
43 | %endif | |
43 | </td> |
|
44 | </td> | |
44 | <td class="td-action"> |
|
45 | <td class="td-action"> | |
45 | ${h.secure_form(h.route_path('my_account_auth_tokens_delete'), request=request)} |
|
46 | ${h.secure_form(h.route_path('my_account_auth_tokens_delete'), request=request)} | |
46 | ${h.hidden('del_auth_token', auth_token.user_api_key_id)} |
|
47 | ${h.hidden('del_auth_token', auth_token.user_api_key_id)} | |
47 | <button class="btn btn-link btn-danger" type="submit" |
|
48 | <button class="btn btn-link btn-danger" type="submit" | |
48 | onclick="return confirm('${_('Confirm to remove this auth token: %s') % auth_token.token_obfuscated}');"> |
|
49 | onclick="return confirm('${_('Confirm to remove this auth token: %s') % auth_token.token_obfuscated}');"> | |
49 | ${_('Delete')} |
|
50 | ${_('Delete')} | |
50 | </button> |
|
51 | </button> | |
51 | ${h.end_form()} |
|
52 | ${h.end_form()} | |
52 | </td> |
|
53 | </td> | |
53 | </tr> |
|
54 | </tr> | |
54 | %endfor |
|
55 | %endfor | |
55 | %else: |
|
56 | %else: | |
56 | <tr><td><div class="ip">${_('No additional auth tokens specified')}</div></td></tr> |
|
57 | <tr><td><div class="ip">${_('No additional auth tokens specified')}</div></td></tr> | |
57 | %endif |
|
58 | %endif | |
58 | </table> |
|
59 | </table> | |
59 | </div> |
|
60 | </div> | |
60 |
|
61 | |||
61 |
|
|
62 | <div class="user_auth_tokens"> | |
62 |
|
|
63 | ${h.secure_form(h.route_path('my_account_auth_tokens_add'), request=request)} | |
63 |
|
|
64 | <div class="form form-vertical"> | |
64 |
|
|
65 | <!-- fields --> | |
65 |
|
|
66 | <div class="fields"> | |
66 |
|
|
67 | <div class="field"> | |
67 |
|
|
68 | <div class="label"> | |
68 |
|
|
69 | <label for="new_email">${_('New authentication token')}:</label> | |
69 |
|
|
70 | </div> | |
70 |
|
|
71 | <div class="input"> | |
71 |
|
|
72 | ${h.text('description', class_='medium', placeholder=_('Description'))} | |
72 |
|
|
73 | ${h.hidden('lifetime')} | |
73 |
|
|
74 | ${h.select('role', '', c.role_options)} | |
74 |
|
75 | |||
75 |
|
|
76 | % if c.allow_scoped_tokens: | |
76 |
|
|
77 | ${h.hidden('scope_repo_id')} | |
77 |
|
|
78 | % else: | |
78 |
|
|
79 | ${h.select('scope_repo_id_disabled', '', ['Scopes available in EE edition'], disabled='disabled')} | |
79 |
|
|
80 | % endif | |
80 | </div> |
|
|||
81 | <p class="help-block"> |
|
|||
82 | ${_('Repository scope works only with tokens with VCS type.')} |
|
|||
83 | </p> |
|
|||
84 | </div> |
|
|||
85 | <div class="buttons"> |
|
|||
86 | ${h.submit('save',_('Add'),class_="btn")} |
|
|||
87 | ${h.reset('reset',_('Reset'),class_="btn")} |
|
|||
88 | </div> |
|
81 | </div> | |
|
82 | <p class="help-block"> | |||
|
83 | ${_('Repository scope works only with tokens with VCS type.')} | |||
|
84 | </p> | |||
|
85 | </div> | |||
|
86 | <div class="buttons"> | |||
|
87 | ${h.submit('save',_('Add'),class_="btn")} | |||
|
88 | ${h.reset('reset',_('Reset'),class_="btn")} | |||
89 | </div> |
|
89 | </div> | |
90 | </div> |
|
90 | </div> | |
91 | ${h.end_form()} |
|
|||
92 | </div> |
|
91 | </div> | |
|
92 | ${h.end_form()} | |||
|
93 | </div> | |||
93 | </div> |
|
94 | </div> | |
94 | </div> |
|
95 | </div> | |
|
96 | ||||
95 | <script> |
|
97 | <script> | |
96 | $(document).ready(function(){ |
|
98 | $(document).ready(function(){ | |
97 |
|
99 | |||
98 | var select2Options = { |
|
100 | var select2Options = { | |
99 | 'containerCssClass': "drop-menu", |
|
101 | 'containerCssClass': "drop-menu", | |
100 | 'dropdownCssClass': "drop-menu-dropdown", |
|
102 | 'dropdownCssClass': "drop-menu-dropdown", | |
101 | 'dropdownAutoWidth': true |
|
103 | 'dropdownAutoWidth': true | |
102 | }; |
|
104 | }; | |
103 | $("#role").select2(select2Options); |
|
105 | $("#role").select2(select2Options); | |
104 |
|
106 | |||
105 | var preloadData = { |
|
107 | var preloadData = { | |
106 | results: [ |
|
108 | results: [ | |
107 | % for entry in c.lifetime_values: |
|
109 | % for entry in c.lifetime_values: | |
108 | {id:${entry[0]}, text:"${entry[1]}"}${'' if loop.last else ','} |
|
110 | {id:${entry[0]}, text:"${entry[1]}"}${'' if loop.last else ','} | |
109 | % endfor |
|
111 | % endfor | |
110 | ] |
|
112 | ] | |
111 | }; |
|
113 | }; | |
112 |
|
114 | |||
113 | $("#lifetime").select2({ |
|
115 | $("#lifetime").select2({ | |
114 | containerCssClass: "drop-menu", |
|
116 | containerCssClass: "drop-menu", | |
115 | dropdownCssClass: "drop-menu-dropdown", |
|
117 | dropdownCssClass: "drop-menu-dropdown", | |
116 | dropdownAutoWidth: true, |
|
118 | dropdownAutoWidth: true, | |
117 | data: preloadData, |
|
119 | data: preloadData, | |
118 | placeholder: "${_('Select or enter expiration date')}", |
|
120 | placeholder: "${_('Select or enter expiration date')}", | |
119 | query: function(query) { |
|
121 | query: function(query) { | |
120 | feedLifetimeOptions(query, preloadData); |
|
122 | feedLifetimeOptions(query, preloadData); | |
121 | } |
|
123 | } | |
122 | }); |
|
124 | }); | |
123 |
|
125 | |||
124 |
|
126 | |||
125 | var repoFilter = function(data) { |
|
127 | var repoFilter = function(data) { | |
126 | var results = []; |
|
128 | var results = []; | |
127 |
|
129 | |||
128 | if (!data.results[0]) { |
|
130 | if (!data.results[0]) { | |
129 | return data |
|
131 | return data | |
130 | } |
|
132 | } | |
131 |
|
133 | |||
132 | $.each(data.results[0].children, function() { |
|
134 | $.each(data.results[0].children, function() { | |
133 | // replace name to ID for submision |
|
135 | // replace name to ID for submision | |
134 | this.id = this.repo_id; |
|
136 | this.id = this.repo_id; | |
135 | results.push(this); |
|
137 | results.push(this); | |
136 | }); |
|
138 | }); | |
137 |
|
139 | |||
138 | data.results[0].children = results; |
|
140 | data.results[0].children = results; | |
139 | return data; |
|
141 | return data; | |
140 | }; |
|
142 | }; | |
141 |
|
143 | |||
142 | $("#scope_repo_id_disabled").select2(select2Options); |
|
144 | $("#scope_repo_id_disabled").select2(select2Options); | |
143 |
|
145 | |||
144 | var selectVcsScope = function() { |
|
146 | var selectVcsScope = function() { | |
145 | // select vcs scope and disable input |
|
147 | // select vcs scope and disable input | |
146 | $("#role").select2("val", "${c.role_vcs}").trigger('change'); |
|
148 | $("#role").select2("val", "${c.role_vcs}").trigger('change'); | |
147 | $("#role").select2("readonly", true) |
|
149 | $("#role").select2("readonly", true) | |
148 | }; |
|
150 | }; | |
149 |
|
151 | |||
150 | $("#scope_repo_id").select2({ |
|
152 | $("#scope_repo_id").select2({ | |
151 | cachedDataSource: {}, |
|
153 | cachedDataSource: {}, | |
152 | minimumInputLength: 2, |
|
154 | minimumInputLength: 2, | |
153 | placeholder: "${_('repository scope')}", |
|
155 | placeholder: "${_('repository scope')}", | |
154 | dropdownAutoWidth: true, |
|
156 | dropdownAutoWidth: true, | |
155 | containerCssClass: "drop-menu", |
|
157 | containerCssClass: "drop-menu", | |
156 | dropdownCssClass: "drop-menu-dropdown", |
|
158 | dropdownCssClass: "drop-menu-dropdown", | |
157 | formatResult: formatRepoResult, |
|
159 | formatResult: formatRepoResult, | |
158 | query: $.debounce(250, function(query){ |
|
160 | query: $.debounce(250, function(query){ | |
159 | self = this; |
|
161 | self = this; | |
160 | var cacheKey = query.term; |
|
162 | var cacheKey = query.term; | |
161 | var cachedData = self.cachedDataSource[cacheKey]; |
|
163 | var cachedData = self.cachedDataSource[cacheKey]; | |
162 |
|
164 | |||
163 | if (cachedData) { |
|
165 | if (cachedData) { | |
164 | query.callback({results: cachedData.results}); |
|
166 | query.callback({results: cachedData.results}); | |
165 | } else { |
|
167 | } else { | |
166 | $.ajax({ |
|
168 | $.ajax({ | |
167 | url: pyroutes.url('repo_list_data'), |
|
169 | url: pyroutes.url('repo_list_data'), | |
168 | data: {'query': query.term}, |
|
170 | data: {'query': query.term}, | |
169 | dataType: 'json', |
|
171 | dataType: 'json', | |
170 | type: 'GET', |
|
172 | type: 'GET', | |
171 | success: function(data) { |
|
173 | success: function(data) { | |
172 | data = repoFilter(data); |
|
174 | data = repoFilter(data); | |
173 | self.cachedDataSource[cacheKey] = data; |
|
175 | self.cachedDataSource[cacheKey] = data; | |
174 | query.callback({results: data.results}); |
|
176 | query.callback({results: data.results}); | |
175 | }, |
|
177 | }, | |
176 | error: function(data, textStatus, errorThrown) { |
|
178 | error: function(data, textStatus, errorThrown) { | |
177 | alert("Error while fetching entries.\nError code {0} ({1}).".format(data.status, data.statusText)); |
|
179 | alert("Error while fetching entries.\nError code {0} ({1}).".format(data.status, data.statusText)); | |
178 | } |
|
180 | } | |
179 | }) |
|
181 | }) | |
180 | } |
|
182 | } | |
181 | }) |
|
183 | }) | |
182 | }); |
|
184 | }); | |
183 | $("#scope_repo_id").on('select2-selecting', function(e){ |
|
185 | $("#scope_repo_id").on('select2-selecting', function(e){ | |
184 | selectVcsScope() |
|
186 | selectVcsScope() | |
185 | }); |
|
187 | }); | |
186 |
|
188 | |||
187 | }); |
|
189 | }); | |
188 | </script> |
|
190 | </script> |
@@ -1,186 +1,191 b'' | |||||
1 | <div class="panel panel-default"> |
|
1 | <div class="panel panel-default"> | |
2 | <div class="panel-heading"> |
|
2 | <div class="panel-heading"> | |
3 | <h3 class="panel-title">${_('Authentication Tokens')}</h3> |
|
3 | <h3 class="panel-title">${_('Authentication Tokens')}</h3> | |
4 | </div> |
|
4 | </div> | |
5 | <div class="panel-body"> |
|
5 | <div class="panel-body"> | |
6 | <div class="apikeys_wrap"> |
|
6 | <div class="apikeys_wrap"> | |
7 | <p> |
|
7 | <p> | |
8 | ${_('Each token can have a role. Token with a role can be used only in given context, ' |
|
8 | ${_('Authentication tokens can be used to interact with the API, or VCS-over-http. ' | |
|
9 | 'Each token can have a role. Token with a role can be used only in given context, ' | |||
9 | 'e.g. VCS tokens can be used together with the authtoken auth plugin for git/hg/svn operations only.')} |
|
10 | 'e.g. VCS tokens can be used together with the authtoken auth plugin for git/hg/svn operations only.')} | |
10 | </p> |
|
11 | </p> | |
11 | <table class="rctable auth_tokens"> |
|
12 | <table class="rctable auth_tokens"> | |
12 | <tr> |
|
13 | <tr> | |
13 | <th>${_('Token')}</th> |
|
14 | <th>${_('Token')}</th> | |
14 | <th>${_('Scope')}</th> |
|
|||
15 | <th>${_('Description')}</th> |
|
15 | <th>${_('Description')}</th> | |
16 | <th>${_('Role')}</th> |
|
16 | <th>${_('Role')}</th> | |
|
17 | <th>${_('Repository Scope')}</th> | |||
17 | <th>${_('Expiration')}</th> |
|
18 | <th>${_('Expiration')}</th> | |
18 | <th>${_('Action')}</th> |
|
19 | <th>${_('Action')}</th> | |
19 | </tr> |
|
20 | </tr> | |
20 | %if c.user_auth_tokens: |
|
21 | %if c.user_auth_tokens: | |
21 | %for auth_token in c.user_auth_tokens: |
|
22 | %for auth_token in c.user_auth_tokens: | |
22 | <tr class="${'expired' if auth_token.expired else ''}"> |
|
23 | <tr class="${('expired' if auth_token.expired else '')}"> | |
23 | <td class="truncate-wrap td-authtoken"><div class="user_auth_tokens truncate autoexpand"><code>${auth_token.api_key}</code></div></td> |
|
24 | <td class="truncate-wrap td-authtoken"> | |
24 |
< |
|
25 | <div class="user_auth_tokens truncate autoexpand"> | |
|
26 | <code>${auth_token.api_key}</code> | |||
|
27 | </div> | |||
|
28 | </td> | |||
25 | <td class="td-wrap">${auth_token.description}</td> |
|
29 | <td class="td-wrap">${auth_token.description}</td> | |
26 | <td class="td-tags"> |
|
30 | <td class="td-tags"> | |
27 | <span class="tag disabled">${auth_token.role_humanized}</span> |
|
31 | <span class="tag disabled">${auth_token.role_humanized}</span> | |
28 | </td> |
|
32 | </td> | |
|
33 | <td class="td">${auth_token.scope_humanized}</td> | |||
29 | <td class="td-exp"> |
|
34 | <td class="td-exp"> | |
30 | %if auth_token.expires == -1: |
|
35 | %if auth_token.expires == -1: | |
31 | ${_('never')} |
|
36 | ${_('never')} | |
32 | %else: |
|
37 | %else: | |
33 | %if auth_token.expired: |
|
38 | %if auth_token.expired: | |
34 | <span style="text-decoration: line-through">${h.age_component(h.time_to_utcdatetime(auth_token.expires))}</span> |
|
39 | <span style="text-decoration: line-through">${h.age_component(h.time_to_utcdatetime(auth_token.expires))}</span> | |
35 | %else: |
|
40 | %else: | |
36 | ${h.age_component(h.time_to_utcdatetime(auth_token.expires))} |
|
41 | ${h.age_component(h.time_to_utcdatetime(auth_token.expires))} | |
37 | %endif |
|
42 | %endif | |
38 | %endif |
|
43 | %endif | |
39 | </td> |
|
44 | </td> | |
40 | <td class="td-action"> |
|
45 | <td class="td-action"> | |
41 | ${h.secure_form(h.route_path('edit_user_auth_tokens_delete', user_id=c.user.user_id), request=request)} |
|
46 | ${h.secure_form(h.route_path('edit_user_auth_tokens_delete', user_id=c.user.user_id), request=request)} | |
42 | ${h.hidden('del_auth_token', auth_token.user_api_key_id)} |
|
47 | ${h.hidden('del_auth_token', auth_token.user_api_key_id)} | |
43 | <button class="btn btn-link btn-danger" type="submit" |
|
48 | <button class="btn btn-link btn-danger" type="submit" | |
44 | onclick="return confirm('${_('Confirm to remove this auth token: %s') % auth_token.token_obfuscated}');"> |
|
49 | onclick="return confirm('${_('Confirm to remove this auth token: %s') % auth_token.token_obfuscated}');"> | |
45 | ${_('Delete')} |
|
50 | ${_('Delete')} | |
46 | </button> |
|
51 | </button> | |
47 | ${h.end_form()} |
|
52 | ${h.end_form()} | |
48 | </td> |
|
53 | </td> | |
49 | </tr> |
|
54 | </tr> | |
50 | %endfor |
|
55 | %endfor | |
51 | %else: |
|
56 | %else: | |
52 | <tr><td><div class="ip">${_('No additional auth tokens specified')}</div></td></tr> |
|
57 | <tr><td><div class="ip">${_('No additional auth tokens specified')}</div></td></tr> | |
53 | %endif |
|
58 | %endif | |
54 | </table> |
|
59 | </table> | |
55 | </div> |
|
60 | </div> | |
56 |
|
61 | |||
57 | <div class="user_auth_tokens"> |
|
62 | <div class="user_auth_tokens"> | |
58 | ${h.secure_form(h.route_path('edit_user_auth_tokens_add', user_id=c.user.user_id), request=request)} |
|
63 | ${h.secure_form(h.route_path('edit_user_auth_tokens_add', user_id=c.user.user_id), request=request)} | |
59 | <div class="form form-vertical"> |
|
64 | <div class="form form-vertical"> | |
60 | <!-- fields --> |
|
65 | <!-- fields --> | |
61 | <div class="fields"> |
|
66 | <div class="fields"> | |
62 | <div class="field"> |
|
67 | <div class="field"> | |
63 | <div class="label"> |
|
68 | <div class="label"> | |
64 | <label for="new_email">${_('New authentication token')}:</label> |
|
69 | <label for="new_email">${_('New authentication token')}:</label> | |
65 | </div> |
|
70 | </div> | |
66 | <div class="input"> |
|
71 | <div class="input"> | |
67 | ${h.text('description', class_='medium', placeholder=_('Description'))} |
|
72 | ${h.text('description', class_='medium', placeholder=_('Description'))} | |
68 | ${h.hidden('lifetime')} |
|
73 | ${h.hidden('lifetime')} | |
69 | ${h.select('role', '', c.role_options)} |
|
74 | ${h.select('role', '', c.role_options)} | |
70 |
|
75 | |||
71 | % if c.allow_scoped_tokens: |
|
76 | % if c.allow_scoped_tokens: | |
72 | ${h.hidden('scope_repo_id')} |
|
77 | ${h.hidden('scope_repo_id')} | |
73 | % else: |
|
78 | % else: | |
74 | ${h.select('scope_repo_id_disabled', '', ['Scopes available in EE edition'], disabled='disabled')} |
|
79 | ${h.select('scope_repo_id_disabled', '', ['Scopes available in EE edition'], disabled='disabled')} | |
75 | % endif |
|
80 | % endif | |
76 | </div> |
|
81 | </div> | |
77 | <p class="help-block"> |
|
82 | <p class="help-block"> | |
78 | ${_('Repository scope works only with tokens with VCS type.')} |
|
83 | ${_('Repository scope works only with tokens with VCS type.')} | |
79 | </p> |
|
84 | </p> | |
80 | </div> |
|
85 | </div> | |
81 | <div class="buttons"> |
|
86 | <div class="buttons"> | |
82 | ${h.submit('save',_('Add'),class_="btn")} |
|
87 | ${h.submit('save',_('Add'),class_="btn")} | |
83 | ${h.reset('reset',_('Reset'),class_="btn")} |
|
88 | ${h.reset('reset',_('Reset'),class_="btn")} | |
84 | </div> |
|
89 | </div> | |
85 | </div> |
|
90 | </div> | |
86 | </div> |
|
91 | </div> | |
87 | ${h.end_form()} |
|
92 | ${h.end_form()} | |
88 | </div> |
|
93 | </div> | |
89 | </div> |
|
94 | </div> | |
90 | </div> |
|
95 | </div> | |
91 |
|
96 | |||
92 | <script> |
|
97 | <script> | |
93 |
|
98 | |||
94 | $(document).ready(function(){ |
|
99 | $(document).ready(function(){ | |
95 |
|
100 | |||
96 | var select2Options = { |
|
101 | var select2Options = { | |
97 | 'containerCssClass': "drop-menu", |
|
102 | 'containerCssClass': "drop-menu", | |
98 | 'dropdownCssClass': "drop-menu-dropdown", |
|
103 | 'dropdownCssClass': "drop-menu-dropdown", | |
99 | 'dropdownAutoWidth': true |
|
104 | 'dropdownAutoWidth': true | |
100 | }; |
|
105 | }; | |
101 | $("#role").select2(select2Options); |
|
106 | $("#role").select2(select2Options); | |
102 |
|
107 | |||
103 | var preloadData = { |
|
108 | var preloadData = { | |
104 | results: [ |
|
109 | results: [ | |
105 | % for entry in c.lifetime_values: |
|
110 | % for entry in c.lifetime_values: | |
106 | {id:${entry[0]}, text:"${entry[1]}"}${'' if loop.last else ','} |
|
111 | {id:${entry[0]}, text:"${entry[1]}"}${'' if loop.last else ','} | |
107 | % endfor |
|
112 | % endfor | |
108 | ] |
|
113 | ] | |
109 | }; |
|
114 | }; | |
110 |
|
115 | |||
111 | $("#lifetime").select2({ |
|
116 | $("#lifetime").select2({ | |
112 | containerCssClass: "drop-menu", |
|
117 | containerCssClass: "drop-menu", | |
113 | dropdownCssClass: "drop-menu-dropdown", |
|
118 | dropdownCssClass: "drop-menu-dropdown", | |
114 | dropdownAutoWidth: true, |
|
119 | dropdownAutoWidth: true, | |
115 | data: preloadData, |
|
120 | data: preloadData, | |
116 | placeholder: "${_('Select or enter expiration date')}", |
|
121 | placeholder: "${_('Select or enter expiration date')}", | |
117 | query: function(query) { |
|
122 | query: function(query) { | |
118 | feedLifetimeOptions(query, preloadData); |
|
123 | feedLifetimeOptions(query, preloadData); | |
119 | } |
|
124 | } | |
120 | }); |
|
125 | }); | |
121 |
|
126 | |||
122 |
|
127 | |||
123 | var repoFilter = function(data) { |
|
128 | var repoFilter = function(data) { | |
124 | var results = []; |
|
129 | var results = []; | |
125 |
|
130 | |||
126 | if (!data.results[0]) { |
|
131 | if (!data.results[0]) { | |
127 | return data |
|
132 | return data | |
128 | } |
|
133 | } | |
129 |
|
134 | |||
130 | $.each(data.results[0].children, function() { |
|
135 | $.each(data.results[0].children, function() { | |
131 | // replace name to ID for submision |
|
136 | // replace name to ID for submision | |
132 | this.id = this.repo_id; |
|
137 | this.id = this.repo_id; | |
133 | results.push(this); |
|
138 | results.push(this); | |
134 | }); |
|
139 | }); | |
135 |
|
140 | |||
136 | data.results[0].children = results; |
|
141 | data.results[0].children = results; | |
137 | return data; |
|
142 | return data; | |
138 | }; |
|
143 | }; | |
139 |
|
144 | |||
140 | $("#scope_repo_id_disabled").select2(select2Options); |
|
145 | $("#scope_repo_id_disabled").select2(select2Options); | |
141 |
|
146 | |||
142 | var selectVcsScope = function() { |
|
147 | var selectVcsScope = function() { | |
143 | // select vcs scope and disable input |
|
148 | // select vcs scope and disable input | |
144 | $("#role").select2("val", "${c.role_vcs}").trigger('change'); |
|
149 | $("#role").select2("val", "${c.role_vcs}").trigger('change'); | |
145 | $("#role").select2("readonly", true) |
|
150 | $("#role").select2("readonly", true) | |
146 | }; |
|
151 | }; | |
147 |
|
152 | |||
148 | $("#scope_repo_id").select2({ |
|
153 | $("#scope_repo_id").select2({ | |
149 | cachedDataSource: {}, |
|
154 | cachedDataSource: {}, | |
150 | minimumInputLength: 2, |
|
155 | minimumInputLength: 2, | |
151 | placeholder: "${_('repository scope')}", |
|
156 | placeholder: "${_('repository scope')}", | |
152 | dropdownAutoWidth: true, |
|
157 | dropdownAutoWidth: true, | |
153 | containerCssClass: "drop-menu", |
|
158 | containerCssClass: "drop-menu", | |
154 | dropdownCssClass: "drop-menu-dropdown", |
|
159 | dropdownCssClass: "drop-menu-dropdown", | |
155 | formatResult: formatRepoResult, |
|
160 | formatResult: formatRepoResult, | |
156 | query: $.debounce(250, function(query){ |
|
161 | query: $.debounce(250, function(query){ | |
157 | self = this; |
|
162 | self = this; | |
158 | var cacheKey = query.term; |
|
163 | var cacheKey = query.term; | |
159 | var cachedData = self.cachedDataSource[cacheKey]; |
|
164 | var cachedData = self.cachedDataSource[cacheKey]; | |
160 |
|
165 | |||
161 | if (cachedData) { |
|
166 | if (cachedData) { | |
162 | query.callback({results: cachedData.results}); |
|
167 | query.callback({results: cachedData.results}); | |
163 | } else { |
|
168 | } else { | |
164 | $.ajax({ |
|
169 | $.ajax({ | |
165 | url: pyroutes.url('repo_list_data'), |
|
170 | url: pyroutes.url('repo_list_data'), | |
166 | data: {'query': query.term}, |
|
171 | data: {'query': query.term}, | |
167 | dataType: 'json', |
|
172 | dataType: 'json', | |
168 | type: 'GET', |
|
173 | type: 'GET', | |
169 | success: function(data) { |
|
174 | success: function(data) { | |
170 | data = repoFilter(data); |
|
175 | data = repoFilter(data); | |
171 | self.cachedDataSource[cacheKey] = data; |
|
176 | self.cachedDataSource[cacheKey] = data; | |
172 | query.callback({results: data.results}); |
|
177 | query.callback({results: data.results}); | |
173 | }, |
|
178 | }, | |
174 | error: function(data, textStatus, errorThrown) { |
|
179 | error: function(data, textStatus, errorThrown) { | |
175 | alert("Error while fetching entries.\nError code {0} ({1}).".format(data.status, data.statusText)); |
|
180 | alert("Error while fetching entries.\nError code {0} ({1}).".format(data.status, data.statusText)); | |
176 | } |
|
181 | } | |
177 | }) |
|
182 | }) | |
178 | } |
|
183 | } | |
179 | }) |
|
184 | }) | |
180 | }); |
|
185 | }); | |
181 | $("#scope_repo_id").on('select2-selecting', function(e){ |
|
186 | $("#scope_repo_id").on('select2-selecting', function(e){ | |
182 | selectVcsScope() |
|
187 | selectVcsScope() | |
183 | }); |
|
188 | }); | |
184 |
|
189 | |||
185 | }); |
|
190 | }); | |
186 | </script> |
|
191 | </script> |
General Comments 0
You need to be logged in to leave comments.
Login now