--- a/web/data/cubicweb.edition.js Fri Jul 10 19:51:19 2009 +0200
+++ b/web/data/cubicweb.edition.js Fri Jul 10 19:51:42 2009 +0200
@@ -454,9 +454,9 @@
* @param eid : the eid of the entity being edited
* @param reload: boolean to reload page if true (when changing URL dependant data)
*/
-function inlineValidateAttributeForm(formid, rtype, eid, divid, reload, default_value) {
+function inlineValidateAttributeForm(rtype, eid, divid, reload, default_value) {
try {
- var form = getNode(formid);
+ var form = getNode(divid+'-form');
if (typeof FCKeditorAPI != "undefined") {
for ( var name in FCKeditorAPI.__Instances ) {
var oEditor = FCKeditorAPI.__Instances[name] ;
@@ -473,7 +473,7 @@
return false;
}
d.addCallback(function (result, req) {
- handleFormValidationResponse(formid, noop, noop, result);
+ handleFormValidationResponse(divid+'-form', noop, noop, result);
if (reload) {
document.location.href = result[1];
} else {
@@ -486,7 +486,7 @@
// hide global error messages
jQuery('div.errorMessage').remove();
jQuery('#appMsg').hide();
- cancelInlineEdit(eid, rtype, divid);
+ hideInlineEdit(eid, rtype, divid);
}
}
return false;
@@ -494,10 +494,10 @@
return false;
}
-function inlineValidateRelationForm(formid, rtype, role, eid, divid, reload, vid,
+function inlineValidateRelationForm(rtype, role, eid, divid, reload, vid,
default_value, lzone) {
try {
- var form = getNode(formid);
+ var form = getNode(divid+'-form');
var relname = rtype + ':' + eid;
var newtarget = jQuery('[name=' + relname + ']').val();
var zipped = formContents(form);
@@ -508,20 +508,15 @@
return false;
}
d.addCallback(function (result, req) {
+ handleFormValidationResponse(divid+'-form', noop, noop, result);
if (reload) {
document.location.href = result[1];
} else {
- handleFormValidationResponse(formid, noop, noop, result);
- var fieldview = getNode(divid);
- fieldview.innerHTML = result[2];
- // switch inline form off only if no error
if (result[0]) {
- // hide global error messages
- jQuery('div.errorMessage').remove();
- jQuery('#appMsg').hide();
- var inputname = 'edit' + role[0] + '-' + relname;
- jQuery('input[name=' + inputname + ']').val(newtarget);
- cancelInlineEdit(eid, rtype, divid);
+ var d = asyncRemoteExec('reledit_form', eid, rtype, role, lzone);
+ d.addCallback(function (result) {
+ jQuery('#'+divid+'-reledit').replaceWith(result);
+ });
}
}
return false;
@@ -533,12 +528,12 @@
/**** inline edition ****/
function showInlineEditionForm(eid, rtype, divid) {
jQuery('#' + divid).hide();
- jQuery('#' + divid + '-form').show();
+ jQuery('#' + divid+'-form').show();
}
-function cancelInlineEdit(eid, rtype, divid) {
+function hideInlineEdit(eid, rtype, divid) {
jQuery('#' + divid).show();
- jQuery('#' + divid + '-form').hide();
+ jQuery('#' + divid+'-form').hide();
}
CubicWeb.provide('edition.js');
--- a/web/views/basecontrollers.py Fri Jul 10 19:51:19 2009 +0200
+++ b/web/views/basecontrollers.py Fri Jul 10 19:51:42 2009 +0200
@@ -404,17 +404,16 @@
@jsonize
def js_edit_relation(self, action, names, values, rtype,
role, eid, vid, default, lzone):
- success, args = self.validate_form(action, names, values)
- if success:
- entity = self.req.eid_rset(eid).get_entity(0, 0)
- rset = entity.related(rtype, role)
- if rset:
- output = self.view(vid, rset)
- else:
- output = default
- return (success, args, lzone + output)
- else:
- return (success, args, None)
+ if rtype == 'license_of':
+ print action, names, values, rtype, role, eid, vid, default
+ success, url = self.validate_form(action, names, values)
+ return (success, url)
+
+ @jsonize
+ def js_reledit_form(self, eid, rtype, role, lzone):
+ entity = self.req.eid_rset(eid).get_entity(0, 0)
+ return entity.view('reledit', rtype=rtype, role=role,
+ landing_zone=lzone)
@jsonize
def js_i18n(self, msgids):
--- a/web/views/editforms.py Fri Jul 10 19:51:19 2009 +0200
+++ b/web/views/editforms.py Fri Jul 10 19:51:42 2009 +0200
@@ -103,6 +103,17 @@
return self._many_rvid
return self._one_rvid
+ def _build_landing_zone(self, lzone):
+ return lzone or self._defaultlandingzone % {'msg' : self.req._(self._landingzonemsg)}
+
+ def _build_renderer(self, entity, rtype, role):
+ return self.vreg.select_object('formrenderers', 'base', self.req,
+ entity=entity,
+ display_label=False, display_help=False,
+ display_fields=[(rtype, role)],
+ table_class='', button_bar_class='buttonbar',
+ display_progress_div=False)
+
def cell_call(self, row, col, rtype=None, role='subject',
reload=False, # controls reloading the whole page after change
rvid=None, # vid to be applied to other side of rtype
@@ -110,20 +121,21 @@
landing_zone=None # prepend value with a separate html element to click onto
# (esp. needed when values are links)
):
- """display field to edit entity's `rtype` relation on double-click"""
+ """display field to edit entity's `rtype` relation on click"""
assert rtype
+ assert role in ('subject', 'object')
+ if default is None:
+ default = xml_escape(self.req._('<no value>'))
entity = self.entity(row, col)
rschema = entity.schema.rschema(rtype)
- if not default:
- default = xml_escape(self.req._('<no value>'))
# compute value, checking perms, build form
if rschema.is_final():
value = entity.printable_value(rtype) or default
if not entity.has_perm('update'):
self.w(value)
return
- form = self._build_attribute_form(entity, value, rtype, role, reload,
- row, col, default, landing_zone)
+ self._attribute_form(entity, value, rtype, role, reload,
+ row, col, default, landing_zone)
else:
vid = uicfg.primaryview_display_ctrl.etype_get(entity.e_schema,
rtype, role)
@@ -135,65 +147,58 @@
rset = entity.related(rtype, role)
candidate = self.view(rvid, rset, 'null')
value = candidate or default
- if role == 'subject'and not rschema.has_perm(self.req, 'add',
- fromeid=entity.eid):
+ if role == 'subject' and not rschema.has_perm(self.req, 'add',
+ fromeid=entity.eid):
return self.w(value)
elif role == 'object' and not rschema.has_perm(self.req, 'add',
toeid=entity.eid):
return self.w(value)
- elif get_schema_property(entity.e_schema,
- entity.schema.rschema(rtype),
+ elif get_schema_property(entity.e_schema, rschema,
role, 'composite') == role:
+ self.warning('reledit cannot be applied : (... %s %s [composite])'
+ % (rtype, entity.e_schema))
return self.w(value)
- form = self._build_relation_form(entity, value, rtype, role, reload, row, col,
- rvid, default, landing_zone)
- renderer = self.vreg.select_object('formrenderers', 'base', self.req,
- entity=entity,
- display_label=False, display_help=False,
- display_fields=[(rtype, role)],
- table_class='', button_bar_class='buttonbar',
- display_progress_div=False)
- self.w(form.form_render(renderer=renderer))
+ self._relation_form(entity, value, rtype, role, reload, row, col,
+ rvid, default, landing_zone)
- def _build_landing_zone(self, lzone):
- return lzone or self._defaultlandingzone % {'msg' : self.req._(self._landingzonemsg)}
- def _build_relation_form(self, entity, value, rtype, role, row, col, reload, rvid,
- default, lzone):
+ def _relation_form(self, entity, value, rtype, role, row, col, reload, rvid, default, lzone):
lzone = self._build_landing_zone(lzone)
value = lzone + value
divid = 'd%s' % make_uid('%s-%s' % (rtype, entity.eid))
event_data = {'divid' : divid, 'eid' : entity.eid, 'rtype' : rtype, 'vid' : rvid,
'reload' : reload, 'default' : default, 'role' : role,
'lzone' : lzone}
- onsubmit = ("return inlineValidateRelationForm('%(divid)s-form', '%(rtype)s', "
- "'%(role)s', '%(eid)s', '%(divid)s', %(reload)s, '%(vid)s', "
- "'%(default)s', '%(lzone)s');"
+ onsubmit = ("return inlineValidateRelationForm('%(rtype)s', '%(role)s', '%(eid)s', "
+ "'%(divid)s', %(reload)s, '%(vid)s', '%(default)s', '%(lzone)s');"
% event_data)
- cancelclick = "cancelInlineEdit(%s,\'%s\',\'%s\')" % (
+ cancelclick = "hideInlineEdit(%s,\'%s\',\'%s\')" % (
entity.eid, rtype, divid)
form = self.vreg.select_object('forms', 'base', self.req, entity=entity,
domid='%s-form' % divid, cssstyle='display: none',
onsubmit=onsubmit, action='#',
form_buttons=[SubmitButton(),
Button(stdmsgs.BUTTON_CANCEL,
- onclick=cancelclick)])
+ onclick=cancelclick)])
field = guess_field(entity.e_schema, entity.schema.rschema(rtype), role)
form.append_field(field)
+ self.w(u'<div id="%s-reledit" class="field">' % divid)
self.w(tags.div(value, klass='editableField', id=divid,
onclick=self._onclick % event_data))
- return form
+ renderer = self._build_renderer(entity, rtype, role)
+ self.w(form.form_render(renderer=renderer))
+ self.w(u'</div>')
- def _build_attribute_form(self, entity, value, rtype, role, reload, row, col, default, lzone):
+ def _attribute_form(self, entity, value, rtype, role, reload, row, col, default, lzone):
eid = entity.eid
divid = 'd%s' % make_uid('%s-%s' % (rtype, eid))
event_data = {'divid' : divid, 'eid' : eid, 'rtype' : rtype,
'reload' : dumps(reload), 'default' : default, 'lzone' : lzone}
- onsubmit = ("return inlineValidateAttributeForm('%(divid)s-form', '%(rtype)s', "
- "'%(eid)s', '%(divid)s', %(reload)s, '%(default)s', '%(lzone)s');")
+ onsubmit = ("return inlineValidateAttributeForm('%(rtype)s', '%(eid)s', '%(divid)s', "
+ "%(reload)s, '%(default)s', '%(lzone)s');")
buttons = [SubmitButton(stdmsgs.BUTTON_OK),
Button(stdmsgs.BUTTON_CANCEL,
- onclick="cancelInlineEdit(%s,\'%s\',\'%s\')" % (
+ onclick="hideInlineEdit(%s,\'%s\',\'%s\')" % (
eid, rtype, divid))]
form = self.vreg.select_object('forms', 'edition', self.req, self.rset,
row=row, col=col, form_buttons=buttons,
@@ -202,7 +207,8 @@
onsubmit=onsubmit % event_data)
self.w(tags.div(value, klass='editableField', id=divid,
onclick=self._onclick % event_data))
- return form
+ renderer = self._build_renderer(entity, rtype, role)
+ self.w(form.form_render(renderer=renderer))
class EditionFormView(FormViewMixIn, EntityView):