author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 25 May 2009 16:09:34 +0200 | |
branch | stable |
changeset 1922 | 1a0ddb675951 |
parent 1868 | af1ae863606d |
child 1971 | 5e6799e86088 |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* :organization: Logilab |
|
1419 | 3 |
* :copyright: 2003-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 4 |
* :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
5 |
*/ |
|
6 |
||
7 |
CubicWeb.require('python.js'); |
|
8 |
CubicWeb.require('htmlhelpers.js'); |
|
9 |
CubicWeb.require('ajax.js'); |
|
10 |
||
11 |
||
12 |
//============= Eproperty form functions =====================================// |
|
13 |
||
14 |
/* called on Eproperty key selection: |
|
15 |
* - get the selected value |
|
16 |
* - get a widget according to the key by a sync query to the server |
|
17 |
* - fill associated div with the returned html |
|
18 |
* |
|
19 |
* @param varname the name of the variable as used in the original creation form |
|
20 |
* @param tabindex the tabindex that should be set on the widget |
|
21 |
*/ |
|
22 |
function setPropValueWidget(varname, tabindex) { |
|
1314
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1292
diff
changeset
|
23 |
var key = firstSelected(document.getElementById('pkey:'+varname)); |
0 | 24 |
if (key) { |
1419 | 25 |
var args = {fname: 'prop_widget', pageid: pageid, |
26 |
arg: map(jQuery.toJSON, [key, varname, tabindex])}; |
|
1314
dc5499bff1a9
fix primary edition of eproperty (weird js pb remaining though)
sylvain.thenault@logilab.fr
parents:
1292
diff
changeset
|
27 |
jqNode('div:value:'+varname).loadxhtml(JSON_BASE_URL, args, 'post'); |
0 | 28 |
} |
29 |
} |
|
30 |
||
31 |
||
32 |
// *** EDITION FUNCTIONS ****************************************** // |
|
33 |
||
34 |
/* |
|
35 |
* this function is called when an AJAX form was generated to |
|
36 |
* make sure tabindex remains consistent |
|
37 |
*/ |
|
38 |
function reorderTabindex(start) { |
|
39 |
var form = getNode('entityForm'); |
|
40 |
var inputTypes = ['INPUT', 'SELECT', 'TEXTAREA']; |
|
41 |
var tabindex = (start==null)?15:start; |
|
42 |
nodeWalkDepthFirst(form, function(elem) { |
|
43 |
var tagName = elem.tagName.toUpperCase(); |
|
44 |
if (inputTypes.contains(tagName)) { |
|
45 |
if (getNodeAttribute(elem, 'tabindex') != null) { |
|
46 |
tabindex += 1; |
|
47 |
elem.setAttribute('tabindex', tabindex); |
|
48 |
} |
|
49 |
return null; |
|
50 |
} |
|
51 |
return filter(isElementNode, elem.childNodes); |
|
52 |
}); |
|
53 |
} |
|
54 |
||
1419 | 55 |
|
0 | 56 |
function showMatchingSelect(selectedValue, eid) { |
57 |
if (selectedValue) { |
|
58 |
divId = 'div' + selectedValue + '_' + eid; |
|
59 |
var divNode = jQuery('#' + divId); |
|
60 |
if (!divNode.length) { |
|
61 |
var args = {vid: 'unrelateddivs', relation: selectedValue, |
|
1419 | 62 |
rql: rql_for_eid(eid), '__notemplate': 1, |
63 |
callback: function() {_showMatchingSelect(eid, jQuery('#' + divId))}}; |
|
64 |
jQuery('#unrelatedDivs_' + eid).loadxhtml(baseuri() + 'view', args, 'post', 'append'); |
|
0 | 65 |
} else { |
66 |
_showMatchingSelect(eid, divNode); |
|
67 |
} |
|
1419 | 68 |
} else { |
0 | 69 |
_showMatchingSelect(eid, null); |
70 |
} |
|
71 |
} |
|
72 |
||
73 |
||
74 |
// @param divNode is a jQuery selection |
|
75 |
function _showMatchingSelect(eid, divNode) { |
|
76 |
// hide all divs, and then show the matching one |
|
77 |
// (would actually be better to directly hide the displayed one) |
|
78 |
jQuery('#unrelatedDivs_' + eid).children().hide(); |
|
79 |
// divNode not found means 'no relation selected' (i.e. first blank item) |
|
80 |
if (divNode && divNode.length) { |
|
81 |
divNode.show(); |
|
82 |
} |
|
83 |
} |
|
84 |
||
85 |
// this function builds a Handle to cancel pending insertion |
|
86 |
function buildPendingInsertHandle(elementId, element_name, selectNodeId, eid) { |
|
87 |
jscall = "javascript: cancelPendingInsert('" + [elementId, element_name, selectNodeId, eid].join("', '") + "')"; |
|
88 |
return A({'class' : 'handle', 'href' : jscall, |
|
89 |
'title' : _("cancel this insert")}, '[x]'); |
|
90 |
} |
|
91 |
||
92 |
function buildEntityLine(relationName, selectedOptionNode, comboId, eid) { |
|
93 |
// textContent doesn't seem to work on selectedOptionNode |
|
94 |
var content = selectedOptionNode.firstChild.nodeValue; |
|
95 |
var handle = buildPendingInsertHandle(selectedOptionNode.id, 'tr', comboId, eid); |
|
96 |
var link = A({'href' : 'view?rql=' + selectedOptionNode.value, |
|
97 |
'class' : 'editionPending', 'id' : 'a' + selectedOptionNode.id}, |
|
98 |
content); |
|
99 |
var tr = TR({'id' : 'tr' + selectedOptionNode.id}, [ TH(null, relationName), |
|
100 |
TD(null, [handle, link]) |
|
101 |
]); |
|
102 |
try { |
|
103 |
var separator = getNode('relationSelectorRow_' + eid); |
|
104 |
//dump('relationSelectorRow_' + eid) XXX warn dump is not implemented in konqueror (at least) |
|
105 |
// XXX Warning: separator.parentNode is not (always ?) the |
|
106 |
// table itself, but an intermediate node (TableSectionElement) |
|
107 |
var tableBody = separator.parentNode; |
|
108 |
tableBody.insertBefore(tr, separator); |
|
109 |
} catch(ex) { |
|
110 |
log("got exception(2)!" + ex); |
|
111 |
} |
|
112 |
} |
|
113 |
||
114 |
function buildEntityCell(relationName, selectedOptionNode, comboId, eid) { |
|
115 |
var handle = buildPendingInsertHandle(selectedOptionNode.id, 'div_insert_', comboId, eid); |
|
116 |
var link = A({'href' : 'view?rql=' + selectedOptionNode.value, |
|
117 |
'class' : 'editionPending', 'id' : 'a' + selectedOptionNode.id}, |
|
118 |
content); |
|
119 |
var div = DIV({'id' : 'div_insert_' + selectedOptionNode.id}, [handle, link]); |
|
120 |
try { |
|
121 |
var td = jQuery('#cell'+ relationName +'_'+eid); |
|
122 |
td.appendChild(div); |
|
123 |
} catch(ex) { |
|
124 |
alert("got exception(3)!" + ex); |
|
125 |
} |
|
126 |
} |
|
127 |
||
128 |
function addPendingInsert(optionNode, eid, cell, relname) { |
|
129 |
var value = getNodeAttribute(optionNode, 'value'); |
|
130 |
if (!value) { |
|
131 |
// occurs when the first element in the box is selected (which is not |
|
132 |
// an entity but the combobox title) |
|
133 |
return; |
|
134 |
} |
|
135 |
// 2nd special case |
|
136 |
if (value.indexOf('http') == 0) { |
|
137 |
document.location = value; |
|
138 |
return; |
|
139 |
} |
|
140 |
// add hidden parameter |
|
141 |
var entityForm = jQuery('#entityForm'); |
|
142 |
var oid = optionNode.id.substring(2); // option id is prefixed by "id" |
|
1419 | 143 |
remoteExec('add_pending_inserts', [oid.split(':')]); |
0 | 144 |
var selectNode = optionNode.parentNode; |
145 |
// remove option node |
|
146 |
selectNode.removeChild(optionNode); |
|
147 |
// add line in table |
|
148 |
if (cell) { |
|
149 |
// new relation as a cell in multiple edit |
|
150 |
// var relation_name = relationSelected.getAttribute('value'); |
|
151 |
// relation_name = relation_name.slice(0, relation_name.lastIndexOf('_')); |
|
152 |
buildEntityCell(relname, optionNode, selectNode.id, eid); |
|
153 |
} |
|
154 |
else { |
|
155 |
var relationSelector = getNode('relationSelector_'+eid); |
|
156 |
var relationSelected = relationSelector.options[relationSelector.selectedIndex]; |
|
157 |
// new relation as a line in simple edit |
|
158 |
buildEntityLine(relationSelected.text, optionNode, selectNode.id, eid); |
|
159 |
} |
|
160 |
} |
|
161 |
||
162 |
function cancelPendingInsert(elementId, element_name, comboId, eid) { |
|
163 |
// remove matching insert element |
|
164 |
var entityView = jqNode('a' + elementId).text(); |
|
165 |
jqNode(element_name + elementId).remove(); |
|
166 |
if (comboId) { |
|
167 |
// re-insert option in combobox if it was taken from there |
|
168 |
var selectNode = getNode(comboId); |
|
1713
d817f23439ba
bix a bug: correct the sended parameter 'no need for id in the string parameter name'
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1419
diff
changeset
|
169 |
// XXX what on object relation |
0 | 170 |
if (selectNode){ |
171 |
var options = selectNode.options; |
|
172 |
var node_id = elementId.substring(0, elementId.indexOf(':')); |
|
173 |
options[options.length] = OPTION({'id' : elementId, 'value' : node_id}, entityView); |
|
174 |
} |
|
175 |
} |
|
1713
d817f23439ba
bix a bug: correct the sended parameter 'no need for id in the string parameter name'
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1419
diff
changeset
|
176 |
elementId = elementId.substring(2, elementId.length); |
1419 | 177 |
remoteExec('remove_pending_insert', elementId.split(':')); |
0 | 178 |
} |
179 |
||
180 |
// this function builds a Handle to cancel pending insertion |
|
181 |
function buildPendingDeleteHandle(elementId, eid) { |
|
182 |
var jscall = "javascript: addPendingDelete('" + elementId + ', ' + eid + "');"; |
|
183 |
return A({'href' : jscall, 'class' : 'pendingDeleteHandle', |
|
184 |
'title' : _("delete this relation")}, '[x]'); |
|
185 |
} |
|
186 |
||
187 |
// @param nodeId eid_from:r_type:eid_to |
|
188 |
function addPendingDelete(nodeId, eid) { |
|
1419 | 189 |
var d = asyncRemoteExec('add_pending_delete', nodeId.split(':')); |
0 | 190 |
d.addCallback(function () { |
191 |
// and strike entity view |
|
192 |
jqNode('span' + nodeId).addClass('pendingDelete'); |
|
193 |
// replace handle text |
|
194 |
jqNode('handle' + nodeId).text('+'); |
|
195 |
}); |
|
196 |
} |
|
197 |
||
198 |
// @param nodeId eid_from:r_type:eid_to |
|
199 |
function cancelPendingDelete(nodeId, eid) { |
|
1419 | 200 |
var d = asyncRemoteExec('remove_pending_delete', nodeId.split(':')); |
0 | 201 |
d.addCallback(function () { |
202 |
// reset link's CSS class |
|
203 |
jqNode('span' + nodeId).removeClass('pendingDelete'); |
|
204 |
// replace handle text |
|
205 |
jqNode('handle' + nodeId).text('x'); |
|
206 |
}); |
|
207 |
} |
|
208 |
||
209 |
// @param nodeId eid_from:r_type:eid_to |
|
210 |
function togglePendingDelete(nodeId, eid) { |
|
211 |
// node found means we should cancel deletion |
|
212 |
if ( hasElementClass(getNode('span' + nodeId), 'pendingDelete') ) { |
|
213 |
cancelPendingDelete(nodeId, eid); |
|
214 |
} else { |
|
215 |
addPendingDelete(nodeId, eid); |
|
216 |
} |
|
217 |
} |
|
218 |
||
219 |
||
220 |
function selectForAssociation(tripletIdsString, originalEid) { |
|
221 |
var tripletlist = map(function (x) { return x.split(':'); }, |
|
222 |
tripletIdsString.split('-')); |
|
1419 | 223 |
var d = asyncRemoteExec('add_pending_inserts', tripletlist); |
0 | 224 |
d.addCallback(function () { |
225 |
var args = {vid: 'edition', __mode: 'normal', |
|
226 |
rql: rql_for_eid(originalEid)}; |
|
1419 | 227 |
document.location = 'view?' + asURL(args); |
0 | 228 |
}); |
229 |
||
230 |
} |
|
231 |
||
232 |
||
233 |
function updateInlinedEntitiesCounters(rtype) { |
|
234 |
jQuery('#inline' + rtype + 'slot span.icounter').each(function (i) { |
|
235 |
this.innerHTML = i+1; |
|
236 |
}); |
|
237 |
} |
|
238 |
||
1419 | 239 |
|
0 | 240 |
/* |
241 |
* makes an AJAX request to get an inline-creation view's content |
|
242 |
* @param peid : the parent entity eid |
|
243 |
* @param ttype : the target (inlined) entity type |
|
244 |
* @param rtype : the relation type between both entities |
|
245 |
*/ |
|
1292
18a86192c9c4
inline_creation_form doesn't take ptype argument anymore
sylvain.thenault@logilab.fr
parents:
992
diff
changeset
|
246 |
function addInlineCreationForm(peid, ttype, rtype, role) { |
1419 | 247 |
var d = asyncRemoteExec('inline_creation_form', peid, ttype, rtype, role); |
0 | 248 |
d.addCallback(function (response) { |
249 |
var linknode = getNode('add' + rtype + ':' + peid + 'link'); |
|
992
d5fe2626695b
call postAjaxLoad in addInlineCreationForm javascript function in order to call buildWysiwygEditors when a section of the page is reloaded
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
977
diff
changeset
|
250 |
var dom = getDomFromResponse(response); |
d5fe2626695b
call postAjaxLoad in addInlineCreationForm javascript function in order to call buildWysiwygEditors when a section of the page is reloaded
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
977
diff
changeset
|
251 |
var form = jQuery(dom); |
0 | 252 |
form.css('display', 'none'); |
253 |
form.insertBefore(linknode.parentNode).slideDown('fast'); |
|
254 |
updateInlinedEntitiesCounters(rtype); |
|
255 |
reorderTabindex(); |
|
256 |
form.trigger('inlinedform-added'); |
|
992
d5fe2626695b
call postAjaxLoad in addInlineCreationForm javascript function in order to call buildWysiwygEditors when a section of the page is reloaded
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
977
diff
changeset
|
257 |
postAjaxLoad(dom); |
0 | 258 |
}); |
259 |
d.addErrback(function (xxx) { |
|
260 |
log('xxx =', xxx); |
|
261 |
}); |
|
262 |
} |
|
263 |
||
264 |
/* |
|
265 |
* removes the part of the form used to edit an inlined entity |
|
266 |
*/ |
|
267 |
function removeInlineForm(peid, rtype, eid) { |
|
268 |
jqNode(['div', peid, rtype, eid].join('-')).slideUp('fast', function() { |
|
269 |
$(this).remove(); |
|
270 |
updateInlinedEntitiesCounters(rtype); |
|
271 |
}); |
|
272 |
} |
|
273 |
||
274 |
/* |
|
275 |
* alternatively adds or removes the hidden input that make the |
|
276 |
* edition of the relation `rtype` possible between `peid` and `eid` |
|
277 |
* @param peid : the parent entity eid |
|
278 |
* @param rtype : the relation type between both entities |
|
279 |
* @param eid : the inlined entity eid |
|
280 |
*/ |
|
281 |
function removeInlinedEntity(peid, rtype, eid) { |
|
282 |
var nodeid = ['rel', peid, rtype, eid].join('-'); |
|
283 |
var node = jqNode(nodeid); |
|
284 |
if (node && node.length) { |
|
285 |
node.remove(); |
|
1419 | 286 |
var divid = ['div', peid, rtype, eid].join('-'); |
0 | 287 |
jqNode(divid).fadeTo('fast', 0.5); |
1419 | 288 |
var noticeid = ['notice', peid, rtype, eid].join('-'); |
0 | 289 |
jqNode(noticeid).fadeIn('fast'); |
290 |
} |
|
291 |
} |
|
292 |
||
293 |
function restoreInlinedEntity(peid, rtype, eid) { |
|
294 |
var nodeid = ['rel', peid, rtype, eid].join('-'); |
|
295 |
var divid = ['div', peid, rtype, eid].join('-'); |
|
296 |
var noticeid = ['notice', peid, rtype, eid].join('-'); |
|
297 |
var node = jqNode(nodeid); |
|
298 |
if (!(node && node.length)) { |
|
299 |
node = INPUT({type: 'hidden', id: nodeid, |
|
300 |
name: rtype+':'+peid, value: eid}); |
|
301 |
jqNode(['fs', peid, rtype, eid].join('-')).append(node); |
|
302 |
jqNode(divid).fadeTo('fast', 1); |
|
303 |
jqNode(noticeid).hide(); |
|
304 |
} |
|
305 |
} |
|
306 |
||
307 |
function _clearPreviousErrors(formid) { |
|
308 |
jQuery('#' + formid + ' span.error').remove(); |
|
309 |
} |
|
310 |
||
311 |
function _displayValidationerrors(formid, eid, errors) { |
|
312 |
var globalerrors = []; |
|
313 |
var firsterrfield = null; |
|
314 |
for (fieldname in errors) { |
|
315 |
var errmsg = errors[fieldname]; |
|
316 |
var fieldid = fieldname + ':' + eid; |
|
317 |
var field = jqNode(fieldname + ':' + eid); |
|
318 |
if (field && getNodeAttribute(field, 'type') != 'hidden') { |
|
319 |
if ( !firsterrfield ) { |
|
320 |
firsterrfield = 'err-' + fieldid; |
|
321 |
} |
|
322 |
addElementClass(field, 'error'); |
|
323 |
var span = SPAN({'id': 'err-' + fieldid, 'class': "error"}, errmsg); |
|
324 |
field.before(span); |
|
325 |
} else { |
|
326 |
firsterrfield = formid; |
|
327 |
globalerrors.push(fieldname + ': ' + errmsg); |
|
328 |
} |
|
329 |
} |
|
330 |
if (globalerrors.length) { |
|
331 |
if (globalerrors.length == 1) { |
|
332 |
var innernode = SPAN(null, globalerrors[0]); |
|
333 |
} else { |
|
334 |
var innernode = UL(null, map(LI, globalerrors)); |
|
335 |
} |
|
336 |
// insert DIV and innernode before the form |
|
337 |
var div = DIV({'class' : "errorMessage"}); |
|
338 |
div.appendChild(innernode); |
|
339 |
jQuery('#' + formid).before(div); |
|
340 |
} |
|
341 |
return firsterrfield || formid; |
|
342 |
} |
|
343 |
||
344 |
||
1864
4ceaf8f2709b
add onfailure fonction for validateForm, return formid on success
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1798
diff
changeset
|
345 |
function handleFormValidationResponse(formid, onsuccess, onfailure, result) { |
0 | 346 |
// Success |
347 |
if (result[0]) { |
|
348 |
if (onsuccess) { |
|
1864
4ceaf8f2709b
add onfailure fonction for validateForm, return formid on success
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1798
diff
changeset
|
349 |
return onsuccess(result[1], formid); |
0 | 350 |
} else { |
351 |
document.location.href = result[1]; |
|
352 |
return ; |
|
353 |
} |
|
354 |
} |
|
355 |
unfreezeFormButtons(formid); |
|
356 |
// Failures |
|
357 |
_clearPreviousErrors(formid); |
|
358 |
var descr = result[1]; |
|
359 |
// Unknown structure |
|
360 |
if ( !isArrayLike(descr) || descr.length != 2 ) { |
|
361 |
log('got strange error :', descr); |
|
362 |
updateMessage(descr); |
|
363 |
return ; |
|
364 |
} |
|
365 |
_displayValidationerrors(formid, descr[0], descr[1]); |
|
366 |
updateMessage(_("please correct errors below")); |
|
367 |
document.location.hash = '#header'; |
|
1864
4ceaf8f2709b
add onfailure fonction for validateForm, return formid on success
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1798
diff
changeset
|
368 |
if (onfailure){ |
4ceaf8f2709b
add onfailure fonction for validateForm, return formid on success
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1798
diff
changeset
|
369 |
onfailure(formid); |
4ceaf8f2709b
add onfailure fonction for validateForm, return formid on success
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1798
diff
changeset
|
370 |
} |
0 | 371 |
return false; |
372 |
} |
|
373 |
||
374 |
||
375 |
/* unfreeze form buttons when the validation process is over*/ |
|
376 |
function unfreezeFormButtons(formid) { |
|
377 |
jQuery('#progress').hide(); |
|
378 |
jQuery('#' + formid + ' input.validateButton').removeAttr('disabled'); |
|
379 |
return true; |
|
380 |
} |
|
381 |
||
382 |
/* disable form buttons while the validation is being done */ |
|
383 |
function freezeFormButtons(formid) { |
|
384 |
jQuery('#progress').show(); |
|
977 | 385 |
jQuery('#' + formid + ' input.validateButton').attr('disabled', 'disabled'); |
0 | 386 |
return true; |
387 |
} |
|
388 |
||
389 |
/* used by additional submit buttons to remember which button was clicked */ |
|
390 |
function postForm(bname, bvalue, formid) { |
|
391 |
var form = getNode(formid); |
|
392 |
if (bname) { |
|
393 |
form.appendChild(INPUT({type: 'hidden', name: bname, value: bvalue})); |
|
394 |
} |
|
395 |
var onsubmit = form.onsubmit; |
|
396 |
if (!onsubmit || (onsubmit && onsubmit())) { |
|
397 |
form.submit(); |
|
398 |
} |
|
399 |
} |
|
400 |
||
401 |
||
402 |
/* called on load to set target and iframeso object. |
|
403 |
* NOTE: this is a hack to make the XHTML compliant. |
|
404 |
* NOTE2: `object` nodes might be a potential replacement for iframes |
|
405 |
* NOTE3: there is a XHTML module allowing iframe elements but there |
|
406 |
* is still the problem of the form's `target` attribute |
|
407 |
*/ |
|
408 |
function setFormsTarget() { |
|
409 |
jQuery('form.entityForm').each(function () { |
|
410 |
var form = jQuery(this); |
|
411 |
var target = form.attr('cubicweb:target'); |
|
412 |
if (target) { |
|
413 |
form.attr('target', target); |
|
1419 | 414 |
/* do not use display: none because some browsers ignore iframe |
415 |
* with no display */ |
|
0 | 416 |
form.append(IFRAME({name: target, id: target, |
417 |
src: 'javascript: void(0)', |
|
418 |
width: '0px', height: '0px'})); |
|
419 |
} |
|
420 |
}); |
|
421 |
} |
|
422 |
||
423 |
$(document).ready(setFormsTarget); |
|
424 |
||
425 |
||
426 |
/* |
|
427 |
* called on traditionnal form submission : the idea is to try |
|
428 |
* to post the form. If the post is successful, `validateForm` redirects |
|
429 |
* to the appropriate URL. Otherwise, the validation errors are displayed |
|
430 |
* around the corresponding input fields. |
|
431 |
*/ |
|
1864
4ceaf8f2709b
add onfailure fonction for validateForm, return formid on success
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1798
diff
changeset
|
432 |
function validateForm(formid, action, onsuccess, onfailure) { |
0 | 433 |
try { |
1419 | 434 |
var zipped = formContents(formid); |
435 |
var d = asyncRemoteExec('validate_form', action, zipped[0], zipped[1]); |
|
0 | 436 |
} catch (ex) { |
437 |
log('got exception', ex); |
|
438 |
return false; |
|
439 |
} |
|
440 |
function _callback(result, req) { |
|
1864
4ceaf8f2709b
add onfailure fonction for validateForm, return formid on success
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1798
diff
changeset
|
441 |
handleFormValidationResponse(formid, onsuccess, onfailure, result); |
0 | 442 |
} |
443 |
d.addCallback(_callback); |
|
444 |
return false; |
|
445 |
} |
|
446 |
||
1419 | 447 |
|
0 | 448 |
/* |
1759
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1713
diff
changeset
|
449 |
* called by reledit forms to submit changes |
0 | 450 |
* @param formid : the dom id of the form used |
451 |
* @param rtype : the attribute being edited |
|
452 |
* @param eid : the eid of the entity being edited |
|
453 |
* @param reload: boolean to reload page if true (when changing URL dependant data) |
|
454 |
*/ |
|
1798
cc86fe8efaaa
pass default values along the whole call chain, fix hidden field update bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1760
diff
changeset
|
455 |
function inlineValidateAttributeForm(formid, rtype, eid, divid, reload, default_value) { |
0 | 456 |
try { |
457 |
var form = getNode(formid); |
|
458 |
if (typeof FCKeditorAPI != "undefined") { |
|
459 |
for ( var name in FCKeditorAPI.__Instances ) { |
|
460 |
var oEditor = FCKeditorAPI.__Instances[name] ; |
|
461 |
if ( oEditor.GetParentForm() == form ) { |
|
462 |
oEditor.UpdateLinkedField(); |
|
463 |
} |
|
464 |
} |
|
465 |
} |
|
466 |
var zipped = formContents(form); |
|
1798
cc86fe8efaaa
pass default values along the whole call chain, fix hidden field update bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1760
diff
changeset
|
467 |
var d = asyncRemoteExec('edit_field', 'apply', zipped[0], zipped[1], |
cc86fe8efaaa
pass default values along the whole call chain, fix hidden field update bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1760
diff
changeset
|
468 |
rtype, eid, default_value); |
0 | 469 |
} catch (ex) { |
470 |
log('got exception', ex); |
|
471 |
return false; |
|
472 |
} |
|
473 |
d.addCallback(function (result, req) { |
|
1868
af1ae863606d
update handleFormValidationResponse calls
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1864
diff
changeset
|
474 |
handleFormValidationResponse(formid, noop, noop, result); |
0 | 475 |
if (reload) { |
476 |
document.location.href = result[1]; |
|
477 |
} else { |
|
478 |
var fieldview = getNode(divid); |
|
479 |
// XXX using innerHTML is very fragile and won't work if |
|
480 |
// we mix XHTML and HTML |
|
481 |
fieldview.innerHTML = result[2]; |
|
482 |
// switch inline form off only if no error |
|
483 |
if (result[0]) { |
|
484 |
// hide global error messages |
|
485 |
jQuery('div.errorMessage').remove(); |
|
486 |
jQuery('#appMsg').hide(); |
|
487 |
cancelInlineEdit(eid, rtype, divid); |
|
488 |
} |
|
489 |
} |
|
490 |
return false; |
|
491 |
}); |
|
492 |
return false; |
|
493 |
} |
|
494 |
||
1798
cc86fe8efaaa
pass default values along the whole call chain, fix hidden field update bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1760
diff
changeset
|
495 |
function inlineValidateRelationForm(formid, rtype, role, eid, divid, vid, default_value) { |
1759
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1713
diff
changeset
|
496 |
try { |
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1713
diff
changeset
|
497 |
var form = getNode(formid); |
1798
cc86fe8efaaa
pass default values along the whole call chain, fix hidden field update bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1760
diff
changeset
|
498 |
var relname = rtype + ':' + eid; |
cc86fe8efaaa
pass default values along the whole call chain, fix hidden field update bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1760
diff
changeset
|
499 |
var newtarget = jQuery('[name=' + relname + ']').val(); |
1759
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1713
diff
changeset
|
500 |
var zipped = formContents(form); |
1798
cc86fe8efaaa
pass default values along the whole call chain, fix hidden field update bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1760
diff
changeset
|
501 |
var d = asyncRemoteExec('edit_relation', 'apply', zipped[0], zipped[1], rtype, role, |
cc86fe8efaaa
pass default values along the whole call chain, fix hidden field update bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1760
diff
changeset
|
502 |
eid, vid, default_value); |
1759
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1713
diff
changeset
|
503 |
} catch (ex) { |
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1713
diff
changeset
|
504 |
log('got exception', ex); |
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1713
diff
changeset
|
505 |
return false; |
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1713
diff
changeset
|
506 |
} |
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1713
diff
changeset
|
507 |
d.addCallback(function (result, req) { |
1868
af1ae863606d
update handleFormValidationResponse calls
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1864
diff
changeset
|
508 |
handleFormValidationResponse(formid, noop, noop, result); |
1760
6b97d286eb5a
[reledit] relation edition : cleanup a bit #343123
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1759
diff
changeset
|
509 |
var fieldview = getNode(divid); |
6b97d286eb5a
[reledit] relation edition : cleanup a bit #343123
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1759
diff
changeset
|
510 |
fieldview.innerHTML = result[2]; |
6b97d286eb5a
[reledit] relation edition : cleanup a bit #343123
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1759
diff
changeset
|
511 |
// switch inline form off only if no error |
6b97d286eb5a
[reledit] relation edition : cleanup a bit #343123
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1759
diff
changeset
|
512 |
if (result[0]) { |
6b97d286eb5a
[reledit] relation edition : cleanup a bit #343123
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1759
diff
changeset
|
513 |
// hide global error messages |
6b97d286eb5a
[reledit] relation edition : cleanup a bit #343123
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1759
diff
changeset
|
514 |
jQuery('div.errorMessage').remove(); |
6b97d286eb5a
[reledit] relation edition : cleanup a bit #343123
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1759
diff
changeset
|
515 |
jQuery('#appMsg').hide(); |
1798
cc86fe8efaaa
pass default values along the whole call chain, fix hidden field update bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1760
diff
changeset
|
516 |
var inputname = 'edit' + role[0] + '-' + relname; |
cc86fe8efaaa
pass default values along the whole call chain, fix hidden field update bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1760
diff
changeset
|
517 |
jQuery('input[name=' + inputname + ']').val(newtarget); |
1760
6b97d286eb5a
[reledit] relation edition : cleanup a bit #343123
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1759
diff
changeset
|
518 |
cancelInlineEdit(eid, rtype, divid); |
1759
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1713
diff
changeset
|
519 |
} |
1760
6b97d286eb5a
[reledit] relation edition : cleanup a bit #343123
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1759
diff
changeset
|
520 |
return false; |
1759
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1713
diff
changeset
|
521 |
}); |
1760
6b97d286eb5a
[reledit] relation edition : cleanup a bit #343123
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1759
diff
changeset
|
522 |
return false; |
1759
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1713
diff
changeset
|
523 |
} |
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1713
diff
changeset
|
524 |
|
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1713
diff
changeset
|
525 |
|
0 | 526 |
/**** inline edition ****/ |
527 |
function showInlineEditionForm(eid, rtype, divid) { |
|
528 |
jQuery('#' + divid).hide(); |
|
529 |
jQuery('#' + divid + '-form').show(); |
|
530 |
} |
|
531 |
||
532 |
function cancelInlineEdit(eid, rtype, divid) { |
|
533 |
jQuery('#' + divid).show(); |
|
534 |
jQuery('#' + divid + '-form').hide(); |
|
535 |
} |
|
536 |
||
537 |
CubicWeb.provide('edition.js'); |