57 return self.build_url('edit') |
57 return self.build_url('edit') |
58 |
58 |
59 def __init__(self, *args, **kwargs): |
59 def __init__(self, *args, **kwargs): |
60 super(DeleteConfForm, self).__init__(*args, **kwargs) |
60 super(DeleteConfForm, self).__init__(*args, **kwargs) |
61 done = set() |
61 done = set() |
62 for entity in self.rset.entities(): |
62 for entity in self.cw_rset.entities(): |
63 if entity.eid in done: |
63 if entity.eid in done: |
64 continue |
64 continue |
65 done.add(entity.eid) |
65 done.add(entity.eid) |
66 subform = self.vreg['forms'].select('base', self.req, entity=entity, |
66 subform = self._cw.vreg['forms'].select('base', self._cw, entity=entity, |
67 mainform=False) |
67 mainform=False) |
68 self.form_add_subform(subform) |
68 self.form_add_subform(subform) |
69 |
69 |
70 |
70 |
71 class DeleteConfFormView(FormViewMixIn, EntityView): |
71 class DeleteConfFormView(FormViewMixIn, EntityView): |
76 # else we will only delete the displayed page |
76 # else we will only delete the displayed page |
77 need_navigation = False |
77 need_navigation = False |
78 |
78 |
79 def call(self, onsubmit=None): |
79 def call(self, onsubmit=None): |
80 """ask for confirmation before real deletion""" |
80 """ask for confirmation before real deletion""" |
81 req, w = self.req, self.w |
81 req, w = self._cw, self.w |
82 _ = req._ |
82 _ = req._ |
83 w(u'<script type="text/javascript">updateMessage(\'%s\');</script>\n' |
83 w(u'<script type="text/javascript">updateMessage(\'%s\');</script>\n' |
84 % _('this action is not reversible!')) |
84 % _('this action is not reversible!')) |
85 # XXX above message should have style of a warning |
85 # XXX above message should have style of a warning |
86 w(u'<h4>%s</h4>\n' % _('Do you want to delete the following element(s) ?')) |
86 w(u'<h4>%s</h4>\n' % _('Do you want to delete the following element(s) ?')) |
87 form = self.vreg['forms'].select(self.id, req, rset=self.rset, |
87 form = self._cw.vreg['forms'].select(self.__regid__, req, rset=self.cw_rset, |
88 onsubmit=onsubmit) |
88 onsubmit=onsubmit) |
89 w(u'<ul>\n') |
89 w(u'<ul>\n') |
90 for entity in self.rset.entities(): |
90 for entity in self.cw_rset.entities(): |
91 # don't use outofcontext view or any other that may contain inline edition form |
91 # don't use outofcontext view or any other that may contain inline edition form |
92 w(u'<li>%s</li>' % tags.a(entity.view('textoutofcontext'), |
92 w(u'<li>%s</li>' % tags.a(entity.view('textoutofcontext'), |
93 href=entity.absolute_url())) |
93 href=entity.absolute_url())) |
94 w(u'</ul>\n') |
94 w(u'</ul>\n') |
95 w(form.form_render()) |
95 w(form.form_render()) |
122 if eschema.cardinality(rschema, role) in '+*': |
122 if eschema.cardinality(rschema, role) in '+*': |
123 return self._many_rvid |
123 return self._many_rvid |
124 return self._one_rvid |
124 return self._one_rvid |
125 |
125 |
126 def _build_landing_zone(self, lzone): |
126 def _build_landing_zone(self, lzone): |
127 return lzone or self._defaultlandingzone % {'msg' : xml_escape(self.req._(self._landingzonemsg))} |
127 return lzone or self._defaultlandingzone % {'msg' : xml_escape(self._cw._(self._landingzonemsg))} |
128 |
128 |
129 def _build_renderer(self, entity, rtype, role): |
129 def _build_renderer(self, entity, rtype, role): |
130 return self.vreg['formrenderers'].select( |
130 return self._cw.vreg['formrenderers'].select( |
131 'base', self.req, entity=entity, display_label=False, |
131 'base', self._cw, entity=entity, display_label=False, |
132 display_help=False, display_fields=[(rtype, role)], table_class='', |
132 display_help=False, display_fields=[(rtype, role)], table_class='', |
133 button_bar_class='buttonbar', display_progress_div=False) |
133 button_bar_class='buttonbar', display_progress_div=False) |
134 |
134 |
135 def _build_form(self, entity, rtype, role, formid, default, onsubmit, reload, |
135 def _build_form(self, entity, rtype, role, formid, default, onsubmit, reload, |
136 extradata=None, **formargs): |
136 extradata=None, **formargs): |
140 if extradata: |
140 if extradata: |
141 event_data.update(extradata) |
141 event_data.update(extradata) |
142 onsubmit %= event_data |
142 onsubmit %= event_data |
143 cancelclick = "hideInlineEdit(%s,\'%s\',\'%s\')" % (entity.eid, rtype, |
143 cancelclick = "hideInlineEdit(%s,\'%s\',\'%s\')" % (entity.eid, rtype, |
144 divid) |
144 divid) |
145 form = self.vreg['forms'].select( |
145 form = self._cw.vreg['forms'].select( |
146 formid, self.req, entity=entity, domid='%s-form' % divid, |
146 formid, self._cw, entity=entity, domid='%s-form' % divid, |
147 cssstyle='display: none', onsubmit=onsubmit, action='#', |
147 cssstyle='display: none', onsubmit=onsubmit, action='#', |
148 form_buttons=[SubmitButton(), Button(stdmsgs.BUTTON_CANCEL, |
148 form_buttons=[SubmitButton(), Button(stdmsgs.BUTTON_CANCEL, |
149 onclick=cancelclick)], |
149 onclick=cancelclick)], |
150 **formargs) |
150 **formargs) |
151 form.event_data = event_data |
151 form.event_data = event_data |
160 ): |
160 ): |
161 """display field to edit entity's `rtype` relation on click""" |
161 """display field to edit entity's `rtype` relation on click""" |
162 assert rtype |
162 assert rtype |
163 assert role in ('subject', 'object') |
163 assert role in ('subject', 'object') |
164 if default is None: |
164 if default is None: |
165 default = xml_escape(self.req._('<no value>')) |
165 default = xml_escape(self._cw._('<no value>')) |
166 entity = self.rset.get_entity(row, col) |
166 schema = self._cw.vreg.schema |
167 rschema = entity.schema.rschema(rtype) |
167 entity = self.cw_rset.get_entity(row, col) |
|
168 rschema = schema.rschema(rtype) |
168 lzone = self._build_landing_zone(landing_zone) |
169 lzone = self._build_landing_zone(landing_zone) |
169 # compute value, checking perms, build form |
170 # compute value, checking perms, build form |
170 if rschema.is_final(): |
171 if rschema.is_final(): |
171 onsubmit = ("return inlineValidateAttributeForm('%(rtype)s', '%(eid)s', '%(divid)s', " |
172 onsubmit = ("return inlineValidateAttributeForm('%(rtype)s', '%(eid)s', '%(divid)s', " |
172 "%(reload)s, '%(default)s');") |
173 "%(reload)s, '%(default)s');") |
183 rvid = self._compute_best_vid(entity.e_schema, rschema, role) |
184 rvid = self._compute_best_vid(entity.e_schema, rschema, role) |
184 if not self.should_edit_relation(entity, rschema, role, rvid): |
185 if not self.should_edit_relation(entity, rschema, role, rvid): |
185 return |
186 return |
186 rset = entity.related(rtype, role) |
187 rset = entity.related(rtype, role) |
187 if rset: |
188 if rset: |
188 value = self.view(rvid, rset) |
189 value = self._cw.view(rvid, rset) |
189 else: |
190 else: |
190 value = default |
191 value = default |
191 onsubmit = ("return inlineValidateRelationForm('%(rtype)s', '%(role)s', '%(eid)s', " |
192 onsubmit = ("return inlineValidateRelationForm('%(rtype)s', '%(role)s', '%(eid)s', " |
192 "'%(divid)s', %(reload)s, '%(vid)s', '%(default)s', '%(lzone)s');") |
193 "'%(divid)s', %(reload)s, '%(vid)s', '%(default)s', '%(lzone)s');") |
193 form = self._build_form( |
194 form = self._build_form( |
194 entity, rtype, role, 'base', default, onsubmit, reload, |
195 entity, rtype, role, 'base', default, onsubmit, reload, |
195 dict(vid=rvid, role=role, lzone=lzone)) |
196 dict(vid=rvid, role=role, lzone=lzone)) |
196 field = guess_field(entity.e_schema, entity.schema.rschema(rtype), role) |
197 field = guess_field(entity.e_schema, schema.rschema(rtype), role) |
197 form.append_field(field) |
198 form.append_field(field) |
198 self.relation_form(lzone, value, form, |
199 self.relation_form(lzone, value, form, |
199 self._build_renderer(entity, rtype, role)) |
200 self._build_renderer(entity, rtype, role)) |
200 |
201 |
201 def should_edit_attribute(self, entity, rschema, role, form): |
202 def should_edit_attribute(self, entity, rschema, role, form): |
202 rtype = str(rschema) |
203 rtype = str(rschema) |
203 ttype = rschema.targets(entity.id, role)[0] |
204 ttype = rschema.targets(entity.__regid__, role)[0] |
204 afs = uicfg.autoform_section.etype_get(entity.id, rtype, role, ttype) |
205 afs = uicfg.autoform_section.etype_get(entity.__regid__, rtype, role, ttype) |
205 if not (afs in self.attrcategories and entity.has_perm('update')): |
206 if not (afs in self.attrcategories and entity.has_perm('update')): |
206 self.w(entity.printable_value(rtype)) |
207 self.w(entity.printable_value(rtype)) |
207 return False |
208 return False |
208 try: |
209 try: |
209 field = form.field_by_name(rtype, role) |
210 field = form.field_by_name(rtype, role) |
294 self.render_form(entity) |
295 self.render_form(entity) |
295 |
296 |
296 def render_form(self, entity): |
297 def render_form(self, entity): |
297 """fetch and render the form""" |
298 """fetch and render the form""" |
298 self.form_title(entity) |
299 self.form_title(entity) |
299 form = self.vreg['forms'].select('edition', self.req, rset=entity.rset, |
300 form = self._cw.vreg['forms'].select('edition', self._cw, rset=entity.rset, |
300 row=entity.row, col=entity.col, entity=entity, |
301 row=entity.row, col=entity.col, entity=entity, |
301 submitmsg=self.submited_message()) |
302 submitmsg=self.submited_message()) |
302 self.init_form(form, entity) |
303 self.init_form(form, entity) |
303 self.w(form.form_render(formvid=u'edition')) |
304 self.w(form.form_render(formvid=u'edition')) |
304 |
305 |
306 """customize your form before rendering here""" |
307 """customize your form before rendering here""" |
307 pass |
308 pass |
308 |
309 |
309 def form_title(self, entity): |
310 def form_title(self, entity): |
310 """the form view title""" |
311 """the form view title""" |
311 ptitle = self.req._(self.title) |
312 ptitle = self._cw._(self.title) |
312 self.w(u'<div class="formTitle"><span>%s %s</span></div>' % ( |
313 self.w(u'<div class="formTitle"><span>%s %s</span></div>' % ( |
313 entity.dc_type(), ptitle and '(%s)' % ptitle)) |
314 entity.dc_type(), ptitle and '(%s)' % ptitle)) |
314 |
315 |
315 def submited_message(self): |
316 def submited_message(self): |
316 """return the message that will be displayed on successful edition""" |
317 """return the message that will be displayed on successful edition""" |
317 return self.req._('entity edited') |
318 return self._cw._('entity edited') |
318 |
319 |
319 |
320 |
320 class CreationFormView(EditionFormView): |
321 class CreationFormView(EditionFormView): |
321 """display primary entity creation form""" |
322 """display primary entity creation form""" |
322 __regid__ = 'creation' |
323 __regid__ = 'creation' |
326 |
327 |
327 def call(self, **kwargs): |
328 def call(self, **kwargs): |
328 """creation view for an entity""" |
329 """creation view for an entity""" |
329 # at this point we know etype is a valid entity type, thanks to our |
330 # at this point we know etype is a valid entity type, thanks to our |
330 # selector |
331 # selector |
331 etype = kwargs.pop('etype', self.req.form.get('etype')) |
332 etype = kwargs.pop('etype', self._cw.form.get('etype')) |
332 entity = self.vreg['etypes'].etype_class(etype)(self.req) |
333 entity = self._cw.vreg['etypes'].etype_class(etype)(self._cw) |
333 self.initialize_varmaker() |
334 entity.eid = self._cw.varmaker.next() |
334 entity.eid = self.varmaker.next() |
|
335 self.render_form(entity) |
335 self.render_form(entity) |
336 |
336 |
337 def form_title(self, entity): |
337 def form_title(self, entity): |
338 """the form view title""" |
338 """the form view title""" |
339 if '__linkto' in self.req.form: |
339 if '__linkto' in self._cw.form: |
340 if isinstance(self.req.form['__linkto'], list): |
340 if isinstance(self._cw.form['__linkto'], list): |
341 # XXX which one should be considered (case: add a ticket to a |
341 # XXX which one should be considered (case: add a ticket to a |
342 # version in jpl) |
342 # version in jpl) |
343 rtype, linkto_eid, role = self.req.form['__linkto'][0].split(':') |
343 rtype, linkto_eid, role = self._cw.form['__linkto'][0].split(':') |
344 else: |
344 else: |
345 rtype, linkto_eid, role = self.req.form['__linkto'].split(':') |
345 rtype, linkto_eid, role = self._cw.form['__linkto'].split(':') |
346 linkto_rset = self.req.eid_rset(linkto_eid) |
346 linkto_rset = self._cw.eid_rset(linkto_eid) |
347 linkto_type = linkto_rset.description[0][0] |
347 linkto_type = linkto_rset.description[0][0] |
348 if role == 'subject': |
348 if role == 'subject': |
349 title = self.req.__('creating %s (%s %s %s %%(linkto)s)' % ( |
349 title = self._cw.__('creating %s (%s %s %s %%(linkto)s)' % ( |
350 entity.e_schema, entity.e_schema, rtype, linkto_type)) |
350 entity.e_schema, entity.e_schema, rtype, linkto_type)) |
351 else: |
351 else: |
352 title = self.req.__('creating %s (%s %%(linkto)s %s %s)' % ( |
352 title = self._cw.__('creating %s (%s %%(linkto)s %s %s)' % ( |
353 entity.e_schema, linkto_type, rtype, entity.e_schema)) |
353 entity.e_schema, linkto_type, rtype, entity.e_schema)) |
354 msg = title % {'linkto' : self.view('incontext', linkto_rset)} |
354 msg = title % {'linkto' : self._cw.view('incontext', linkto_rset)} |
355 self.w(u'<div class="formTitle notransform"><span>%s</span></div>' % msg) |
355 self.w(u'<div class="formTitle notransform"><span>%s</span></div>' % msg) |
356 else: |
356 else: |
357 super(CreationFormView, self).form_title(entity) |
357 super(CreationFormView, self).form_title(entity) |
358 |
358 |
359 def url(self): |
359 def url(self): |
360 """return the url associated with this view""" |
360 """return the url associated with this view""" |
361 return self.create_url(self.req.form.get('etype')) |
361 return self.create_url(self._cw.form.get('etype')) |
362 |
362 |
363 def submited_message(self): |
363 def submited_message(self): |
364 """return the message that will be displayed on successful edition""" |
364 """return the message that will be displayed on successful edition""" |
365 return self.req._('entity created') |
365 return self._cw._('entity created') |
366 |
366 |
367 |
367 |
368 class CopyFormView(EditionFormView): |
368 class CopyFormView(EditionFormView): |
369 """display primary entity creation form initialized with values from another |
369 """display primary entity creation form initialized with values from another |
370 entity |
370 entity |
412 ResetButton(_('revert changes'))] |
411 ResetButton(_('revert changes'))] |
413 |
412 |
414 def __init__(self, req, rset, **kwargs): |
413 def __init__(self, req, rset, **kwargs): |
415 kwargs.setdefault('__redirectrql', rset.printable_rql()) |
414 kwargs.setdefault('__redirectrql', rset.printable_rql()) |
416 super(TableEditForm, self).__init__(req, rset=rset, **kwargs) |
415 super(TableEditForm, self).__init__(req, rset=rset, **kwargs) |
417 for row in xrange(len(self.rset)): |
416 for row in xrange(len(self.cw_rset)): |
418 form = self.vreg['forms'].select('edition', self.req, |
417 form = self._cw.vreg['forms'].select('edition', self._cw, |
419 rset=self.rset, row=row, |
418 rset=self.cw_rset, row=row, |
420 attrcategories=('primary',), |
419 attrcategories=('primary',), |
421 mainform=False) |
420 mainform=False) |
422 # XXX rely on the EntityCompositeFormRenderer to put the eid input |
421 # XXX rely on the EntityCompositeFormRenderer to put the eid input |
423 form.remove_field(form.field_by_name('eid')) |
422 form.remove_field(form.field_by_name('eid')) |
424 self.form_add_subform(form) |
423 self.form_add_subform(form) |
446 def call(self, **kwargs): |
445 def call(self, **kwargs): |
447 """redefine default call() method to avoid automatic |
446 """redefine default call() method to avoid automatic |
448 insertions of <div class="section"> between each row of |
447 insertions of <div class="section"> between each row of |
449 the resultset |
448 the resultset |
450 """ |
449 """ |
451 rset = self.rset |
450 rset = self.cw_rset |
452 for i in xrange(len(rset)): |
451 for i in xrange(len(rset)): |
453 self.wview(self.id, rset, row=i, **kwargs) |
452 self.wview(self.__regid__, rset, row=i, **kwargs) |
454 |
453 |
455 def cell_call(self, row, col, peid, rtype, role, i18nctx, **kwargs): |
454 def cell_call(self, row, col, peid, rtype, role, i18nctx, **kwargs): |
456 """ |
455 """ |
457 :param peid: the parent entity's eid hosting the inline form |
456 :param peid: the parent entity's eid hosting the inline form |
458 :param rtype: the relation bridging `etype` and `peid` |
457 :param rtype: the relation bridging `etype` and `peid` |
459 :param role: the role played by the `peid` in the relation |
458 :param role: the role played by the `peid` in the relation |
460 """ |
459 """ |
461 entity = self.rset.get_entity(row, col) |
460 entity = self.cw_rset.get_entity(row, col) |
462 divonclick = "restoreInlinedEntity('%s', '%s', '%s')" % (peid, rtype, |
461 divonclick = "restoreInlinedEntity('%s', '%s', '%s')" % (peid, rtype, |
463 entity.eid) |
462 entity.eid) |
464 self.render_form(entity, peid, rtype, role, i18nctx, |
463 self.render_form(entity, peid, rtype, role, i18nctx, |
465 divonclick=divonclick) |
464 divonclick=divonclick) |
466 |
465 |
467 def render_form(self, entity, peid, rtype, role, i18nctx, **kwargs): |
466 def render_form(self, entity, peid, rtype, role, i18nctx, **kwargs): |
468 """fetch and render the form""" |
467 """fetch and render the form""" |
469 form = self.vreg['forms'].select('edition', self.req, entity=entity, |
468 form = self._cw.vreg['forms'].select('edition', self._cw, entity=entity, |
470 form_renderer_id='inline', |
469 form_renderer_id='inline', |
471 mainform=False, copy_nav_params=False) |
470 mainform=False, copy_nav_params=False) |
472 self.add_hiddens(form, entity, peid, rtype, role) |
471 self.add_hiddens(form, entity, peid, rtype, role) |
473 divid = '%s-%s-%s' % (peid, rtype, entity.eid) |
472 divid = '%s-%s-%s' % (peid, rtype, entity.eid) |
474 title = self.req.pgettext(i18nctx, 'This %s' % entity.e_schema) |
473 title = self._cw.pgettext(i18nctx, 'This %s' % entity.e_schema) |
475 removejs = self.removejs % (peid, rtype, entity.eid) |
474 removejs = self.removejs % (peid, rtype, entity.eid) |
476 countkey = '%s_count' % rtype |
475 countkey = '%s_count' % rtype |
477 try: |
476 try: |
478 self.req.data[countkey] += 1 |
477 self._cw.data[countkey] += 1 |
479 except: |
478 except: |
480 self.req.data[countkey] = 1 |
479 self._cw.data[countkey] = 1 |
481 self.w(form.form_render(divid=divid, title=title, removejs=removejs, |
480 self.w(form.form_render(divid=divid, title=title, removejs=removejs, |
482 i18nctx=i18nctx, |
481 i18nctx=i18nctx, |
483 counter=self.req.data[countkey], **kwargs)) |
482 counter=self._cw.data[countkey], **kwargs)) |
484 |
483 |
485 def add_hiddens(self, form, entity, peid, rtype, role): |
484 def add_hiddens(self, form, entity, peid, rtype, role): |
486 # to ease overriding (see cubes.vcsfile.views.forms for instance) |
485 # to ease overriding (see cubes.vcsfile.views.forms for instance) |
487 form.form_add_hidden(name='%s:%s' % (rtype, peid), value=entity.eid, |
486 form.form_add_hidden(name='%s:%s' % (rtype, peid), value=entity.eid, |
488 id='rel-%s-%s-%s' % (peid, rtype, entity.eid)) |
487 id='rel-%s-%s-%s' % (peid, rtype, entity.eid)) |