33 |
33 |
34 /* |
34 /* |
35 * this function is called when an AJAX form was generated to |
35 * this function is called when an AJAX form was generated to |
36 * make sure tabindex remains consistent |
36 * make sure tabindex remains consistent |
37 */ |
37 */ |
38 function reorderTabindex(start) { |
38 function reorderTabindex(start, formid) { |
39 var form = getNode('entityForm'); |
39 var form = getNode(formid || 'entityForm'); |
40 var inputTypes = ['INPUT', 'SELECT', 'TEXTAREA']; |
40 var inputTypes = ['INPUT', 'SELECT', 'TEXTAREA']; |
41 var tabindex = (start==null)?15:start; |
41 var tabindex = (start==null)?15:start; |
42 nodeWalkDepthFirst(form, function(elem) { |
42 nodeWalkDepthFirst(form, function(elem) { |
43 var tagName = elem.tagName.toUpperCase(); |
43 var tagName = elem.tagName.toUpperCase(); |
44 if (inputTypes.contains(tagName)) { |
44 if (inputTypes.contains(tagName)) { |
228 }); |
228 }); |
229 |
229 |
230 } |
230 } |
231 |
231 |
232 |
232 |
233 function updateInlinedEntitiesCounters(rtype) { |
233 function updateInlinedEntitiesCounters(rtype, role) { |
234 jQuery('#inline' + rtype + 'slot span.icounter').each(function (i) { |
234 jQuery('div.inline-' + rtype + '-' + role + '-slot span.icounter').each(function (i) { |
235 this.innerHTML = i+1; |
235 this.innerHTML = i+1; |
236 }); |
236 }); |
237 } |
237 } |
238 |
238 |
239 |
239 |
240 /* |
240 /* |
241 * makes an AJAX request to get an inline-creation view's content |
241 * makes an AJAX request to get an inline-creation view's content |
242 * @param peid : the parent entity eid |
242 * @param peid : the parent entity eid |
|
243 * @param petype : the parent entity type |
243 * @param ttype : the target (inlined) entity type |
244 * @param ttype : the target (inlined) entity type |
244 * @param rtype : the relation type between both entities |
245 * @param rtype : the relation type between both entities |
245 */ |
246 */ |
246 function addInlineCreationForm(peid, ttype, rtype, role, i18nctx, insertBefore) { |
247 function addInlineCreationForm(peid, petype, ttype, rtype, role, i18nctx, insertBefore) { |
247 insertBefore = insertBefore || getNode('add' + rtype + ':' + peid + 'link').parentNode; |
248 insertBefore = insertBefore || getNode('add' + rtype + ':' + peid + 'link').parentNode; |
248 var d = asyncRemoteExec('inline_creation_form', peid, ttype, rtype, role, i18nctx); |
249 var d = asyncRemoteExec('inline_creation_form', peid, petype, ttype, rtype, role, i18nctx); |
249 d.addCallback(function (response) { |
250 d.addCallback(function (response) { |
250 var dom = getDomFromResponse(response); |
251 var dom = getDomFromResponse(response); |
251 preprocessAjaxLoad(null, dom); |
252 preprocessAjaxLoad(null, dom); |
252 var form = jQuery(dom); |
253 var form = jQuery(dom); |
253 form.css('display', 'none'); |
254 form.css('display', 'none'); |
254 form.insertBefore(insertBefore).slideDown('fast'); |
255 form.insertBefore(insertBefore).slideDown('fast'); |
255 updateInlinedEntitiesCounters(rtype); |
256 updateInlinedEntitiesCounters(rtype, role); |
256 reorderTabindex(); |
257 reorderTabindex(null, $(insertBefore).closest('form')[0]); |
257 jQuery(CubicWeb).trigger('inlinedform-added', form); |
258 jQuery(CubicWeb).trigger('inlinedform-added', form); |
258 // if the inlined form contains a file input, we must force |
259 // if the inlined form contains a file input, we must force |
259 // the form enctype to multipart/form-data |
260 // the form enctype to multipart/form-data |
260 if (form.find('input:file').length) { |
261 if (form.find('input:file').length) { |
261 // NOTE: IE doesn't support dynamic enctype modification, we have |
262 // NOTE: IE doesn't support dynamic enctype modification, we have |
271 } |
272 } |
272 |
273 |
273 /* |
274 /* |
274 * removes the part of the form used to edit an inlined entity |
275 * removes the part of the form used to edit an inlined entity |
275 */ |
276 */ |
276 function removeInlineForm(peid, rtype, eid, showaddnewlink) { |
277 function removeInlineForm(peid, rtype, role, eid, showaddnewlink) { |
277 jqNode(['div', peid, rtype, eid].join('-')).slideUp('fast', function() { |
278 jqNode(['div', peid, rtype, eid].join('-')).slideUp('fast', function() { |
278 $(this).remove(); |
279 $(this).remove(); |
279 updateInlinedEntitiesCounters(rtype); |
280 updateInlinedEntitiesCounters(rtype, role); |
280 }); |
281 }); |
281 if (showaddnewlink) { |
282 if (showaddnewlink) { |
282 toggleVisibility(showaddnewlink); |
283 toggleVisibility(showaddnewlink); |
283 } |
284 } |
284 } |
285 } |
329 var globalerrors = []; |
330 var globalerrors = []; |
330 var firsterrfield = null; |
331 var firsterrfield = null; |
331 for (fieldname in errors) { |
332 for (fieldname in errors) { |
332 var errmsg = errors[fieldname]; |
333 var errmsg = errors[fieldname]; |
333 var fieldid = fieldname + ':' + eid; |
334 var fieldid = fieldname + ':' + eid; |
334 var field = jqNode(fieldname + ':' + eid); |
335 var suffixes = ['', '-subject', '-object']; |
335 if (field && getNodeAttribute(field, 'type') != 'hidden') { |
336 var found = false; |
336 if ( !firsterrfield ) { |
337 for (var i=0, length=suffixes.length; i<length;i++) { |
337 firsterrfield = 'err-' + fieldid; |
338 var field = jqNode(fieldname + suffixes[i] + ':' + eid); |
|
339 if (field && getNodeAttribute(field, 'type') != 'hidden') { |
|
340 if ( !firsterrfield ) { |
|
341 firsterrfield = 'err-' + fieldid; |
|
342 } |
|
343 addElementClass(field, 'error'); |
|
344 var span = SPAN({'id': 'err-' + fieldid, 'class': "error"}, errmsg); |
|
345 field.before(span); |
|
346 found = true; |
|
347 break; |
338 } |
348 } |
339 addElementClass(field, 'error'); |
349 } |
340 var span = SPAN({'id': 'err-' + fieldid, 'class': "error"}, errmsg); |
350 if (!found) { |
341 field.before(span); |
|
342 } else { |
|
343 firsterrfield = formid; |
351 firsterrfield = formid; |
344 globalerrors.push(_(fieldname) + ' : ' + errmsg); |
352 globalerrors.push(_(fieldname) + ' : ' + errmsg); |
345 } |
353 } |
346 } |
354 } |
347 if (globalerrors.length) { |
355 if (globalerrors.length) { |
348 if (globalerrors.length == 1) { |
356 if (globalerrors.length == 1) { |
349 var innernode = SPAN(null, globalerrors[0]); |
357 var innernode = SPAN(null, globalerrors[0]); |
350 } else { |
358 } else { |
351 var innernode = UL(null, map(LI, globalerrors)); |
359 var innernode = UL(null, map(partial(LI, null), globalerrors)); |
352 } |
360 } |
353 // insert DIV and innernode before the form |
361 // insert DIV and innernode before the form |
354 var div = DIV({'class' : "errorMessage", 'id': formid + 'ErrorMessage'}); |
362 var div = DIV({'class' : "errorMessage", 'id': formid + 'ErrorMessage'}); |
355 div.appendChild(innernode); |
363 div.appendChild(innernode); |
356 jQuery('#' + formid).before(div); |
364 jQuery('#' + formid).before(div); |
405 |
413 |
406 /* used by additional submit buttons to remember which button was clicked */ |
414 /* used by additional submit buttons to remember which button was clicked */ |
407 function postForm(bname, bvalue, formid) { |
415 function postForm(bname, bvalue, formid) { |
408 var form = getNode(formid); |
416 var form = getNode(formid); |
409 if (bname) { |
417 if (bname) { |
410 form.appendChild(INPUT({type: 'hidden', name: bname, value: bvalue})); |
418 var child = form.appendChild(INPUT({type: 'hidden', name: bname, value: bvalue})); |
411 } |
419 } |
412 var onsubmit = form.onsubmit; |
420 var onsubmit = form.onsubmit; |
413 if (!onsubmit || (onsubmit && onsubmit())) { |
421 if (!onsubmit || (onsubmit && onsubmit())) { |
414 form.submit(); |
422 form.submit(); |
|
423 } |
|
424 if (bname) { |
|
425 jQuery(child).remove(); /* cleanup */ |
415 } |
426 } |
416 } |
427 } |
417 |
428 |
418 |
429 |
419 /* called on load to set target and iframeso object. |
430 /* called on load to set target and iframeso object. |