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