web/data/cubicweb.ajax.box.js
author Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
Mon, 11 Oct 2010 19:12:59 +0200
changeset 6448 8590d82e9b1b
parent 6215 759cf097f5aa
child 6947 3d72028a6cd4
permissions -rw-r--r--
[javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5 The most notable changes are : - A bug in jQuery 1.4.2 forces us to add 2 noop() methods on cw objects to handle event unbinding, see : http://dev.jquery.com/ticket/6184 for more details. - jquery.autocomplete.js is not maintained anymore as it now has a standard implementation in jquery ui. The downside is that the new autocomplete version needs more work to be used. cubicweb.widgets.js defines a cwautocomplete plugin which is just a (not so) thin wrapper around the std autocomplete plugin to keep backward compatibility and usage simplicty. The original autocomplete author wrote a nice migration guide : http://www.learningjquery.com/2010/06/autocomplete-migration-guide - If you're using jQuery.ajax directly, you might have surprises with arguments serialization for arrays. To get the old behaviour, you need to pass a `traditional: true` extra arguments to jQuery.ajax. Of course, it's transparent if you're using cubicweb higher level helpers such as loadxhtml, loadRemote, etc.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5949
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     1
/**
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     2
 * Functions for ajax boxes.
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     3
 *
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     4
 *  :organization: Logilab
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     5
 *  :copyright: 2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     6
 *  :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     7
 *
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     8
 */
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     9
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    10
function ajaxBoxValidateSelectorInput(boxid, eid, separator, fname, msg) {
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    11
    var holderid = cw.utils.domid(boxid) + eid + 'Holder';
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    12
    var value = $('#' + holderid + 'Input').val();
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    13
    if (separator) {
6215
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    14
        value = $.map(value.split(separator), jQuery.trim);
5949
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    15
    }
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    16
    var d = loadRemote('json', ajaxFuncArgs(fname, null, eid, value));
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    17
    d.addCallback(function() {
6215
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    18
            $('#' + holderid).empty();
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    19
            var formparams = ajaxFuncArgs('render', null, 'boxes', boxid, eid);
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    20
            $('#' + cw.utils.domid(boxid) + eid).loadxhtml('json', formparams);
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    21
            if (msg) {
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    22
                document.location.hash = '#header';
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    23
                updateMessage(msg);
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    24
            }
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    25
        });
5949
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    26
}
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    27
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    28
function ajaxBoxRemoveLinkedEntity(boxid, eid, relatedeid, delfname, msg) {
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    29
    var d = loadRemote('json', ajaxFuncArgs(delfname, null, eid, relatedeid));
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    30
    d.addCallback(function() {
6215
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    31
            var formparams = ajaxFuncArgs('render', null, 'boxes', boxid, eid);
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    32
            $('#' + cw.utils.domid(boxid) + eid).loadxhtml('json', formparams);
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    33
            if (msg) {
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    34
                document.location.hash = '#header';
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    35
                updateMessage(msg);
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    36
            }
5949
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    37
    });
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    38
}
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    39
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    40
function ajaxBoxShowSelector(boxid, eid,
6215
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    41
                             unrelfname,
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    42
                             addfname, msg,
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    43
                             oklabel, cancellabel,
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    44
                             separator) {
5949
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    45
    var holderid = cw.utils.domid(boxid) + eid + 'Holder';
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    46
    var holder = $('#' + holderid);
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    47
    if (holder.children().length) {
6215
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    48
        holder.empty();
5949
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    49
    }
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    50
    else {
6215
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    51
        var inputid = holderid + 'Input';
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    52
        var deferred = loadRemote('json', ajaxFuncArgs(unrelfname, null, eid));
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    53
        deferred.addCallback(function (unrelated) {
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    54
            var input = INPUT({'type': 'text', 'id': inputid, 'size': 20});
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    55
            holder.append(input).show();
6448
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6215
diff changeset
    56
            var $input = $(input);
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6215
diff changeset
    57
            $input.keypress(function (evt) {
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6215
diff changeset
    58
                if (evt.keyCode == $.ui.keyCode.ENTER) {
6215
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    59
                    ajaxBoxValidateSelectorInput(boxid, eid, separator, addfname, msg);
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    60
                }
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    61
            });
6448
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6215
diff changeset
    62
            $input.cwautocomplete(unrelated, {multiple: true});
6215
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    63
            var buttons = DIV({'class' : "sgformbuttons"},
6448
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6215
diff changeset
    64
                              A({href : "javascript: noop();",
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6215
diff changeset
    65
                                 onclick : cw.utils.strFuncCall('ajaxBoxValidateSelectorInput',
6215
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    66
                                                                  boxid, eid, separator, addfname, msg)},
6448
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6215
diff changeset
    67
                                oklabel),
6215
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    68
                              ' / ',
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    69
                              A({'href' : "javascript: noop();",
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    70
                                 'onclick' : '$("#' + holderid + '").empty()'},
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    71
                                  cancellabel));
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    72
            holder.append(buttons);
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    73
            $input.focus();
759cf097f5aa [javascript] get rid of tabs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5949
diff changeset
    74
        });
5949
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    75
    }
2a273c896a38 [box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    76
}