##// END OF EJS Templates
code cleanup
marcink -
r1961:f48bce87 beta
parent child Browse files
Show More
@@ -1,251 +1,250
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 rhodecode.controllers.admin.repos_groups
4 4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 5
6 6 repos groups controller for RhodeCode
7 7
8 8 :created_on: Mar 23, 2010
9 9 :author: marcink
10 10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
11 11 :license: GPLv3, see COPYING for more details.
12 12 """
13 13 # This program is free software: you can redistribute it and/or modify
14 14 # it under the terms of the GNU General Public License as published by
15 15 # the Free Software Foundation, either version 3 of the License, or
16 16 # (at your option) any later version.
17 17 #
18 18 # This program is distributed in the hope that it will be useful,
19 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 21 # GNU General Public License for more details.
22 22 #
23 23 # You should have received a copy of the GNU General Public License
24 24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 25
26 26 import logging
27 27 import traceback
28 28 import formencode
29 29
30 30 from formencode import htmlfill
31 31
32 32 from pylons import request, response, session, tmpl_context as c, url
33 33 from pylons.controllers.util import abort, redirect
34 34 from pylons.i18n.translation import _
35 35
36 36 from sqlalchemy.exc import IntegrityError
37 37
38 38 from rhodecode.lib import helpers as h
39 39 from rhodecode.lib.auth import LoginRequired, HasPermissionAnyDecorator
40 40 from rhodecode.lib.base import BaseController, render
41 41 from rhodecode.model.db import RepoGroup
42 42 from rhodecode.model.repos_group import ReposGroupModel
43 43 from rhodecode.model.forms import ReposGroupForm
44 44 from rhodecode.model.meta import Session
45 45
46 46 log = logging.getLogger(__name__)
47 47
48 48
49 49 class ReposGroupsController(BaseController):
50 50 """REST Controller styled on the Atom Publishing Protocol"""
51 51 # To properly map this controller, ensure your config/routing.py
52 52 # file has a resource setup:
53 53 # map.resource('repos_group', 'repos_groups')
54 54
55 55 @LoginRequired()
56 56 def __before__(self):
57 57 super(ReposGroupsController, self).__before__()
58 58
59 59 def __load_defaults(self):
60 60 c.repo_groups = RepoGroup.groups_choices()
61 61 c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
62 62
63 63 def __load_data(self, group_id):
64 64 """
65 65 Load defaults settings for edit, and update
66 66
67 67 :param group_id:
68 68 """
69 69 self.__load_defaults()
70 70
71 71 repo_group = RepoGroup.get(group_id)
72 72
73 73 data = repo_group.get_dict()
74 74
75 75 data['group_name'] = repo_group.name
76 76
77 77 return data
78 78
79 79 @HasPermissionAnyDecorator('hg.admin')
80 80 def index(self, format='html'):
81 81 """GET /repos_groups: All items in the collection"""
82 82 # url('repos_groups')
83 83
84 84 sk = lambda g: g.parents[0].group_name if g.parents else g.group_name
85 85 c.groups = sorted(RepoGroup.query().all(), key=sk)
86 86 return render('admin/repos_groups/repos_groups_show.html')
87 87
88 88 @HasPermissionAnyDecorator('hg.admin')
89 89 def create(self):
90 90 """POST /repos_groups: Create a new item"""
91 91 # url('repos_groups')
92 92 self.__load_defaults()
93 93 repos_group_form = ReposGroupForm(available_groups =
94 94 c.repo_groups_choices)()
95 95 try:
96 96 form_result = repos_group_form.to_python(dict(request.POST))
97 97 ReposGroupModel().create(form_result)
98 98 Session.commit()
99 99 h.flash(_('created repos group %s') \
100 100 % form_result['group_name'], category='success')
101 101 #TODO: in futureaction_logger(, '', '', '', self.sa)
102 102 except formencode.Invalid, errors:
103 103
104 104 return htmlfill.render(
105 105 render('admin/repos_groups/repos_groups_add.html'),
106 106 defaults=errors.value,
107 107 errors=errors.error_dict or {},
108 108 prefix_error=False,
109 109 encoding="UTF-8")
110 110 except Exception:
111 111 log.error(traceback.format_exc())
112 112 h.flash(_('error occurred during creation of repos group %s') \
113 113 % request.POST.get('group_name'), category='error')
114 114
115 115 return redirect(url('repos_groups'))
116 116
117 117 @HasPermissionAnyDecorator('hg.admin')
118 118 def new(self, format='html'):
119 119 """GET /repos_groups/new: Form to create a new item"""
120 120 # url('new_repos_group')
121 121 self.__load_defaults()
122 122 return render('admin/repos_groups/repos_groups_add.html')
123 123
124 124 @HasPermissionAnyDecorator('hg.admin')
125 125 def update(self, id):
126 126 """PUT /repos_groups/id: Update an existing item"""
127 127 # Forms posted to this method should contain a hidden field:
128 128 # <input type="hidden" name="_method" value="PUT" />
129 129 # Or using helpers:
130 130 # h.form(url('repos_group', id=ID),
131 131 # method='put')
132 132 # url('repos_group', id=ID)
133 133
134 134 self.__load_defaults()
135 135 c.repos_group = RepoGroup.get(id)
136 136
137 137 repos_group_form = ReposGroupForm(edit=True,
138 138 old_data=c.repos_group.get_dict(),
139 139 available_groups=
140 140 c.repo_groups_choices)()
141 141 try:
142 142 form_result = repos_group_form.to_python(dict(request.POST))
143 143 ReposGroupModel().update(id, form_result)
144 144 Session.commit()
145 145 h.flash(_('updated repos group %s') \
146 146 % form_result['group_name'], category='success')
147 147 #TODO: in futureaction_logger(, '', '', '', self.sa)
148 148 except formencode.Invalid, errors:
149 149
150 150 return htmlfill.render(
151 151 render('admin/repos_groups/repos_groups_edit.html'),
152 152 defaults=errors.value,
153 153 errors=errors.error_dict or {},
154 154 prefix_error=False,
155 155 encoding="UTF-8")
156 156 except Exception:
157 157 log.error(traceback.format_exc())
158 158 h.flash(_('error occurred during update of repos group %s') \
159 159 % request.POST.get('group_name'), category='error')
160 160
161 161 return redirect(url('repos_groups'))
162 162
163
164 163 @HasPermissionAnyDecorator('hg.admin')
165 164 def delete(self, id):
166 165 """DELETE /repos_groups/id: Delete an existing item"""
167 166 # Forms posted to this method should contain a hidden field:
168 167 # <input type="hidden" name="_method" value="DELETE" />
169 168 # Or using helpers:
170 169 # h.form(url('repos_group', id=ID),
171 170 # method='delete')
172 171 # url('repos_group', id=ID)
173 172
174 173 gr = RepoGroup.get(id)
175 174 repos = gr.repositories.all()
176 175 if repos:
177 176 h.flash(_('This group contains %s repositores and cannot be '
178 177 'deleted' % len(repos)),
179 178 category='error')
180 179 return redirect(url('repos_groups'))
181 180
182 181 try:
183 182 ReposGroupModel().delete(id)
184 183 Session.commit()
185 184 h.flash(_('removed repos group %s' % gr.group_name), category='success')
186 185 #TODO: in future action_logger(, '', '', '', self.sa)
187 186 except IntegrityError, e:
188 187 if e.message.find('groups_group_parent_id_fkey') != -1:
189 188 log.error(traceback.format_exc())
190 189 h.flash(_('Cannot delete this group it still contains '
191 190 'subgroups'),
192 191 category='warning')
193 192 else:
194 193 log.error(traceback.format_exc())
195 194 h.flash(_('error occurred during deletion of repos '
196 195 'group %s' % gr.group_name), category='error')
197 196
198 197 except Exception:
199 198 log.error(traceback.format_exc())
200 199 h.flash(_('error occurred during deletion of repos '
201 200 'group %s' % gr.group_name), category='error')
202 201
203 202 return redirect(url('repos_groups'))
204 203
205 204 def show_by_name(self, group_name):
206 205 id_ = RepoGroup.get_by_group_name(group_name).group_id
207 206 return self.show(id_)
208 207
209 208 def show(self, id, format='html'):
210 209 """GET /repos_groups/id: Show a specific item"""
211 210 # url('repos_group', id=ID)
212 211
213 212 c.group = RepoGroup.get(id)
214 213
215 214 if c.group:
216 215 c.group_repos = c.group.repositories.all()
217 216 else:
218 217 return redirect(url('home'))
219 218
220 219 #overwrite our cached list with current filter
221 220 gr_filter = c.group_repos
222 221 c.cached_repo_list = self.scm_model.get_repos(all_repos=gr_filter)
223 222
224 223 c.repos_list = c.cached_repo_list
225 224
226 225 c.repo_cnt = 0
227 226
228 227 c.groups = self.sa.query(RepoGroup).order_by(RepoGroup.group_name)\
229 228 .filter(RepoGroup.group_parent_id == id).all()
230 229
231 230 return render('admin/repos_groups/repos_groups.html')
232 231
233 232 @HasPermissionAnyDecorator('hg.admin')
234 233 def edit(self, id, format='html'):
235 234 """GET /repos_groups/id/edit: Form to edit an existing item"""
236 235 # url('edit_repos_group', id=ID)
237 236
238 237 id_ = int(id)
239 238
240 239 c.repos_group = RepoGroup.get(id_)
241 240 defaults = self.__load_data(id_)
242 241
243 242 # we need to exclude this group from the group list for editing
244 243 c.repo_groups = filter(lambda x:x[0] != id_, c.repo_groups)
245 244
246 245 return htmlfill.render(
247 246 render('admin/repos_groups/repos_groups_edit.html'),
248 247 defaults=defaults,
249 248 encoding="UTF-8",
250 249 force_defaults=False
251 250 )
@@ -1,190 +1,190
1 1 ## -*- coding: utf-8 -*-
2 2 <%inherit file="/base/base.html"/>
3 3
4 4 <%def name="title()">
5 5 ${_('My account')} ${c.rhodecode_user.username} - ${c.rhodecode_name}
6 6 </%def>
7 7
8 8 <%def name="breadcrumbs_links()">
9 9 ${_('My Account')}
10 10 </%def>
11 11
12 12 <%def name="page_nav()">
13 13 ${self.menu('admin')}
14 14 </%def>
15 15
16 16 <%def name="main()">
17 17
18 18 <div class="box box-left">
19 19 <!-- box / title -->
20 20 <div class="title">
21 21 ${self.breadcrumbs()}
22 22 </div>
23 23 <!-- end box / title -->
24 24 <div>
25 25 ${h.form(url('admin_settings_my_account_update'),method='put')}
26 26 <div class="form">
27 27
28 28 <div class="field">
29 29 <div class="gravatar_box">
30 30 <div class="gravatar"><img alt="gravatar" src="${h.gravatar_url(c.user.email)}"/></div>
31 31 <p>
32 32 %if c.use_gravatar:
33 33 <strong>${_('Change your avatar at')} <a href="http://gravatar.com">gravatar.com</a></strong>
34 34 <br/>${_('Using')} ${c.user.email}
35 35 %else:
36 36 <br/>${c.user.email}
37 37 %endif
38 38 </p>
39 39 </div>
40 40 </div>
41 41 <div class="field">
42 42 <div class="label">
43 43 <label>${_('API key')}</label> ${c.user.api_key}
44 44 </div>
45 45 </div>
46 46 <div class="fields">
47 47 <div class="field">
48 48 <div class="label">
49 49 <label for="username">${_('Username')}:</label>
50 50 </div>
51 51 <div class="input">
52 52 ${h.text('username',class_="medium")}
53 53 </div>
54 54 </div>
55 55
56 56 <div class="field">
57 57 <div class="label">
58 58 <label for="new_password">${_('New password')}:</label>
59 59 </div>
60 60 <div class="input">
61 61 ${h.password('new_password',class_="medium",autocomplete="off")}
62 62 </div>
63 63 </div>
64 64
65 65 <div class="field">
66 66 <div class="label">
67 67 <label for="password_confirmation">${_('New password confirmation')}:</label>
68 68 </div>
69 69 <div class="input">
70 70 ${h.password('password_confirmation',class_="medium",autocomplete="off")}
71 71 </div>
72 72 </div>
73 73
74 74 <div class="field">
75 75 <div class="label">
76 76 <label for="name">${_('First Name')}:</label>
77 77 </div>
78 78 <div class="input">
79 79 ${h.text('name',class_="medium")}
80 80 </div>
81 81 </div>
82 82
83 83 <div class="field">
84 84 <div class="label">
85 85 <label for="lastname">${_('Last Name')}:</label>
86 86 </div>
87 87 <div class="input">
88 88 ${h.text('lastname',class_="medium")}
89 89 </div>
90 90 </div>
91 91
92 92 <div class="field">
93 93 <div class="label">
94 94 <label for="email">${_('Email')}:</label>
95 95 </div>
96 96 <div class="input">
97 97 ${h.text('email',class_="medium")}
98 98 </div>
99 99 </div>
100 100
101 101 <div class="buttons">
102 102 ${h.submit('save',_('Save'),class_="ui-button")}
103 103 ${h.reset('reset',_('Reset'),class_="ui-button")}
104 104 </div>
105 105 </div>
106 106 </div>
107 107 ${h.end_form()}
108 108 </div>
109 109 </div>
110 110
111 111 <div class="box box-right">
112 112 <!-- box / title -->
113 113 <div class="title">
114 114 <h5>
115 115 <input class="q_filter_box" id="q_filter" size="15" type="text" name="filter" value="${_('quick filter...')}"/>
116 116 ${_('My repositories')}
117 117 </h5>
118 118 %if h.HasPermissionAny('hg.admin','hg.create.repository')():
119 119 <ul class="links">
120 120 <li>
121 121 <span>${h.link_to(_('ADD REPOSITORY'),h.url('admin_settings_create_repository'))}</span>
122 122 </li>
123 123 </ul>
124 124 %endif
125 125 </div>
126 126 <!-- end box / title -->
127 127 <div class="table">
128 128 <table>
129 129 <thead>
130 130 <tr>
131 131 <th class="left">${_('Name')}</th>
132 132 <th class="left">${_('revision')}</th>
133 133 <th colspan="2" class="left">${_('action')}</th>
134 134 </thead>
135 135 <tbody>
136 136 %if c.user_repos:
137 137 %for repo in c.user_repos:
138 138 <tr>
139 139 <td>
140 %if repo['dbrepo']['repo_type'] =='hg':
140 %if h.is_hg(repo['dbrepo']['repo_type']):
141 141 <img class="icon" title="${_('Mercurial repository')}" alt="${_('Mercurial repository')}" src="${h.url('/images/icons/hgicon.png')}"/>
142 %elif repo['dbrepo']['repo_type'] =='git':
142 %elif h.is_git(repo['dbrepo']['repo_type']):
143 143 <img class="icon" title="${_('Git repository')}" alt="${_('Git repository')}" src="${h.url('/images/icons/giticon.png')}"/>
144 144 %else:
145 145
146 146 %endif
147 147 %if repo['dbrepo']['private']:
148 148 <img class="icon" alt="${_('private')}" src="${h.url('/images/icons/lock.png')}"/>
149 149 %else:
150 150 <img class="icon" alt="${_('public')}" src="${h.url('/images/icons/lock_open.png')}"/>
151 151 %endif
152 152
153 153 ${h.link_to(repo['name'], h.url('summary_home',repo_name=repo['name']),class_="repo_name")}
154 154 %if repo['dbrepo_fork']:
155 155 <a href="${h.url('summary_home',repo_name=repo['dbrepo_fork']['repo_name'])}">
156 156 <img class="icon" alt="${_('public')}"
157 157 title="${_('Fork of')} ${repo['dbrepo_fork']['repo_name']}"
158 158 src="${h.url('/images/icons/arrow_divide.png')}"/></a>
159 159 %endif
160 160 </td>
161 161 <td><span class="tooltip" title="${repo['last_change']}">${("r%s:%s") % (repo['rev'],h.short_id(repo['tip']))}</span></td>
162 162 <td><a href="${h.url('repo_settings_home',repo_name=repo['name'])}" title="${_('edit')}"><img class="icon" alt="${_('private')}" src="${h.url('/images/icons/application_form_edit.png')}"/></a></td>
163 163 <td>
164 164 ${h.form(url('repo_settings_delete', repo_name=repo['name']),method='delete')}
165 165 ${h.submit('remove_%s' % repo['name'],'',class_="delete_icon action_button",onclick="return confirm('"+_('Confirm to delete this repository: %s') % repo['name']+"');")}
166 166 ${h.end_form()}
167 167 </td>
168 168 </tr>
169 169 %endfor
170 170 %else:
171 171 <div style="padding:5px 0px 10px 0px;">
172 172 ${_('No repositories yet')}
173 173 %if h.HasPermissionAny('hg.admin','hg.create.repository')():
174 174 ${h.link_to(_('create one now'),h.url('admin_settings_create_repository'),class_="ui-btn")}
175 175 %endif
176 176 </div>
177 177 %endif
178 178 </tbody>
179 179 </table>
180 180 </div>
181 181 </div>
182 182 <script type="text/javascript">
183 183 var nodes = YUQ('div.table tr td a.repo_name');
184 184 var target = 'q_filter';
185 185 var func = function(node){
186 186 return node.parentNode.parentNode;
187 187 }
188 188 q_filter(target,nodes,func);
189 189 </script>
190 190 </%def>
@@ -1,290 +1,280
1 1 ## -*- coding: utf-8 -*-
2 2 <%inherit file="/base/base.html"/>
3 3
4 4 <%def name="title()">
5 5 ${_('Edit users group')} ${c.users_group.users_group_name} - ${c.rhodecode_name}
6 6 </%def>
7 7
8 8 <%def name="breadcrumbs_links()">
9 9 ${h.link_to(_('Admin'),h.url('admin_home'))}
10 10 &raquo;
11 11 ${h.link_to(_('UsersGroups'),h.url('users_groups'))}
12 12 &raquo;
13 13 ${_('edit')} "${c.users_group.users_group_name}"
14 14 </%def>
15 15
16 16 <%def name="page_nav()">
17 17 ${self.menu('admin')}
18 18 </%def>
19 19
20 20 <%def name="main()">
21 21 <div class="box box-left">
22 22 <!-- box / title -->
23 23 <div class="title">
24 24 ${self.breadcrumbs()}
25 25 </div>
26 26 <!-- end box / title -->
27 27 ${h.form(url('users_group', id=c.users_group.users_group_id),method='put', id='edit_users_group')}
28 28 <div class="form">
29 29 <!-- fields -->
30 30 <div class="fields">
31 31 <div class="field">
32 32 <div class="label">
33 33 <label for="users_group_name">${_('Group name')}:</label>
34 34 </div>
35 35 <div class="input">
36 36 ${h.text('users_group_name',class_='small')}
37 37 </div>
38 38 </div>
39 39
40 40 <div class="field">
41 41 <div class="label label-checkbox">
42 42 <label for="users_group_active">${_('Active')}:</label>
43 43 </div>
44 44 <div class="checkboxes">
45 45 ${h.checkbox('users_group_active',value=True)}
46 46 </div>
47 47 </div>
48 48 <div class="field">
49 49 <div class="label">
50 50 <label for="users_group_active">${_('Members')}:</label>
51 51 </div>
52 52 <div class="select">
53 53 <table>
54 54 <tr>
55 55 <td>
56 56 <div>
57 57 <div style="float:left">
58 58 <div class="text" style="padding: 0px 0px 6px;">${_('Choosen group members')}</div>
59 59 ${h.select('users_group_members',[x[0] for x in c.group_members],c.group_members,multiple=True,size=8,style="min-width:210px")}
60 60 <div id="remove_all_elements" style="cursor:pointer;text-align:center">
61 61 ${_('Remove all elements')}
62 62 <img alt="remove" style="vertical-align:text-bottom" src="${h.url('/images/icons/arrow_right.png')}"/>
63 63 </div>
64 64 </div>
65 65 <div style="float:left;width:20px;padding-top:50px">
66 66 <img alt="add" id="add_element"
67 67 style="padding:2px;cursor:pointer"
68 68 src="${h.url('/images/icons/arrow_left.png')}"/>
69 69 <br />
70 70 <img alt="remove" id="remove_element"
71 71 style="padding:2px;cursor:pointer"
72 72 src="${h.url('/images/icons/arrow_right.png')}"/>
73 73 </div>
74 74 <div style="float:left">
75 75 <div class="text" style="padding: 0px 0px 6px;">${_('Available members')}</div>
76 76 ${h.select('available_members',[],c.available_members,multiple=True,size=8,style="min-width:210px")}
77 77 <div id="add_all_elements" style="cursor:pointer;text-align:center">
78 78 <img alt="add" style="vertical-align:text-bottom" src="${h.url('/images/icons/arrow_left.png')}"/>
79 79 ${_('Add all elements')}
80 80 </div>
81 81 </div>
82 82 </div>
83 83 </td>
84 84 </tr>
85 85 </table>
86 86 </div>
87 87
88 88 </div>
89 89 <div class="buttons">
90 90 ${h.submit('save',_('save'),class_="ui-button")}
91 91 </div>
92 92 </div>
93 93 </div>
94 94 ${h.end_form()}
95 95 </div>
96 96
97 97 <div class="box box-right">
98 98 <!-- box / title -->
99 99 <div class="title">
100 100 <h5>${_('Permissions')}</h5>
101 101 </div>
102 102 ${h.form(url('users_group_perm', id=c.users_group.users_group_id), method='put')}
103 103 <div class="form">
104 104 <!-- fields -->
105 105 <div class="fields">
106 106 <div class="field">
107 107 <div class="label label-checkbox">
108 108 <label for="create_repo_perm">${_('Create repositories')}:</label>
109 109 </div>
110 110 <div class="checkboxes">
111 111 ${h.checkbox('create_repo_perm',value=True)}
112 112 </div>
113 113 </div>
114 114 <div class="buttons">
115 115 ${h.submit('save',_('Save'),class_="ui-button")}
116 116 ${h.reset('reset',_('Reset'),class_="ui-button")}
117 117 </div>
118 118 </div>
119 119 </div>
120 120 ${h.end_form()}
121 121 </div>
122 122
123 123 <div class="box box-right">
124 124 <!-- box / title -->
125 125 <div class="title">
126 126 <h5>${_('Group members')}</h5>
127 127 </div>
128 128 <div class="group_members_wrap">
129 129 <ul class="group_members">
130 130 %for user in c.group_members_obj:
131 131 <li>
132 132 <div class="group_member">
133 133 <div class="gravatar"><img alt="gravatar" src="${h.gravatar_url(user.email,24)}"/> </div>
134 134 <div>${user.username}</div>
135 135 <div>${user.full_name}</div>
136 136 </div>
137 137 </li>
138 138 %endfor
139 139 </ul>
140 140 </div>
141 141 </div>
142 142 <script type="text/javascript">
143 143 YAHOO.util.Event.onDOMReady(function(){
144 144 var D = YAHOO.util.Dom;
145 145 var E = YAHOO.util.Event;
146 146
147 147 //definition of containers ID's
148 148 var available_container = 'available_members';
149 149 var selected_container = 'users_group_members';
150 150
151 151 //form containing containers id
152 152 var form_id = 'edit_users_group';
153 153
154 154 //temp container for selected storage.
155 155 var cache = new Array();
156 156 var av_cache = new Array();
157 157 var c = D.get(selected_container);
158 158 var ac = D.get(available_container);
159 159
160 160 //get only selected options for further fullfilment
161 161 for(var i = 0;node =c.options[i];i++){
162 162 if(node.selected){
163 163 //push selected to my temp storage left overs :)
164 164 cache.push(node);
165 165 }
166 166 }
167 167
168 //clear 'selected' select
169 //c.options.length = 0;
170
171 //fill it with remembered options
172 //for(var i = 0;node = cache[i];i++){
173 // c.options[i]=new Option(node.text, node.value, false, false);
174 //}
175
176
177 168 //get all available options to cache
178 169 for(var i = 0;node =ac.options[i];i++){
179 170 //push selected to my temp storage left overs :)
180 171 av_cache.push(node);
181 172 }
182 173
183 174 //fill available only with those not in choosen
184 175 ac.options.length=0;
185 176 tmp_cache = new Array();
186 177
187 178 for(var i = 0;node = av_cache[i];i++){
188 179 var add = true;
189 180 for(var i2 = 0;node_2 = cache[i2];i2++){
190 181 if(node.value == node_2.value){
191 182 add=false;
192 183 break;
193 184 }
194 185 }
195 186 if(add){
196 187 tmp_cache.push(new Option(node.text, node.value, false, false));
197 188 }
198 189 }
199 190
200 191 for(var i = 0;node = tmp_cache[i];i++){
201 192 ac.options[i] = node;
202 193 }
203 194
204 195 function prompts_action_callback(e){
205 196
206 197 var choosen = D.get(selected_container);
207 198 var available = D.get(available_container);
208 199
209 200 //get checked and unchecked options from field
210 201 function get_checked(from_field){
211 202 //temp container for storage.
212 203 var sel_cache = new Array();
213 204 var oth_cache = new Array();
214 205
215 206 for(var i = 0;node = from_field.options[i];i++){
216 207 if(node.selected){
217 208 //push selected fields :)
218 209 sel_cache.push(node);
219 210 }
220 211 else{
221 212 oth_cache.push(node)
222 213 }
223 214 }
224 215
225 216 return [sel_cache,oth_cache]
226 217 }
227 218
228 219 //fill the field with given options
229 220 function fill_with(field,options){
230 221 //clear firtst
231 222 field.options.length=0;
232 223 for(var i = 0;node = options[i];i++){
233 224 field.options[i]=new Option(node.text, node.value,
234 225 false, false);
235 226 }
236 227
237 228 }
238 229 //adds to current field
239 230 function add_to(field,options){
240 231 for(var i = 0;node = options[i];i++){
241 232 field.appendChild(new Option(node.text, node.value,
242 233 false, false));
243 234 }
244 235 }
245 236
246 237 // add action
247 238 if (this.id=='add_element'){
248 239 var c = get_checked(available);
249 240 add_to(choosen,c[0]);
250 241 fill_with(available,c[1]);
251 242 }
252 243 // remove action
253 244 if (this.id=='remove_element'){
254 245 var c = get_checked(choosen);
255 246 add_to(available,c[0]);
256 247 fill_with(choosen,c[1]);
257 248 }
258 249 // add all elements
259 250 if(this.id=='add_all_elements'){
260 251 for(var i=0; node = available.options[i];i++){
261 252 choosen.appendChild(new Option(node.text,
262 253 node.value, false, false));
263 254 }
264 255 available.options.length = 0;
265 256 }
266 257 //remove all elements
267 258 if(this.id=='remove_all_elements'){
268 259 for(var i=0; node = choosen.options[i];i++){
269 260 available.appendChild(new Option(node.text,
270 261 node.value, false, false));
271 262 }
272 263 choosen.options.length = 0;
273 264 }
274 265
275 266 }
276 267
277
278 268 E.addListener(['add_element','remove_element',
279 269 'add_all_elements','remove_all_elements'],'click',
280 270 prompts_action_callback)
281 271
282 272 E.addListener(form_id,'submit',function(){
283 273 var choosen = D.get(selected_container);
284 274 for (var i = 0; i < choosen.options.length; i++) {
285 275 choosen.options[i].selected = 'selected';
286 276 }
287 })
277 });
288 278 });
289 279 </script>
290 280 </%def>
General Comments 0
You need to be logged in to leave comments. Login now