--- a/web/data/cubicweb.ajax.js Thu Apr 30 01:21:48 2009 +0200
+++ b/web/data/cubicweb.ajax.js Thu Apr 30 08:51:54 2009 +0200
@@ -29,7 +29,7 @@
*/
function loadAjaxHtmlHead(node) {
var head = jQuery('head');
- var node = jQuery(node).find('div.ajaxHtmlHead');
+ node = jQuery(node).find('div.ajaxHtmlHead');
_loadAjaxHtmlHead(node, head, 'script', 'src');
_loadAjaxHtmlHead(node, head, 'link', 'href');
node.find('*').appendTo(head);
@@ -144,18 +144,6 @@
}
}
-/*
- * This function is the equivalent of MochiKit's loadJSONDoc but
- * uses POST instead of GET
- */
-function loadJSONDocUsingPOST(url, data) {
- setProgressCursor();
- var deferred = loadJSON(url, data, 'POST');
- deferred = deferred.addErrback(remoteCallFailed);
- deferred = deferred.addCallback(resetCursor);
- return deferred;
-}
-
/*
* This function will call **synchronously** a remote method on the cubicweb server
@@ -187,10 +175,16 @@
*
* It looks at http headers to guess the response type.
*/
+
function asyncRemoteExec(fname /* ... */) {
+ setProgressCursor();
var props = {'fname' : fname, 'pageid' : pageid,
'arg': map(jQuery.toJSON, sliceList(arguments, 1))};
- return loadJSONDocUsingPOST(JSON_BASE_URL, props);
+ var deferred = loadRemote(JSON_BASE_URL, props, 'POST');
+ deferred = deferred.addErrback(remoteCallFailed);
+ deferred = deferred.addErrback(resetCursor);
+ deferred = deferred.addCallback(resetCursor);
+ return deferred;
}
--- a/web/data/cubicweb.compat.js Thu Apr 30 01:21:48 2009 +0200
+++ b/web/data/cubicweb.compat.js Thu Apr 30 08:51:54 2009 +0200
@@ -365,11 +365,16 @@
};
-function loadJSON(url, data, type) {
+/*
+ * Asynchronously load an url and return a deferred
+ * whose callbacks args are decoded according to
+ * the Content-Type response header
+ */
+function loadRemote(url, data, reqtype) {
var d = new Deferred();
jQuery.ajax({
url: url,
- type: type,
+ type: reqtype,
data: data,
beforeSend: function(xhr) {
@@ -377,6 +382,9 @@
},
success: function(data, status) {
+ if (d.req.getResponseHeader("content-type") == 'application/json') {
+ data = evalJSON(data);
+ }
d.success(data);
},
@@ -506,23 +514,7 @@
var KEYS = {
KEY_ESC: 27,
KEY_ENTER: 13
-}
+};
-// XHR = null;
-// function test() {
-// var d = loadJSON('http://crater:9876/json?mode=remote&fname=i18n&pageid=xxx&arg=' + jQuery.toJSON(['modify']));
-// d = d.addCallback(function (result, xhr) {
-// XHR = xhr;
-// log('got ajax result 1' + result + xhr);
-// log('got ajax result 1' + xhr);
-// log('got ajax result 1' + xhr + 'arguments =', arguments.length);
-// });
-// d.addCallback(function (x, req, y, z) {
-// log('callback 2 x =' + x, ' req=', req, 'y =', y, 'z=',z);
-// }, 12, 13)
-// d.addErrback(function (error, xhr) {
-// XHR = xhr;
-// log('got err', error, ' code =', xhr.status, 'arguments length=', arguments.length);
-// })
-// }
+
--- a/web/form.py Thu Apr 30 01:21:48 2009 +0200
+++ b/web/form.py Thu Apr 30 08:51:54 2009 +0200
@@ -421,7 +421,7 @@
class EntityFieldsForm(FieldsForm):
__select__ = (match_kwargs('entity') | (one_line_rset & non_final_entity()))
- internal_fields = FieldsForm.internal_fields + ('__type', 'eid')
+ internal_fields = FieldsForm.internal_fields + ('__type', 'eid', '__maineid')
domid = 'entityForm'
def __init__(self, *args, **kwargs):
--- a/web/formfields.py Thu Apr 30 01:21:48 2009 +0200
+++ b/web/formfields.py Thu Apr 30 08:51:54 2009 +0200
@@ -94,9 +94,9 @@
Field.__creation_rank += 1
def __unicode__(self):
- return u'<%s name=%r label=%r id=%r initial=%r @%x>' % (
+ return u'<%s name=%r label=%r id=%r initial=%r visible=%r @%x>' % (
self.__class__.__name__, self.name, self.label,
- self.id, self.initial, id(self))
+ self.id, self.initial, self.is_visible(), id(self))
def __repr__(self):
return self.__unicode__().encode('utf-8')
@@ -406,7 +406,10 @@
relatedvocab = [(e.view('combobox'), e.eid) for e in rset.entities()]
else:
relatedvocab = []
- return res + form.form_field_vocabulary(self) + relatedvocab
+ vocab = res + form.form_field_vocabulary(self) + relatedvocab
+ if self.sort:
+ vocab = sorted(vocab)
+ return vocab
def format_single_value(self, req, value):
return value
--- a/web/formwidgets.py Thu Apr 30 01:21:48 2009 +0200
+++ b/web/formwidgets.py Thu Apr 30 08:51:54 2009 +0200
@@ -161,20 +161,16 @@
class Select(FieldWidget):
"""<select>, for field having a specific vocabulary"""
- def __init__(self, attrs=None, multiple=False, sort=False):
+ def __init__(self, attrs=None, multiple=False):
super(Select, self).__init__(attrs)
self._multiple = multiple
- self._sort = sort
def render(self, form, field):
name, curvalues, attrs = self._render_attrs(form, field)
if not 'size' in attrs and self._multiple:
attrs['size'] = '5'
options = []
- vocab = field.vocabulary(form)
- if self._sort:
- vocab = sorted(vocab)
- for label, value in vocab:
+ for label, value in field.vocabulary(form):
if value is None:
# handle separator
options.append(u'<optgroup label="%s"/>' % (label or ''))
--- a/web/request.py Thu Apr 30 01:21:48 2009 +0200
+++ b/web/request.py Thu Apr 30 08:51:54 2009 +0200
@@ -23,7 +23,7 @@
from cubicweb.common.uilib import remove_html_tags
from cubicweb.utils import SizeConstrainedList, HTMLHead
from cubicweb.web import (INTERNAL_FIELD_VALUE, LOGGER, NothingToEdit, RequestError,
- StatusResponse)
+ StatusResponse)
_MARKER = object()
--- a/web/views/autoform.py Thu Apr 30 01:21:48 2009 +0200
+++ b/web/views/autoform.py Thu Apr 30 08:51:54 2009 +0200
@@ -20,7 +20,7 @@
class AutomaticEntityForm(EntityFieldsForm):
"""base automatic form to edit any entity.
- Designed to be flly generated from schema but highly configurable through:
+ Designed to be fully generated from schema but highly configurable through:
* rtags (rcategories, rfields, rwidgets, inlined, rpermissions)
* various standard form parameters
--- a/web/views/basecontrollers.py Thu Apr 30 01:21:48 2009 +0200
+++ b/web/views/basecontrollers.py Thu Apr 30 08:51:54 2009 +0200
@@ -395,6 +395,8 @@
def js_edit_field(self, action, names, values, rtype, eid):
success, args = self.validate_form(action, names, values)
if success:
+ # Any X,N where we don't seem to use N is an optimisation
+ # printable_value won't need to query N again
rset = self.req.execute('Any X,N WHERE X eid %%(x)s, X %s N' % rtype,
{'x': eid}, 'x')
entity = rset.get_entity(0, 0)
@@ -402,9 +404,17 @@
else:
return (success, args, None)
-# def js_rql(self, rql):
-# rset = self._exec(rql)
-# return rset and rset.rows or []
+ @jsonize
+ def js_edit_relation(self, action, names, values,
+ rtype, eid, role='subject', vid='list'):
+ # XXX validate_form
+ success, args = self.validate_form(action, names, values)
+ if success:
+ entity = self.req.eid_rset(eid).get_entity(0, 0)
+ rset = entity.related('person_in_charge', role)
+ return (success, args, self.view(vid, rset))
+ else:
+ return (success, args, None)
@jsonize
def js_i18n(self, msgids):
--- a/web/views/editforms.py Thu Apr 30 01:21:48 2009 +0200
+++ b/web/views/editforms.py Thu Apr 30 08:51:54 2009 +0200
@@ -103,22 +103,22 @@
self.w(value)
return
eid = entity.eid
- edit_key = make_uid('%s-%s' % (rtype, eid))
- divid = 'd%s' % edit_key
- reload = dumps(reload)
- buttons = [SubmitButton(stdmsgs.BUTTON_OK, cwaction='apply'),
+ divid = 'd%s' % make_uid('%s-%s' % (rtype, eid))
+ event_data = {'divid' : divid, 'eid' : eid, 'rtype' : rtype, 'reload' : dumps(reload)}
+ buttons = [SubmitButton(stdmsgs.BUTTON_OK),
Button(stdmsgs.BUTTON_CANCEL,
onclick="cancelInlineEdit(%s,\'%s\',\'%s\')" % (eid, rtype, divid))]
form = self.vreg.select_object('forms', 'edition', self.req, self.rset,
row=row, col=col, form_buttons=buttons,
domid='%s-form' % divid, action='#',
cssstyle='display: none',
- onsubmit=self.onsubmit % locals())
+ onsubmit=self.onsubmit % event_data)
+ form.form_add_hidden(u'__maineid', entity.eid)
renderer = FormRenderer(display_label=False, display_help=False,
display_fields=(rtype,), button_bar_class='buttonbar',
display_progress_div=False)
self.w(tags.div(value, klass='editableField', id=divid,
- ondblclick=self.ondblclick % locals()))
+ ondblclick=self.ondblclick % event_data))
self.w(form.form_render(renderer=renderer))