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