author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 08 Jul 2010 12:54:14 +0200 | |
changeset 5936 | 98ac4000e820 |
parent 5909 | 9af8ac182f53 |
child 5937 | 82cac9383dd8 |
permissions | -rw-r--r-- |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
1 |
/* copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
2 |
* contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
3 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
4 |
* This file is part of CubicWeb. |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
5 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
6 |
* CubicWeb is free software: you can redistribute it and/or modify it under the |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
7 |
* terms of the GNU Lesser General Public License as published by the Free |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
8 |
* Software Foundation, either version 2.1 of the License, or (at your option) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
9 |
* any later version. |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
10 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
11 |
* CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
14 |
* details. |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
15 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
16 |
* You should have received a copy of the GNU Lesser General Public License along |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
17 |
* with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
0 | 18 |
*/ |
19 |
||
5698
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
20 |
/** |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
21 |
* .. function:: Deferred |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
22 |
* |
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
|
23 |
* dummy ultra minimalist implementation of deferred for jQuery |
5698
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
24 |
*/ |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
25 |
function Deferred() { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
26 |
this.__init__(this); |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
27 |
} |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
28 |
|
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
29 |
jQuery.extend(Deferred.prototype, { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
30 |
__init__: function() { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
31 |
this._onSuccess = []; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
32 |
this._onFailure = []; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
33 |
this._req = null; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
34 |
this._result = null; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
35 |
this._error = null; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
36 |
}, |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
37 |
|
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
38 |
addCallback: function(callback) { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
39 |
if (this._req.readyState == 4) { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
40 |
if (this._result) { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
41 |
var args = [this._result, this._req]; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
42 |
jQuery.merge(args, cw.utils.sliceList(arguments, 1)); |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
43 |
callback.apply(null, args); |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
44 |
} |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
45 |
} |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
46 |
else { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
47 |
this._onSuccess.push([callback, cw.utils.sliceList(arguments, 1)]); |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
48 |
} |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
49 |
return this; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
50 |
}, |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
51 |
|
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
52 |
addErrback: function(callback) { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
53 |
if (this._req.readyState == 4) { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
54 |
if (this._error) { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
55 |
callback.apply(null, [this._error, this._req]); |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
56 |
} |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
57 |
} |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
58 |
else { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
59 |
this._onFailure.push([callback, cw.utils.sliceList(arguments, 1)]); |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
60 |
} |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
61 |
return this; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
62 |
}, |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
63 |
|
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
64 |
success: function(result) { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
65 |
this._result = result; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
66 |
try { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
67 |
for (var i = 0; i < this._onSuccess.length; i++) { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
68 |
var callback = this._onSuccess[i][0]; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
69 |
var args = [result, this._req]; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
70 |
jQuery.merge(args, this._onSuccess[i][1]); |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
71 |
callback.apply(null, args); |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
72 |
} |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
73 |
} catch(error) { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
74 |
this.error(this.xhr, null, error); |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
75 |
} |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
76 |
}, |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
77 |
|
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
78 |
error: function(xhr, status, error) { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
79 |
this._error = error; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
80 |
for (var i = 0; i < this._onFailure.length; i++) { |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
81 |
var callback = this._onFailure[i][0]; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
82 |
var args = [error, this._req]; |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
83 |
jQuery.merge(args, this._onFailure[i][1]); |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
84 |
callback.apply(null, args); |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
85 |
} |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
86 |
} |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
87 |
|
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
88 |
}); |
5c8fa1650299
[javascript] move Deferred implementation to cubicweb.ajax.js
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
89 |
|
0 | 90 |
|
91 |
var JSON_BASE_URL = baseuri() + 'json?'; |
|
92 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
93 |
//============= utility function handling remote calls responses. ==============// |
1512
c51ca5f49a78
fix insertion of head content on ajax queries
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
94 |
function _loadAjaxHtmlHead(node, head, tag, srcattr) { |
c51ca5f49a78
fix insertion of head content on ajax queries
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
95 |
var loaded = []; |
2257
2c9eceeaae6a
fix w/ tags without src/href
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1801
diff
changeset
|
96 |
var jqtagfilter = tag + '[' + srcattr + ']'; |
2c9eceeaae6a
fix w/ tags without src/href
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1801
diff
changeset
|
97 |
jQuery('head ' + jqtagfilter).each(function(i) { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
98 |
loaded.push(this.getAttribute(srcattr)); |
1512
c51ca5f49a78
fix insertion of head content on ajax queries
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
99 |
}); |
c51ca5f49a78
fix insertion of head content on ajax queries
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
100 |
node.find(tag).each(function(i) { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
101 |
if (this.getAttribute(srcattr)) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
102 |
if (jQuery.inArray(this.getAttribute(srcattr), loaded) == -1) { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
103 |
jQuery(this).appendTo(head); |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
104 |
} |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
105 |
} else { |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
106 |
jQuery(this).appendTo(head); |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
107 |
} |
1512
c51ca5f49a78
fix insertion of head content on ajax queries
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
108 |
}); |
2257
2c9eceeaae6a
fix w/ tags without src/href
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1801
diff
changeset
|
109 |
node.find(jqtagfilter).remove(); |
1512
c51ca5f49a78
fix insertion of head content on ajax queries
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
110 |
} |
c51ca5f49a78
fix insertion of head content on ajax queries
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
111 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
112 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
113 |
* .. function:: function loadAjaxHtmlHead(response) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
114 |
* |
4174
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
115 |
* inspect dom response (as returned by getDomFromResponse), search for |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
116 |
* a <div class="ajaxHtmlHead"> node and put its content into the real |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
117 |
* document's head. |
642
2cf7b79d8e77
[javascript] rewrote loadxhtml() plugin in order to be able to pass the XHR object to postAjaxLoad
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
540
diff
changeset
|
118 |
* This enables dynamic css and js loading and is used by replacePageChunk |
2cf7b79d8e77
[javascript] rewrote loadxhtml() plugin in order to be able to pass the XHR object to postAjaxLoad
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
540
diff
changeset
|
119 |
*/ |
4174
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
120 |
function loadAjaxHtmlHead(response) { |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
121 |
var $head = jQuery('head'); |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
122 |
var $responseHead = jQuery(response).find('div.ajaxHtmlHead'); |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
123 |
// no ajaxHtmlHead found, no processing required |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
124 |
if (!$responseHead.length) { |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
125 |
return response; |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
126 |
} |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
127 |
_loadAjaxHtmlHead($responseHead, $head, 'script', 'src'); |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
128 |
_loadAjaxHtmlHead($responseHead, $head, 'link', 'href'); |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
129 |
// add any remaining children (e.g. meta) |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
130 |
$responseHead.children().appendTo($head); |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
131 |
// remove original container, which is now empty |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
132 |
$responseHead.remove(); |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
133 |
// if there was only one actual node in the reponse besides |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
134 |
// the ajaxHtmlHead, then remove the wrapper created by |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
135 |
// getDomFromResponse() and return this single element |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
136 |
// For instance : |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
137 |
// 1/ CW returned the following content : |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
138 |
// <div>the-actual-content</div><div class="ajaxHtmlHead">...</div> |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
139 |
// 2/ getDomFromReponse() wrapped this into a single DIV to hold everything |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
140 |
// in one, unique, dom element |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
141 |
// 3/ now that we've removed the ajaxHtmlHead div, the only |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
142 |
// node left in the wrapper if the 'real' node built by the view, |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
143 |
// we can safely return this node. Otherwise, the view itself |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
144 |
// returned several 'root' nodes and we need to keep the wrapper |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
145 |
// created by getDomFromResponse() |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
146 |
if (response.childNodes.length == 1 && response.getAttribute('cubicweb:type') == 'cwResponseWrapper') { |
4174
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
147 |
return response.firstChild; |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
148 |
} |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
149 |
return response; |
1512
c51ca5f49a78
fix insertion of head content on ajax queries
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
150 |
} |
c51ca5f49a78
fix insertion of head content on ajax queries
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
151 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
152 |
function _postAjaxLoad(node) { |
540
e5c97f6f119d
[javascript] extract ajax postprocessing in a separate function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
492
diff
changeset
|
153 |
// find sortable tables if there are some |
e5c97f6f119d
[javascript] extract ajax postprocessing in a separate function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
492
diff
changeset
|
154 |
if (typeof(Sortable) != 'undefined') { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
155 |
Sortable.sortTables(node); |
540
e5c97f6f119d
[javascript] extract ajax postprocessing in a separate function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
492
diff
changeset
|
156 |
} |
e5c97f6f119d
[javascript] extract ajax postprocessing in a separate function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
492
diff
changeset
|
157 |
// find textareas and wrap them if there are some |
e5c97f6f119d
[javascript] extract ajax postprocessing in a separate function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
492
diff
changeset
|
158 |
if (typeof(FCKeditor) != 'undefined') { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
159 |
buildWysiwygEditors(); |
540
e5c97f6f119d
[javascript] extract ajax postprocessing in a separate function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
492
diff
changeset
|
160 |
} |
e5c97f6f119d
[javascript] extract ajax postprocessing in a separate function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
492
diff
changeset
|
161 |
if (typeof initFacetBoxEvents != 'undefined') { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
162 |
initFacetBoxEvents(node); |
540
e5c97f6f119d
[javascript] extract ajax postprocessing in a separate function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
492
diff
changeset
|
163 |
} |
e5c97f6f119d
[javascript] extract ajax postprocessing in a separate function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
492
diff
changeset
|
164 |
if (typeof buildWidgets != 'undefined') { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
165 |
buildWidgets(node); |
540
e5c97f6f119d
[javascript] extract ajax postprocessing in a separate function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
492
diff
changeset
|
166 |
} |
2338
3f7c7fbae94e
call postAjaxLoad in reloadComponent; add corners only on reloaded elements
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2257
diff
changeset
|
167 |
if (typeof roundedCorners != 'undefined') { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
168 |
roundedCorners(node); |
955 | 169 |
} |
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:
3784
diff
changeset
|
170 |
if (typeof setFormsTarget != 'undefined') { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
171 |
setFormsTarget(node); |
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:
3784
diff
changeset
|
172 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
173 |
_loadDynamicFragments(node); |
4830
10e8bc190695
[javascript] fix #736185: add_onload / jQuery.bind() vs. jQuery.one()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4208
diff
changeset
|
174 |
// XXX [3.7] jQuery.one is now used instead jQuery.bind, |
10e8bc190695
[javascript] fix #736185: add_onload / jQuery.bind() vs. jQuery.one()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4208
diff
changeset
|
175 |
// jquery.treeview.js can be unpatched accordingly. |
10e8bc190695
[javascript] fix #736185: add_onload / jQuery.bind() vs. jQuery.one()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4208
diff
changeset
|
176 |
jQuery(CubicWeb).trigger('server-response', [true, node]); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
177 |
jQuery(node).trigger('server-response', [true, node]); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
178 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
179 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
180 |
function remoteCallFailed(err, req) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
181 |
cw.log(err); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
182 |
if (req.status == 500) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
183 |
updateMessage(err); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
184 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
185 |
updateMessage(_("an error occured while processing your request")); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
186 |
} |
540
e5c97f6f119d
[javascript] extract ajax postprocessing in a separate function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
492
diff
changeset
|
187 |
} |
e5c97f6f119d
[javascript] extract ajax postprocessing in a separate function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
492
diff
changeset
|
188 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
189 |
//============= base AJAX functions to make remote calls =====================// |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
190 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
191 |
* .. function:: ajaxFuncArgs(fname, form, *args) |
3011 | 192 |
* |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
193 |
* extend `form` parameters to call the js_`fname` function of the json |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
194 |
* controller with `args` arguments. |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
195 |
*/ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
196 |
function ajaxFuncArgs(fname, form /* ... */) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
197 |
form = form || {}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
198 |
$.extend(form, { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
199 |
'fname': fname, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
200 |
'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
|
201 |
'arg': $.map(cw.utils.sliceList(arguments, 2), jQuery.toJSON) |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
202 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
203 |
return form; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
204 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
205 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
206 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
207 |
* .. function:: loadxhtml(url, form, reqtype='get', mode='replace', cursor=true) |
3011 | 208 |
* |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
209 |
* build url given by absolute or relative `url` and `form` parameters |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
210 |
* (dictionary), fetch it using `reqtype` method, then evaluate the |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
211 |
* returned XHTML and insert it according to `mode` in the |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
212 |
* document. Possible modes are : |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
213 |
* |
3011 | 214 |
* - 'replace' to replace the node's content with the generated HTML |
215 |
* - 'swap' to replace the node itself with the generated HTML |
|
216 |
* - 'append' to append the generated HTML to the node's content |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
217 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
218 |
* If `cursor`, turn mouse cursor into 'progress' cursor until the remote call |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
219 |
* is back. |
3011 | 220 |
*/ |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
221 |
jQuery.fn.loadxhtml = function(url, form, reqtype, mode, cursor) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
222 |
if (this.size() > 1) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
223 |
cw.log('loadxhtml was called with more than one element'); |
0 | 224 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
225 |
var callback = null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
226 |
if (form && form.callback) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
227 |
cw.log('[3.9] callback given through form.callback is deprecated, add ' + 'callback on the defered'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
228 |
callback = form.callback; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
229 |
delete form.callback; |
0 | 230 |
} |
642
2cf7b79d8e77
[javascript] rewrote loadxhtml() plugin in order to be able to pass the XHR object to postAjaxLoad
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
540
diff
changeset
|
231 |
var node = this.get(0); // only consider the first element |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
232 |
if (cursor) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
233 |
setProgressCursor(); |
0 | 234 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
235 |
var d = loadRemote(url, form, reqtype); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
236 |
d.addCallback(function(response) { |
4174
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
237 |
var domnode = getDomFromResponse(response); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
238 |
domnode = loadAjaxHtmlHead(domnode); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
239 |
mode = mode || 'replace'; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
240 |
// make sure the component is visible |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
241 |
$(node).removeClass("hidden"); |
4174
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
242 |
if (mode == 'swap') { |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
243 |
var origId = node.id; |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
244 |
node = swapDOM(node, domnode); |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
245 |
if (!node.id) { |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
246 |
node.id = origId; |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
247 |
} |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
248 |
} else if (mode == 'replace') { |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
249 |
jQuery(node).empty().append(domnode); |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
250 |
} else if (mode == 'append') { |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
251 |
jQuery(node).append(domnode); |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
252 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
253 |
_postAjaxLoad(node); |
4174
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
254 |
while (jQuery.isFunction(callback)) { |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
255 |
callback = callback.apply(this, [domnode]); |
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
256 |
} |
0 | 257 |
}); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
258 |
if (cursor) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
259 |
d.addCallback(resetCursor); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
260 |
d.addErrback(resetCursor); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
261 |
d.addErrback(remoteCallFailed); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
262 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
263 |
return d; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
264 |
} |
0 | 265 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
266 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
267 |
* .. function:: loadRemote(url, form, reqtype='GET', async=true) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
268 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
269 |
* Asynchronously (unless `async` argument is set to false) load an url or path |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
270 |
* and return a deferred whose callbacks args are decoded according to the |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
271 |
* Content-Type response header. `form` should be additional form params |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
272 |
* dictionary, `reqtype` the HTTP request type (get 'GET' or 'POST'). |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
273 |
*/ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
274 |
function loadRemote(url, form, reqtype, sync) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
275 |
if (!url.startswith(baseuri())) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
276 |
url = baseuri() + url; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
277 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
278 |
if (!sync) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
279 |
var deferred = new Deferred(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
280 |
jQuery.ajax({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
281 |
url: url, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
282 |
type: (reqtype || 'GET').toUpperCase(), |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
283 |
data: form, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
284 |
async: true, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
285 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
286 |
beforeSend: function(xhr) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
287 |
deferred._req = xhr; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
288 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
289 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
290 |
success: function(data, status) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
291 |
if (deferred._req.getResponseHeader("content-type") == 'application/json') { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
292 |
data = cw.evalJSON(data); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
293 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
294 |
deferred.success(data); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
295 |
}, |
0 | 296 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
297 |
error: function(xhr, status, error) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
298 |
try { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
299 |
if (xhr.status == 500) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
300 |
var reason_dict = cw.evalJSON(xhr.responseText); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
301 |
deferred.error(xhr, status, reason_dict['reason']); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
302 |
return; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
303 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
304 |
} catch(exc) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
305 |
cw.log('error with server side error report:' + exc); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
306 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
307 |
deferred.error(xhr, status, null); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
308 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
309 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
310 |
return deferred; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
311 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
312 |
var result = jQuery.ajax({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
313 |
url: url, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
314 |
type: (reqtype || 'GET').toUpperCase(), |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
315 |
data: form, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
316 |
async: false |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
317 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
318 |
if (result) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
319 |
// XXX no good reason to force json here, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
320 |
// it should depends on request content-type |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
321 |
result = cw.evalJSON(result.responseText); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
322 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
323 |
return result |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
324 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
325 |
} |
0 | 326 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
327 |
//============= higher level AJAX functions using remote calls ===============// |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
328 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
329 |
* .. function:: _(message) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
330 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
331 |
* emulation of gettext's _ shortcut |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
332 |
*/ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
333 |
function _(message) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
334 |
return loadRemote('json', ajaxFuncArgs('i18n', null, [message]), 'GET', true)[0]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
335 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
336 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
337 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
338 |
* .. function:: _loadDynamicFragments(node) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
339 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
340 |
* finds each dynamic fragment in the page and executes the |
0 | 341 |
* the associated RQL to build them (Async call) |
342 |
*/ |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
343 |
function _loadDynamicFragments(node) { |
1512
c51ca5f49a78
fix insertion of head content on ajax queries
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
344 |
if (node) { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
345 |
var fragments = jQuery(node).find('div.dynamicFragment'); |
1512
c51ca5f49a78
fix insertion of head content on ajax queries
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
346 |
} else { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
347 |
var fragments = jQuery('div.dynamicFragment'); |
1512
c51ca5f49a78
fix insertion of head content on ajax queries
sylvain.thenault@logilab.fr
parents:
1498
diff
changeset
|
348 |
} |
0 | 349 |
if (fragments.length == 0) { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
350 |
return; |
0 | 351 |
} |
352 |
if (typeof LOADING_MSG == 'undefined') { |
|
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
353 |
LOADING_MSG = 'loading'; // this is only a safety belt, it should not happen |
0 | 354 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
355 |
for (var i = 0; i < fragments.length; i++) { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
356 |
var fragment = fragments[i]; |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
357 |
fragment.innerHTML = '<h3>' + LOADING_MSG + ' ... <img src="data/loading.gif" /></h3>'; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
358 |
var $fragment = jQuery(fragment); |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
359 |
// if cubicweb:loadurl is set, just pick the url et send it to loadxhtml |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
360 |
var url = $fragment.attr('cubicweb:loadurl'); |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
361 |
if (url) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
362 |
$fragment.loadxhtml(url); |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
363 |
continue; |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
364 |
} |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
365 |
// else: rebuild full url by fetching cubicweb:rql, cubicweb:vid, etc. |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
366 |
var rql = $fragment.attr('cubicweb:rql'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
367 |
var items = $fragment.attr('cubicweb:vid').split('&'); |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
368 |
var vid = items[0]; |
0 | 369 |
var extraparams = {}; |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
370 |
// case where vid='myvid¶m1=val1¶m2=val2': this is a deprecated abuse-case |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
371 |
if (items.length > 1) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
372 |
cw.log("[3.5] you're using extraargs in cubicweb:vid " + |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
373 |
"attribute, this is deprecated, consider using " + |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
374 |
"loadurl instead"); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
375 |
for (var j = 1; j < items.length; j++) { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
376 |
var keyvalue = items[j].split('='); |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
377 |
extraparams[keyvalue[0]] = keyvalue[1]; |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
378 |
} |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
379 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
380 |
var actrql = $fragment.attr('cubicweb:actualrql'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
381 |
if (actrql) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
382 |
extraparams['actualrql'] = actrql; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
383 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
384 |
var fbvid = $fragment.attr('cubicweb:fallbackvid'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
385 |
if (fbvid) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
386 |
extraparams['fallbackvid'] = fbvid; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
387 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
388 |
extraparams['rql'] = rql; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
389 |
extraparams['vid'] = vid; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
390 |
$(fragment.id).loadxhtml('json', ajaxFuncArgs('view', extraparams)); |
0 | 391 |
} |
392 |
} |
|
5820
b176ac0e3aaa
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5774
diff
changeset
|
393 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
394 |
jQuery(document).ready(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
395 |
_loadDynamicFragments(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
396 |
}); |
0 | 397 |
|
398 |
function unloadPageData() { |
|
399 |
// NOTE: do not make async calls on unload if you want to avoid |
|
400 |
// strange bugs |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
401 |
loadRemote('json', ajaxFuncArgs('unload_page_data'), 'GET', true); |
0 | 402 |
} |
403 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
404 |
function removeBookmark(beid) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
405 |
var d = loadRemote('json', ajaxFuncArgs('delete_bookmark', null, beid)); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
406 |
d.addCallback(function(boxcontent) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
407 |
$('#bookmarks_box').loadxhtml('json', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
408 |
ajaxFuncArgs('render', null, 'boxes', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
409 |
'bookmarks_box')); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
410 |
document.location.hash = '#header'; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
411 |
updateMessage(_("bookmark has been removed")); |
0 | 412 |
}); |
413 |
} |
|
414 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
415 |
function userCallback(cbname) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
416 |
setProgressCursor(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
417 |
var d = loadRemote('json', ajaxFuncArgs('user_callback', null, cbname)); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
418 |
d.addCallback(resetCursor); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
419 |
d.addErrback(resetCursor); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
420 |
d.addErrback(remoteCallFailed); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
421 |
return d; |
0 | 422 |
} |
423 |
||
424 |
function userCallbackThenUpdateUI(cbname, compid, rql, msg, registry, nodeid) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
425 |
var d = userCallback(cbname); |
0 | 426 |
d.addCallback(function() { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
427 |
$('#' + nodeid).loadxhtml('json', ajaxFuncArgs('render', { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
428 |
'rql': rql |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
429 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
430 |
registry, compid)); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
431 |
if (msg) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
432 |
updateMessage(msg); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
433 |
} |
0 | 434 |
}); |
435 |
} |
|
436 |
||
437 |
function userCallbackThenReloadPage(cbname, msg) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
438 |
var d = userCallback(cbname); |
0 | 439 |
d.addCallback(function() { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
440 |
window.location.reload(); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
441 |
if (msg) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
442 |
updateMessage(msg); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
443 |
} |
0 | 444 |
}); |
445 |
} |
|
446 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
447 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
448 |
* .. function:: unregisterUserCallback(cbname) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
449 |
* |
0 | 450 |
* unregisters the python function registered on the server's side |
451 |
* while the page was generated. |
|
452 |
*/ |
|
453 |
function unregisterUserCallback(cbname) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
454 |
setProgressCursor(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
455 |
var d = loadRemote('json', ajaxFuncArgs('unregister_user_callback', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
456 |
null, cbname)); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
457 |
d.addCallback(resetCursor); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
458 |
d.addErrback(resetCursor); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
459 |
d.addErrback(remoteCallFailed); |
0 | 460 |
} |
461 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
462 |
//============= XXX move those functions? ====================================// |
0 | 463 |
function openHash() { |
464 |
if (document.location.hash) { |
|
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
465 |
var nid = document.location.hash.replace('#', ''); |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
466 |
var node = jQuery('#' + nid); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
467 |
if (node) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
468 |
$(node).removeClass("hidden"); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
469 |
} |
0 | 470 |
}; |
471 |
} |
|
472 |
jQuery(document).ready(openHash); |
|
473 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
474 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
475 |
* .. function:: buildWysiwygEditors(parent) |
0 | 476 |
* |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
477 |
*XXX: this function should go in edition.js but as for now, htmlReplace |
0 | 478 |
* references it. |
479 |
* |
|
480 |
* replace all textareas with fckeditors. |
|
481 |
*/ |
|
482 |
function buildWysiwygEditors(parent) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
483 |
jQuery('textarea').each(function() { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
484 |
if (this.getAttribute('cubicweb:type') == 'wysiwyg') { |
3060
ea967a4f6ccb
avoid installing editor n times for n ajax loads
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3011
diff
changeset
|
485 |
// mark editor as instanciated, we may be called a number of times |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
486 |
// (see _postAjaxLoad) |
3060
ea967a4f6ccb
avoid installing editor n times for n ajax loads
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3011
diff
changeset
|
487 |
this.setAttribute('cubicweb:type', 'fckeditor'); |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
488 |
if (typeof FCKeditor != "undefined") { |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
489 |
var fck = new FCKeditor(this.id); |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
490 |
fck.Config['CustomConfigurationsPath'] = fckconfigpath; |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
491 |
fck.Config['DefaultLanguage'] = fcklang; |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
492 |
fck.BasePath = "fckeditor/"; |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
493 |
fck.ReplaceTextarea(); |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
494 |
} else { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
495 |
cw.log('fckeditor could not be found.'); |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
496 |
} |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
497 |
} |
0 | 498 |
}); |
499 |
} |
|
500 |
jQuery(document).ready(buildWysiwygEditors); |
|
501 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
502 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
503 |
* .. function:: stripEmptyTextNodes(nodelist) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
504 |
* |
1419 | 505 |
* takes a list of DOM nodes and removes all empty text nodes |
506 |
*/ |
|
507 |
function stripEmptyTextNodes(nodelist) { |
|
4208
b2826afdaf8c
fix stripEmptyTextNodes for IE (part of #615337)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4175
diff
changeset
|
508 |
/* this DROPS empty text nodes */ |
1419 | 509 |
var stripped = []; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
510 |
for (var i = 0; i < nodelist.length; i++) { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
511 |
var node = nodelist[i]; |
4208
b2826afdaf8c
fix stripEmptyTextNodes for IE (part of #615337)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4175
diff
changeset
|
512 |
if (isTextNode(node)) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
513 |
/* all browsers but FF -> innerText, FF -> textContent */ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
514 |
var text = node.innerText || node.textContent; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
515 |
if (text && ! text.strip()) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
516 |
continue; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
517 |
} |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
518 |
} else { |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
519 |
stripped.push(node); |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
520 |
} |
1419 | 521 |
} |
522 |
return stripped; |
|
523 |
} |
|
524 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
525 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
526 |
* .. function:: getDomFromResponse(response) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
527 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
528 |
* convenience function that returns a DOM node based on req's result. |
3104 | 529 |
* XXX clarify the need to clone |
530 |
* */ |
|
0 | 531 |
function getDomFromResponse(response) { |
532 |
if (typeof(response) == 'string') { |
|
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
533 |
var doc = html2dom(response); |
3073
09c6fe0db381
do postprocessing as in the xhtml case fix #345293
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3060
diff
changeset
|
534 |
} else { |
09c6fe0db381
do postprocessing as in the xhtml case fix #345293
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3060
diff
changeset
|
535 |
var doc = response.documentElement; |
0 | 536 |
} |
537 |
var children = doc.childNodes; |
|
538 |
if (!children.length) { |
|
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
539 |
// no child (error cases) => return the whole document |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
540 |
return jQuery(doc).clone().context; |
0 | 541 |
} |
1419 | 542 |
children = stripEmptyTextNodes(children); |
0 | 543 |
if (children.length == 1) { |
4175
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
544 |
// only one child => return it |
92a10d2a09af
[javascript] cleanup, remove tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4174
diff
changeset
|
545 |
return jQuery(children[0]).clone().context; |
0 | 546 |
} |
547 |
// several children => wrap them in a single node and return the wrap |
|
4174
860f622a31aa
[javascript] remove ajaxHtmlHead from dom response once it has been processed.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3863
diff
changeset
|
548 |
return DIV({'cubicweb:type': "cwResponseWrapper"}, |
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
|
549 |
$.map(children, function(node) { |
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
|
550 |
return jQuery(node).clone().context;}) |
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
|
551 |
); |
0 | 552 |
} |
553 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
554 |
/* DEPRECATED *****************************************************************/ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
555 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
556 |
preprocessAjaxLoad = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
557 |
'[3.9] preprocessAjaxLoad() is deprecated, use loadAjaxHtmlHead instead', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
558 |
function(node, newdomnode) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
559 |
return loadAjaxHtmlHead(newdomnode); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
560 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
561 |
); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
562 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
563 |
reloadComponent = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
564 |
'[3.9] reloadComponent() is deprecated, use loadxhtml instead', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
565 |
function(compid, rql, registry, nodeid, extraargs) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
566 |
registry = registry || 'components'; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
567 |
rql = rql || ''; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
568 |
nodeid = nodeid || (compid + 'Component'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
569 |
extraargs = extraargs || {}; |
5909
9af8ac182f53
[javascript] fix some javascript errors and remove some deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5820
diff
changeset
|
570 |
var node = cw.jqNode(nodeid); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
571 |
return node.loadxhtml('json', ajaxFuncArgs('component', null, compid, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
572 |
rql, registry, extraargs)); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
573 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
574 |
); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
575 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
576 |
reloadBox = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
577 |
'[3.9] reloadBox() is deprecated, use loadxhtml instead', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
578 |
function(boxid, rql) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
579 |
return reloadComponent(boxid, rql, 'boxes', boxid); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
580 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
581 |
); |
0 | 582 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
583 |
replacePageChunk = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
584 |
'[3.9] replacePageChunk() is deprecated, use loadxhtml instead', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
585 |
function(nodeId, rql, vid, extraparams, /* ... */ swap, callback) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
586 |
var params = null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
587 |
if (callback) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
588 |
params = { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
589 |
callback: callback |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
590 |
}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
591 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
592 |
var node = jQuery('#' + nodeId)[0]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
593 |
var props = {}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
594 |
if (node) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
595 |
props['rql'] = rql; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
596 |
props['fname'] = 'view'; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
597 |
props['pageid'] = pageid; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
598 |
if (vid) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
599 |
props['vid'] = vid; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
600 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
601 |
if (extraparams) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
602 |
jQuery.extend(props, extraparams); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
603 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
604 |
// FIXME we need to do asURL(props) manually instead of |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
605 |
// passing `props` directly to loadxml because replacePageChunk |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
606 |
// is sometimes called (abusively) with some extra parameters in `vid` |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
607 |
var mode = swap ? 'swap': 'replace'; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
608 |
var url = JSON_BASE_URL + asURL(props); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
609 |
jQuery(node).loadxhtml(url, params, 'get', mode); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
610 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
611 |
cw.log('Node', nodeId, 'not found'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
612 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
613 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
614 |
); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
615 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
616 |
loadxhtml = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
617 |
'[3.9] loadxhtml() function is deprecated, use loadxhtml method instead', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
618 |
function(nodeid, url, /* ... */ replacemode) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
619 |
jQuery('#' + nodeid).loadxhtml(url, null, 'post', replacemode); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
620 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
621 |
); |
0 | 622 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
623 |
remoteExec = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
624 |
'[3.9] remoteExec() is deprecated, use loadRemote instead', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
625 |
function(fname /* ... */) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
626 |
setProgressCursor(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
627 |
var props = { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
628 |
'fname': fname, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
629 |
'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
|
630 |
'arg': $.map(cw.utils.sliceList(arguments, 1), jQuery.toJSON) |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
631 |
}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
632 |
var result = jQuery.ajax({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
633 |
url: JSON_BASE_URL, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
634 |
data: props, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
635 |
async: false |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
636 |
}).responseText; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
637 |
if (result) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
638 |
result = cw.evalJSON(result); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
639 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
640 |
resetCursor(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
641 |
return result; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
642 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
643 |
); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
644 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
645 |
asyncRemoteExec = cw.utils.deprecatedFunction( |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
646 |
'[3.9] asyncRemoteExec() is deprecated, use loadRemote instead', |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
647 |
function(fname /* ... */) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
648 |
setProgressCursor(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
649 |
var props = { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
650 |
'fname': fname, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
651 |
'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
|
652 |
'arg': $.map(cw.utils.sliceList(arguments, 1), jQuery.toJSON) |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
653 |
}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
654 |
// XXX we should inline the content of loadRemote here |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
655 |
var deferred = loadRemote(JSON_BASE_URL, props, 'POST'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
656 |
deferred = deferred.addErrback(remoteCallFailed); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
657 |
deferred = deferred.addErrback(resetCursor); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
658 |
deferred = deferred.addCallback(resetCursor); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
659 |
return deferred; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
660 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5506
diff
changeset
|
661 |
); |