author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
Fri, 22 Mar 2013 20:10:19 +0100 | |
changeset 8773 | 21edcb0a5ed7 |
parent 8713 | 4b34dc3046e6 |
child 8914 | e80dfffc2c2a |
permissions | -rw-r--r-- |
5937
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5910
diff
changeset
|
1 |
/** filter form, aka facets, javascript functions |
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5910
diff
changeset
|
2 |
* |
0 | 3 |
* :organization: Logilab |
7628
56022cf13887
[facet] fix facet values update, broken by 7626:56300bec75f8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7606
diff
changeset
|
4 |
* :copyright: 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 5 |
* :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 |
*/ |
|
7 |
||
5937
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5910
diff
changeset
|
8 |
var SELECTED_IMG = baseuri() + "data/black-check.png"; |
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5910
diff
changeset
|
9 |
var UNSELECTED_IMG = baseuri() + "data/no-check-no-border.png"; |
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5910
diff
changeset
|
10 |
var UNSELECTED_BORDER_IMG = baseuri() + "data/black-uncheck.png"; |
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5910
diff
changeset
|
11 |
|
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5910
diff
changeset
|
12 |
|
0 | 13 |
function copyParam(origparams, newparams, param) { |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
14 |
var index = $.inArray(param, origparams[0]); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
15 |
if (index > - 1) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
16 |
newparams[param] = origparams[1][index]; |
0 | 17 |
} |
18 |
} |
|
19 |
||
5937
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5910
diff
changeset
|
20 |
|
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5910
diff
changeset
|
21 |
function facetFormContent($form) { |
4
8a607bdc11dc
[javascript] indentation fixes + missing semi colons
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
22 |
var names = []; |
8a607bdc11dc
[javascript] indentation fixes + missing semi colons
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
23 |
var values = []; |
5937
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5910
diff
changeset
|
24 |
$form.find('.facet').each(function() { |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
25 |
var facetName = $(this).find('.facetTitle').attr('cubicweb:facetName'); |
7692
b37f4fdc44d4
[facets] make sure has_text facet data is posted correctly (closes #1857405)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7628
diff
changeset
|
26 |
// FacetVocabularyWidget |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
27 |
$(this).find('.facetValueSelected').each(function(x) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
28 |
names.push(facetName); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
29 |
values.push(this.getAttribute('cubicweb:value')); |
4
8a607bdc11dc
[javascript] indentation fixes + missing semi colons
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
30 |
}); |
7692
b37f4fdc44d4
[facets] make sure has_text facet data is posted correctly (closes #1857405)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7628
diff
changeset
|
31 |
// FacetStringWidget (e.g. has-text) |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
32 |
$(this).find('input:text').each(function(){ |
7692
b37f4fdc44d4
[facets] make sure has_text facet data is posted correctly (closes #1857405)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7628
diff
changeset
|
33 |
names.push(facetName); |
b37f4fdc44d4
[facets] make sure has_text facet data is posted correctly (closes #1857405)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7628
diff
changeset
|
34 |
values.push(this.value); |
b37f4fdc44d4
[facets] make sure has_text facet data is posted correctly (closes #1857405)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7628
diff
changeset
|
35 |
}); |
4
8a607bdc11dc
[javascript] indentation fixes + missing semi colons
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
36 |
}); |
7692
b37f4fdc44d4
[facets] make sure has_text facet data is posted correctly (closes #1857405)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7628
diff
changeset
|
37 |
// pick up hidden inputs (required metadata inputs such as 'facets' |
b37f4fdc44d4
[facets] make sure has_text facet data is posted correctly (closes #1857405)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7628
diff
changeset
|
38 |
// but also RangeWidgets) |
b37f4fdc44d4
[facets] make sure has_text facet data is posted correctly (closes #1857405)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7628
diff
changeset
|
39 |
$form.find('input:hidden').each(function() { |
4
8a607bdc11dc
[javascript] indentation fixes + missing semi colons
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
40 |
names.push(this.name); |
8a607bdc11dc
[javascript] indentation fixes + missing semi colons
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
41 |
values.push(this.value); |
8a607bdc11dc
[javascript] indentation fixes + missing semi colons
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
42 |
}); |
7692
b37f4fdc44d4
[facets] make sure has_text facet data is posted correctly (closes #1857405)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7628
diff
changeset
|
43 |
// And / Or operators |
5937
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5910
diff
changeset
|
44 |
$form.find('select option[selected]').each(function() { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
45 |
names.push(this.parentNode.name); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
46 |
values.push(this.value); |
0 | 47 |
}); |
4
8a607bdc11dc
[javascript] indentation fixes + missing semi colons
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
48 |
return [names, values]; |
0 | 49 |
} |
50 |
||
5937
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5910
diff
changeset
|
51 |
|
7949
ce64860b3cdc
[facets] on the way to vidargs removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7923
diff
changeset
|
52 |
// XXX deprecate vidargs once TableView is gone |
0 | 53 |
function buildRQL(divid, vid, paginate, vidargs) { |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
54 |
$(CubicWeb).trigger('facets-content-loading', [divid, vid, paginate, vidargs]); |
5937
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5910
diff
changeset
|
55 |
var $form = $('#' + divid + 'Form'); |
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5910
diff
changeset
|
56 |
var zipped = facetFormContent($form); |
4
8a607bdc11dc
[javascript] indentation fixes + missing semi colons
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
57 |
zipped[0].push('facetargs'); |
8a607bdc11dc
[javascript] indentation fixes + missing semi colons
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
58 |
zipped[1].push(vidargs); |
8260
5a81fa526b30
[ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8185
diff
changeset
|
59 |
var d = loadRemote(AJAX_BASE_URL, ajaxFuncArgs('filter_build_rql', null, zipped[0], zipped[1])); |
0 | 60 |
d.addCallback(function(result) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
61 |
var rql = result[0]; |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
62 |
var $bkLink = $('#facetBkLink'); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
63 |
if ($bkLink.length) { |
7923
ece4bc9b9314
[facets] use encodeURIComponent instead of escape to encode url paremters (closes #1984727)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7912
diff
changeset
|
64 |
var bkPath = 'view?rql=' + encodeURIComponent(rql); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
65 |
if (vid) { |
7923
ece4bc9b9314
[facets] use encodeURIComponent instead of escape to encode url paremters (closes #1984727)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7912
diff
changeset
|
66 |
bkPath += '&vid=' + encodeURIComponent(vid); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
67 |
} |
7923
ece4bc9b9314
[facets] use encodeURIComponent instead of escape to encode url paremters (closes #1984727)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7912
diff
changeset
|
68 |
var bkUrl = $bkLink.attr('cubicweb:target') + '&path=' + encodeURIComponent(bkPath); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
69 |
$bkLink.attr('href', bkUrl); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
70 |
} |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
71 |
var $focusLink = $('#focusLink'); |
8551
6cf9e4da54a9
[facets] add link 'focus on selection' (closes #525277)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8260
diff
changeset
|
72 |
if ($focusLink.length) { |
6cf9e4da54a9
[facets] add link 'focus on selection' (closes #525277)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8260
diff
changeset
|
73 |
var url = baseuri()+ 'view?rql=' + encodeURIComponent(rql); |
6cf9e4da54a9
[facets] add link 'focus on selection' (closes #525277)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8260
diff
changeset
|
74 |
if (vid) { |
6cf9e4da54a9
[facets] add link 'focus on selection' (closes #525277)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8260
diff
changeset
|
75 |
url += '&vid=' + encodeURIComponent(vid); |
6cf9e4da54a9
[facets] add link 'focus on selection' (closes #525277)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8260
diff
changeset
|
76 |
} |
6cf9e4da54a9
[facets] add link 'focus on selection' (closes #525277)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8260
diff
changeset
|
77 |
$focusLink.attr('href', url); |
6cf9e4da54a9
[facets] add link 'focus on selection' (closes #525277)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8260
diff
changeset
|
78 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
79 |
var toupdate = result[1]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
80 |
var extraparams = vidargs; |
5910
432c657ebfec
[facets] fix bug w/ vid in facet's js introduced in 3.9, improve navigation component so that show all link use ajax when called from ajax.
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5699
diff
changeset
|
81 |
if (paginate) { extraparams['paginate'] = '1'; } // XXX in vidargs |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
82 |
// copy some parameters |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
83 |
// XXX cleanup vid/divid mess |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
84 |
// if vid argument is specified , the one specified in form params will |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
85 |
// be overriden by replacePageChunk |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
86 |
copyParam(zipped, extraparams, 'vid'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
87 |
extraparams['divid'] = divid; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
88 |
copyParam(zipped, extraparams, 'divid'); |
7949
ce64860b3cdc
[facets] on the way to vidargs removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7923
diff
changeset
|
89 |
copyParam(zipped, extraparams, 'subvid'); // XXX deprecate once TableView is gone |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
90 |
copyParam(zipped, extraparams, 'fromformfilter'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
91 |
// paginate used to know if the filter box is acting, in which case we |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
92 |
// want to reload action box to match current selection (we don't want |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
93 |
// this from a table filter) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
94 |
extraparams['rql'] = rql; |
5910
432c657ebfec
[facets] fix bug w/ vid in facet's js introduced in 3.9, improve navigation component so that show all link use ajax when called from ajax.
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5699
diff
changeset
|
95 |
if (vid) { // XXX see copyParam above. Need cleanup |
432c657ebfec
[facets] fix bug w/ vid in facet's js introduced in 3.9, improve navigation component so that show all link use ajax when called from ajax.
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5699
diff
changeset
|
96 |
extraparams['vid'] = vid; |
432c657ebfec
[facets] fix bug w/ vid in facet's js introduced in 3.9, improve navigation component so that show all link use ajax when called from ajax.
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5699
diff
changeset
|
97 |
} |
8260
5a81fa526b30
[ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8185
diff
changeset
|
98 |
d = $('#' + divid).loadxhtml(AJAX_BASE_URL, ajaxFuncArgs('view', extraparams), |
5910
432c657ebfec
[facets] fix bug w/ vid in facet's js introduced in 3.9, improve navigation component so that show all link use ajax when called from ajax.
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5699
diff
changeset
|
99 |
null, 'swap'); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
100 |
d.addCallback(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
101 |
// XXX rql/vid in extraparams |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
102 |
$(CubicWeb).trigger('facets-content-loaded', [divid, rql, vid, extraparams]); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
103 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
104 |
if (paginate) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
105 |
// FIXME the edit box might not be displayed in which case we don't |
5937
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5910
diff
changeset
|
106 |
// know where to put the potential new one, just skip this case for |
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5910
diff
changeset
|
107 |
// now |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
108 |
var $node = $('#edit_box'); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
109 |
if ($node.length) { |
8260
5a81fa526b30
[ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8185
diff
changeset
|
110 |
$node.loadxhtml(AJAX_BASE_URL, ajaxFuncArgs('render', { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
111 |
'rql': rql |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
112 |
}, |
6551
50ec97e4f9cc
breadcrumbs/edid_box are now contextual component (closes #1334196)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5937
diff
changeset
|
113 |
'ctxcomponents', 'edit_box')); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
114 |
} |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
115 |
$node = $('#breadcrumbs'); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
116 |
if ($node.length) { |
8260
5a81fa526b30
[ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8185
diff
changeset
|
117 |
$node.loadxhtml(AJAX_BASE_URL, ajaxFuncArgs('render', { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
118 |
'rql': rql |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
119 |
}, |
6551
50ec97e4f9cc
breadcrumbs/edid_box are now contextual component (closes #1334196)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5937
diff
changeset
|
120 |
'ctxcomponents', 'breadcrumbs')); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
121 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
122 |
} |
7912
7a2e2a3c3b0c
[js] Remove tab mixed with space in ``web/data/cubicweb.facets.js``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7692
diff
changeset
|
123 |
var mainvar = null; |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
124 |
var index = $.inArray('mainvar', zipped[0]); |
7912
7a2e2a3c3b0c
[js] Remove tab mixed with space in ``web/data/cubicweb.facets.js``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7692
diff
changeset
|
125 |
if (index > - 1) { |
7606
01b49ec8fe80
[facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7604
diff
changeset
|
126 |
mainvar = zipped[1][index]; |
7912
7a2e2a3c3b0c
[js] Remove tab mixed with space in ``web/data/cubicweb.facets.js``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7692
diff
changeset
|
127 |
} |
7606
01b49ec8fe80
[facets] allow to specify on which rqlst's variable facets should be applied. Closes #1795915
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7604
diff
changeset
|
128 |
|
8260
5a81fa526b30
[ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
8185
diff
changeset
|
129 |
var d = loadRemote(AJAX_BASE_URL, ajaxFuncArgs('filter_select_content', null, toupdate, rql, mainvar)); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
130 |
d.addCallback(function(updateMap) { |
7628
56022cf13887
[facet] fix facet values update, broken by 7626:56300bec75f8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7606
diff
changeset
|
131 |
for (facetName in updateMap) { |
56022cf13887
[facet] fix facet values update, broken by 7626:56300bec75f8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7606
diff
changeset
|
132 |
var values = updateMap[facetName]; |
7912
7a2e2a3c3b0c
[js] Remove tab mixed with space in ``web/data/cubicweb.facets.js``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7692
diff
changeset
|
133 |
// XXX fine with jquery 1.6 |
7628
56022cf13887
[facet] fix facet values update, broken by 7626:56300bec75f8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7606
diff
changeset
|
134 |
//$form.find('div[cubicweb\\:facetName="' + facetName + '"] ~ div .facetCheckBox').each(function() { |
56022cf13887
[facet] fix facet values update, broken by 7626:56300bec75f8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7606
diff
changeset
|
135 |
$form.find('div').filter(function () {return $(this).attr('cubicweb:facetName') == facetName}).parent().find('.facetCheckBox').each(function() { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
136 |
var value = this.getAttribute('cubicweb:value'); |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
137 |
if ($.inArray(value, values) == -1) { |
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
138 |
if (!$(this).hasClass('facetValueDisabled')) { |
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
139 |
$(this).addClass('facetValueDisabled'); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
140 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
141 |
} else { |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
142 |
if ($(this).hasClass('facetValueDisabled')) { |
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
143 |
$(this).removeClass('facetValueDisabled'); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
144 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
145 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
146 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
147 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
148 |
}); |
0 | 149 |
}); |
150 |
} |
|
151 |
||
152 |
||
933
ad99da207edd
late evaluation of cubicweb:facetargs is necessary since its value may change
sylvain.thenault@logilab.fr
parents:
434
diff
changeset
|
153 |
function initFacetBoxEvents(root) { |
ad99da207edd
late evaluation of cubicweb:facetargs is necessary since its value may change
sylvain.thenault@logilab.fr
parents:
434
diff
changeset
|
154 |
// facetargs : (divid, vid, paginate, extraargs) |
0 | 155 |
root = root || document; |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
156 |
$(root).find('form').each(function() { |
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
157 |
var form = $(this); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
158 |
// NOTE: don't evaluate facetargs here but in callbacks since its value |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
159 |
// may changes and we must send its value when the callback is |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
160 |
// called, not when the page is initialized |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
161 |
var facetargs = form.attr('cubicweb:facetargs'); |
7602
fbda46a4944f
[facets js] better cubicweb:facetargs handling and avoid initializing a same form twice (that may occurs)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6551
diff
changeset
|
162 |
if (facetargs != undefined && !form.attr('cubicweb:initialized')) { |
7912
7a2e2a3c3b0c
[js] Remove tab mixed with space in ``web/data/cubicweb.facets.js``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7692
diff
changeset
|
163 |
form.attr('cubicweb:initialized', '1'); |
7a2e2a3c3b0c
[js] Remove tab mixed with space in ``web/data/cubicweb.facets.js``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7692
diff
changeset
|
164 |
var jsfacetargs = cw.evalJSON(form.attr('cubicweb:facetargs')); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
165 |
form.submit(function() { |
7602
fbda46a4944f
[facets js] better cubicweb:facetargs handling and avoid initializing a same form twice (that may occurs)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6551
diff
changeset
|
166 |
buildRQL.apply(null, jsfacetargs); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
167 |
return false; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
168 |
}); |
7912
7a2e2a3c3b0c
[js] Remove tab mixed with space in ``web/data/cubicweb.facets.js``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7692
diff
changeset
|
169 |
var divid = jsfacetargs[0]; |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
170 |
if ($('#'+divid).length) { |
7912
7a2e2a3c3b0c
[js] Remove tab mixed with space in ``web/data/cubicweb.facets.js``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7692
diff
changeset
|
171 |
var $loadingDiv = $(DIV({id:'facetLoading'}, |
7a2e2a3c3b0c
[js] Remove tab mixed with space in ``web/data/cubicweb.facets.js``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7692
diff
changeset
|
172 |
facetLoadingMsg)); |
7a2e2a3c3b0c
[js] Remove tab mixed with space in ``web/data/cubicweb.facets.js``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7692
diff
changeset
|
173 |
$loadingDiv.corner(); |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
174 |
$($('#'+divid).get(0).parentNode).append($loadingDiv); |
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
175 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
176 |
form.find('div.facet').each(function() { |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
177 |
var facet = $(this); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
178 |
facet.find('div.facetCheckBox').each(function(i) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
179 |
this.setAttribute('cubicweb:idx', i); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
180 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
181 |
facet.find('div.facetCheckBox').click(function() { |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
182 |
var $this = $(this); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
183 |
// NOTE : add test on the facet operator (i.e. OR, AND) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
184 |
// if ($this.hasClass('facetValueDisabled')){ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
185 |
// return |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
186 |
// } |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
187 |
if ($this.hasClass('facetValueSelected')) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
188 |
$this.removeClass('facetValueSelected'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
189 |
$this.find('img').each(function(i) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
190 |
if (this.getAttribute('cubicweb:unselimg')) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
191 |
this.setAttribute('src', UNSELECTED_BORDER_IMG); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
192 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
193 |
else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
194 |
this.setAttribute('src', UNSELECTED_IMG); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
195 |
} |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
196 |
this.setAttribute('alt', (_("not selected"))); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
197 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
198 |
var index = parseInt($this.attr('cubicweb:idx')); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
199 |
// we dont need to move the element when cubicweb:idx == 0 |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
200 |
if (index > 0) { |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
201 |
var shift = $.grep(facet.find('.facetValueSelected'), function(n) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
202 |
var nindex = parseInt(n.getAttribute('cubicweb:idx')); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
203 |
return nindex > index; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
204 |
}).length; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
205 |
index += shift; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
206 |
var parent = this.parentNode; |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
207 |
var $insertAfter = $(parent).find('.facetCheckBox:nth(' + index + ')'); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
208 |
if (! ($insertAfter.length == 1 && shift == 0)) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
209 |
// only rearrange element if necessary |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
210 |
$insertAfter.after(this); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
211 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
212 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
213 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
214 |
var lastSelected = facet.find('.facetValueSelected:last'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
215 |
if (lastSelected.length) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
216 |
lastSelected.after(this); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
217 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
218 |
var parent = this.parentNode; |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
219 |
$(parent).prepend(this); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
220 |
} |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
221 |
$(this).addClass('facetValueSelected'); |
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
222 |
var $img = $(this).find('img'); |
8185
864fc1f147a4
[js, i18n] translated strings should use " not ' else they are discarded by xgettext. Closes #1892489
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8165
diff
changeset
|
223 |
$img.attr('src', SELECTED_IMG).attr('alt', (_("selected"))); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
224 |
} |
7602
fbda46a4944f
[facets js] better cubicweb:facetargs handling and avoid initializing a same form twice (that may occurs)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6551
diff
changeset
|
225 |
buildRQL.apply(null, jsfacetargs); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
226 |
facet.find('.facetBody').animate({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
227 |
scrollTop: 0 |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
228 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
229 |
''); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
230 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
231 |
facet.find('select.facetOperator').change(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
232 |
var nbselected = facet.find('div.facetValueSelected').length; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
233 |
if (nbselected >= 2) { |
7602
fbda46a4944f
[facets js] better cubicweb:facetargs handling and avoid initializing a same form twice (that may occurs)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6551
diff
changeset
|
234 |
buildRQL.apply(null, jsfacetargs); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
235 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
236 |
}); |
8165
1fe089765187
[facets] Make hiding facet body optional (closes #2105862)
Julien Cristau <julien.cristau@logilab.fr>
parents:
7949
diff
changeset
|
237 |
facet.find('div.facetTitle.hideFacetBody').click(function() { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
238 |
facet.find('div.facetBody').toggleClass('hidden').toggleClass('opened'); |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
239 |
$(this).toggleClass('opened'); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
240 |
}); |
0 | 241 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
242 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
243 |
} |
0 | 244 |
}); |
245 |
} |
|
246 |
||
5937
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5910
diff
changeset
|
247 |
|
0 | 248 |
// trigger this function on document ready event if you provide some kind of |
249 |
// persistent search (eg crih) |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
250 |
function reorderFacetsItems(root) { |
0 | 251 |
root = root || document; |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
252 |
$(root).find('form').each(function() { |
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
253 |
var form = $(this); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
254 |
if (form.attr('cubicweb:facetargs')) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
255 |
form.find('div.facet').each(function() { |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
256 |
var facet = $(this); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
257 |
var lastSelected = null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
258 |
facet.find('div.facetCheckBox').each(function(i) { |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
259 |
var $this = $(this); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
260 |
if ($this.hasClass('facetValueSelected')) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
261 |
if (lastSelected) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
262 |
lastSelected.after(this); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
263 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
264 |
var parent = this.parentNode; |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
265 |
$(parent).prepend(this); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
266 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
267 |
lastSelected = $this; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
268 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
269 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
270 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
271 |
} |
0 | 272 |
}); |
273 |
} |
|
274 |
||
7281
daee8aec3b9b
[facets] mark titles of active facets with red dot (closes #1624857)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6551
diff
changeset
|
275 |
// change css class of facets that have a value selected |
daee8aec3b9b
[facets] mark titles of active facets with red dot (closes #1624857)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6551
diff
changeset
|
276 |
function updateFacetTitles() { |
daee8aec3b9b
[facets] mark titles of active facets with red dot (closes #1624857)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6551
diff
changeset
|
277 |
$('.facet').each(function() { |
daee8aec3b9b
[facets] mark titles of active facets with red dot (closes #1624857)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6551
diff
changeset
|
278 |
var $divTitle = $(this).find('.facetTitle'); |
7282
f2dbac46031e
[facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7281
diff
changeset
|
279 |
var facetSelected = $(this).find('.facetValueSelected'); |
f2dbac46031e
[facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7281
diff
changeset
|
280 |
if (facetSelected.length) { |
f2dbac46031e
[facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7281
diff
changeset
|
281 |
$divTitle.addClass('facetTitleSelected'); |
f2dbac46031e
[facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7281
diff
changeset
|
282 |
} else { |
f2dbac46031e
[facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7281
diff
changeset
|
283 |
$divTitle.removeClass('facetTitleSelected'); |
f2dbac46031e
[facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7281
diff
changeset
|
284 |
} |
7281
daee8aec3b9b
[facets] mark titles of active facets with red dot (closes #1624857)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6551
diff
changeset
|
285 |
}); |
daee8aec3b9b
[facets] mark titles of active facets with red dot (closes #1624857)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6551
diff
changeset
|
286 |
} |
5937
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5910
diff
changeset
|
287 |
|
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5910
diff
changeset
|
288 |
// we need to differenciate cases where initFacetBoxEvents is called with one |
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5910
diff
changeset
|
289 |
// argument or without any argument. If we use `initFacetBoxEvents` as the |
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5910
diff
changeset
|
290 |
// direct callback on the jQuery.ready event, jQuery will pass some argument of |
82cac9383dd8
[javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5910
diff
changeset
|
291 |
// his, so we use this small anonymous function instead. |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
292 |
$(document).ready(function() { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
293 |
initFacetBoxEvents(); |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
294 |
$(cw).bind('facets-content-loaded', onFacetContentLoaded); |
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
295 |
$(cw).bind('facets-content-loading', onFacetFiltering); |
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
296 |
$(cw).bind('facets-content-loading', updateFacetTitles); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5112
diff
changeset
|
297 |
}); |
7282
f2dbac46031e
[facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7281
diff
changeset
|
298 |
|
f2dbac46031e
[facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7281
diff
changeset
|
299 |
function showFacetLoading(parentid) { |
f2dbac46031e
[facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7281
diff
changeset
|
300 |
var loadingWidth = 200; // px |
f2dbac46031e
[facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7281
diff
changeset
|
301 |
var loadingHeight = 100; // px |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
302 |
var $msg = $('#facetLoading'); |
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
303 |
var $parent = $('#' + parentid); |
7282
f2dbac46031e
[facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7281
diff
changeset
|
304 |
var leftPos = $parent.offset().left + ($parent.width() - loadingWidth) / 2; |
f2dbac46031e
[facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7281
diff
changeset
|
305 |
$parent.fadeTo('normal', 0.2); |
f2dbac46031e
[facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7281
diff
changeset
|
306 |
$msg.css('left', leftPos).show(); |
f2dbac46031e
[facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7281
diff
changeset
|
307 |
} |
f2dbac46031e
[facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7281
diff
changeset
|
308 |
|
f2dbac46031e
[facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7281
diff
changeset
|
309 |
function onFacetFiltering(event, divid /* ... */) { |
f2dbac46031e
[facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7281
diff
changeset
|
310 |
showFacetLoading(divid); |
f2dbac46031e
[facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7281
diff
changeset
|
311 |
} |
f2dbac46031e
[facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7281
diff
changeset
|
312 |
|
f2dbac46031e
[facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7281
diff
changeset
|
313 |
function onFacetContentLoaded(event, divid, rql, vid, extraparams) { |
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
314 |
$('#facetLoading').hide(); |
7282
f2dbac46031e
[facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7281
diff
changeset
|
315 |
} |
f2dbac46031e
[facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7281
diff
changeset
|
316 |
|
8713
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
317 |
$(document).ready(function () { |
4b34dc3046e6
[facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8551
diff
changeset
|
318 |
if ($('div.facetBody').length) { |
7300
4058ed1e3bc2
[js] remove facet-loading.png, use plain-text / i18n
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7282
diff
changeset
|
319 |
var $loadingDiv = $(DIV({id:'facetLoading'}, |
4058ed1e3bc2
[js] remove facet-loading.png, use plain-text / i18n
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7282
diff
changeset
|
320 |
facetLoadingMsg)); |
4058ed1e3bc2
[js] remove facet-loading.png, use plain-text / i18n
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7282
diff
changeset
|
321 |
$loadingDiv.corner(); |
4058ed1e3bc2
[js] remove facet-loading.png, use plain-text / i18n
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7282
diff
changeset
|
322 |
$('body').append($loadingDiv); |
7282
f2dbac46031e
[facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7281
diff
changeset
|
323 |
} |
f2dbac46031e
[facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7281
diff
changeset
|
324 |
}); |