cubicweb/web/data/cubicweb.js
author Laurent Peuch <cortex@worlddomination.be>
Thu, 05 Dec 2019 18:39:09 +0100
changeset 12807 fb0936668535
parent 12503 b01dd0ef43aa
permissions -rw-r--r--
[comment] add comment for maybe unhandled situation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5699
f4f6ee3af50b [javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5658
diff changeset
     1
5705
30b94973bc67 [javascript] add a name property to namespaces, mainly for convenience in helpers such as movedToNamespace
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5699
diff changeset
     2
function Namespace(name) {
30b94973bc67 [javascript] add a name property to namespaces, mainly for convenience in helpers such as movedToNamespace
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5699
diff changeset
     3
   this.__name__ = name;
30b94973bc67 [javascript] add a name property to namespaces, mainly for convenience in helpers such as movedToNamespace
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5699
diff changeset
     4
}
30b94973bc67 [javascript] add a name property to namespaces, mainly for convenience in helpers such as movedToNamespace
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5699
diff changeset
     5
30b94973bc67 [javascript] add a name property to namespaces, mainly for convenience in helpers such as movedToNamespace
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5699
diff changeset
     6
cw = new Namespace('cw');
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     7
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     8
jQuery.extend(cw, {
6388
34317f395619 [js] add cubes namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5949
diff changeset
     9
    cubes: new Namespace('cubes'),
6448
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6388
diff changeset
    10
    /* provide a removeEventListener / detachEvent definition to
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6388
diff changeset
    11
     * to bypass a jQuery 1.4.2 bug when unbind() is called on a
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6388
diff changeset
    12
     * plain JS object and not a DOM node.
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6388
diff changeset
    13
     * see http://dev.jquery.com/ticket/6184 for more details
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6388
diff changeset
    14
     */
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6388
diff changeset
    15
    removeEventListener: function() {},
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6388
diff changeset
    16
    detachEvent: function() {},
6388
34317f395619 [js] add cubes namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5949
diff changeset
    17
10407
18d1ef2d2a3e [js] simplify cw.log implementation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 9990
diff changeset
    18
    log: function log() {
10433
523a7f098066 [js] lint : make it explicit that typeof is an operator, not a function.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 10407
diff changeset
    19
        if (typeof window !== "undefined" && window.console && window.console.log) {
10407
18d1ef2d2a3e [js] simplify cw.log implementation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 9990
diff changeset
    20
            // NOTE console.log requires "console" to be the console to be "this"
18d1ef2d2a3e [js] simplify cw.log implementation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 9990
diff changeset
    21
            window.console.log.apply(console, arguments);
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
    },
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    25
    //removed: getElementsByTagAndClassName, replaceChildNodes, toggleElementClass
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
    //         partial, merge, isNotEmpty, update,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
    //         String.in_, String.join, list, getattr, attrgetter, methodcaller,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
    //         min, max, dict, concat
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
    jqNode: function (node) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
    /**
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
     * .. function:: jqNode(node)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    32
     *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
     * safe version of jQuery('#nodeid') because we use ':' in nodeids
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
     * which messes with jQuery selection mechanism
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
     */
10433
523a7f098066 [js] lint : make it explicit that typeof is an operator, not a function.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 10407
diff changeset
    36
        if (typeof node === 'string') {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
            node = document.getElementById(node);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
        if (node) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
            return $(node);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    41
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
        return null;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
    },
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
9284
4c37808fd284 [js] add a selector string escaping function
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9259
diff changeset
    45
    // escapes string selectors (e.g. "foo.[subject]:42" -> "foo\.\[subject\]\:42"
4c37808fd284 [js] add a selector string escaping function
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9259
diff changeset
    46
    escape: function(selector) {
10433
523a7f098066 [js] lint : make it explicit that typeof is an operator, not a function.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 10407
diff changeset
    47
        if (typeof selector === 'string') {
9284
4c37808fd284 [js] add a selector string escaping function
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9259
diff changeset
    48
            return  selector.replace( /(:|\.|\[|\])/g, "\\$1" );
4c37808fd284 [js] add a selector string escaping function
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9259
diff changeset
    49
        }
4c37808fd284 [js] add a selector string escaping function
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9259
diff changeset
    50
        // cw.log('non string selector', selector);
4c37808fd284 [js] add a selector string escaping function
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9259
diff changeset
    51
        return '';
4c37808fd284 [js] add a selector string escaping function
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9259
diff changeset
    52
    },
4c37808fd284 [js] add a selector string escaping function
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9259
diff changeset
    53
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    54
    getNode: function (node) {
10433
523a7f098066 [js] lint : make it explicit that typeof is an operator, not a function.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 10407
diff changeset
    55
        if (typeof node === 'string') {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
            return document.getElementById(node);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    57
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    58
        return node;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
    },
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
    evalJSON: function (json) { // trust source
7831
6af00dbfaadd [cubicweb.js] log evalJSON errors (closes #1947473)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7649
diff changeset
    62
        try {
6af00dbfaadd [cubicweb.js] log evalJSON errors (closes #1947473)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7649
diff changeset
    63
            return eval("(" + json + ")");
6af00dbfaadd [cubicweb.js] log evalJSON errors (closes #1947473)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7649
diff changeset
    64
        } catch(e) {
6af00dbfaadd [cubicweb.js] log evalJSON errors (closes #1947473)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7649
diff changeset
    65
          cw.log(e);
6af00dbfaadd [cubicweb.js] log evalJSON errors (closes #1947473)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7649
diff changeset
    66
          cw.log('The faulty json source was', json);
6af00dbfaadd [cubicweb.js] log evalJSON errors (closes #1947473)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7649
diff changeset
    67
          throw (e);
6af00dbfaadd [cubicweb.js] log evalJSON errors (closes #1947473)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7649
diff changeset
    68
       }
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
    },
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    71
    urlEncode: function (str) {
10433
523a7f098066 [js] lint : make it explicit that typeof is an operator, not a function.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 10407
diff changeset
    72
        if (typeof encodeURIComponent !== "undefined") {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    73
            return encodeURIComponent(str).replace(/\'/g, '%27');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    74
        } else {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
            return escape(str).replace(/\+/g, '%2B').replace(/\"/g, '%22').
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    76
                    rval.replace(/\'/g, '%27');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    77
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
    },
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
    swapDOM: function (dest, src) {
5727
29afb9e715bb [3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5705
diff changeset
    81
        dest = cw.getNode(dest);
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
        var parent = dest.parentNode;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
        if (src) {
5727
29afb9e715bb [3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5705
diff changeset
    84
            src = cw.getNode(src);
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
            parent.replaceChild(src, dest);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    86
        } else {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    87
            parent.removeChild(dest);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    88
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    89
        return src;
7961
f7ab1db39778 [js] missing trailing comma
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7953
diff changeset
    90
    },
7953
a37531c8a4a6 merge and fix cubicwebSortValueExtraction pb which disappeared when tablesorter.js has been updated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7831
diff changeset
    91
a37531c8a4a6 merge and fix cubicwebSortValueExtraction pb which disappeared when tablesorter.js has been updated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7831
diff changeset
    92
    sortValueExtraction: function (node) {
8129
2dedcc15208d [table] use cell text content when cubicweb:sortvalue is not defined (closes #2093183)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8071
diff changeset
    93
        var $node = $(node);
2dedcc15208d [table] use cell text content when cubicweb:sortvalue is not defined (closes #2093183)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8071
diff changeset
    94
        var sortvalue = $node.attr('cubicweb:sortvalue');
2dedcc15208d [table] use cell text content when cubicweb:sortvalue is not defined (closes #2093183)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8071
diff changeset
    95
        // No metadata found, use cell content as sort key
10433
523a7f098066 [js] lint : make it explicit that typeof is an operator, not a function.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 10407
diff changeset
    96
        if (typeof sortvalue === 'undefined') {
8129
2dedcc15208d [table] use cell text content when cubicweb:sortvalue is not defined (closes #2093183)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8071
diff changeset
    97
            return $node.text();
2dedcc15208d [table] use cell text content when cubicweb:sortvalue is not defined (closes #2093183)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8071
diff changeset
    98
        }
2dedcc15208d [table] use cell text content when cubicweb:sortvalue is not defined (closes #2093183)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 8071
diff changeset
    99
        return cw.evalJSON(sortvalue);
9784
790956c311ef EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents: 9661
diff changeset
   100
    },
790956c311ef EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents: 9661
diff changeset
   101
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
});
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
5705
30b94973bc67 [javascript] add a name property to namespaces, mainly for convenience in helpers such as movedToNamespace
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5699
diff changeset
   105
cw.utils = new Namespace('cw.utils');
30b94973bc67 [javascript] add a name property to namespaces, mainly for convenience in helpers such as movedToNamespace
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5699
diff changeset
   106
jQuery.extend(cw.utils, {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
    deprecatedFunction: function (msg, newfunc) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
        return function () {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
            cw.log(msg);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
            return newfunc.apply(this, arguments);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   112
        };
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
    },
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   114
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   115
    createDomFunction: function (tag) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   116
        function builddom(params, children) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   117
            var node = document.createElement(tag);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   118
            for (key in params) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   119
                var value = params[key];
10433
523a7f098066 [js] lint : make it explicit that typeof is an operator, not a function.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 10407
diff changeset
   120
                if (key.substring(0, 2) === 'on') {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
                    // this is an event handler definition
10433
523a7f098066 [js] lint : make it explicit that typeof is an operator, not a function.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 10407
diff changeset
   122
                    if (typeof value === 'string') {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
                        // litteral definition
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   124
                        value = new Function(value);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
                    }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   126
                    node[key] = value;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   127
                } else { // normal node attribute
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   128
                    jQuery(node).attr(key, params[key]);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   129
                }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   130
            }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   131
            if (children) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   132
                if (!cw.utils.isArrayLike(children)) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   133
                    children = [children];
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   134
                    for (var i = 2; i < arguments.length; i++) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
                        var arg = arguments[i];
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   136
                        if (cw.utils.isArray(arg)) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   137
                            jQuery.merge(children, arg);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   138
                        } else {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
                            children.push(arg);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   140
                        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   141
                    }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   142
                }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   143
                for (var i = 0; i < children.length; i++) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   144
                    var child = children[i];
10433
523a7f098066 [js] lint : make it explicit that typeof is an operator, not a function.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 10407
diff changeset
   145
                    if (typeof child === "string" || typeof child === "number") {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   146
                        child = document.createTextNode(child);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   147
                    }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   148
                    node.appendChild(child);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   149
                }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   150
            }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   151
            return node;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   152
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
        return builddom;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
    },
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   155
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
    /**
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   157
     * .. function:: toISOTimestamp(date)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   158
     *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   159
     */
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   160
    toISOTimestamp: function (date) {
10433
523a7f098066 [js] lint : make it explicit that typeof is an operator, not a function.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 10407
diff changeset
   161
        if (date == null) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   162
            return null;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   163
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   164
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   165
        function _padTwo(n) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   166
            return (n > 9) ? n : "0" + n;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   167
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   168
        var isoTime = [_padTwo(date.getHours()), _padTwo(date.getMinutes()),
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   169
                       _padTwo(date.getSeconds())].join(':');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   170
        var isoDate = [date.getFullYear(), _padTwo(date.getMonth() + 1),
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   171
                       _padTwo(date.getDate())].join("-");
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   172
        return isoDate + " " + isoTime;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   173
    },
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   174
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   175
    /**
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   176
     * .. function:: nodeWalkDepthFirst(node, visitor)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   177
     *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   178
     * depth-first implementation of the nodeWalk function found
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   179
     * in `MochiKit.Base <http://mochikit.com/doc/html/MochiKit/Base.html#fn-nodewalk>`_
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   180
     */
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   181
    nodeWalkDepthFirst: function (node, visitor) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   182
        var children = visitor(node);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   183
        if (children) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   184
            for (var i = 0; i < children.length; i++) {
5727
29afb9e715bb [3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5705
diff changeset
   185
                cw.utils.nodeWalkDepthFirst(children[i], visitor);
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   186
            }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   187
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   188
    },
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   189
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   190
    isArray: function (it) { // taken from dojo
10433
523a7f098066 [js] lint : make it explicit that typeof is an operator, not a function.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 10407
diff changeset
   191
        return it && (it instanceof Array || typeof it === "array");
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   192
    },
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   193
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   194
    isString: function (it) { // taken from dojo
10433
523a7f098066 [js] lint : make it explicit that typeof is an operator, not a function.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 10407
diff changeset
   195
        return !!arguments.length && it != null && (typeof it === "string" || it instanceof String);
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   196
    },
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   197
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   198
    isArrayLike: function (it) { // taken from dojo
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   199
        return (it && it !== undefined &&
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   200
                // keep out built-in constructors (Number, String, ...)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   201
                // which have length properties
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   202
                !cw.utils.isString(it) && !jQuery.isFunction(it) &&
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   203
                !(it.tagName && it.tagName.toLowerCase() == 'form') &&
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   204
                (cw.utils.isArray(it) || isFinite(it.length)));
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   205
    },
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   206
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   207
    /**
9815
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   208
     * .. function:: formContents(elem)
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   209
     *
9815
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   210
     * cannot use jQuery.serializeArray() directly because of FCKeditor
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   211
     */
9815
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   212
    formContents: function (elem) {
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   213
        var $elem, array, names, values;
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   214
        $elem = cw.jqNode(elem);
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   215
        array = $elem.serializeArray();
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   216
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   217
        if (typeof FCKeditor !== 'undefined') {
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   218
            $elem.find('textarea').each(function (idx, textarea) {
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   219
                var fck = FCKeditorAPI.GetInstance(textarea.id);
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   220
                if (fck) {
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   221
                    array = jQuery.map(array, function (dict) {
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   222
                        if (dict.name === textarea.name) {
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   223
                            // filter out the textarea's - likely empty - value ...
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   224
                            return null;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   225
                        }
9815
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   226
                        return dict;
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   227
                    });
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   228
                    // ... so we can put the HTML coming from FCKeditor instead.
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   229
                    array.push({
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   230
                        name: textarea.name,
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   231
                        value: fck.GetHTML()
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   232
                    });
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   233
                }
9815
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   234
            });
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   235
        }
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   236
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   237
        names = [];
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   238
        values = [];
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   239
        jQuery.each(array, function (idx, dict) {
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   240
            names.push(dict.name);
12e6d911027a [views] Rewrite cw.utils.formContents() with jQuery (closes #3747244)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9661
diff changeset
   241
            values.push(dict.value);
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   242
        });
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   243
        return [names, values];
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   244
    },
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   245
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   246
    /**
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   247
     * .. function:: sliceList(lst, start, stop, step)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   248
     *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   249
     * returns a subslice of `lst` using `start`/`stop`/`step`
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   250
     * start, stop might be negative
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   251
     *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   252
     * >>> sliceList(['a', 'b', 'c', 'd', 'e', 'f'], 2)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   253
     * ['c', 'd', 'e', 'f']
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   254
     * >>> sliceList(['a', 'b', 'c', 'd', 'e', 'f'], 2, -2)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   255
     * ['c', 'd']
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   256
     * >>> sliceList(['a', 'b', 'c', 'd', 'e', 'f'], -3)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   257
     * ['d', 'e', 'f']
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   258
     */
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   259
    sliceList: function (lst, start, stop, step) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   260
        start = start || 0;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   261
        stop = stop || lst.length;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   262
        step = step || 1;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   263
        if (stop < 0) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   264
            stop = Math.max(lst.length + stop, 0);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   265
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   266
        if (start < 0) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   267
            start = Math.min(lst.length + start, lst.length);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   268
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   269
        var result = [];
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   270
        for (var i = start; i < stop; i += step) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   271
            result.push(lst[i]);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   272
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   273
        return result;
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: 5727
diff changeset
   274
    },
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: 5727
diff changeset
   275
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: 5727
diff changeset
   276
    /**
7284
a474cb989546 [js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6448
diff changeset
   277
     * returns the last element of an array-like object or undefined if empty
a474cb989546 [js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6448
diff changeset
   278
     */
a474cb989546 [js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6448
diff changeset
   279
    lastOf: function(array) {
a474cb989546 [js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6448
diff changeset
   280
        if (array.length) {
a474cb989546 [js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6448
diff changeset
   281
            return array[array.length-1];
a474cb989546 [js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6448
diff changeset
   282
        } else {
a474cb989546 [js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6448
diff changeset
   283
            return undefined;
a474cb989546 [js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6448
diff changeset
   284
        }
a474cb989546 [js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6448
diff changeset
   285
    },
a474cb989546 [js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6448
diff changeset
   286
7649
ede740bd7077 [ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7284
diff changeset
   287
ede740bd7077 [ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7284
diff changeset
   288
    /**
ede740bd7077 [ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7284
diff changeset
   289
     * .. function:: extend(array1, array2)
ede740bd7077 [ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7284
diff changeset
   290
     *
ede740bd7077 [ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7284
diff changeset
   291
     * equivalent of python ``+=`` statement on lists (array1 += array2)
ede740bd7077 [ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7284
diff changeset
   292
     */
ede740bd7077 [ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7284
diff changeset
   293
    extend: function(array1, array2) {
ede740bd7077 [ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7284
diff changeset
   294
        array1.push.apply(array1, array2);
ede740bd7077 [ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7284
diff changeset
   295
        return array1; // return array1 for convenience
ede740bd7077 [ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7284
diff changeset
   296
    },
ede740bd7077 [ajax, IE] rewrite some code to avoid duplicated evaluation with IE
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7284
diff changeset
   297
7284
a474cb989546 [js] make _loadAjaxHtmlHead aware of mod_concat-like urls
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6448
diff changeset
   298
    /**
6448
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6388
diff changeset
   299
     * .. function:: difference(lst1, lst2)
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6388
diff changeset
   300
     *
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6388
diff changeset
   301
     * returns a list containing all elements in `lst1` that are not
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6388
diff changeset
   302
     * in `lst2`.
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6388
diff changeset
   303
     */
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6388
diff changeset
   304
    difference: function(lst1, lst2) {
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6388
diff changeset
   305
        return jQuery.grep(lst1, function(elt, i) {
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6388
diff changeset
   306
            return jQuery.inArray(elt, lst2) == -1;
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6388
diff changeset
   307
        });
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6388
diff changeset
   308
    },
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6388
diff changeset
   309
    /**
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: 5727
diff changeset
   310
     * .. function:: domid(string)
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: 5727
diff changeset
   311
     *
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: 5727
diff changeset
   312
     * return a valid DOM id from a string (should also be usable in jQuery
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: 5727
diff changeset
   313
     * search expression...). This is the javascript implementation of
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: 5727
diff changeset
   314
     * :func:`cubicweb.uilib.domid`.
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: 5727
diff changeset
   315
     */
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: 5727
diff changeset
   316
    domid: function (string) {
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: 5727
diff changeset
   317
	var newstring = string.replace(".", "_").replace("-", "_");
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: 5727
diff changeset
   318
	while (newstring != string) {
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: 5727
diff changeset
   319
	    string = newstring;
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: 5727
diff changeset
   320
	    newstring = newstring.replace(".", "_").replace("-", "_");
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: 5727
diff changeset
   321
	}
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: 5727
diff changeset
   322
	return newstring; // XXX
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: 5727
diff changeset
   323
    },
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: 5727
diff changeset
   324
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: 5727
diff changeset
   325
    /**
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: 5727
diff changeset
   326
     * .. function:: strFuncCall(fname, *args)
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: 5727
diff changeset
   327
     *
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: 5727
diff changeset
   328
     * return a string suitable to call the `fname` javascript function with the
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: 5727
diff changeset
   329
     * given arguments (which should be correctly typed).. This is providing
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: 5727
diff changeset
   330
     * javascript implementation equivalent to :func:`cubicweb.uilib.js`.
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: 5727
diff changeset
   331
     */
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: 5727
diff changeset
   332
    strFuncCall: function(fname /* ...*/) {
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: 5727
diff changeset
   333
	    return (fname + '(' +
9661
c170ec8a4525 [web/data] Remove broken jquery-json plugin (closes #3590335)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9534
diff changeset
   334
		    $.map(cw.utils.sliceList(arguments, 1), JSON.stringify).join(',')
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: 5727
diff changeset
   335
		    + ')'
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: 5727
diff changeset
   336
		    );
9784
790956c311ef EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents: 9661
diff changeset
   337
    },
790956c311ef EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents: 9661
diff changeset
   338
9914
30b56a56c1f4 [web/js] replace callAddOrDeleteThenReload with more generic callAjaxFuncThenReload
Julien Cristau <julien.cristau@logilab.fr>
parents: 9784
diff changeset
   339
    callAjaxFuncThenReload: function callAjaxFuncThenReload (/*...*/) {
30b56a56c1f4 [web/js] replace callAddOrDeleteThenReload with more generic callAjaxFuncThenReload
Julien Cristau <julien.cristau@logilab.fr>
parents: 9784
diff changeset
   340
        var d = asyncRemoteExec.apply(null, arguments);
30b56a56c1f4 [web/js] replace callAddOrDeleteThenReload with more generic callAjaxFuncThenReload
Julien Cristau <julien.cristau@logilab.fr>
parents: 9784
diff changeset
   341
        d.addCallback(function(msg) {
9784
790956c311ef EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents: 9661
diff changeset
   342
            window.location.reload();
9914
30b56a56c1f4 [web/js] replace callAddOrDeleteThenReload with more generic callAjaxFuncThenReload
Julien Cristau <julien.cristau@logilab.fr>
parents: 9784
diff changeset
   343
            if (msg)
30b56a56c1f4 [web/js] replace callAddOrDeleteThenReload with more generic callAjaxFuncThenReload
Julien Cristau <julien.cristau@logilab.fr>
parents: 9784
diff changeset
   344
                updateMessage(msg);
9784
790956c311ef EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents: 9661
diff changeset
   345
        });
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   346
    }
5705
30b94973bc67 [javascript] add a name property to namespaces, mainly for convenience in helpers such as movedToNamespace
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5699
diff changeset
   347
});
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   348
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   349
/** DOM factories ************************************************************/
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   350
A = cw.utils.createDomFunction('a');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   351
BUTTON = cw.utils.createDomFunction('button');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   352
BR = cw.utils.createDomFunction('br');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   353
CANVAS = cw.utils.createDomFunction('canvas');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   354
DD = cw.utils.createDomFunction('dd');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   355
DIV = cw.utils.createDomFunction('div');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   356
DL = cw.utils.createDomFunction('dl');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   357
DT = cw.utils.createDomFunction('dt');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   358
FIELDSET = cw.utils.createDomFunction('fieldset');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   359
FORM = cw.utils.createDomFunction('form');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   360
H1 = cw.utils.createDomFunction('H1');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   361
H2 = cw.utils.createDomFunction('H2');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   362
H3 = cw.utils.createDomFunction('H3');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   363
H4 = cw.utils.createDomFunction('H4');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   364
H5 = cw.utils.createDomFunction('H5');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   365
H6 = cw.utils.createDomFunction('H6');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   366
HR = cw.utils.createDomFunction('hr');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   367
IMG = cw.utils.createDomFunction('img');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   368
INPUT = cw.utils.createDomFunction('input');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   369
LABEL = cw.utils.createDomFunction('label');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   370
LEGEND = cw.utils.createDomFunction('legend');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   371
LI = cw.utils.createDomFunction('li');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   372
OL = cw.utils.createDomFunction('ol');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   373
OPTGROUP = cw.utils.createDomFunction('optgroup');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   374
OPTION = cw.utils.createDomFunction('option');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   375
P = cw.utils.createDomFunction('p');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   376
PRE = cw.utils.createDomFunction('pre');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   377
SELECT = cw.utils.createDomFunction('select');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   378
SPAN = cw.utils.createDomFunction('span');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   379
STRONG = cw.utils.createDomFunction('strong');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   380
TABLE = cw.utils.createDomFunction('table');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   381
TBODY = cw.utils.createDomFunction('tbody');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   382
TD = cw.utils.createDomFunction('td');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   383
TEXTAREA = cw.utils.createDomFunction('textarea');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   384
TFOOT = cw.utils.createDomFunction('tfoot');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   385
TH = cw.utils.createDomFunction('th');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   386
THEAD = cw.utils.createDomFunction('thead');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   387
TR = cw.utils.createDomFunction('tr');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   388
TT = cw.utils.createDomFunction('tt');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   389
UL = cw.utils.createDomFunction('ul');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   390
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   391
// cubicweb specific
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   392
//IFRAME = cw.utils.createDomFunction('iframe');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   393
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   394
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   395
function IFRAME(params) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   396
    if ('name' in params) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   397
        try {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   398
            var node = document.createElement('<iframe name="' + params['name'] + '">');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   399
        } catch (ex) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   400
            var node = document.createElement('iframe');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   401
            node.id = node.name = params.name;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   402
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   403
    }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   404
    else {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   405
        var node = document.createElement('iframe');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   406
    }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   407
    for (key in params) {
10433
523a7f098066 [js] lint : make it explicit that typeof is an operator, not a function.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 10407
diff changeset
   408
        if (key !== 'name') {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   409
            var value = params[key];
10433
523a7f098066 [js] lint : make it explicit that typeof is an operator, not a function.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 10407
diff changeset
   410
            if (key.substring(0, 2) === 'on') {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   411
                // this is an event handler definition
10433
523a7f098066 [js] lint : make it explicit that typeof is an operator, not a function.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 10407
diff changeset
   412
                if (typeof value === 'string') {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   413
                    // litteral definition
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   414
                    value = new Function(value);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   415
                }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   416
                node[key] = value;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   417
            } else { // normal node attribute
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   418
                node.setAttribute(key, params[key]);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   419
            }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   420
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   421
    }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   422
    return node;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   423
}
5699
f4f6ee3af50b [javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5658
diff changeset
   424
9259
68cde7431c2c [js] remove 3.9 bw compat (where apparently unused)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8129
diff changeset
   425
// cubes: tag, keyword and apycot seem to use this, including require/provide
68cde7431c2c [js] remove 3.9 bw compat (where apparently unused)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8129
diff changeset
   426
// backward compat
6448
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6388
diff changeset
   427
CubicWeb = cw;
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6388
diff changeset
   428
5699
f4f6ee3af50b [javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5658
diff changeset
   429
jQuery(document).ready(function() {
6448
8590d82e9b1b [javascript] update to jQuery 1.4.2 and jQuery-ui 1.8.5
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6388
diff changeset
   430
    $(cw).trigger('server-response', [false, document]);
5699
f4f6ee3af50b [javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5658
diff changeset
   431
});