[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
--- a/web/data/cubicweb.ajax.js Fri Jun 11 07:58:52 2010 +0200
+++ b/web/data/cubicweb.ajax.js Fri Jun 11 07:58:53 2010 +0200
@@ -20,7 +20,7 @@
/**
* .. function:: Deferred
*
- * dummy ultra minimalist implementation on deferred for jQuery
+ * dummy ultra minimalist implementation of deferred for jQuery
*/
function Deferred() {
this.__init__(this);
@@ -198,7 +198,7 @@
$.extend(form, {
'fname': fname,
'pageid': pageid,
- 'arg': map(jQuery.toJSON, sliceList(arguments, 2))
+ 'arg': $.map(cw.utils.sliceList(arguments, 2), jQuery.toJSON)
});
return form;
}
@@ -544,13 +544,10 @@
return jQuery(children[0]).clone().context;
}
// several children => wrap them in a single node and return the wrap
- return DIV({
- 'cubicweb:type': "cwResponseWrapper"
- },
- map(function(node) {
- return jQuery(node).clone().context;
- },
- children));
+ return DIV({'cubicweb:type': "cwResponseWrapper"},
+ $.map(children, function(node) {
+ return jQuery(node).clone().context;})
+ );
}
/* DEPRECATED *****************************************************************/
@@ -629,7 +626,7 @@
var props = {
'fname': fname,
'pageid': pageid,
- 'arg': map(jQuery.toJSON, sliceList(arguments, 1))
+ 'arg': $.map(cw.utils.sliceList(arguments, 1), jQuery.toJSON)
};
var result = jQuery.ajax({
url: JSON_BASE_URL,
@@ -651,7 +648,7 @@
var props = {
'fname': fname,
'pageid': pageid,
- 'arg': map(jQuery.toJSON, sliceList(arguments, 1))
+ 'arg': $.map(cw.utils.sliceList(arguments, 1), jQuery.toJSON)
};
// XXX we should inline the content of loadRemote here
var deferred = loadRemote(JSON_BASE_URL, props, 'POST');
--- a/web/data/cubicweb.calendar.js Fri Jun 11 07:58:52 2010 +0200
+++ b/web/data/cubicweb.calendar.js Fri Jun 11 07:58:53 2010 +0200
@@ -62,7 +62,7 @@
var _td = function(elt) {
return TD(this.cellprops, elt);
};
- return TR(null, map(_td, row));
+ return TR(null, $.map(row, _td));
};
this._makecell = function(cellinfo) {
@@ -88,7 +88,7 @@
this._domForRows = function(rows) {
var lines = [];
for (i = 0; i < rows.length; i++) {
- lines.push(TR(null, map(this._makecell, rows[i])));
+ lines.push(TR(null, $.map(rows[i], this._makecell)));
}
return lines;
};
@@ -106,7 +106,7 @@
var _th = function(day) {
return TH(null, self._uppercaseFirst(day));
};
- return TR(null, map(_th, DAYNAMES));
+ return TR(null, $.map(DAYNAMES, _th));
};
this._getrows = function() {
@@ -273,7 +273,7 @@
*/
function dateSelected(cell, containerId) {
var cal = Calendar.REGISTRY[containerId];
- var input = getNode(cal.inputId);
+ var input = cw.getNode(cal.inputId);
// XXX: the use of innerHTML might cause problems, but it seems to be
// the only way understood by both IE and Mozilla. Otherwise,
// IE accepts innerText and mozilla accepts textContent
--- a/web/data/cubicweb.compat.js Fri Jun 11 07:58:52 2010 +0200
+++ b/web/data/cubicweb.compat.js Fri Jun 11 07:58:53 2010 +0200
@@ -93,16 +93,6 @@
}
);
-getNode = cw.utils.deprecatedFunction(
- '[3.9] getNode(nodeid) is deprecated, use $(#nodeid) instead',
- function(node) {
- if (typeof node == 'string') {
- return document.getElementById(node);
- }
- return node;
- }
-);
-
/**
* The only known usage of KEYS is in the tag cube. Once cubicweb-tag 1.7.0 is out,
* this current definition can be removed.
--- a/web/data/cubicweb.edition.js Fri Jun 11 07:58:52 2010 +0200
+++ b/web/data/cubicweb.edition.js Fri Jun 11 07:58:53 2010 +0200
@@ -25,9 +25,9 @@
var args = {
fname: 'prop_widget',
pageid: pageid,
- arg: map(jQuery.toJSON, [key, varname, tabindex])
+ arg: $.map([key, varname, tabindex], jQuery.toJSON)
};
- jqNode('div:value:' + varname).loadxhtml(JSON_BASE_URL, args, 'post');
+ cw.jqNode('div:value:' + varname).loadxhtml(JSON_BASE_URL, args, 'post');
}
}
@@ -39,10 +39,10 @@
* make sure tabindex remains consistent
*/
function reorderTabindex(start, formid) {
- var form = getNode(formid || 'entityForm');
+ var form = cw.getNode(formid || 'entityForm');
var inputTypes = ['INPUT', 'SELECT', 'TEXTAREA'];
var tabindex = (start == null) ? 15: start;
- nodeWalkDepthFirst(form, function(elem) {
+ cw.utils.nodeWalkDepthFirst(form, function(elem) {
var tagName = elem.tagName.toUpperCase();
if (inputTypes.contains(tagName)) {
if (jQuery(elem).attr('tabindex') != null) {
@@ -123,7 +123,7 @@
},
[TH(null, relationName), TD(null, [handle, link])]);
try {
- var separator = getNode('relationSelectorRow_' + eid);
+ var separator = cw.getNode('relationSelectorRow_' + eid);
//dump('relationSelectorRow_' + eid) XXX warn dump is not implemented in konqueror (at least)
// XXX Warning: separator.parentNode is not (always ?) the
// table itself, but an intermediate node (TableSectionElement)
@@ -181,7 +181,7 @@
buildEntityCell(relname, optionNode, selectNode.id, eid);
}
else {
- var relationSelector = getNode('relationSelector_' + eid);
+ var relationSelector = cw.getNode('relationSelector_' + eid);
var relationSelected = relationSelector.options[relationSelector.selectedIndex];
// new relation as a line in simple edit
buildEntityLine(relationSelected.text, optionNode, selectNode.id, eid);
@@ -190,11 +190,11 @@
function cancelPendingInsert(elementId, element_name, comboId, eid) {
// remove matching insert element
- var entityView = jqNode('a' + elementId).text();
- jqNode(element_name + elementId).remove();
+ var entityView = cw.jqNode('a' + elementId).text();
+ cw.jqNode(element_name + elementId).remove();
if (comboId) {
// re-insert option in combobox if it was taken from there
- var selectNode = getNode(comboId);
+ var selectNode = cw.getNode(comboId);
// XXX what on object relation
if (selectNode) {
var options = selectNode.options;
@@ -234,9 +234,9 @@
var d = loadRemote('json', ajaxFuncArgs('add_pending_delete', null, nodeId.split(':')));
d.addCallback(function() {
// and strike entity view
- jqNode('span' + nodeId).addClass('pendingDelete');
+ cw.jqNode('span' + nodeId).addClass('pendingDelete');
// replace handle text
- jqNode('handle' + nodeId).text('+');
+ cw.jqNode('handle' + nodeId).text('+');
});
}
@@ -249,9 +249,9 @@
var d = loadRemote('json', ajaxFuncArgs('remove_pending_delete', null, nodeId.split(':')));
d.addCallback(function() {
// reset link's CSS class
- jqNode('span' + nodeId).removeClass('pendingDelete');
+ cw.jqNode('span' + nodeId).removeClass('pendingDelete');
// replace handle text
- jqNode('handle' + nodeId).text('x');
+ cw.jqNode('handle' + nodeId).text('x');
});
}
@@ -262,7 +262,7 @@
*/
function togglePendingDelete(nodeId, eid) {
// node found means we should cancel deletion
- if (jQuery.className.has(getNode('span' + nodeId), 'pendingDelete')) {
+ if (jQuery.className.has(cw.getNode('span' + nodeId), 'pendingDelete')) {
cancelPendingDelete(nodeId, eid);
} else {
addPendingDelete(nodeId, eid);
@@ -270,10 +270,8 @@
}
function selectForAssociation(tripletIdsString, originalEid) {
- var tripletlist = map(function(x) {
- return x.split(':');
- },
- tripletIdsString.split('-'));
+ var tripletlist = $.map(tripletIdsString.split('-'),
+ function(x) { return x.split(':');});
var d = loadRemote('json', ajaxFuncArgs('add_pending_inserts', null, tripletlist));
d.addCallback(function() {
var args = {
@@ -305,7 +303,7 @@
* * `rtype`, the relation type between both entities
*/
function addInlineCreationForm(peid, petype, ttype, rtype, role, i18nctx, insertBefore) {
- insertBefore = insertBefore || getNode('add' + rtype + ':' + peid + 'link').parentNode;
+ insertBefore = insertBefore || cw.getNode('add' + rtype + ':' + peid + 'link').parentNode;
var args = ajaxFuncArgs('inline_creation_form', null, peid, petype, ttype, rtype, role, i18nctx);
var d = loadRemote('json', args);
d.addCallback(function(response) {
@@ -337,9 +335,9 @@
* removes the part of the form used to edit an inlined entity
*/
function removeInlineForm(peid, rtype, role, eid, showaddnewlink) {
- jqNode(['div', peid, rtype, eid].join('-')).slideUp('fast', function() {
- $(this).remove();
- updateInlinedEntitiesCounters(rtype, role);
+ cw.jqNode(['div', peid, rtype, eid].join('-')).slideUp('fast', function() {
+ $(this).remove();
+ updateInlinedEntitiesCounters(rtype, role);
});
if (showaddnewlink) {
toggleVisibility(showaddnewlink);
@@ -360,29 +358,29 @@
function removeInlinedEntity(peid, rtype, eid) {
// XXX work around the eid_param thing (eid + ':' + eid) for #471746
var nodeid = ['rel', peid, rtype, eid + ':' + eid].join('-');
- var node = jqNode(nodeid);
+ var node = cw.jqNode(nodeid);
if (!node.attr('cubicweb:type')) {
node.attr('cubicweb:type', node.val());
node.val('');
var divid = ['div', peid, rtype, eid].join('-');
- jqNode(divid).fadeTo('fast', 0.5);
+ cw.jqNode(divid).fadeTo('fast', 0.5);
var noticeid = ['notice', peid, rtype, eid].join('-');
- jqNode(noticeid).fadeIn('fast');
+ cw.jqNode(noticeid).fadeIn('fast');
}
}
function restoreInlinedEntity(peid, rtype, eid) {
// XXX work around the eid_param thing (eid + ':' + eid) for #471746
var nodeid = ['rel', peid, rtype, eid + ':' + eid].join('-');
- var node = jqNode(nodeid);
+ var node = cw.jqNode(nodeid);
if (node.attr('cubicweb:type')) {
node.val(node.attr('cubicweb:type'));
node.attr('cubicweb:type', '');
- jqNode(['fs', peid, rtype, eid].join('-')).append(node);
+ cw.jqNode(['fs', peid, rtype, eid].join('-')).append(node);
var divid = ['div', peid, rtype, eid].join('-');
- jqNode(divid).fadeTo('fast', 1);
+ cw.jqNode(divid).fadeTo('fast', 1);
var noticeid = ['notice', peid, rtype, eid].join('-');
- jqNode(noticeid).hide();
+ cw.jqNode(noticeid).hide();
}
}
@@ -411,7 +409,7 @@
var found = false;
// XXX remove suffixes at some point
for (var i = 0, length = suffixes.length; i < length; i++) {
- var field = jqNode(fieldname + suffixes[i] + ':' + eid);
+ var field = cw.jqNode(fieldname + suffixes[i] + ':' + eid);
if (field && jQuery(field).attr('type') != 'hidden') {
if (!firsterrfield) {
firsterrfield = 'err-' + fieldid;
@@ -437,7 +435,7 @@
if (globalerrors.length == 1) {
var innernode = SPAN(null, globalerrors[0]);
} else {
- var innernode = UL(null, map(partial(LI, null), globalerrors));
+ var innernode = UL(null, $.map(globalerrors, partial(LI, null)));
}
// insert DIV and innernode before the form
var div = DIV({
@@ -469,7 +467,7 @@
var descr = result[1];
var errmsg;
// Unknown structure
- if ( !isArrayLike(descr) || descr.length != 2 ) {
+ if ( !cw.utils.isArrayLike(descr) || descr.length != 2 ) {
errmsg = descr;
} else {
_displayValidationerrors(formid, descr[0], descr[1]);
@@ -514,9 +512,9 @@
* used by additional submit buttons to remember which button was clicked
*/
function postForm(bname, bvalue, formid) {
- var form = getNode(formid);
+ var form = cw.getNode(formid);
if (bname) {
- var child = form.appendChild(INPUT({
+ var child = form.append(INPUT({
type: 'hidden',
name: bname,
value: bvalue
@@ -584,7 +582,7 @@
*/
function validateForm(formid, action, onsuccess, onfailure) {
try {
- var zipped = formContents(formid);
+ var zipped = cw.utils.formContents(formid);
var args = ajaxFuncArgs('validate_form', null, action, zipped[0], zipped[1]);
var d = loadRemote('json', args);
} catch(ex) {
@@ -621,7 +619,7 @@
*/
function inlineValidateRelationFormOptions(rtype, eid, divid, options) {
try {
- var form = getNode(divid + '-form');
+ var form = cw.getNode(divid + '-form');
var relname = rtype + ':' + eid;
var newtarget = jQuery('[name=' + relname + ']').val();
var zipped = cw.utils.formContents(form);
@@ -698,17 +696,16 @@
jQuery('#' + divid + '-form').hide();
}
-CubicWeb.provide('edition.js');
// ======================= DEPRECATED FUNCTIONS ========================= //
inlineValidateRelationForm = cw.utils.deprecatedFunction(
'[3.9] inlineValidateRelationForm() function is deprecated, use inlineValidateRelationFormOptions instead',
function(rtype, role, eid, divid, reload, vid, default_value, lzone, onsucess, onfailure) {
try {
- var form = getNode(divid + '-form');
+ var form = cw.getNode(divid + '-form');
var relname = rtype + ':' + eid;
var newtarget = jQuery('[name=' + relname + ']').val();
- var zipped = formContents(form);
+ var zipped = cw.utils.formContents(form);
var d = asyncRemoteExec('validate_form', 'apply', zipped[0], zipped[1]);
} catch(ex) {
return false;
--- a/web/data/cubicweb.js Fri Jun 11 07:58:52 2010 +0200
+++ b/web/data/cubicweb.js Fri Jun 11 07:58:53 2010 +0200
@@ -57,10 +57,10 @@
},
swapDOM: function (dest, src) {
- dest = getNode(dest);
+ dest = cw.getNode(dest);
var parent = dest.parentNode;
if (src) {
- src = getNode(src);
+ src = cw.getNode(src);
parent.replaceChild(src, dest);
} else {
parent.removeChild(dest);
@@ -159,7 +159,7 @@
var children = visitor(node);
if (children) {
for (var i = 0; i < children.length; i++) {
- nodeWalkDepthFirst(children[i], visitor);
+ cw.utils.nodeWalkDepthFirst(children[i], visitor);
}
}
},
@@ -192,7 +192,7 @@
if (typeof(elem) == "undefined" || elem === null) {
elem = document.body;
} else {
- elem = getNode(elem);
+ elem = cw.getNode(elem);
}
cw.utils.nodeWalkDepthFirst(elem, function (elem) {
var name = elem.name;
@@ -250,8 +250,17 @@
if (tagName === "FORM" || tagName === "P" || tagName === "SPAN" || tagName === "DIV") {
return elem.childNodes;
}
+ var value = elem.value;
+ if (tagName === "TEXTAREA") {
+ if (typeof(FCKeditor) != 'undefined') {
+ var fck = FCKeditorAPI.GetInstance(elem.id);
+ if (fck) {
+ value = fck.GetHTML();
+ }
+ }
+ }
names.push(name);
- values.push(elem.value || '');
+ values.push(value || '');
return null;
}
return elem.childNodes;
--- a/web/data/cubicweb.python.js Fri Jun 11 07:58:52 2010 +0200
+++ b/web/data/cubicweb.python.js Fri Jun 11 07:58:53 2010 +0200
@@ -197,7 +197,7 @@
*/
function makeUnboundMethod(meth) {
function unboundMeth(self) {
- var newargs = sliceList(arguments, 1);
+ var newargs = cw.utils.sliceList(arguments, 1);
return meth.apply(self, newargs);
}
unboundMeth.__name__ = meth.__name__;
--- a/web/htmlwidgets.py Fri Jun 11 07:58:52 2010 +0200
+++ b/web/htmlwidgets.py Fri Jun 11 07:58:53 2010 +0200
@@ -307,8 +307,8 @@
self._cw.add_js('jquery.tablesorter.js')
self._cw.add_css(('cubicweb.tablesorter.css', 'cubicweb.tableview.css'))
"""
- highlight = "onmouseover=\"addElementClass(this, 'highlighted');\" " \
- "onmouseout=\"removeElementClass(this, 'highlighted');\""
+ highlight = "onmouseover=\"$(this).addClass('highlighted');\" " \
+ "onmouseout=\"$(this).removeClass('highlighted');\""
def __init__(self, model):
self.model = model
--- a/web/test/unittest_form.py Fri Jun 11 07:58:52 2010 +0200
+++ b/web/test/unittest_form.py Fri Jun 11 07:58:53 2010 +0200
@@ -15,9 +15,6 @@
#
# You should have received a copy of the GNU Lesser General Public License along
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
-"""
-
-"""
from xml.etree.ElementTree import fromstring
--- a/web/views/editforms.py Fri Jun 11 07:58:52 2010 +0200
+++ b/web/views/editforms.py Fri Jun 11 07:58:53 2010 +0200
@@ -340,7 +340,7 @@
self._build_renderer(entity, rtype, role))
def should_edit_attribute(self, entity, rschema, form):
- if not entity.has_perm('update'):
+ if not entity.cw_has_perm('update'):
return False
rdef = entity.e_schema.rdef(rschema)
if not rdef.has_perm(self._cw, 'update', eid=entity.eid):
@@ -370,8 +370,8 @@
w = self.w
divid = form.event_args['divid']
w(u'<div id="%s-reledit" class="field" '
- u'onmouseout="addElementClass(jQuery(\'#%s\'), \'hidden\')" '
- u'onmouseover="removeElementClass(jQuery(\'#%s\'), \'hidden\')">'
+ u'onmouseout="jQuery(\'#%s\').addClass(\'hidden\')" '
+ u'onmouseover="jQuery(\'#%s\').removeClass(\'hidden\')">'
% (divid, divid, divid))
w(u'<div id="%s-value" class="editableFieldValue">%s</div>' % (divid, value))
w(form.render(renderer=renderer))
--- a/web/views/iprogress.py Fri Jun 11 07:58:52 2010 +0200
+++ b/web/views/iprogress.py Fri Jun 11 07:58:53 2010 +0200
@@ -71,8 +71,8 @@
content = entity.printable_value(col)
infos[col] = content
cssclass = entity.cw_adapt_to('IMileStone').progress_class()
- self.w(u"""<tr class="%s" onmouseover="addElementClass(this, 'highlighted');"
- onmouseout="removeElementClass(this, 'highlighted')">""" % cssclass)
+ self.w(u"""<tr class="%s" onmouseover="$(this).addClass('highlighted');"
+ onmouseout="$(this).removeClass('highlighted')">""" % cssclass)
line = u''.join(u'<td>%%(%s)s</td>' % col for col in self.columns)
self.w(line % infos)
self.w(u'</tr>\n')
--- a/web/views/tableview.py Fri Jun 11 07:58:52 2010 +0200
+++ b/web/views/tableview.py Fri Jun 11 07:58:53 2010 +0200
@@ -407,8 +407,8 @@
else:
content = entity.printable_value(col)
infos[col] = content
- self.w(u"""<tr onmouseover="addElementClass(this, 'highlighted');"
- onmouseout="removeElementClass(this, 'highlighted')">""")
+ self.w(u"""<tr onmouseover="$(this).addClass('highlighted');"
+ onmouseout="$(this).removeClass('highlighted')">""")
line = u''.join(u'<td>%%(%s)s</td>' % col for col in self.columns)
self.w(line % infos)
self.w(u'</tr>\n')