author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 13 Sep 2011 15:41:11 +0200 | |
changeset 7784 | 7f5c455ec7d1 |
parent 7517 | a05bad3aec2e |
child 8185 | 864fc1f147a4 |
permissions | -rw-r--r-- |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
1 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
2 |
* Functions dedicated to edition. |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
3 |
* |
0 | 4 |
* :organization: Logilab |
4382
6fb02edd05da
3.6 api update, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4378
diff
changeset
|
5 |
* :copyright: 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 6 |
* :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
7 |
* |
0 | 8 |
*/ |
9 |
||
10 |
//============= Eproperty form functions =====================================// |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
11 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
12 |
* .. function:: setPropValueWidget(varname, tabindex) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
13 |
* |
6727
2eeccd6f8abe
[edition js] update docstring and remove a 3.9 deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6726
diff
changeset
|
14 |
* called on CWProperty key selection: |
0 | 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 |
* |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
19 |
* * `varname`, the name of the variable as used in the original creation form |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
20 |
* * `tabindex`, the tabindex that should be set on the widget |
0 | 21 |
*/ |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5727
diff
changeset
|
22 |
|
0 | 23 |
function setPropValueWidget(varname, tabindex) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
24 |
var key = firstSelected(document.getElementById('pkey:' + varname)); |
0 | 25 |
if (key) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
26 |
var args = { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
27 |
fname: 'prop_widget', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
28 |
pageid: pageid, |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
29 |
arg: $.map([key, varname, tabindex], jQuery.toJSON) |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
30 |
}; |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
31 |
cw.jqNode('div:value:' + varname).loadxhtml(JSON_BASE_URL, args, 'post'); |
0 | 32 |
} |
33 |
} |
|
34 |
||
35 |
// *** EDITION FUNCTIONS ****************************************** // |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
36 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
37 |
* .. function:: reorderTabindex(start, formid) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
38 |
* |
0 | 39 |
* this function is called when an AJAX form was generated to |
40 |
* make sure tabindex remains consistent |
|
41 |
*/ |
|
4969
0ad18e41053a
[form js] apply vgodard patch fixing #750056: reorderTabindex js function crashes when form dom id is not 'entityForm'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4629
diff
changeset
|
42 |
function reorderTabindex(start, formid) { |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
43 |
var form = cw.getNode(formid || 'entityForm'); |
0 | 44 |
var inputTypes = ['INPUT', 'SELECT', 'TEXTAREA']; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
45 |
var tabindex = (start == null) ? 15: start; |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
46 |
cw.utils.nodeWalkDepthFirst(form, function(elem) { |
0 | 47 |
var tagName = elem.tagName.toUpperCase(); |
7258
2e7f0d6fa2d6
[js] fix inArray usage in reorderTabIndex() : inArray returns -1 if element is not found, not 'false'
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6903
diff
changeset
|
48 |
if (jQuery.inArray(tagName, inputTypes) != -1) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
49 |
if (jQuery(elem).attr('tabindex') != null) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
50 |
tabindex += 1; |
5937
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5936
diff
changeset
|
51 |
jQuery(elem).attr('tabindex', tabindex); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
52 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
53 |
return null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
54 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
55 |
return jQuery.grep(elem.childNodes, isElementNode); |
0 | 56 |
}); |
57 |
} |
|
58 |
||
59 |
function showMatchingSelect(selectedValue, eid) { |
|
60 |
if (selectedValue) { |
|
7258
2e7f0d6fa2d6
[js] fix inArray usage in reorderTabIndex() : inArray returns -1 if element is not found, not 'false'
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6903
diff
changeset
|
61 |
var divId = 'div' + selectedValue + '_' + eid; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
62 |
var divNode = jQuery('#' + divId); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
63 |
if (!divNode.length) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
64 |
var args = { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
65 |
vid: 'unrelateddivs', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
66 |
relation: selectedValue, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
67 |
rql: rql_for_eid(eid), |
6746
f29a5f015fc3
[js/edition] remove trailing coma
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6727
diff
changeset
|
68 |
'__notemplate': 1 |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
69 |
}; |
6727
2eeccd6f8abe
[edition js] update docstring and remove a 3.9 deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6726
diff
changeset
|
70 |
var d = jQuery('#unrelatedDivs_' + eid).loadxhtml(baseuri() + 'view', args, 'post', 'append'); |
2eeccd6f8abe
[edition js] update docstring and remove a 3.9 deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6726
diff
changeset
|
71 |
d.addCallback(function() { |
2eeccd6f8abe
[edition js] update docstring and remove a 3.9 deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6726
diff
changeset
|
72 |
_showMatchingSelect(eid, jQuery('#' + divId)); |
2eeccd6f8abe
[edition js] update docstring and remove a 3.9 deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6726
diff
changeset
|
73 |
}); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
74 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
75 |
_showMatchingSelect(eid, divNode); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
76 |
} |
1419 | 77 |
} else { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
78 |
_showMatchingSelect(eid, null); |
0 | 79 |
} |
80 |
} |
|
81 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
82 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
83 |
* .. function:: _showMatchingSelect(eid, divNode) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
84 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
85 |
* * `divNode`, a jQuery selection |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
86 |
*/ |
0 | 87 |
function _showMatchingSelect(eid, divNode) { |
88 |
// hide all divs, and then show the matching one |
|
89 |
// (would actually be better to directly hide the displayed one) |
|
90 |
jQuery('#unrelatedDivs_' + eid).children().hide(); |
|
91 |
// divNode not found means 'no relation selected' (i.e. first blank item) |
|
92 |
if (divNode && divNode.length) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
93 |
divNode.show(); |
0 | 94 |
} |
95 |
} |
|
96 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
97 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
98 |
* .. function:: buildPendingInsertHandle(elementId, element_name, selectNodeId, eid) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
99 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
100 |
* this function builds a Handle to cancel pending insertion |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
101 |
*/ |
0 | 102 |
function buildPendingInsertHandle(elementId, element_name, selectNodeId, eid) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
103 |
jscall = "javascript: cancelPendingInsert('" + [elementId, element_name, selectNodeId, eid].join("', '") + "')"; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
104 |
return A({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
105 |
'class': 'handle', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
106 |
'href': jscall, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
107 |
'title': _("cancel this insert") |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
108 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
109 |
'[x]'); |
0 | 110 |
} |
111 |
||
112 |
function buildEntityLine(relationName, selectedOptionNode, comboId, eid) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
113 |
// textContent doesn't seem to work on selectedOptionNode |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
114 |
var content = selectedOptionNode.firstChild.nodeValue; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
115 |
var handle = buildPendingInsertHandle(selectedOptionNode.id, 'tr', comboId, eid); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
116 |
var link = A({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
117 |
'href': 'view?rql=' + selectedOptionNode.value, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
118 |
'class': 'editionPending', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
119 |
'id': 'a' + selectedOptionNode.id |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
120 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
121 |
content); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
122 |
var tr = TR({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
123 |
'id': 'tr' + selectedOptionNode.id |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
124 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
125 |
[TH(null, relationName), TD(null, [handle, link])]); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
126 |
try { |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
127 |
var separator = cw.getNode('relationSelectorRow_' + eid); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
128 |
//dump('relationSelectorRow_' + eid) XXX warn dump is not implemented in konqueror (at least) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
129 |
// XXX Warning: separator.parentNode is not (always ?) the |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
130 |
// table itself, but an intermediate node (TableSectionElement) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
131 |
var tableBody = separator.parentNode; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
132 |
tableBody.insertBefore(tr, separator); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
133 |
} catch(ex) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
134 |
log("got exception(2)!" + ex); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
135 |
} |
0 | 136 |
} |
137 |
||
138 |
function buildEntityCell(relationName, selectedOptionNode, comboId, eid) { |
|
139 |
var handle = buildPendingInsertHandle(selectedOptionNode.id, 'div_insert_', comboId, eid); |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
140 |
var link = A({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
141 |
'href': 'view?rql=' + selectedOptionNode.value, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
142 |
'class': 'editionPending', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
143 |
'id': 'a' + selectedOptionNode.id |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
144 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
145 |
content); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
146 |
var div = DIV({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
147 |
'id': 'div_insert_' + selectedOptionNode.id |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
148 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
149 |
[handle, link]); |
0 | 150 |
try { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
151 |
var td = jQuery('#cell' + relationName + '_' + eid); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
152 |
td.appendChild(div); |
0 | 153 |
} catch(ex) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
154 |
alert("got exception(3)!" + ex); |
0 | 155 |
} |
156 |
} |
|
157 |
||
158 |
function addPendingInsert(optionNode, eid, cell, relname) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
159 |
var value = jQuery(optionNode).attr('value'); |
0 | 160 |
if (!value) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
161 |
// occurs when the first element in the box is selected (which is not |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
162 |
// an entity but the combobox title) |
0 | 163 |
return; |
164 |
} |
|
165 |
// 2nd special case |
|
166 |
if (value.indexOf('http') == 0) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
167 |
document.location = value; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
168 |
return; |
0 | 169 |
} |
170 |
// add hidden parameter |
|
171 |
var entityForm = jQuery('#entityForm'); |
|
172 |
var oid = optionNode.id.substring(2); // option id is prefixed by "id" |
|
5937
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5936
diff
changeset
|
173 |
loadRemote('json', ajaxFuncArgs('add_pending_inserts', null, |
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5936
diff
changeset
|
174 |
[oid.split(':')]), 'GET', true); |
0 | 175 |
var selectNode = optionNode.parentNode; |
176 |
// remove option node |
|
177 |
selectNode.removeChild(optionNode); |
|
178 |
// add line in table |
|
179 |
if (cell) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
180 |
// new relation as a cell in multiple edit |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
181 |
// var relation_name = relationSelected.getAttribute('value'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
182 |
// relation_name = relation_name.slice(0, relation_name.lastIndexOf('_')); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
183 |
buildEntityCell(relname, optionNode, selectNode.id, eid); |
0 | 184 |
} |
185 |
else { |
|
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
186 |
var relationSelector = cw.getNode('relationSelector_' + eid); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
187 |
var relationSelected = relationSelector.options[relationSelector.selectedIndex]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
188 |
// new relation as a line in simple edit |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
189 |
buildEntityLine(relationSelected.text, optionNode, selectNode.id, eid); |
0 | 190 |
} |
191 |
} |
|
192 |
||
193 |
function cancelPendingInsert(elementId, element_name, comboId, eid) { |
|
194 |
// remove matching insert element |
|
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
195 |
var entityView = cw.jqNode('a' + elementId).text(); |
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
196 |
cw.jqNode(element_name + elementId).remove(); |
0 | 197 |
if (comboId) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
198 |
// re-insert option in combobox if it was taken from there |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
199 |
var selectNode = cw.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
|
200 |
// XXX what on object relation |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
201 |
if (selectNode) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
202 |
var options = selectNode.options; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
203 |
var node_id = elementId.substring(0, elementId.indexOf(':')); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
204 |
options[options.length] = OPTION({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
205 |
'id': elementId, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
206 |
'value': node_id |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
207 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
208 |
entityView); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
209 |
} |
0 | 210 |
} |
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
|
211 |
elementId = elementId.substring(2, elementId.length); |
6726
51880d28ef63
[autoform] fix call to remove pending generic relation: reference bad function name
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6544
diff
changeset
|
212 |
loadRemote('json', ajaxFuncArgs('remove_pending_insert', null, |
5937
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5936
diff
changeset
|
213 |
elementId.split(':')), 'GET', true); |
0 | 214 |
} |
215 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
216 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
217 |
* .. function:: buildPendingDeleteHandle(elementId, eid) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
218 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
219 |
* this function builds a Handle to cancel pending insertion |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
220 |
*/ |
0 | 221 |
function buildPendingDeleteHandle(elementId, eid) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
222 |
var jscall = "javascript: addPendingDelete('" + elementId + ', ' + eid + "');"; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
223 |
return A({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
224 |
'href': jscall, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
225 |
'class': 'pendingDeleteHandle', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
226 |
'title': _("delete this relation") |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
227 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
228 |
'[x]'); |
0 | 229 |
} |
230 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
231 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
232 |
* .. function:: addPendingDelete(nodeId, eid) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
233 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
234 |
* * `nodeId`, eid_from:r_type:eid_to |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
235 |
*/ |
0 | 236 |
function addPendingDelete(nodeId, eid) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
237 |
var d = loadRemote('json', ajaxFuncArgs('add_pending_delete', null, nodeId.split(':'))); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
238 |
d.addCallback(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
239 |
// and strike entity view |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
240 |
cw.jqNode('span' + nodeId).addClass('pendingDelete'); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
241 |
// replace handle text |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
242 |
cw.jqNode('handle' + nodeId).text('+'); |
0 | 243 |
}); |
244 |
} |
|
245 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
246 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
247 |
* .. function:: cancelPendingDelete(nodeId, eid) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
248 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
249 |
* * `nodeId`, eid_from:r_type:eid_to |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
250 |
*/ |
0 | 251 |
function cancelPendingDelete(nodeId, eid) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
252 |
var d = loadRemote('json', ajaxFuncArgs('remove_pending_delete', null, nodeId.split(':'))); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
253 |
d.addCallback(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
254 |
// reset link's CSS class |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
255 |
cw.jqNode('span' + nodeId).removeClass('pendingDelete'); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
256 |
// replace handle text |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
257 |
cw.jqNode('handle' + nodeId).text('x'); |
0 | 258 |
}); |
259 |
} |
|
260 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
261 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
262 |
* .. function:: togglePendingDelete(nodeId, eid) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
263 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
264 |
* * `nodeId`, eid_from:r_type:eid_to |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
265 |
*/ |
0 | 266 |
function togglePendingDelete(nodeId, eid) { |
267 |
// node found means we should cancel deletion |
|
6544
e0d20fb46389
[jquery] className doesn't exist anymore in 1.4
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6421
diff
changeset
|
268 |
if (jQuery(cw.getNode('span' + nodeId)).hasClass('pendingDelete')) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
269 |
cancelPendingDelete(nodeId, eid); |
0 | 270 |
} else { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
271 |
addPendingDelete(nodeId, eid); |
0 | 272 |
} |
273 |
} |
|
274 |
||
275 |
function selectForAssociation(tripletIdsString, originalEid) { |
|
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
276 |
var tripletlist = $.map(tripletIdsString.split('-'), |
6215
759cf097f5aa
[javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6043
diff
changeset
|
277 |
function(x) { return [x.split(':')] ;}); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
278 |
var d = loadRemote('json', ajaxFuncArgs('add_pending_inserts', null, tripletlist)); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
279 |
d.addCallback(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
280 |
var args = { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
281 |
vid: 'edition', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
282 |
__mode: 'normal', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
283 |
rql: rql_for_eid(originalEid) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
284 |
}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
285 |
document.location = 'view?' + asURL(args); |
0 | 286 |
}); |
287 |
||
288 |
} |
|
289 |
||
4378
785c56bdacc6
[forms] the last touch: handle inlined relation forms as fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
290 |
function updateInlinedEntitiesCounters(rtype, role) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
291 |
jQuery('div.inline-' + rtype + '-' + role + '-slot span.icounter').each(function(i) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
292 |
this.innerHTML = i + 1; |
0 | 293 |
}); |
294 |
} |
|
295 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
296 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
297 |
* .. function:: addInlineCreationForm(peid, petype, ttype, rtype, role, i18nctx, insertBefore) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
298 |
* |
0 | 299 |
* makes an AJAX request to get an inline-creation view's content |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
300 |
* * `peid`, the parent entity eid |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
301 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
302 |
* * `petype`, the parent entity type |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
303 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
304 |
* * `ttype`, the target (inlined) entity type |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
305 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
306 |
* * `rtype`, the relation type between both entities |
0 | 307 |
*/ |
4629
1eeef3cbf528
fix 4626:c26b4df9fc90 (#703911): use can't rely on peid since it's not an actual eid when we're creating the parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4436
diff
changeset
|
308 |
function addInlineCreationForm(peid, petype, ttype, rtype, role, i18nctx, insertBefore) { |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
309 |
insertBefore = insertBefore || cw.getNode('add' + rtype + ':' + peid + 'link').parentNode; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
310 |
var args = ajaxFuncArgs('inline_creation_form', null, peid, petype, ttype, rtype, role, i18nctx); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
311 |
var d = loadRemote('json', args); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
312 |
d.addCallback(function(response) { |
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
|
313 |
var dom = getDomFromResponse(response); |
5909
9af8ac182f53
[javascript] fix some javascript errors and remove some deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5869
diff
changeset
|
314 |
loadAjaxHtmlHead(dom); |
2859
822258915ff0
[javascript] allow customization of inlineCreationForm insertion point
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2852
diff
changeset
|
315 |
var form = jQuery(dom); |
822258915ff0
[javascript] allow customization of inlineCreationForm insertion point
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2852
diff
changeset
|
316 |
form.css('display', 'none'); |
822258915ff0
[javascript] allow customization of inlineCreationForm insertion point
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2852
diff
changeset
|
317 |
form.insertBefore(insertBefore).slideDown('fast'); |
4378
785c56bdacc6
[forms] the last touch: handle inlined relation forms as fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
318 |
updateInlinedEntitiesCounters(rtype, role); |
4969
0ad18e41053a
[form js] apply vgodard patch fixing #750056: reorderTabindex js function crashes when form dom id is not 'entityForm'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4629
diff
changeset
|
319 |
reorderTabindex(null, $(insertBefore).closest('form')[0]); |
6264
0dcd19d89767
[reledit] cut methods to make overriding easier, add event on success update after reload
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6215
diff
changeset
|
320 |
jQuery(cw).trigger('inlinedform-added', form); |
3124
c929360212ca
[forms] fix form enctype handling with inlined forms
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2859
diff
changeset
|
321 |
// if the inlined form contains a file input, we must force |
c929360212ca
[forms] fix form enctype handling with inlined forms
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2859
diff
changeset
|
322 |
// the form enctype to multipart/form-data |
c929360212ca
[forms] fix form enctype handling with inlined forms
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2859
diff
changeset
|
323 |
if (form.find('input:file').length) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
324 |
// NOTE: IE doesn't support dynamic enctype modification, we have |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
325 |
// to set encoding too. |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
326 |
form.closest('form').attr('enctype', 'multipart/form-data').attr('encoding', 'multipart/form-data'); |
3124
c929360212ca
[forms] fix form enctype handling with inlined forms
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2859
diff
changeset
|
327 |
} |
5909
9af8ac182f53
[javascript] fix some javascript errors and remove some deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5869
diff
changeset
|
328 |
_postAjaxLoad(dom); |
0 | 329 |
}); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
330 |
d.addErrback(function(xxx) { |
2859
822258915ff0
[javascript] allow customization of inlineCreationForm insertion point
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2852
diff
changeset
|
331 |
log('xxx =', xxx); |
0 | 332 |
}); |
333 |
} |
|
334 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
335 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
336 |
* .. function:: removeInlineForm(peid, rtype, role, eid, showaddnewlink) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
337 |
* |
0 | 338 |
* removes the part of the form used to edit an inlined entity |
339 |
*/ |
|
4378
785c56bdacc6
[forms] the last touch: handle inlined relation forms as fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
340 |
function removeInlineForm(peid, rtype, role, eid, showaddnewlink) { |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
341 |
cw.jqNode(['div', peid, rtype, eid].join('-')).slideUp('fast', function() { |
5937
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5936
diff
changeset
|
342 |
$(this).remove(); |
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5936
diff
changeset
|
343 |
updateInlinedEntitiesCounters(rtype, role); |
0 | 344 |
}); |
3947
8d06bce45c02
when one is adding an inline entity for a relation of a single card,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3863
diff
changeset
|
345 |
if (showaddnewlink) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
346 |
toggleVisibility(showaddnewlink); |
3947
8d06bce45c02
when one is adding an inline entity for a relation of a single card,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3863
diff
changeset
|
347 |
} |
0 | 348 |
} |
349 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
350 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
351 |
* .. function:: removeInlinedEntity(peid, rtype, eid) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
352 |
* |
0 | 353 |
* alternatively adds or removes the hidden input that make the |
354 |
* edition of the relation `rtype` possible between `peid` and `eid` |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
355 |
* * `peid`, the parent entity eid |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
356 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
357 |
* * `rtype`, the relation type between both entities |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
358 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
359 |
* * `eid`, the inlined entity eid |
0 | 360 |
*/ |
361 |
function removeInlinedEntity(peid, rtype, eid) { |
|
3544
188d86631c45
fix #471746
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3343
diff
changeset
|
362 |
// XXX work around the eid_param thing (eid + ':' + eid) for #471746 |
188d86631c45
fix #471746
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3343
diff
changeset
|
363 |
var nodeid = ['rel', peid, rtype, eid + ':' + eid].join('-'); |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
364 |
var node = cw.jqNode(nodeid); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
365 |
if (!node.attr('cubicweb:type')) { |
3545
242b07b6d820
fix remove/do not remove action sequence (using a temp attribute instead of setting a wrong value in the resurrected hidden input)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3544
diff
changeset
|
366 |
node.attr('cubicweb:type', node.val()); |
242b07b6d820
fix remove/do not remove action sequence (using a temp attribute instead of setting a wrong value in the resurrected hidden input)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3544
diff
changeset
|
367 |
node.val(''); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
368 |
var divid = ['div', peid, rtype, eid].join('-'); |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
369 |
cw.jqNode(divid).fadeTo('fast', 0.5); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
370 |
var noticeid = ['notice', peid, rtype, eid].join('-'); |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
371 |
cw.jqNode(noticeid).fadeIn('fast'); |
0 | 372 |
} |
373 |
} |
|
374 |
||
375 |
function restoreInlinedEntity(peid, rtype, eid) { |
|
3544
188d86631c45
fix #471746
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3343
diff
changeset
|
376 |
// XXX work around the eid_param thing (eid + ':' + eid) for #471746 |
188d86631c45
fix #471746
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3343
diff
changeset
|
377 |
var nodeid = ['rel', peid, rtype, eid + ':' + eid].join('-'); |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
378 |
var node = cw.jqNode(nodeid); |
3545
242b07b6d820
fix remove/do not remove action sequence (using a temp attribute instead of setting a wrong value in the resurrected hidden input)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3544
diff
changeset
|
379 |
if (node.attr('cubicweb:type')) { |
242b07b6d820
fix remove/do not remove action sequence (using a temp attribute instead of setting a wrong value in the resurrected hidden input)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3544
diff
changeset
|
380 |
node.val(node.attr('cubicweb:type')); |
242b07b6d820
fix remove/do not remove action sequence (using a temp attribute instead of setting a wrong value in the resurrected hidden input)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3544
diff
changeset
|
381 |
node.attr('cubicweb:type', ''); |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
382 |
cw.jqNode(['fs', peid, rtype, eid].join('-')).append(node); |
3544
188d86631c45
fix #471746
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3343
diff
changeset
|
383 |
var divid = ['div', peid, rtype, eid].join('-'); |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
384 |
cw.jqNode(divid).fadeTo('fast', 1); |
3544
188d86631c45
fix #471746
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3343
diff
changeset
|
385 |
var noticeid = ['notice', peid, rtype, eid].join('-'); |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
386 |
cw.jqNode(noticeid).hide(); |
0 | 387 |
} |
388 |
} |
|
389 |
||
390 |
function _clearPreviousErrors(formid) { |
|
5335
9aed0b607130
[etwist] nicer, thouhg really not perferct) request max size exceeded support of json/frame posts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5087
diff
changeset
|
391 |
// on some case (eg max request size exceeded, we don't know the formid |
9aed0b607130
[etwist] nicer, thouhg really not perferct) request max size exceeded support of json/frame posts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5087
diff
changeset
|
392 |
if (formid) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
393 |
jQuery('#' + formid + 'ErrorMessage').remove(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
394 |
jQuery('#' + formid + ' span.errorMsg').remove(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
395 |
jQuery('#' + formid + ' .error').removeClass('error'); |
5335
9aed0b607130
[etwist] nicer, thouhg really not perferct) request max size exceeded support of json/frame posts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5087
diff
changeset
|
396 |
} else { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
397 |
jQuery('span.errorMsg').remove(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
398 |
jQuery('.error').removeClass('error'); |
5335
9aed0b607130
[etwist] nicer, thouhg really not perferct) request max size exceeded support of json/frame posts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5087
diff
changeset
|
399 |
} |
0 | 400 |
} |
401 |
||
402 |
function _displayValidationerrors(formid, eid, errors) { |
|
403 |
var globalerrors = []; |
|
404 |
var firsterrfield = null; |
|
405 |
for (fieldname in errors) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
406 |
var errmsg = errors[fieldname]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
407 |
if (!fieldname) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
408 |
globalerrors.push(errmsg); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
409 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
410 |
var fieldid = fieldname + ':' + eid; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
411 |
var suffixes = ['', '-subject', '-object']; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
412 |
var found = false; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
413 |
// XXX remove suffixes at some point |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
414 |
for (var i = 0, length = suffixes.length; i < length; i++) { |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
415 |
var field = cw.jqNode(fieldname + suffixes[i] + ':' + eid); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
416 |
if (field && jQuery(field).attr('type') != 'hidden') { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
417 |
if (!firsterrfield) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
418 |
firsterrfield = 'err-' + fieldid; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
419 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
420 |
jQuery(field).addClass('error'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
421 |
var span = SPAN({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
422 |
'id': 'err-' + fieldid, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
423 |
'class': "errorMsg" |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
424 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
425 |
errmsg); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
426 |
field.before(span); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
427 |
found = true; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
428 |
break; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
429 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
430 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
431 |
if (!found) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
432 |
firsterrfield = formid; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
433 |
globalerrors.push(_(fieldname) + ' : ' + errmsg); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
434 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
435 |
} |
0 | 436 |
} |
437 |
if (globalerrors.length) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
438 |
if (globalerrors.length == 1) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
439 |
var innernode = SPAN(null, globalerrors[0]); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
440 |
} else { |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
441 |
var innernode = UL(null, $.map(globalerrors, partial(LI, null))); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
442 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
443 |
// insert DIV and innernode before the form |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
444 |
var div = DIV({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
445 |
'class': "errorMessage", |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
446 |
'id': formid + 'ErrorMessage' |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
447 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
448 |
div.appendChild(innernode); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
449 |
jQuery('#' + formid).before(div); |
0 | 450 |
} |
451 |
return firsterrfield || formid; |
|
452 |
} |
|
453 |
||
3343
383b42263bb1
[validatecontroller] allow additional args to be passed to the js callback
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3342
diff
changeset
|
454 |
function handleFormValidationResponse(formid, onsuccess, onfailure, result, cbargs) { |
0 | 455 |
// Success |
456 |
if (result[0]) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
457 |
if (onsuccess) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
458 |
onsuccess(result, formid, cbargs); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
459 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
460 |
document.location.href = result[1]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
461 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
462 |
return true; |
0 | 463 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
464 |
if (onfailure && ! onfailure(result, formid, cbargs)) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
465 |
return false; |
3834
e3e64352063d
[javascript] fid form / onfailure behaviour
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3767
diff
changeset
|
466 |
} |
0 | 467 |
unfreezeFormButtons(formid); |
468 |
// Failures |
|
469 |
_clearPreviousErrors(formid); |
|
470 |
var descr = result[1]; |
|
5665
1b5d9ec38c1b
[javascript] refactor execution flow of handleFormValidationResponse so that location hash is set to #header whatever the error is
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
471 |
var errmsg; |
0 | 472 |
// Unknown structure |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
473 |
if ( !cw.utils.isArrayLike(descr) || descr.length != 2 ) { |
5937
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5936
diff
changeset
|
474 |
errmsg = descr; |
5665
1b5d9ec38c1b
[javascript] refactor execution flow of handleFormValidationResponse so that location hash is set to #header whatever the error is
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
475 |
} else { |
5937
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5936
diff
changeset
|
476 |
_displayValidationerrors(formid, descr[0], descr[1]); |
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5936
diff
changeset
|
477 |
errmsg = _('please correct errors below'); |
0 | 478 |
} |
5665
1b5d9ec38c1b
[javascript] refactor execution flow of handleFormValidationResponse so that location hash is set to #header whatever the error is
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
479 |
updateMessage(errmsg); |
5475
b44bad36e609
[doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5336
diff
changeset
|
480 |
// ensure the browser does not scroll down |
0 | 481 |
document.location.hash = '#header'; |
3100
b0a583156d6d
fix reledit validation error handling for relations #345477
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2859
diff
changeset
|
482 |
return false; |
0 | 483 |
} |
484 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
485 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
486 |
* .. function:: unfreezeFormButtons(formid) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
487 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
488 |
* unfreeze form buttons when the validation process is over |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
489 |
*/ |
0 | 490 |
function unfreezeFormButtons(formid) { |
491 |
jQuery('#progress').hide(); |
|
5335
9aed0b607130
[etwist] nicer, thouhg really not perferct) request max size exceeded support of json/frame posts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5087
diff
changeset
|
492 |
// on some case (eg max request size exceeded, we don't know the formid |
9aed0b607130
[etwist] nicer, thouhg really not perferct) request max size exceeded support of json/frame posts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5087
diff
changeset
|
493 |
if (formid) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
494 |
jQuery('#' + formid + ' .validateButton').removeAttr('disabled'); |
5335
9aed0b607130
[etwist] nicer, thouhg really not perferct) request max size exceeded support of json/frame posts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5087
diff
changeset
|
495 |
} else { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
496 |
jQuery('.validateButton').removeAttr('disabled'); |
5335
9aed0b607130
[etwist] nicer, thouhg really not perferct) request max size exceeded support of json/frame posts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5087
diff
changeset
|
497 |
} |
0 | 498 |
return true; |
499 |
} |
|
500 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
501 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
502 |
* .. function:: freezeFormButtons(formid) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
503 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
504 |
* disable form buttons while the validation is being done |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
505 |
*/ |
0 | 506 |
function freezeFormButtons(formid) { |
507 |
jQuery('#progress').show(); |
|
4271
dfee17fa363f
remove input from jquery filter, so it works as well with buttons
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4217
diff
changeset
|
508 |
jQuery('#' + formid + ' .validateButton').attr('disabled', 'disabled'); |
0 | 509 |
return true; |
510 |
} |
|
511 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
512 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
513 |
* .. function:: postForm(bname, bvalue, formid) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
514 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
515 |
* used by additional submit buttons to remember which button was clicked |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
516 |
*/ |
0 | 517 |
function postForm(bname, bvalue, formid) { |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
518 |
var form = cw.getNode(formid); |
0 | 519 |
if (bname) { |
5869
8a129b3a5aff
reledit refactoring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5727
diff
changeset
|
520 |
var child = form.appendChild(INPUT({ |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
521 |
type: 'hidden', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
522 |
name: bname, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
523 |
value: bvalue |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
524 |
})); |
0 | 525 |
} |
526 |
var onsubmit = form.onsubmit; |
|
527 |
if (!onsubmit || (onsubmit && onsubmit())) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
528 |
form.submit(); |
0 | 529 |
} |
4274
4601ba407ed6
apply patch proposed by 2web to properly remove hidden input set to represent the button used to submit the form, so forms may be properly reused after a post
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
530 |
if (bname) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
531 |
jQuery(child).remove(); |
4274
4601ba407ed6
apply patch proposed by 2web to properly remove hidden input set to represent the button used to submit the form, so forms may be properly reused after a post
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
532 |
} |
0 | 533 |
} |
534 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
535 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
536 |
* .. function:: setFormsTarget(node) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
537 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
538 |
* called on load to set target and iframeso object. |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
539 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
540 |
* .. note:: |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
541 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
542 |
* this is a hack to make the XHTML compliant. |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
543 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
544 |
* .. note:: |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
545 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
546 |
* `object` nodes might be a potential replacement for iframes |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
547 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
548 |
* .. note:: |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
549 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
550 |
* there is a XHTML module allowing iframe elements but there |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
551 |
* is still the problem of the form's `target` attribute |
0 | 552 |
*/ |
3863
fe22502d4ab1
[forms] add setFormsTarget() to the list of postAjaxLoad callbacks to have iframe on ajax-rendered forms
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3834
diff
changeset
|
553 |
function setFormsTarget(node) { |
fe22502d4ab1
[forms] add setFormsTarget() to the list of postAjaxLoad callbacks to have iframe on ajax-rendered forms
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3834
diff
changeset
|
554 |
var $node = jQuery(node || document.body); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
555 |
$node.find('form').each(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
556 |
var form = jQuery(this); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
557 |
var target = form.attr('cubicweb:target'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
558 |
if (target) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
559 |
form.attr('target', target); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
560 |
/* do not use display: none because some browsers ignore iframe |
1419 | 561 |
* with no display */ |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
562 |
form.append(IFRAME({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
563 |
name: target, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
564 |
id: target, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
565 |
src: 'javascript: void(0)', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
566 |
width: '0px', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
567 |
height: '0px' |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
568 |
})); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
569 |
} |
0 | 570 |
}); |
571 |
} |
|
572 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
573 |
jQuery(document).ready(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
574 |
setFormsTarget(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
575 |
}); |
0 | 576 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
577 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
578 |
* .. function:: validateForm(formid, action, onsuccess, onfailure) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
579 |
* |
0 | 580 |
* called on traditionnal form submission : the idea is to try |
581 |
* to post the form. If the post is successful, `validateForm` redirects |
|
582 |
* to the appropriate URL. Otherwise, the validation errors are displayed |
|
583 |
* around the corresponding input fields. |
|
584 |
*/ |
|
1864
4ceaf8f2709b
add onfailure fonction for validateForm, return formid on success
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1798
diff
changeset
|
585 |
function validateForm(formid, action, onsuccess, onfailure) { |
7517
a05bad3aec2e
[ajax edition] freeze form button when calling validateForm, so it freeze nicely for e.g. comment submitting form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7258
diff
changeset
|
586 |
freezeFormButtons(formid); |
0 | 587 |
try { |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
588 |
var zipped = cw.utils.formContents(formid); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
589 |
var args = ajaxFuncArgs('validate_form', null, action, zipped[0], zipped[1]); |
6043
bfe13118b5aa
[js/edition] fix pb with IE not handling long GETs #1203789
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5937
diff
changeset
|
590 |
var d = loadRemote('json', args, 'POST'); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
591 |
} catch(ex) { |
6903
d16b42c1e517
[js] fix deprecated call
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6746
diff
changeset
|
592 |
cw.log('got exception', ex); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
593 |
return false; |
0 | 594 |
} |
6421
32a6b11c4013
[js/edition] kill deprecated (& dead) reledit code
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6264
diff
changeset
|
595 |
d.addCallback(function(result, req) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
596 |
handleFormValidationResponse(formid, onsuccess, onfailure, result); |
6421
32a6b11c4013
[js/edition] kill deprecated (& dead) reledit code
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6264
diff
changeset
|
597 |
}); |
0 | 598 |
return false; |
599 |
} |