178 def entity_for_key(self, key): |
178 def entity_for_key(self, key): |
179 values = self.defined_keys |
179 values = self.defined_keys |
180 if key in values: |
180 if key in values: |
181 entity = self.cwprops_rset.get_entity(values[key], 0) |
181 entity = self.cwprops_rset.get_entity(values[key], 0) |
182 else: |
182 else: |
183 entity = self.vreg.etype_class('CWProperty')(self.req, None, None) |
183 entity = self.vreg['etypes'].etype_class('CWProperty')(self.req) |
184 entity.eid = self.req.varmaker.next() |
184 entity.eid = self.req.varmaker.next() |
185 entity['pkey'] = key |
185 entity['pkey'] = key |
186 entity['value'] = self.vreg.property_value(key) |
186 entity['value'] = self.vreg.property_value(key) |
187 return entity |
187 return entity |
188 |
188 |
189 def form(self, formid, keys, splitlabel=False): |
189 def form(self, formid, keys, splitlabel=False): |
190 buttons = [SubmitButton()] |
190 buttons = [SubmitButton()] |
191 form = self.vreg.select('forms', 'composite', self.req, |
191 form = self.vreg['forms'].select( |
192 domid=formid, action=self.build_url(), |
192 'composite', self.req, domid=formid, action=self.build_url(), |
193 form_buttons=buttons, |
193 form_buttons=buttons, |
194 onsubmit="return validatePrefsForm('%s')" % formid, |
194 onsubmit="return validatePrefsForm('%s')" % formid, |
195 submitmsg=self.req._('changes applied')) |
195 submitmsg=self.req._('changes applied')) |
196 path = self.req.relative_path() |
196 path = self.req.relative_path() |
197 if '?' in path: |
197 if '?' in path: |
198 path, params = path.split('?', 1) |
198 path, params = path.split('?', 1) |
199 form.form_add_hidden('__redirectparams', params) |
199 form.form_add_hidden('__redirectparams', params) |
200 form.form_add_hidden('__redirectpath', path) |
200 form.form_add_hidden('__redirectpath', path) |
201 for key in keys: |
201 for key in keys: |
202 self.form_row(form, key, splitlabel) |
202 self.form_row(form, key, splitlabel) |
203 renderer = self.vreg.select('formrenderers', 'cwproperties', self.req, |
203 renderer = self.vreg['formrenderers'].select('cwproperties', self.req, |
204 display_progress_div=False) |
204 display_progress_div=False) |
205 return form.form_render(renderer=renderer) |
205 return form.form_render(renderer=renderer) |
206 |
206 |
207 def form_row(self, form, key, splitlabel): |
207 def form_row(self, form, key, splitlabel): |
208 entity = self.entity_for_key(key) |
208 entity = self.entity_for_key(key) |
209 if splitlabel: |
209 if splitlabel: |
210 label = key.split('.')[-1] |
210 label = key.split('.')[-1] |
211 else: |
211 else: |
212 label = key |
212 label = key |
213 subform = self.vreg.select('forms', 'base', self.req, entity=entity, |
213 subform = self.vreg['forms'].select('base', self.req, entity=entity, |
214 mainform=False) |
214 mainform=False) |
215 subform.append_field(PropertyValueField(name='value', label=label, |
215 subform.append_field(PropertyValueField(name='value', label=label, |
216 eidparam=True)) |
216 eidparam=True)) |
217 subform.vreg = self.vreg |
217 subform.vreg = self.vreg |
218 subform.form_add_hidden('pkey', key, eidparam=True) |
218 subform.form_add_hidden('pkey', key, eidparam=True) |
219 form.form_add_subform(subform) |
219 form.form_add_subform(subform) |