web/data/cubicweb.facets.js
author Aurelien Campeas <aurelien.campeas@logilab.fr>
Thu, 05 Jun 2014 16:13:48 +0200
branchstable
changeset 9766 5071b69b6b0b
parent 9379 b0b1148b6963
child 9819 95902c0b991b
child 10029 832a2a0b7bd2
permissions -rw-r--r--
[pkg] prepare 3.18.5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     3
 *  :organization: Logilab
9176
8139f82c8bbe [facets,js] fix bogus checkbox icon appearing after the first interaction (closes #2790332)
David Douard <david.douard@logilab.fr>
parents: 9139
diff changeset
     4
 *  :copyright: 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     5
 *  :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     6
 */
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     7
9176
8139f82c8bbe [facets,js] fix bogus checkbox icon appearing after the first interaction (closes #2790332)
David Douard <david.douard@logilab.fr>
parents: 9139
diff changeset
     8
var SELECTED_IMG = DATA_URL + 'black-check.png';
8139f82c8bbe [facets,js] fix bogus checkbox icon appearing after the first interaction (closes #2790332)
David Douard <david.douard@logilab.fr>
parents: 9139
diff changeset
     9
var UNSELECTED_IMG = DATA_URL + 'no-check-no-border.png';
8139f82c8bbe [facets,js] fix bogus checkbox icon appearing after the first interaction (closes #2790332)
David Douard <david.douard@logilab.fr>
parents: 9139
diff changeset
    10
var UNSELECTED_BORDER_IMG = DATA_URL + 'black-uncheck.png';
5937
82cac9383dd8 [javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5910
diff changeset
    11
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    12
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
    13
    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
    14
    if (index > - 1) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
    15
        newparams[param] = origparams[1][index];
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    16
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    17
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    18
5937
82cac9383dd8 [javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5910
diff changeset
    19
82cac9383dd8 [javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5910
diff changeset
    20
function facetFormContent($form) {
4
8a607bdc11dc [javascript] indentation fixes + missing semi colons
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    21
    var names = [];
8a607bdc11dc [javascript] indentation fixes + missing semi colons
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    22
    var values = [];
5937
82cac9383dd8 [javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5910
diff changeset
    23
    $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
    24
        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
    25
        // FacetVocabularyWidget
8713
4b34dc3046e6 [facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8551
diff changeset
    26
        $(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
    27
            names.push(facetName);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
    28
            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
    29
        });
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
    30
        // 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
    31
        $(this).find('input:text').each(function(){
9139
5ca6e0ab0227 [facet] use facet name as input name for text widget (eg has_text)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8923
diff changeset
    32
            names.push(this.name);
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
            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
    34
        });
4
8a607bdc11dc [javascript] indentation fixes + missing semi colons
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    35
    });
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
    36
    // 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
    37
    // 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
    38
    $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
    39
        names.push(this.name);
8a607bdc11dc [javascript] indentation fixes + missing semi colons
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    40
        values.push(this.value);
8a607bdc11dc [javascript] indentation fixes + missing semi colons
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    41
    });
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
    42
    // And / Or operators
5937
82cac9383dd8 [javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5910
diff changeset
    43
    $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
    44
        names.push(this.parentNode.name);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
    45
        values.push(this.value);
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
    });
4
8a607bdc11dc [javascript] indentation fixes + missing semi colons
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    47
    return [names, values];
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
5937
82cac9383dd8 [javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5910
diff changeset
    50
7949
ce64860b3cdc [facets] on the way to vidargs removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7923
diff changeset
    51
// XXX deprecate vidargs once TableView is gone
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
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
    53
    $(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
    54
    var $form = $('#' + divid + 'Form');
82cac9383dd8 [javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5910
diff changeset
    55
    var zipped = facetFormContent($form);
4
8a607bdc11dc [javascript] indentation fixes + missing semi colons
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    56
    zipped[0].push('facetargs');
8a607bdc11dc [javascript] indentation fixes + missing semi colons
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    57
    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
    58
    var d = loadRemote(AJAX_BASE_URL, ajaxFuncArgs('filter_build_rql', null, zipped[0], zipped[1]));
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
    d.addCallback(function(result) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
    60
        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
    61
        var $bkLink = $('#facetBkLink');
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
    62
        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
    63
            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
    64
            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
    65
                bkPath += '&vid=' + encodeURIComponent(vid);
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
    66
            }
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
    67
            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
    68
            $bkLink.attr('href', bkUrl);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
    69
        }
8713
4b34dc3046e6 [facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8551
diff changeset
    70
        var $focusLink = $('#focusLink');
8551
6cf9e4da54a9 [facets] add link 'focus on selection' (closes #525277)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8260
diff changeset
    71
        if ($focusLink.length) {
6cf9e4da54a9 [facets] add link 'focus on selection' (closes #525277)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8260
diff changeset
    72
            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
    73
            if (vid) {
6cf9e4da54a9 [facets] add link 'focus on selection' (closes #525277)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8260
diff changeset
    74
                url += '&vid=' + encodeURIComponent(vid);
6cf9e4da54a9 [facets] add link 'focus on selection' (closes #525277)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8260
diff changeset
    75
            }
6cf9e4da54a9 [facets] add link 'focus on selection' (closes #525277)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8260
diff changeset
    76
            $focusLink.attr('href', url);
6cf9e4da54a9 [facets] add link 'focus on selection' (closes #525277)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8260
diff changeset
    77
        }
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
    78
        var toupdate = result[1];
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
    79
        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
    80
        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
    81
        // copy some parameters
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
    82
        // XXX cleanup vid/divid mess
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
    83
        // 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
    84
        // be overriden by replacePageChunk
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
    85
        copyParam(zipped, extraparams, 'vid');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
    86
        extraparams['divid'] = divid;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
    87
        copyParam(zipped, extraparams, 'divid');
7949
ce64860b3cdc [facets] on the way to vidargs removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7923
diff changeset
    88
        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
    89
        copyParam(zipped, extraparams, 'fromformfilter');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
    90
        // 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
    91
        // 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
    92
        // this from a table filter)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
    93
        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
    94
        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
    95
            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
    96
        }
8260
5a81fa526b30 [ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8185
diff changeset
    97
        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
    98
                                     null, 'swap');
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
    99
        d.addCallback(function() {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   100
            // 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
   101
            $(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
   102
        });
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   103
        if (paginate) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   104
            // 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
   105
            // 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
   106
            // now
8713
4b34dc3046e6 [facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8551
diff changeset
   107
            var $node = $('#edit_box');
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   108
            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
   109
                $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
   110
                    'rql': rql
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   111
                },
9239
dde9fe1e0ce3 [facets] Correctly replace old 'edit box' HTML on facet-induced page refresh (closes #3161100)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9176
diff changeset
   112
                'ctxcomponents', 'edit_box'), 'GET', 'swap');
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   113
            }
8713
4b34dc3046e6 [facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8551
diff changeset
   114
            $node = $('#breadcrumbs');
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   115
            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
   116
                $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
   117
                    'rql': rql
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   118
                },
6551
50ec97e4f9cc breadcrumbs/edid_box are now contextual component (closes #1334196)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5937
diff changeset
   119
                'ctxcomponents', 'breadcrumbs'));
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   120
            }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   121
        }
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
   122
        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
   123
        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
   124
        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
   125
            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
   126
        }
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
   127
8260
5a81fa526b30 [ajax] use AJAX_BASE_URL instead of JSON_BASE_URL
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8185
diff changeset
   128
        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
   129
        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
   130
            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
   131
                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
   132
                // 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
   133
                //$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
   134
                $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
   135
                    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
   136
                    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
   137
                        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
   138
                            $(this).addClass('facetValueDisabled');
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   139
                        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   140
                    } else {
8713
4b34dc3046e6 [facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8551
diff changeset
   141
                        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
   142
                            $(this).removeClass('facetValueDisabled');
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   143
                        }
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
        });
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   148
    });
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   149
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   150
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   151
933
ad99da207edd late evaluation of cubicweb:facetargs is necessary since its value may change
sylvain.thenault@logilab.fr
parents: 434
diff changeset
   152
function initFacetBoxEvents(root) {
ad99da207edd late evaluation of cubicweb:facetargs is necessary since its value may change
sylvain.thenault@logilab.fr
parents: 434
diff changeset
   153
    // facetargs : (divid, vid, paginate, extraargs)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
    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
   155
    $(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
   156
        var form = $(this);
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   157
        // 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
   158
        //       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
   159
        //       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
   160
        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
   161
        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
   162
            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
   163
            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
   164
            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
   165
                buildRQL.apply(null, jsfacetargs);
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   166
                return false;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   167
            });
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
   168
            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
   169
            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
   170
                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
   171
                                        facetLoadingMsg));
8713
4b34dc3046e6 [facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8551
diff changeset
   172
                $($('#'+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
   173
            }
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   174
            form.find('div.facet').each(function() {
8923
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   175
                var $facet = $(this);
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   176
                $facet.find('div.facetCheckBox').each(function(i) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   177
                    this.setAttribute('cubicweb:idx', i);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   178
                });
8923
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   179
                $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
   180
                    var $this = $(this);
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   181
                    // 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
   182
                    // if ($this.hasClass('facetValueDisabled')){
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   183
                    //          return
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   184
                    // }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   185
                    if ($this.hasClass('facetValueSelected')) {
8923
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   186
                        facetCheckBoxUnselect($this);
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   187
                    } else {
8923
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   188
                        facetCheckBoxSelect($this);
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   189
                    }
8923
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   190
                    facetCheckBoxReorder($facet);
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
   191
                    buildRQL.apply(null, jsfacetargs);
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   192
                });
8923
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   193
                $facet.find('select.facetOperator').change(function() {
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   194
                    var nbselected = $facet.find('div.facetValueSelected').length;
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   195
                    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
   196
                        buildRQL.apply(null, jsfacetargs);
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
                });
8923
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   199
                $facet.find('div.facetTitle.hideFacetBody').click(function() {
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   200
                    $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
   201
                    $(this).toggleClass('opened');
8923
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   202
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   203
                });
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   204
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   205
            });
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   206
        }
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   207
    });
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   208
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   209
8923
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   210
// facetCheckBoxSelect: select the given facet checkbox item (.facetValue
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   211
// class)
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   212
function facetCheckBoxSelect($item) {
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   213
    $item.addClass('facetValueSelected');
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   214
    $item.find('img').attr('src', SELECTED_IMG).attr('alt', (_("selected")));
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   215
}
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   216
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   217
// facetCheckBoxUnselect: unselect the given facet checkbox item (.facetValue
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   218
// class)
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   219
function facetCheckBoxUnselect($item) {
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   220
    $item.removeClass('facetValueSelected');
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   221
    $item.find('img').each(function(i) {
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   222
        if (this.getAttribute('cubicweb:unselimg')) {
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   223
            this.setAttribute('src', UNSELECTED_BORDER_IMG);
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   224
        }
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   225
        else {
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   226
            this.setAttribute('src', UNSELECTED_IMG);
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   227
        }
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   228
        this.setAttribute('alt', (_("not selected")));
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   229
    });
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   230
}
acff6dfcb9f4 [facet js] minor refactoring and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8914
diff changeset
   231
8914
e80dfffc2c2a [facet js] fix reordering of facet check boxes. Closes #2732947
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8713
diff changeset
   232
// facetCheckBoxReorder: reorder all items according to cubicweb:idx attribute
e80dfffc2c2a [facet js] fix reordering of facet check boxes. Closes #2732947
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8713
diff changeset
   233
function facetCheckBoxReorder($facet) {
e80dfffc2c2a [facet js] fix reordering of facet check boxes. Closes #2732947
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8713
diff changeset
   234
    var sortfunc = function (a, b) {
e80dfffc2c2a [facet js] fix reordering of facet check boxes. Closes #2732947
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8713
diff changeset
   235
        // convert from string to integer
e80dfffc2c2a [facet js] fix reordering of facet check boxes. Closes #2732947
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8713
diff changeset
   236
        a = +a.getAttribute("cubicweb:idx");
e80dfffc2c2a [facet js] fix reordering of facet check boxes. Closes #2732947
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8713
diff changeset
   237
        b = +b.getAttribute("cubicweb:idx");
e80dfffc2c2a [facet js] fix reordering of facet check boxes. Closes #2732947
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8713
diff changeset
   238
        // compare
e80dfffc2c2a [facet js] fix reordering of facet check boxes. Closes #2732947
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8713
diff changeset
   239
        if (a > b) {
e80dfffc2c2a [facet js] fix reordering of facet check boxes. Closes #2732947
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8713
diff changeset
   240
            return 1;
e80dfffc2c2a [facet js] fix reordering of facet check boxes. Closes #2732947
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8713
diff changeset
   241
        } else if (a < b) {
e80dfffc2c2a [facet js] fix reordering of facet check boxes. Closes #2732947
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8713
diff changeset
   242
            return -1;
e80dfffc2c2a [facet js] fix reordering of facet check boxes. Closes #2732947
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8713
diff changeset
   243
        } else {
e80dfffc2c2a [facet js] fix reordering of facet check boxes. Closes #2732947
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8713
diff changeset
   244
            return 0;
e80dfffc2c2a [facet js] fix reordering of facet check boxes. Closes #2732947
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8713
diff changeset
   245
        }
e80dfffc2c2a [facet js] fix reordering of facet check boxes. Closes #2732947
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8713
diff changeset
   246
    };
e80dfffc2c2a [facet js] fix reordering of facet check boxes. Closes #2732947
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8713
diff changeset
   247
    var $items = $facet.find('.facetValue.facetValueSelected')
e80dfffc2c2a [facet js] fix reordering of facet check boxes. Closes #2732947
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8713
diff changeset
   248
    $items.sort(sortfunc);
e80dfffc2c2a [facet js] fix reordering of facet check boxes. Closes #2732947
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8713
diff changeset
   249
    $facet.find('.facetBody').append($items);
e80dfffc2c2a [facet js] fix reordering of facet check boxes. Closes #2732947
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8713
diff changeset
   250
    var $items = $facet.find('.facetValue:not(.facetValueSelected)')
e80dfffc2c2a [facet js] fix reordering of facet check boxes. Closes #2732947
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8713
diff changeset
   251
    $items.sort(sortfunc);
e80dfffc2c2a [facet js] fix reordering of facet check boxes. Closes #2732947
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8713
diff changeset
   252
    $facet.find('.facetBody').append($items);
e80dfffc2c2a [facet js] fix reordering of facet check boxes. Closes #2732947
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8713
diff changeset
   253
    $facet.find('.facetBody').animate({scrollTop: 0}, '');
e80dfffc2c2a [facet js] fix reordering of facet check boxes. Closes #2732947
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8713
diff changeset
   254
}
5937
82cac9383dd8 [javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5910
diff changeset
   255
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   256
// trigger this function on document ready event if you provide some kind of
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   257
// persistent search (eg crih)
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   258
function reorderFacetsItems(root) {
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   259
    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
   260
    $(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
   261
        var form = $(this);
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   262
        if (form.attr('cubicweb:facetargs')) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   263
            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
   264
                var facet = $(this);
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   265
                var lastSelected = null;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   266
                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
   267
                    var $this = $(this);
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   268
                    if ($this.hasClass('facetValueSelected')) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   269
                        if (lastSelected) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   270
                            lastSelected.after(this);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   271
                        } else {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   272
                            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
   273
                            $(parent).prepend(this);
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   274
                        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   275
                        lastSelected = $this;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   276
                    }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   277
                });
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   278
            });
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   279
        }
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   280
    });
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   281
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   282
7281
daee8aec3b9b [facets] mark titles of active facets with red dot (closes #1624857)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6551
diff changeset
   283
// 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
   284
function updateFacetTitles() {
daee8aec3b9b [facets] mark titles of active facets with red dot (closes #1624857)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6551
diff changeset
   285
    $('.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
   286
        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
   287
        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
   288
        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
   289
            $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
   290
        } else {
f2dbac46031e [facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7281
diff changeset
   291
            $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
   292
        }
7281
daee8aec3b9b [facets] mark titles of active facets with red dot (closes #1624857)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6551
diff changeset
   293
    });
daee8aec3b9b [facets] mark titles of active facets with red dot (closes #1624857)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6551
diff changeset
   294
}
5937
82cac9383dd8 [javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5910
diff changeset
   295
82cac9383dd8 [javascript] more cleanups and deprecation warnings removal
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5910
diff changeset
   296
// 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
   297
// 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
   298
// 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
   299
// 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
   300
$(document).ready(function() {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5112
diff changeset
   301
    initFacetBoxEvents();
8713
4b34dc3046e6 [facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8551
diff changeset
   302
    $(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
   303
    $(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
   304
    $(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
   305
});
7282
f2dbac46031e [facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7281
diff changeset
   306
f2dbac46031e [facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7281
diff changeset
   307
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
   308
    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
   309
    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
   310
    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
   311
    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
   312
    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
   313
    $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
   314
    $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
   315
}
f2dbac46031e [facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7281
diff changeset
   316
f2dbac46031e [facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7281
diff changeset
   317
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
   318
    showFacetLoading(divid);
f2dbac46031e [facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7281
diff changeset
   319
}
f2dbac46031e [facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7281
diff changeset
   320
f2dbac46031e [facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7281
diff changeset
   321
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
   322
    $('#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
   323
}
f2dbac46031e [facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7281
diff changeset
   324
8713
4b34dc3046e6 [facets js] use $ instead of jQuery and other small cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8551
diff changeset
   325
$(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
   326
    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
   327
        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
   328
                                facetLoadingMsg));
4058ed1e3bc2 [js] remove facet-loading.png, use plain-text / i18n
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 7282
diff changeset
   329
        $('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
   330
    }
f2dbac46031e [facets] display splash image while facets are reloading content (closes #1624851)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7281
diff changeset
   331
});