author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 07 Jun 2010 13:22:24 +0200 | |
changeset 5679 | 0f2ded880d01 |
parent 5658 | 7b9553a9db65 |
parent 5665 | 1b5d9ec38c1b |
child 5699 | f4f6ee3af50b |
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 |
CubicWeb.require('python.js'); |
|
11 |
CubicWeb.require('htmlhelpers.js'); |
|
12 |
CubicWeb.require('ajax.js'); |
|
13 |
||
14 |
//============= Eproperty form functions =====================================// |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
15 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
16 |
* .. function:: setPropValueWidget(varname, tabindex) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
17 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
18 |
* called on Eproperty key selection: |
0 | 19 |
* - get the selected value |
20 |
* - get a widget according to the key by a sync query to the server |
|
21 |
* - fill associated div with the returned html |
|
22 |
* |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
23 |
* * `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
|
24 |
* * `tabindex`, the tabindex that should be set on the widget |
0 | 25 |
*/ |
26 |
function setPropValueWidget(varname, tabindex) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
27 |
var key = firstSelected(document.getElementById('pkey:' + varname)); |
0 | 28 |
if (key) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
29 |
var args = { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
30 |
fname: 'prop_widget', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
31 |
pageid: pageid, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
32 |
arg: map(jQuery.toJSON, [key, varname, tabindex]) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
33 |
}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
34 |
jqNode('div:value:' + varname).loadxhtml(JSON_BASE_URL, args, 'post'); |
0 | 35 |
} |
36 |
} |
|
37 |
||
38 |
// *** EDITION FUNCTIONS ****************************************** // |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
39 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
40 |
* .. function:: reorderTabindex(start, formid) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
41 |
* |
0 | 42 |
* this function is called when an AJAX form was generated to |
43 |
* make sure tabindex remains consistent |
|
44 |
*/ |
|
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
|
45 |
function reorderTabindex(start, formid) { |
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
|
46 |
var form = getNode(formid || 'entityForm'); |
0 | 47 |
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
|
48 |
var tabindex = (start == null) ? 15: start; |
0 | 49 |
nodeWalkDepthFirst(form, function(elem) { |
50 |
var tagName = elem.tagName.toUpperCase(); |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
51 |
if (inputTypes.contains(tagName)) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
52 |
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
|
53 |
tabindex += 1; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
54 |
jQuery(elem).attr('tabindex', tabindex); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
55 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
56 |
return null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
57 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
58 |
return jQuery.grep(elem.childNodes, isElementNode); |
0 | 59 |
}); |
60 |
} |
|
61 |
||
62 |
function showMatchingSelect(selectedValue, eid) { |
|
63 |
if (selectedValue) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
64 |
divId = 'div' + selectedValue + '_' + eid; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
65 |
var divNode = jQuery('#' + divId); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
66 |
if (!divNode.length) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
67 |
var args = { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
68 |
vid: 'unrelateddivs', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
69 |
relation: selectedValue, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
70 |
rql: rql_for_eid(eid), |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
71 |
'__notemplate': 1, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
72 |
callback: function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
73 |
_showMatchingSelect(eid, jQuery('#' + divId)); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
74 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
75 |
}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
76 |
jQuery('#unrelatedDivs_' + eid).loadxhtml(baseuri() + 'view', args, 'post', 'append'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
77 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
78 |
_showMatchingSelect(eid, divNode); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
79 |
} |
1419 | 80 |
} else { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
81 |
_showMatchingSelect(eid, null); |
0 | 82 |
} |
83 |
} |
|
84 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
85 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
86 |
* .. function:: _showMatchingSelect(eid, divNode) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
87 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
88 |
* * `divNode`, a jQuery selection |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
89 |
*/ |
0 | 90 |
function _showMatchingSelect(eid, divNode) { |
91 |
// hide all divs, and then show the matching one |
|
92 |
// (would actually be better to directly hide the displayed one) |
|
93 |
jQuery('#unrelatedDivs_' + eid).children().hide(); |
|
94 |
// divNode not found means 'no relation selected' (i.e. first blank item) |
|
95 |
if (divNode && divNode.length) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
96 |
divNode.show(); |
0 | 97 |
} |
98 |
} |
|
99 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
100 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
101 |
* .. 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
|
102 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
103 |
* 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
|
104 |
*/ |
0 | 105 |
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
|
106 |
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
|
107 |
return A({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
108 |
'class': 'handle', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
109 |
'href': jscall, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
110 |
'title': _("cancel this insert") |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
111 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
112 |
'[x]'); |
0 | 113 |
} |
114 |
||
115 |
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
|
116 |
// 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
|
117 |
var content = selectedOptionNode.firstChild.nodeValue; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
118 |
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
|
119 |
var link = A({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
120 |
'href': 'view?rql=' + selectedOptionNode.value, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
121 |
'class': 'editionPending', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
122 |
'id': 'a' + selectedOptionNode.id |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
123 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
124 |
content); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
125 |
var tr = TR({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
126 |
'id': 'tr' + selectedOptionNode.id |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
127 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
128 |
[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
|
129 |
try { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
130 |
var separator = getNode('relationSelectorRow_' + eid); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
131 |
//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
|
132 |
// 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
|
133 |
// 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
|
134 |
var tableBody = separator.parentNode; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
135 |
tableBody.insertBefore(tr, separator); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
136 |
} catch(ex) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
137 |
log("got exception(2)!" + ex); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
138 |
} |
0 | 139 |
} |
140 |
||
141 |
function buildEntityCell(relationName, selectedOptionNode, comboId, eid) { |
|
142 |
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
|
143 |
var link = A({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
144 |
'href': 'view?rql=' + selectedOptionNode.value, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
145 |
'class': 'editionPending', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
146 |
'id': 'a' + selectedOptionNode.id |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
147 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
148 |
content); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
149 |
var div = DIV({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
150 |
'id': 'div_insert_' + selectedOptionNode.id |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
151 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
152 |
[handle, link]); |
0 | 153 |
try { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
154 |
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
|
155 |
td.appendChild(div); |
0 | 156 |
} catch(ex) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
157 |
alert("got exception(3)!" + ex); |
0 | 158 |
} |
159 |
} |
|
160 |
||
161 |
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
|
162 |
var value = jQuery(optionNode).attr('value'); |
0 | 163 |
if (!value) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
164 |
// 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
|
165 |
// an entity but the combobox title) |
0 | 166 |
return; |
167 |
} |
|
168 |
// 2nd special case |
|
169 |
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
|
170 |
document.location = value; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
171 |
return; |
0 | 172 |
} |
173 |
// add hidden parameter |
|
174 |
var entityForm = jQuery('#entityForm'); |
|
175 |
var oid = optionNode.id.substring(2); // option id is prefixed by "id" |
|
1419 | 176 |
remoteExec('add_pending_inserts', [oid.split(':')]); |
0 | 177 |
var selectNode = optionNode.parentNode; |
178 |
// remove option node |
|
179 |
selectNode.removeChild(optionNode); |
|
180 |
// add line in table |
|
181 |
if (cell) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
182 |
// 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
|
183 |
// 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
|
184 |
// 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
|
185 |
buildEntityCell(relname, optionNode, selectNode.id, eid); |
0 | 186 |
} |
187 |
else { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
188 |
var relationSelector = getNode('relationSelector_' + eid); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
189 |
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
|
190 |
// 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
|
191 |
buildEntityLine(relationSelected.text, optionNode, selectNode.id, eid); |
0 | 192 |
} |
193 |
} |
|
194 |
||
195 |
function cancelPendingInsert(elementId, element_name, comboId, eid) { |
|
196 |
// remove matching insert element |
|
197 |
var entityView = jqNode('a' + elementId).text(); |
|
198 |
jqNode(element_name + elementId).remove(); |
|
199 |
if (comboId) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
200 |
// re-insert option in combobox if it was taken from there |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
201 |
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
|
202 |
// 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
|
203 |
if (selectNode) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
204 |
var options = selectNode.options; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
205 |
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
|
206 |
options[options.length] = OPTION({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
207 |
'id': elementId, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
208 |
'value': node_id |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
209 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
210 |
entityView); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
211 |
} |
0 | 212 |
} |
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
|
213 |
elementId = elementId.substring(2, elementId.length); |
1419 | 214 |
remoteExec('remove_pending_insert', elementId.split(':')); |
0 | 215 |
} |
216 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
217 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
218 |
* .. function:: buildPendingDeleteHandle(elementId, eid) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
219 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
220 |
* 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
|
221 |
*/ |
0 | 222 |
function buildPendingDeleteHandle(elementId, eid) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
223 |
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
|
224 |
return A({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
225 |
'href': jscall, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
226 |
'class': 'pendingDeleteHandle', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
227 |
'title': _("delete this relation") |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
228 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
229 |
'[x]'); |
0 | 230 |
} |
231 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
232 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
233 |
* .. function:: addPendingDelete(nodeId, eid) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
234 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
235 |
* * `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
|
236 |
*/ |
0 | 237 |
function addPendingDelete(nodeId, eid) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
238 |
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
|
239 |
d.addCallback(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
240 |
// and strike entity view |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
241 |
jqNode('span' + nodeId).addClass('pendingDelete'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
242 |
// replace handle text |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
243 |
jqNode('handle' + nodeId).text('+'); |
0 | 244 |
}); |
245 |
} |
|
246 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
247 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
248 |
* .. function:: cancelPendingDelete(nodeId, eid) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
249 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
250 |
* * `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
|
251 |
*/ |
0 | 252 |
function cancelPendingDelete(nodeId, eid) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
253 |
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
|
254 |
d.addCallback(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
255 |
// reset link's CSS class |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
256 |
jqNode('span' + nodeId).removeClass('pendingDelete'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
257 |
// replace handle text |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
258 |
jqNode('handle' + nodeId).text('x'); |
0 | 259 |
}); |
260 |
} |
|
261 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
262 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
263 |
* .. function:: togglePendingDelete(nodeId, eid) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
264 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
265 |
* * `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
|
266 |
*/ |
0 | 267 |
function togglePendingDelete(nodeId, eid) { |
268 |
// node found means we should cancel deletion |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
269 |
if (jQuery.className.has(getNode('span' + nodeId), 'pendingDelete')) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
270 |
cancelPendingDelete(nodeId, eid); |
0 | 271 |
} else { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
272 |
addPendingDelete(nodeId, eid); |
0 | 273 |
} |
274 |
} |
|
275 |
||
276 |
function selectForAssociation(tripletIdsString, originalEid) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
277 |
var tripletlist = map(function(x) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
278 |
return x.split(':'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
279 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
280 |
tripletIdsString.split('-')); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
281 |
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
|
282 |
d.addCallback(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
283 |
var args = { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
284 |
vid: 'edition', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
285 |
__mode: 'normal', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
286 |
rql: rql_for_eid(originalEid) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
287 |
}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
288 |
document.location = 'view?' + asURL(args); |
0 | 289 |
}); |
290 |
||
291 |
} |
|
292 |
||
4378
785c56bdacc6
[forms] the last touch: handle inlined relation forms as fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
293 |
function updateInlinedEntitiesCounters(rtype, role) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
294 |
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
|
295 |
this.innerHTML = i + 1; |
0 | 296 |
}); |
297 |
} |
|
298 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
299 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
300 |
* .. 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
|
301 |
* |
0 | 302 |
* 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
|
303 |
* * `peid`, the parent entity eid |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
304 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
305 |
* * `petype`, the parent entity type |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
306 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
307 |
* * `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
|
308 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
309 |
* * `rtype`, the relation type between both entities |
0 | 310 |
*/ |
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
|
311 |
function addInlineCreationForm(peid, petype, ttype, rtype, role, i18nctx, insertBefore) { |
2859
822258915ff0
[javascript] allow customization of inlineCreationForm insertion point
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2852
diff
changeset
|
312 |
insertBefore = insertBefore || 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
|
313 |
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
|
314 |
var d = loadRemote('json', args); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
315 |
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
|
316 |
var dom = getDomFromResponse(response); |
2859
822258915ff0
[javascript] allow customization of inlineCreationForm insertion point
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2852
diff
changeset
|
317 |
preprocessAjaxLoad(null, dom); |
822258915ff0
[javascript] allow customization of inlineCreationForm insertion point
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2852
diff
changeset
|
318 |
var form = jQuery(dom); |
822258915ff0
[javascript] allow customization of inlineCreationForm insertion point
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2852
diff
changeset
|
319 |
form.css('display', 'none'); |
822258915ff0
[javascript] allow customization of inlineCreationForm insertion point
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2852
diff
changeset
|
320 |
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
|
321 |
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
|
322 |
reorderTabindex(null, $(insertBefore).closest('form')[0]); |
3342
8b30ae9c4e67
[javascript] make inlinedform-added event bindable
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3327
diff
changeset
|
323 |
jQuery(CubicWeb).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
|
324 |
// 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
|
325 |
// 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
|
326 |
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
|
327 |
// 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
|
328 |
// to set encoding too. |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
329 |
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
|
330 |
} |
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
|
331 |
postAjaxLoad(dom); |
0 | 332 |
}); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
333 |
d.addErrback(function(xxx) { |
2859
822258915ff0
[javascript] allow customization of inlineCreationForm insertion point
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2852
diff
changeset
|
334 |
log('xxx =', xxx); |
0 | 335 |
}); |
336 |
} |
|
337 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
338 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
339 |
* .. 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
|
340 |
* |
0 | 341 |
* removes the part of the form used to edit an inlined entity |
342 |
*/ |
|
4378
785c56bdacc6
[forms] the last touch: handle inlined relation forms as fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4279
diff
changeset
|
343 |
function removeInlineForm(peid, rtype, role, eid, showaddnewlink) { |
0 | 344 |
jqNode(['div', peid, rtype, eid].join('-')).slideUp('fast', function() { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
345 |
$(this).remove(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
346 |
updateInlinedEntitiesCounters(rtype, role); |
0 | 347 |
}); |
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
|
348 |
if (showaddnewlink) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
349 |
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
|
350 |
} |
0 | 351 |
} |
352 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
353 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
354 |
* .. function:: removeInlinedEntity(peid, rtype, eid) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
355 |
* |
0 | 356 |
* alternatively adds or removes the hidden input that make the |
357 |
* 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
|
358 |
* * `peid`, the parent entity eid |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
359 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
360 |
* * `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
|
361 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
362 |
* * `eid`, the inlined entity eid |
0 | 363 |
*/ |
364 |
function removeInlinedEntity(peid, rtype, eid) { |
|
3544
188d86631c45
fix #471746
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3343
diff
changeset
|
365 |
// XXX work around the eid_param thing (eid + ':' + eid) for #471746 |
188d86631c45
fix #471746
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3343
diff
changeset
|
366 |
var nodeid = ['rel', peid, rtype, eid + ':' + eid].join('-'); |
0 | 367 |
var node = jqNode(nodeid); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
368 |
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
|
369 |
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
|
370 |
node.val(''); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
371 |
var divid = ['div', peid, rtype, eid].join('-'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
372 |
jqNode(divid).fadeTo('fast', 0.5); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
373 |
var noticeid = ['notice', peid, rtype, eid].join('-'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
374 |
jqNode(noticeid).fadeIn('fast'); |
0 | 375 |
} |
376 |
} |
|
377 |
||
378 |
function restoreInlinedEntity(peid, rtype, eid) { |
|
3544
188d86631c45
fix #471746
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3343
diff
changeset
|
379 |
// XXX work around the eid_param thing (eid + ':' + eid) for #471746 |
188d86631c45
fix #471746
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3343
diff
changeset
|
380 |
var nodeid = ['rel', peid, rtype, eid + ':' + eid].join('-'); |
0 | 381 |
var node = 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
|
382 |
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
|
383 |
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
|
384 |
node.attr('cubicweb:type', ''); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
385 |
jqNode(['fs', peid, rtype, eid].join('-')).append(node); |
3544
188d86631c45
fix #471746
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3343
diff
changeset
|
386 |
var divid = ['div', peid, rtype, eid].join('-'); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
387 |
jqNode(divid).fadeTo('fast', 1); |
3544
188d86631c45
fix #471746
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3343
diff
changeset
|
388 |
var noticeid = ['notice', peid, rtype, eid].join('-'); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
389 |
jqNode(noticeid).hide(); |
0 | 390 |
} |
391 |
} |
|
392 |
||
393 |
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
|
394 |
// 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
|
395 |
if (formid) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
396 |
jQuery('#' + formid + 'ErrorMessage').remove(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
397 |
jQuery('#' + formid + ' span.errorMsg').remove(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
398 |
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
|
399 |
} else { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
400 |
jQuery('span.errorMsg').remove(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
401 |
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
|
402 |
} |
0 | 403 |
} |
404 |
||
405 |
function _displayValidationerrors(formid, eid, errors) { |
|
406 |
var globalerrors = []; |
|
407 |
var firsterrfield = null; |
|
408 |
for (fieldname in errors) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
409 |
var errmsg = errors[fieldname]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
410 |
if (!fieldname) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
411 |
globalerrors.push(errmsg); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
412 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
413 |
var fieldid = fieldname + ':' + eid; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
414 |
var suffixes = ['', '-subject', '-object']; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
415 |
var found = false; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
416 |
// 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
|
417 |
for (var i = 0, length = suffixes.length; i < length; i++) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
418 |
var field = jqNode(fieldname + suffixes[i] + ':' + eid); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
419 |
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
|
420 |
if (!firsterrfield) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
421 |
firsterrfield = 'err-' + fieldid; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
422 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
423 |
jQuery(field).addClass('error'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
424 |
var span = SPAN({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
425 |
'id': 'err-' + fieldid, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
426 |
'class': "errorMsg" |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
427 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
428 |
errmsg); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
429 |
field.before(span); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
430 |
found = true; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
431 |
break; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
432 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
433 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
434 |
if (!found) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
435 |
firsterrfield = formid; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
436 |
globalerrors.push(_(fieldname) + ' : ' + errmsg); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
437 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
438 |
} |
0 | 439 |
} |
440 |
if (globalerrors.length) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
441 |
if (globalerrors.length == 1) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
442 |
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
|
443 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
444 |
var innernode = UL(null, map(partial(LI, null), globalerrors)); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
445 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
446 |
// 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
|
447 |
var div = DIV({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
448 |
'class': "errorMessage", |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
449 |
'id': formid + 'ErrorMessage' |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
450 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
451 |
div.appendChild(innernode); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
452 |
jQuery('#' + formid).before(div); |
0 | 453 |
} |
454 |
return firsterrfield || formid; |
|
455 |
} |
|
456 |
||
3343
383b42263bb1
[validatecontroller] allow additional args to be passed to the js callback
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3342
diff
changeset
|
457 |
function handleFormValidationResponse(formid, onsuccess, onfailure, result, cbargs) { |
0 | 458 |
// Success |
459 |
if (result[0]) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
460 |
if (onsuccess) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
461 |
onsuccess(result, formid, cbargs); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
462 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
463 |
document.location.href = result[1]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
464 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
465 |
return true; |
0 | 466 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
467 |
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
|
468 |
return false; |
3834
e3e64352063d
[javascript] fid form / onfailure behaviour
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3767
diff
changeset
|
469 |
} |
0 | 470 |
unfreezeFormButtons(formid); |
471 |
// Failures |
|
472 |
_clearPreviousErrors(formid); |
|
473 |
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
|
474 |
var errmsg; |
0 | 475 |
// Unknown structure |
476 |
if ( !isArrayLike(descr) || descr.length != 2 ) { |
|
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
|
477 |
errmsg = descr; |
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
|
478 |
} else { |
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 |
_displayValidationerrors(formid, descr[0], descr[1]); |
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
|
480 |
errmsg = _('please correct errors below'); |
0 | 481 |
} |
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
|
482 |
updateMessage(errmsg); |
5475
b44bad36e609
[doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5336
diff
changeset
|
483 |
// ensure the browser does not scroll down |
0 | 484 |
document.location.hash = '#header'; |
3100
b0a583156d6d
fix reledit validation error handling for relations #345477
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2859
diff
changeset
|
485 |
return false; |
0 | 486 |
} |
487 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
488 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
489 |
* .. function:: unfreezeFormButtons(formid) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
490 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
491 |
* 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
|
492 |
*/ |
0 | 493 |
function unfreezeFormButtons(formid) { |
494 |
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
|
495 |
// 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
|
496 |
if (formid) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
497 |
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
|
498 |
} else { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
499 |
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
|
500 |
} |
0 | 501 |
return true; |
502 |
} |
|
503 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
504 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
505 |
* .. function:: freezeFormButtons(formid) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
506 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
507 |
* 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
|
508 |
*/ |
0 | 509 |
function freezeFormButtons(formid) { |
510 |
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
|
511 |
jQuery('#' + formid + ' .validateButton').attr('disabled', 'disabled'); |
0 | 512 |
return true; |
513 |
} |
|
514 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
515 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
516 |
* .. function:: postForm(bname, bvalue, formid) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
517 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
518 |
* 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
|
519 |
*/ |
0 | 520 |
function postForm(bname, bvalue, formid) { |
521 |
var form = getNode(formid); |
|
522 |
if (bname) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
523 |
var child = form.appendChild(INPUT({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
524 |
type: 'hidden', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
525 |
name: bname, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
526 |
value: bvalue |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
527 |
})); |
0 | 528 |
} |
529 |
var onsubmit = form.onsubmit; |
|
530 |
if (!onsubmit || (onsubmit && onsubmit())) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
531 |
form.submit(); |
0 | 532 |
} |
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
|
533 |
if (bname) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
534 |
jQuery(child).remove(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
535 |
/* cleanup */ |
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
|
536 |
} |
0 | 537 |
} |
538 |
||
5658
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 |
* .. function:: setFormsTarget(node) |
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 |
* 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
|
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 |
* 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
|
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 |
* `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
|
551 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
552 |
* .. note:: |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
553 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
554 |
* 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
|
555 |
* is still the problem of the form's `target` attribute |
0 | 556 |
*/ |
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
|
557 |
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
|
558 |
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
|
559 |
$node.find('form').each(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
560 |
var form = jQuery(this); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
561 |
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
|
562 |
if (target) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
563 |
form.attr('target', target); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
564 |
/* do not use display: none because some browsers ignore iframe |
1419 | 565 |
* with no display */ |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
566 |
form.append(IFRAME({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
567 |
name: target, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
568 |
id: target, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
569 |
src: 'javascript: void(0)', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
570 |
width: '0px', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
571 |
height: '0px' |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
572 |
})); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
573 |
} |
0 | 574 |
}); |
575 |
} |
|
576 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
577 |
jQuery(document).ready(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
578 |
setFormsTarget(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
579 |
}); |
0 | 580 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
581 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
582 |
* .. 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
|
583 |
* |
0 | 584 |
* called on traditionnal form submission : the idea is to try |
585 |
* to post the form. If the post is successful, `validateForm` redirects |
|
586 |
* to the appropriate URL. Otherwise, the validation errors are displayed |
|
587 |
* around the corresponding input fields. |
|
588 |
*/ |
|
1864
4ceaf8f2709b
add onfailure fonction for validateForm, return formid on success
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1798
diff
changeset
|
589 |
function validateForm(formid, action, onsuccess, onfailure) { |
0 | 590 |
try { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
591 |
var zipped = formContents(formid); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
592 |
var args = ajaxFuncArgs('validate_form', null, action, zipped[0], zipped[1]); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
593 |
var d = loadRemote('json', args); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
594 |
} catch(ex) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
595 |
log('got exception', ex); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
596 |
return false; |
0 | 597 |
} |
598 |
function _callback(result, req) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
599 |
handleFormValidationResponse(formid, onsuccess, onfailure, result); |
0 | 600 |
} |
601 |
d.addCallback(_callback); |
|
602 |
return false; |
|
603 |
} |
|
604 |
||
1419 | 605 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
606 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
607 |
* .. function:: inlineValidateRelationFormOptions(rtype, eid, divid, options) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
608 |
* |
1759
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1713
diff
changeset
|
609 |
* called by reledit forms to submit changes |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
610 |
* * `rtype`, the attribute being edited |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
611 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
612 |
* * `eid`, the eid of the entity being edited |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
613 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
614 |
* * `options`, a dictionnary of options used by the form validation handler such |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
615 |
* as ``role``, ``onsuccess``, ``onfailure``, ``reload``, ``vid``, ``lzone`` |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
616 |
* and ``default_value``: |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
617 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
618 |
* * `onsucess`, javascript function to execute on success, default is noop |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
619 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
620 |
* * `onfailure`, javascript function to execute on failure, default is noop |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
621 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
622 |
* * `default_value`, value if the field is empty |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
623 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
624 |
* * `lzone`, html fragment (string) for a clic-zone triggering actual edition |
0 | 625 |
*/ |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
626 |
function inlineValidateRelationFormOptions(rtype, eid, divid, options) { |
1759
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1713
diff
changeset
|
627 |
try { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
628 |
var form = getNode(divid + '-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
|
629 |
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
|
630 |
var newtarget = jQuery('[name=' + relname + ']').val(); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
631 |
var zipped = cw.utils.formContents(form); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
632 |
var args = ajaxFuncArgs('validate_form', null, 'apply', zipped[0], zipped[1]); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
633 |
var d = loadRemote(JSON_BASE_URL, args, 'POST') |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
634 |
} catch(ex) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
635 |
return false; |
1759
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1713
diff
changeset
|
636 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
637 |
d.addCallback(function(result, req) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
638 |
execFormValidationResponse(rtype, eid, divid, options, result); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
639 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
640 |
return false; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
641 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
642 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
643 |
function execFormValidationResponse(rtype, eid, divid, options, result) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
644 |
options = $.extend({onsuccess: noop, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
645 |
onfailure: noop |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
646 |
}, options); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
647 |
if (handleFormValidationResponse(divid + '-form', options.onsucess , options.onfailure, result)) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
648 |
if (options.reload) { |
3742
20f429eb5f46
kill separate attribute client-side handling #473636
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3545
diff
changeset
|
649 |
document.location.reload(); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
650 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
651 |
var args = { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
652 |
fname: 'reledit_form', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
653 |
rtype: rtype, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
654 |
role: options.role, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
655 |
eid: eid, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
656 |
divid: divid, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
657 |
reload: options.reload, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
658 |
vid: options.vid, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
659 |
default_value: options.default_value, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
660 |
landing_zone: options.lzone |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
661 |
}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
662 |
jQuery('#' + divid + '-reledit').parent().loadxhtml(JSON_BASE_URL, args, 'post'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
663 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
664 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
665 |
|
1759
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1713
diff
changeset
|
666 |
} |
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1713
diff
changeset
|
667 |
|
61d026ced19f
preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1713
diff
changeset
|
668 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
669 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
670 |
* .. function:: loadInlineEditionFormOptions(eid, rtype, divid, options) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
671 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
672 |
* inline edition |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
673 |
*/ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
674 |
function loadInlineEditionFormOptions(eid, rtype, divid, options) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
675 |
var args = { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
676 |
fname: 'reledit_form', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
677 |
rtype: rtype, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
678 |
role: options.role, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
679 |
eid: eid, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
680 |
divid: divid, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
681 |
reload: options.reload, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
682 |
vid: options.vid, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
683 |
default_value: options.default_value, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
684 |
landing_zone: options.lzone, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
685 |
callback: function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
686 |
showInlineEditionForm(eid, rtype, divid); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
687 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
688 |
}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
689 |
jQuery('#' + divid + '-reledit').parent().loadxhtml(JSON_BASE_URL, args, 'post'); |
3744
767b5d0cd3cc
reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3742
diff
changeset
|
690 |
} |
0 | 691 |
function showInlineEditionForm(eid, rtype, divid) { |
692 |
jQuery('#' + divid).hide(); |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
693 |
jQuery('#' + divid + '-value').hide(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
694 |
jQuery('#' + divid + '-form').show(); |
0 | 695 |
} |
696 |
||
2371
76bf522c27be
[reledit] simplify, fixing #344545
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2364
diff
changeset
|
697 |
function hideInlineEdit(eid, rtype, divid) { |
3100
b0a583156d6d
fix reledit validation error handling for relations #345477
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2859
diff
changeset
|
698 |
jQuery('#appMsg').hide(); |
b0a583156d6d
fix reledit validation error handling for relations #345477
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2859
diff
changeset
|
699 |
jQuery('div.errorMessage').remove(); |
0 | 700 |
jQuery('#' + divid).show(); |
3767
03924de0014d
reledit: stuff the value into its own div and properly hide it when necessary (but dont lump it with the landingzone div for it switches the form on when one clicks on a value to traverse it)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3760
diff
changeset
|
701 |
jQuery('#' + divid + '-value').show(); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
702 |
jQuery('#' + divid + '-form').hide(); |
0 | 703 |
} |
704 |
||
705 |
CubicWeb.provide('edition.js'); |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
706 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
707 |
// ======================= DEPRECATED FUNCTIONS ========================= // |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
708 |
inlineValidateRelationForm = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
709 |
'[3.9] inlineValidateRelationForm() function is deprecated, use inlineValidateRelationFormOptions instead', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
710 |
function(rtype, role, eid, divid, reload, vid, default_value, lzone, onsucess, onfailure) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
711 |
try { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
712 |
var form = getNode(divid + '-form'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
713 |
var relname = rtype + ':' + eid; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
714 |
var newtarget = jQuery('[name=' + relname + ']').val(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
715 |
var zipped = formContents(form); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
716 |
var d = asyncRemoteExec('validate_form', 'apply', zipped[0], zipped[1]); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
717 |
} catch(ex) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
718 |
return false; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
719 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
720 |
d.addCallback(function(result, req) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
721 |
var options = {role : role, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
722 |
reload: reload, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
723 |
vid: vid, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
724 |
default_value: default_value, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
725 |
lzone: lzone, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
726 |
onsucess: onsucess || $.noop, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
727 |
onfailure: onfailure || $.noop |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
728 |
}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
729 |
execFormValidationResponse(rtype, eid, divid, options); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
730 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
731 |
return false; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
732 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
733 |
); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
734 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
735 |
loadInlineEditionForm = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
736 |
'[3.9] loadInlineEditionForm() function is deprecated, use loadInlineEditionFormOptions instead', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
737 |
function(eid, rtype, role, divid, reload, vid, default_value, lzone) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
738 |
var args = { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
739 |
fname: 'reledit_form', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
740 |
rtype: rtype, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
741 |
role: role, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
742 |
eid: eid, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
743 |
divid: divid, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
744 |
reload: reload, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
745 |
vid: vid, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
746 |
default_value: default_value, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
747 |
landing_zone: lzone, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
748 |
callback: function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
749 |
showInlineEditionForm(eid, rtype, divid); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
750 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
751 |
}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
752 |
jQuery('#' + divid + '-reledit').parent().loadxhtml(JSON_BASE_URL, args, 'post'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
753 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5475
diff
changeset
|
754 |
); |