author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Mon, 17 Dec 2012 14:26:41 +0100 | |
branch | stable |
changeset 8633 | 36197bd1d78b |
parent 8238 | 087bb529035c |
child 9259 | 68cde7431c2c |
permissions | -rw-r--r-- |
6389
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6220
diff
changeset
|
1 |
/* in CW 3.10, we should move these functions in this namespace */ |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6220
diff
changeset
|
2 |
cw.htmlhelpers = new Namespace('cw.htmlhelpers'); |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6220
diff
changeset
|
3 |
|
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6220
diff
changeset
|
4 |
jQuery.extend(cw.htmlhelpers, { |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6220
diff
changeset
|
5 |
popupLoginBox: function(loginboxid, focusid) { |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6220
diff
changeset
|
6 |
$('#'+loginboxid).toggleClass('hidden'); |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6220
diff
changeset
|
7 |
jQuery('#' + focusid +':visible').focus(); |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6220
diff
changeset
|
8 |
} |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6220
diff
changeset
|
9 |
}); |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6220
diff
changeset
|
10 |
|
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6220
diff
changeset
|
11 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
12 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
13 |
* .. function:: baseuri() |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
14 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
15 |
* returns the document's baseURI. (baseuri() uses document.baseURI if |
0 | 16 |
* available and inspects the <base> tag manually otherwise.) |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
17 |
*/ |
0 | 18 |
function baseuri() { |
7069
8bf2337a6f3b
[views] #1499661 get rid of base tag
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6858
diff
changeset
|
19 |
if (typeof BASE_URL === 'undefined') { |
8bf2337a6f3b
[views] #1499661 get rid of base tag
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6858
diff
changeset
|
20 |
// backward compatibility, BASE_URL might be undefined |
8bf2337a6f3b
[views] #1499661 get rid of base tag
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6858
diff
changeset
|
21 |
var uri = document.baseURI; |
8bf2337a6f3b
[views] #1499661 get rid of base tag
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6858
diff
changeset
|
22 |
if (uri) { // some browsers don't define baseURI |
8bf2337a6f3b
[views] #1499661 get rid of base tag
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6858
diff
changeset
|
23 |
return uri.toLowerCase(); |
8bf2337a6f3b
[views] #1499661 get rid of base tag
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6858
diff
changeset
|
24 |
} |
8bf2337a6f3b
[views] #1499661 get rid of base tag
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6858
diff
changeset
|
25 |
return jQuery('base').attr('href').toLowerCase(); |
0 | 26 |
} |
7069
8bf2337a6f3b
[views] #1499661 get rid of base tag
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6858
diff
changeset
|
27 |
return BASE_URL; |
0 | 28 |
} |
29 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
30 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
31 |
* .. function:: setProgressCursor() |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
32 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
33 |
* set body's cursor to 'progress' |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
34 |
*/ |
0 | 35 |
function setProgressCursor() { |
36 |
var body = document.getElementsByTagName('body')[0]; |
|
37 |
body.style.cursor = 'progress'; |
|
38 |
} |
|
39 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
40 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
41 |
* .. function:: resetCursor(result) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
42 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
43 |
* reset body's cursor to default (mouse cursor). The main |
0 | 44 |
* purpose of this function is to be used as a callback in the |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
45 |
* deferreds' callbacks chain. |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
46 |
*/ |
0 | 47 |
function resetCursor(result) { |
48 |
var body = document.getElementsByTagName('body')[0]; |
|
49 |
body.style.cursor = 'default'; |
|
50 |
// pass result to next callback in the callback chain |
|
51 |
return result; |
|
52 |
} |
|
53 |
||
54 |
function updateMessage(msg) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
55 |
var msgdiv = DIV({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
56 |
'class': 'message' |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
57 |
}); |
0 | 58 |
// don't pass msg to DIV() directly because DIV will html escape it |
59 |
// and msg should alreay be html escaped at this point. |
|
60 |
msgdiv.innerHTML = msg; |
|
61 |
jQuery('#appMsg').removeClass('hidden').empty().append(msgdiv); |
|
62 |
} |
|
63 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
64 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
65 |
* .. function:: asURL(props) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
66 |
* |
8238
087bb529035c
[spelling] fix dictionnary -> dictionary typo
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7069
diff
changeset
|
67 |
* builds an url from an object (used as a dictionary) |
29
7d14f1eadded
fix focus problems on login inputs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
68 |
* |
1419 | 69 |
* >>> asURL({'rql' : "RQL", 'x': [1, 2], 'itemvid' : "oneline"}) |
0 | 70 |
* rql=RQL&vid=list&itemvid=oneline&x=1&x=2 |
3781
c7ef58db0e4b
[javascript] asURL now escapes request arguments
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3494
diff
changeset
|
71 |
* >>> asURL({'rql' : "a&b", 'x': [1, 2], 'itemvid' : "oneline"}) |
c7ef58db0e4b
[javascript] asURL now escapes request arguments
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3494
diff
changeset
|
72 |
* rql=a%26b&x=1&x=2&itemvid=oneline |
0 | 73 |
*/ |
1419 | 74 |
function asURL(props) { |
0 | 75 |
var chunks = []; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
76 |
for (key in props) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
77 |
var value = props[key]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
78 |
// generate a list of couple key=value if key is multivalued |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
79 |
if (cw.utils.isArrayLike(value)) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
80 |
for (var i = 0; i < value.length; i++) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
81 |
chunks.push(key + '=' + urlEncode(value[i])); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
82 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
83 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
84 |
chunks.push(key + '=' + urlEncode(value)); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
85 |
} |
0 | 86 |
} |
87 |
return chunks.join('&'); |
|
88 |
} |
|
89 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
90 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
91 |
* .. function:: firstSelected(selectNode) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
92 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
93 |
* return selected value of a combo box if any |
0 | 94 |
*/ |
95 |
function firstSelected(selectNode) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
96 |
var $selection = $(selectNode).find('option:selected:first'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
97 |
return ($selection.length > 0) ? $selection[0] : null; |
0 | 98 |
} |
99 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
100 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
101 |
* .. function:: toggleVisibility(elemId) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
102 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
103 |
* toggle visibility of an element by its id |
0 | 104 |
*/ |
105 |
function toggleVisibility(elemId) { |
|
6220
e23231d482fb
[js] jqNode is more robust here wrt some node ids
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5699
diff
changeset
|
106 |
cw.jqNode(elemId).toggleClass('hidden'); |
0 | 107 |
} |
108 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
109 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
110 |
* .. function:: popupLoginBox() |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
111 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
112 |
* toggles visibility of login popup div |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
113 |
*/ |
2385
8fa16dc4b8c8
[js] shrink htmlhelpers, extract massmailing functionality, jslint
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2378
diff
changeset
|
114 |
// XXX used exactly ONCE in basecomponents |
6389
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6220
diff
changeset
|
115 |
popupLoginBox = cw.utils.deprecatedFunction( |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6220
diff
changeset
|
116 |
function() { |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6220
diff
changeset
|
117 |
$('#popupLoginBox').toggleClass('hidden'); |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6220
diff
changeset
|
118 |
jQuery('#__login:visible').focus(); |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6220
diff
changeset
|
119 |
}); |
29
7d14f1eadded
fix focus problems on login inputs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
120 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
121 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
122 |
* .. function getElementsMatching(tagName, properties, \/* optional \*\/ parent) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
123 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
124 |
* returns the list of elements in the document matching the tag name |
0 | 125 |
* and the properties provided |
29
7d14f1eadded
fix focus problems on login inputs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
126 |
* |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
127 |
* * `tagName`, the tag's name |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
128 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
129 |
* * `properties`, a js Object used as a dict |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
130 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
131 |
* Return an iterator (if a *real* array is needed, you can use the |
0 | 132 |
* list() function) |
133 |
*/ |
|
134 |
function getElementsMatching(tagName, properties, /* optional */ parent) { |
|
135 |
parent = parent || document; |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
136 |
return jQuery.grep(parent.getElementsByTagName(tagName), function elementMatches(element) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
137 |
for (prop in properties) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
138 |
if (jQuery(element).attr(prop) != properties[prop]) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
139 |
return false; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
140 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
141 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
142 |
return true; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
143 |
}); |
0 | 144 |
} |
145 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
146 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
147 |
* .. function:: setCheckboxesState(nameprefix, value, checked) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
148 |
* |
29
7d14f1eadded
fix focus problems on login inputs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
149 |
* sets checked/unchecked status of checkboxes |
0 | 150 |
*/ |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
151 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
152 |
function setCheckboxesState(nameprefix, value, checked) { |
0 | 153 |
// XXX: this looks in *all* the document for inputs |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
154 |
jQuery('input:checkbox[name^=' + nameprefix + ']').each(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
155 |
if (value == null || this.value == value) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
156 |
this.checked = checked; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
157 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
158 |
}); |
0 | 159 |
} |
160 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
161 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
162 |
* .. function:: html2dom(source) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
163 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
164 |
* this function is a hack to build a dom node from html source |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
165 |
*/ |
0 | 166 |
function html2dom(source) { |
167 |
var tmpNode = SPAN(); |
|
168 |
tmpNode.innerHTML = source; |
|
169 |
if (tmpNode.childNodes.length == 1) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
170 |
return tmpNode.firstChild; |
0 | 171 |
} |
172 |
else { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
173 |
// we leave the span node when `source` has no root node |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
174 |
// XXX This is cleary not the best solution, but css/html-wise, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
175 |
/// a span not should not be too much disturbing |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
176 |
return tmpNode; |
0 | 177 |
} |
178 |
} |
|
179 |
||
180 |
// *** HELPERS **************************************************** // |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
181 |
function rql_for_eid(eid) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
182 |
return 'Any X WHERE X eid ' + eid; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
183 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
184 |
function isTextNode(domNode) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
185 |
return domNode.nodeType == 3; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
186 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
187 |
function isElementNode(domNode) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
188 |
return domNode.nodeType == 1; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
189 |
} |
0 | 190 |
|
191 |
function autogrow(area) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
192 |
if (area.scrollHeight > area.clientHeight && ! window.opera) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
193 |
if (area.rows < 20) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
194 |
area.rows += 2; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
195 |
} |
0 | 196 |
} |
197 |
} |
|
198 |
//============= page loading events ==========================================// |
|
5699
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
199 |
cw.rounded = [['div.sideBoxBody', 'bottom 6px'], |
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
200 |
['div.boxTitle, div.sideBoxTitle, th.month', 'top 6px']]; |
2338
3f7c7fbae94e
call postAjaxLoad in reloadComponent; add corners only on reloaded elements
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2232
diff
changeset
|
201 |
|
3f7c7fbae94e
call postAjaxLoad in reloadComponent; add corners only on reloaded elements
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2232
diff
changeset
|
202 |
function roundedCorners(node) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
203 |
if (jQuery.fn.corner !== undefined) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
204 |
node = jQuery(node); |
5699
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
205 |
for (var r = 0; r < cw.rounded.length; r++) { |
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
206 |
node.find(cw.rounded[r][0]).corner(cw.rounded[r][1]); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
207 |
} |
2338
3f7c7fbae94e
call postAjaxLoad in reloadComponent; add corners only on reloaded elements
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
2232
diff
changeset
|
208 |
} |
0 | 209 |
} |
210 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
211 |
jQuery(document).ready(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
212 |
roundedCorners(this.body); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5479
diff
changeset
|
213 |
}); |