web/data/cubicweb.edition.js
author Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
Thu, 03 Jun 2010 14:51:42 +0200
changeset 5658 7b9553a9db65
parent 5475 b44bad36e609
child 5679 0f2ded880d01
permissions -rw-r--r--
[ajax] refactor/cleanup low-level ajax functions * loadxhtml/replacePageChunck/reload_component/reload_box deprecated in favor of loadXHTML / ajaxFuncArgs * some other cleanups in cubicweb.ajax.js * add js_render which will replace js_component (more generic, nicer argument passing handling)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
     1
/**
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
     2
 * Functions dedicated to edition.
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
     3
 *
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     4
 *  :organization: Logilab
4382
6fb02edd05da 3.6 api update, cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4378
diff changeset
     5
 *  :copyright: 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     6
 *  :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
     7
 *
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     8
 */
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     9
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    10
CubicWeb.require('python.js');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    11
CubicWeb.require('htmlhelpers.js');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    12
CubicWeb.require('ajax.js');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    13
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    14
//============= Eproperty form functions =====================================//
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    15
/**
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    16
 * .. function:: setPropValueWidget(varname, tabindex)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    17
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    18
 * called on Eproperty key selection:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
 * - get the selected value
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
 * - get a widget according to the key by a sync query to the server
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
 * - fill associated div with the returned html
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
 *
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    23
 * * `varname`, the name of the variable as used in the original creation form
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    24
 * * `tabindex`, the tabindex that should be set on the widget
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    25
 */
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
function setPropValueWidget(varname, tabindex) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    27
    var key = firstSelected(document.getElementById('pkey:' + varname));
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
    if (key) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    29
        var args = {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    30
            fname: 'prop_widget',
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    31
            pageid: pageid,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    32
            arg: map(jQuery.toJSON, [key, varname, tabindex])
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    33
        };
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    34
        jqNode('div:value:' + varname).loadxhtml(JSON_BASE_URL, args, 'post');
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
// *** EDITION FUNCTIONS ****************************************** //
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    39
/**
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    40
 * .. function:: reorderTabindex(start, formid)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    41
 *
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
 * this function is called when an AJAX form was generated to
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
 * make sure tabindex remains consistent
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
 */
4969
0ad18e41053a [form js] apply vgodard patch fixing #750056: reorderTabindex js function crashes when form dom id is not 'entityForm'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4629
diff changeset
    45
function reorderTabindex(start, formid) {
0ad18e41053a [form js] apply vgodard patch fixing #750056: reorderTabindex js function crashes when form dom id is not 'entityForm'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4629
diff changeset
    46
    var form = getNode(formid || 'entityForm');
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
    var inputTypes = ['INPUT', 'SELECT', 'TEXTAREA'];
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    48
    var tabindex = (start == null) ? 15: start;
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
    nodeWalkDepthFirst(form, function(elem) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
        var tagName = elem.tagName.toUpperCase();
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    51
        if (inputTypes.contains(tagName)) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    52
            if (jQuery(elem).attr('tabindex') != null) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    53
                tabindex += 1;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    54
		jQuery(elem).attr('tabindex', tabindex);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    55
            }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    56
            return null;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    57
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    58
        return jQuery.grep(elem.childNodes, isElementNode);
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
    });
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
function showMatchingSelect(selectedValue, eid) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
    if (selectedValue) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    64
        divId = 'div' + selectedValue + '_' + eid;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    65
        var divNode = jQuery('#' + divId);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    66
        if (!divNode.length) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    67
            var args = {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    68
                vid: 'unrelateddivs',
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    69
                relation: selectedValue,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    70
                rql: rql_for_eid(eid),
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    71
                '__notemplate': 1,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    72
                callback: function() {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    73
                    _showMatchingSelect(eid, jQuery('#' + divId));
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    74
                }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    75
            };
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    76
            jQuery('#unrelatedDivs_' + eid).loadxhtml(baseuri() + 'view', args, 'post', 'append');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    77
        } else {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    78
            _showMatchingSelect(eid, divNode);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    79
        }
1419
7ff24154351d javascript + json refactoring
sylvain.thenault@logilab.fr
parents: 1314
diff changeset
    80
    } else {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    81
        _showMatchingSelect(eid, null);
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    85
/**
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    86
 * .. function:: _showMatchingSelect(eid, divNode)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    87
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    88
 * * `divNode`, a jQuery selection
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    89
 */
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    90
function _showMatchingSelect(eid, divNode) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    91
    // hide all divs, and then show the matching one
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    92
    // (would actually be better to directly hide the displayed one)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    93
    jQuery('#unrelatedDivs_' + eid).children().hide();
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
    // divNode not found means 'no relation selected' (i.e. first blank item)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    95
    if (divNode && divNode.length) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
    96
        divNode.show();
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   100
/**
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   101
 * .. function:: buildPendingInsertHandle(elementId, element_name, selectNodeId, eid)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   102
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   103
 * this function builds a Handle to cancel pending insertion
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   104
 */
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
function buildPendingInsertHandle(elementId, element_name, selectNodeId, eid) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   106
    jscall = "javascript: cancelPendingInsert('" + [elementId, element_name, selectNodeId, eid].join("', '") + "')";
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   107
    return A({
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   108
        'class': 'handle',
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   109
        'href': jscall,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   110
        'title': _("cancel this insert")
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   111
    },
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   112
    '[x]');
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   114
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   115
function buildEntityLine(relationName, selectedOptionNode, comboId, eid) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   116
    // textContent doesn't seem to work on selectedOptionNode
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   117
    var content = selectedOptionNode.firstChild.nodeValue;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   118
    var handle = buildPendingInsertHandle(selectedOptionNode.id, 'tr', comboId, eid);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   119
    var link = A({
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   120
        'href': 'view?rql=' + selectedOptionNode.value,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   121
        'class': 'editionPending',
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   122
        'id': 'a' + selectedOptionNode.id
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   123
    },
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   124
    content);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   125
    var tr = TR({
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   126
        'id': 'tr' + selectedOptionNode.id
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   127
    },
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   128
    [TH(null, relationName), TD(null, [handle, link])]);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   129
    try {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   130
        var separator = getNode('relationSelectorRow_' + eid);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   131
        //dump('relationSelectorRow_' + eid) XXX warn dump is not implemented in konqueror (at least)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   132
        // XXX Warning: separator.parentNode is not (always ?) the
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   133
        // table itself, but an intermediate node (TableSectionElement)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   134
        var tableBody = separator.parentNode;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   135
        tableBody.insertBefore(tr, separator);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   136
    } catch(ex) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   137
        log("got exception(2)!" + ex);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   138
    }
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   140
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   141
function buildEntityCell(relationName, selectedOptionNode, comboId, eid) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   142
    var handle = buildPendingInsertHandle(selectedOptionNode.id, 'div_insert_', comboId, eid);
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   143
    var link = A({
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   144
        'href': 'view?rql=' + selectedOptionNode.value,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   145
        'class': 'editionPending',
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   146
        'id': 'a' + selectedOptionNode.id
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   147
    },
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   148
    content);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   149
    var div = DIV({
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   150
        'id': 'div_insert_' + selectedOptionNode.id
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   151
    },
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   152
    [handle, link]);
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
    try {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   154
        var td = jQuery('#cell' + relationName + '_' + eid);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   155
        td.appendChild(div);
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
    } catch(ex) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   157
        alert("got exception(3)!" + ex);
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   158
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   159
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   160
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   161
function addPendingInsert(optionNode, eid, cell, relname) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   162
    var value = jQuery(optionNode).attr('value');
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   163
    if (!value) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   164
        // occurs when the first element in the box is selected (which is not
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   165
        // an entity but the combobox title)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   166
        return;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   167
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   168
    // 2nd special case
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   169
    if (value.indexOf('http') == 0) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   170
        document.location = value;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   171
        return;
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   172
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   173
    // add hidden parameter
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   174
    var entityForm = jQuery('#entityForm');
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   175
    var oid = optionNode.id.substring(2); // option id is prefixed by "id"
1419
7ff24154351d javascript + json refactoring
sylvain.thenault@logilab.fr
parents: 1314
diff changeset
   176
    remoteExec('add_pending_inserts', [oid.split(':')]);
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   177
    var selectNode = optionNode.parentNode;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   178
    // remove option node
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   179
    selectNode.removeChild(optionNode);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   180
    // add line in table
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   181
    if (cell) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   182
        // new relation as a cell in multiple edit
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   183
        // var relation_name = relationSelected.getAttribute('value');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   184
        // relation_name = relation_name.slice(0, relation_name.lastIndexOf('_'));
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   185
        buildEntityCell(relname, optionNode, selectNode.id, eid);
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   186
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   187
    else {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   188
        var relationSelector = getNode('relationSelector_' + eid);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   189
        var relationSelected = relationSelector.options[relationSelector.selectedIndex];
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   190
        // new relation as a line in simple edit
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   191
        buildEntityLine(relationSelected.text, optionNode, selectNode.id, eid);
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   192
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   193
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   194
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   195
function cancelPendingInsert(elementId, element_name, comboId, eid) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   196
    // remove matching insert element
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   197
    var entityView = jqNode('a' + elementId).text();
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   198
    jqNode(element_name + elementId).remove();
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   199
    if (comboId) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   200
        // re-insert option in combobox if it was taken from there
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   201
        var selectNode = getNode(comboId);
1713
d817f23439ba bix a bug: correct the sended parameter 'no need for id in the string parameter name'
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents: 1419
diff changeset
   202
        // XXX what on object relation
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   203
        if (selectNode) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   204
            var options = selectNode.options;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   205
            var node_id = elementId.substring(0, elementId.indexOf(':'));
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   206
            options[options.length] = OPTION({
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   207
                'id': elementId,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   208
                'value': node_id
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   209
            },
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   210
            entityView);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   211
        }
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   212
    }
1713
d817f23439ba bix a bug: correct the sended parameter 'no need for id in the string parameter name'
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents: 1419
diff changeset
   213
    elementId = elementId.substring(2, elementId.length);
1419
7ff24154351d javascript + json refactoring
sylvain.thenault@logilab.fr
parents: 1314
diff changeset
   214
    remoteExec('remove_pending_insert', elementId.split(':'));
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   215
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   216
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   217
/**
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   218
 * .. function:: buildPendingDeleteHandle(elementId, eid)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   219
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   220
 * this function builds a Handle to cancel pending insertion
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   221
 */
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   222
function buildPendingDeleteHandle(elementId, eid) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   223
    var jscall = "javascript: addPendingDelete('" + elementId + ', ' + eid + "');";
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   224
    return A({
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   225
        'href': jscall,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   226
        'class': 'pendingDeleteHandle',
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   227
        'title': _("delete this relation")
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   228
    },
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   229
    '[x]');
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   230
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   231
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   232
/**
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   233
 * .. function:: addPendingDelete(nodeId, eid)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   234
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   235
 * * `nodeId`, eid_from:r_type:eid_to
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   236
 */
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   237
function addPendingDelete(nodeId, eid) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   238
    var d = loadRemote('json', ajaxFuncArgs('add_pending_delete', null, nodeId.split(':')));
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   239
    d.addCallback(function() {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   240
        // and strike entity view
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   241
        jqNode('span' + nodeId).addClass('pendingDelete');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   242
        // replace handle text
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   243
        jqNode('handle' + nodeId).text('+');
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   244
    });
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   245
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   246
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   247
/**
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   248
 * .. function:: cancelPendingDelete(nodeId, eid)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   249
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   250
 * * `nodeId`, eid_from:r_type:eid_to
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   251
 */
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   252
function cancelPendingDelete(nodeId, eid) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   253
    var d = loadRemote('json', ajaxFuncArgs('remove_pending_delete', null, nodeId.split(':')));
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   254
    d.addCallback(function() {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   255
        // reset link's CSS class
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   256
        jqNode('span' + nodeId).removeClass('pendingDelete');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   257
        // replace handle text
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   258
        jqNode('handle' + nodeId).text('x');
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   259
    });
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   260
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   261
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   262
/**
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   263
 * .. function:: togglePendingDelete(nodeId, eid)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   264
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   265
 * * `nodeId`, eid_from:r_type:eid_to
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   266
 */
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   267
function togglePendingDelete(nodeId, eid) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   268
    // node found means we should cancel deletion
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   269
    if (jQuery.className.has(getNode('span' + nodeId), 'pendingDelete')) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   270
        cancelPendingDelete(nodeId, eid);
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   271
    } else {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   272
        addPendingDelete(nodeId, eid);
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   273
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   274
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   275
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   276
function selectForAssociation(tripletIdsString, originalEid) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   277
    var tripletlist = map(function(x) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   278
        return x.split(':');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   279
    },
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   280
    tripletIdsString.split('-'));
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   281
    var d = loadRemote('json', ajaxFuncArgs('add_pending_inserts', null, tripletlist));
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   282
    d.addCallback(function() {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   283
        var args = {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   284
            vid: 'edition',
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   285
            __mode: 'normal',
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   286
            rql: rql_for_eid(originalEid)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   287
        };
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   288
        document.location = 'view?' + asURL(args);
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   289
    });
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   290
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   291
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   292
4378
785c56bdacc6 [forms] the last touch: handle inlined relation forms as fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   293
function updateInlinedEntitiesCounters(rtype, role) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   294
    jQuery('div.inline-' + rtype + '-' + role + '-slot span.icounter').each(function(i) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   295
        this.innerHTML = i + 1;
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   296
    });
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   297
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   298
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   299
/**
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   300
 * .. function:: addInlineCreationForm(peid, petype, ttype, rtype, role, i18nctx, insertBefore)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   301
 *
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   302
 * makes an AJAX request to get an inline-creation view's content
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   303
 * * `peid`, the parent entity eid
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   304
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   305
 * * `petype`, the parent entity type
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   306
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   307
 * * `ttype`, the target (inlined) entity type
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   308
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   309
 * * `rtype`, the relation type between both entities
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   310
 */
4629
1eeef3cbf528 fix 4626:c26b4df9fc90 (#703911): use can't rely on peid since it's not an actual eid when we're creating the parent entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4436
diff changeset
   311
function addInlineCreationForm(peid, petype, ttype, rtype, role, i18nctx, insertBefore) {
2859
822258915ff0 [javascript] allow customization of inlineCreationForm insertion point
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2852
diff changeset
   312
    insertBefore = insertBefore || getNode('add' + rtype + ':' + peid + 'link').parentNode;
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   313
    var args = ajaxFuncArgs('inline_creation_form', null, peid, petype, ttype, rtype, role, i18nctx);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   314
    var d = loadRemote('json', args);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   315
    d.addCallback(function(response) {
992
d5fe2626695b call postAjaxLoad in addInlineCreationForm javascript function in order to call buildWysiwygEditors when a section of the page is reloaded
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 977
diff changeset
   316
        var dom = getDomFromResponse(response);
2859
822258915ff0 [javascript] allow customization of inlineCreationForm insertion point
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2852
diff changeset
   317
        preprocessAjaxLoad(null, dom);
822258915ff0 [javascript] allow customization of inlineCreationForm insertion point
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2852
diff changeset
   318
        var form = jQuery(dom);
822258915ff0 [javascript] allow customization of inlineCreationForm insertion point
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2852
diff changeset
   319
        form.css('display', 'none');
822258915ff0 [javascript] allow customization of inlineCreationForm insertion point
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2852
diff changeset
   320
        form.insertBefore(insertBefore).slideDown('fast');
4378
785c56bdacc6 [forms] the last touch: handle inlined relation forms as fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   321
        updateInlinedEntitiesCounters(rtype, role);
4969
0ad18e41053a [form js] apply vgodard patch fixing #750056: reorderTabindex js function crashes when form dom id is not 'entityForm'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4629
diff changeset
   322
        reorderTabindex(null, $(insertBefore).closest('form')[0]);
3342
8b30ae9c4e67 [javascript] make inlinedform-added event bindable
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3327
diff changeset
   323
        jQuery(CubicWeb).trigger('inlinedform-added', form);
3124
c929360212ca [forms] fix form enctype handling with inlined forms
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2859
diff changeset
   324
        // if the inlined form contains a file input, we must force
c929360212ca [forms] fix form enctype handling with inlined forms
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2859
diff changeset
   325
        // the form enctype to multipart/form-data
c929360212ca [forms] fix form enctype handling with inlined forms
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2859
diff changeset
   326
        if (form.find('input:file').length) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   327
            // NOTE: IE doesn't support dynamic enctype modification, we have
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   328
            //       to set encoding too.
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   329
            form.closest('form').attr('enctype', 'multipart/form-data').attr('encoding', 'multipart/form-data');
3124
c929360212ca [forms] fix form enctype handling with inlined forms
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2859
diff changeset
   330
        }
992
d5fe2626695b call postAjaxLoad in addInlineCreationForm javascript function in order to call buildWysiwygEditors when a section of the page is reloaded
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 977
diff changeset
   331
        postAjaxLoad(dom);
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   332
    });
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   333
    d.addErrback(function(xxx) {
2859
822258915ff0 [javascript] allow customization of inlineCreationForm insertion point
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2852
diff changeset
   334
        log('xxx =', xxx);
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   335
    });
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   336
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   337
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   338
/**
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   339
 * .. function:: removeInlineForm(peid, rtype, role, eid, showaddnewlink)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   340
 *
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   341
 * removes the part of the form used to edit an inlined entity
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   342
 */
4378
785c56bdacc6 [forms] the last touch: handle inlined relation forms as fields
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4279
diff changeset
   343
function removeInlineForm(peid, rtype, role, eid, showaddnewlink) {
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   344
    jqNode(['div', peid, rtype, eid].join('-')).slideUp('fast', function() {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   345
        $(this).remove();
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   346
        updateInlinedEntitiesCounters(rtype, role);
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   347
    });
3947
8d06bce45c02 when one is adding an inline entity for a relation of a single card,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3863
diff changeset
   348
    if (showaddnewlink) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   349
        toggleVisibility(showaddnewlink);
3947
8d06bce45c02 when one is adding an inline entity for a relation of a single card,
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3863
diff changeset
   350
    }
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   351
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   352
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   353
/**
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   354
 * .. function:: removeInlinedEntity(peid, rtype, eid)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   355
 *
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   356
 * alternatively adds or removes the hidden input that make the
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   357
 * edition of the relation `rtype` possible between `peid` and `eid`
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   358
 * * `peid`, the parent entity eid
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   359
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   360
 * * `rtype`, the relation type between both entities
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   361
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   362
 * * `eid`, the inlined entity eid
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   363
 */
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   364
function removeInlinedEntity(peid, rtype, eid) {
3544
188d86631c45 fix #471746
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3343
diff changeset
   365
    // XXX work around the eid_param thing (eid + ':' + eid) for #471746
188d86631c45 fix #471746
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3343
diff changeset
   366
    var nodeid = ['rel', peid, rtype, eid + ':' + eid].join('-');
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   367
    var node = jqNode(nodeid);
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   368
    if (!node.attr('cubicweb:type')) {
3545
242b07b6d820 fix remove/do not remove action sequence (using a temp attribute instead of setting a wrong value in the resurrected hidden input)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3544
diff changeset
   369
        node.attr('cubicweb:type', node.val());
242b07b6d820 fix remove/do not remove action sequence (using a temp attribute instead of setting a wrong value in the resurrected hidden input)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3544
diff changeset
   370
        node.val('');
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   371
        var divid = ['div', peid, rtype, eid].join('-');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   372
        jqNode(divid).fadeTo('fast', 0.5);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   373
        var noticeid = ['notice', peid, rtype, eid].join('-');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   374
        jqNode(noticeid).fadeIn('fast');
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   375
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   376
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   377
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   378
function restoreInlinedEntity(peid, rtype, eid) {
3544
188d86631c45 fix #471746
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3343
diff changeset
   379
    // XXX work around the eid_param thing (eid + ':' + eid) for #471746
188d86631c45 fix #471746
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3343
diff changeset
   380
    var nodeid = ['rel', peid, rtype, eid + ':' + eid].join('-');
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   381
    var node = jqNode(nodeid);
3545
242b07b6d820 fix remove/do not remove action sequence (using a temp attribute instead of setting a wrong value in the resurrected hidden input)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3544
diff changeset
   382
    if (node.attr('cubicweb:type')) {
242b07b6d820 fix remove/do not remove action sequence (using a temp attribute instead of setting a wrong value in the resurrected hidden input)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3544
diff changeset
   383
        node.val(node.attr('cubicweb:type'));
242b07b6d820 fix remove/do not remove action sequence (using a temp attribute instead of setting a wrong value in the resurrected hidden input)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3544
diff changeset
   384
        node.attr('cubicweb:type', '');
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   385
        jqNode(['fs', peid, rtype, eid].join('-')).append(node);
3544
188d86631c45 fix #471746
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3343
diff changeset
   386
        var divid = ['div', peid, rtype, eid].join('-');
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   387
        jqNode(divid).fadeTo('fast', 1);
3544
188d86631c45 fix #471746
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3343
diff changeset
   388
        var noticeid = ['notice', peid, rtype, eid].join('-');
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   389
        jqNode(noticeid).hide();
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   390
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   391
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   392
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   393
function _clearPreviousErrors(formid) {
5335
9aed0b607130 [etwist] nicer, thouhg really not perferct) request max size exceeded support of json/frame posts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5087
diff changeset
   394
    // on some case (eg max request size exceeded, we don't know the formid
9aed0b607130 [etwist] nicer, thouhg really not perferct) request max size exceeded support of json/frame posts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5087
diff changeset
   395
    if (formid) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   396
        jQuery('#' + formid + 'ErrorMessage').remove();
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   397
        jQuery('#' + formid + ' span.errorMsg').remove();
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   398
        jQuery('#' + formid + ' .error').removeClass('error');
5335
9aed0b607130 [etwist] nicer, thouhg really not perferct) request max size exceeded support of json/frame posts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5087
diff changeset
   399
    } else {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   400
        jQuery('span.errorMsg').remove();
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   401
        jQuery('.error').removeClass('error');
5335
9aed0b607130 [etwist] nicer, thouhg really not perferct) request max size exceeded support of json/frame posts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5087
diff changeset
   402
    }
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   403
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   404
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   405
function _displayValidationerrors(formid, eid, errors) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   406
    var globalerrors = [];
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   407
    var firsterrfield = null;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   408
    for (fieldname in errors) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   409
        var errmsg = errors[fieldname];
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   410
        if (!fieldname) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   411
            globalerrors.push(errmsg);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   412
        } else {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   413
            var fieldid = fieldname + ':' + eid;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   414
            var suffixes = ['', '-subject', '-object'];
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   415
            var found = false;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   416
            // XXX remove suffixes at some point
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   417
            for (var i = 0, length = suffixes.length; i < length; i++) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   418
                var field = jqNode(fieldname + suffixes[i] + ':' + eid);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   419
                if (field && jQuery(field).attr('type') != 'hidden') {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   420
                    if (!firsterrfield) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   421
                        firsterrfield = 'err-' + fieldid;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   422
                    }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   423
                    jQuery(field).addClass('error');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   424
                    var span = SPAN({
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   425
                        'id': 'err-' + fieldid,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   426
                        'class': "errorMsg"
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   427
                    },
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   428
                    errmsg);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   429
                    field.before(span);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   430
                    found = true;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   431
                    break;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   432
                }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   433
            }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   434
            if (!found) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   435
                firsterrfield = formid;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   436
                globalerrors.push(_(fieldname) + ' : ' + errmsg);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   437
            }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   438
        }
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   439
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   440
    if (globalerrors.length) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   441
        if (globalerrors.length == 1) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   442
            var innernode = SPAN(null, globalerrors[0]);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   443
        } else {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   444
            var innernode = UL(null, map(partial(LI, null), globalerrors));
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   445
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   446
        // insert DIV and innernode before the form
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   447
        var div = DIV({
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   448
            'class': "errorMessage",
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   449
            'id': formid + 'ErrorMessage'
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   450
        });
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   451
        div.appendChild(innernode);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   452
        jQuery('#' + formid).before(div);
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   453
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   454
    return firsterrfield || formid;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   455
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   456
3343
383b42263bb1 [validatecontroller] allow additional args to be passed to the js callback
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3342
diff changeset
   457
function handleFormValidationResponse(formid, onsuccess, onfailure, result, cbargs) {
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   458
    // Success
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   459
    if (result[0]) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   460
        if (onsuccess) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   461
            onsuccess(result, formid, cbargs);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   462
        } else {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   463
            document.location.href = result[1];
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   464
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   465
        return true;
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   466
    }
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   467
    if (onfailure && ! onfailure(result, formid, cbargs)) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   468
        return false;
3834
e3e64352063d [javascript] fid form / onfailure behaviour
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3767
diff changeset
   469
    }
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   470
    unfreezeFormButtons(formid);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   471
    // Failures
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   472
    _clearPreviousErrors(formid);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   473
    var descr = result[1];
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   474
    // Unknown structure
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   475
    if (!isArrayLike(descr) || descr.length != 2) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   476
        updateMessage(descr);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   477
        return false;
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   478
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   479
    _displayValidationerrors(formid, descr[0], descr[1]);
3100
b0a583156d6d fix reledit validation error handling for relations #345477
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2859
diff changeset
   480
    updateMessage(_('please correct errors below'));
5475
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5336
diff changeset
   481
    // ensure the browser does not scroll down
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   482
    document.location.hash = '#header';
3100
b0a583156d6d fix reledit validation error handling for relations #345477
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2859
diff changeset
   483
    return false;
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   484
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   485
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   486
/**
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   487
 * .. function:: unfreezeFormButtons(formid)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   488
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   489
 * unfreeze form buttons when the validation process is over
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   490
 */
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   491
function unfreezeFormButtons(formid) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   492
    jQuery('#progress').hide();
5335
9aed0b607130 [etwist] nicer, thouhg really not perferct) request max size exceeded support of json/frame posts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5087
diff changeset
   493
    // on some case (eg max request size exceeded, we don't know the formid
9aed0b607130 [etwist] nicer, thouhg really not perferct) request max size exceeded support of json/frame posts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5087
diff changeset
   494
    if (formid) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   495
        jQuery('#' + formid + ' .validateButton').removeAttr('disabled');
5335
9aed0b607130 [etwist] nicer, thouhg really not perferct) request max size exceeded support of json/frame posts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5087
diff changeset
   496
    } else {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   497
        jQuery('.validateButton').removeAttr('disabled');
5335
9aed0b607130 [etwist] nicer, thouhg really not perferct) request max size exceeded support of json/frame posts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5087
diff changeset
   498
    }
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   499
    return true;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   500
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   501
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   502
/**
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   503
 * .. function:: freezeFormButtons(formid)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   504
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   505
 * disable form buttons while the validation is being done
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   506
 */
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   507
function freezeFormButtons(formid) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   508
    jQuery('#progress').show();
4271
dfee17fa363f remove input from jquery filter, so it works as well with buttons
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4217
diff changeset
   509
    jQuery('#' + formid + ' .validateButton').attr('disabled', 'disabled');
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   510
    return true;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   511
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   512
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   513
/**
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   514
 * .. function:: postForm(bname, bvalue, formid)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   515
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   516
 * used by additional submit buttons to remember which button was clicked
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   517
 */
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   518
function postForm(bname, bvalue, formid) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   519
    var form = getNode(formid);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   520
    if (bname) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   521
        var child = form.appendChild(INPUT({
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   522
            type: 'hidden',
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   523
            name: bname,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   524
            value: bvalue
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   525
        }));
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   526
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   527
    var onsubmit = form.onsubmit;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   528
    if (!onsubmit || (onsubmit && onsubmit())) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   529
        form.submit();
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   530
    }
4274
4601ba407ed6 apply patch proposed by 2web to properly remove hidden input set to represent the button used to submit the form, so forms may be properly reused after a post
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   531
    if (bname) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   532
        jQuery(child).remove();
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   533
        /* cleanup */
4274
4601ba407ed6 apply patch proposed by 2web to properly remove hidden input set to represent the button used to submit the form, so forms may be properly reused after a post
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   534
    }
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   535
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   536
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   537
/**
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   538
 * .. function:: setFormsTarget(node)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   539
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   540
 * called on load to set target and iframeso object.
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   541
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   542
 * .. note::
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   543
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   544
 *    this is a hack to make the XHTML compliant.
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   545
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   546
 * .. note::
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   547
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   548
 *   `object` nodes might be a potential replacement for iframes
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   549
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   550
 * .. note::
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   551
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   552
 *    there is a XHTML module allowing iframe elements but there
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   553
 *    is still the problem of the form's `target` attribute
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   554
 */
3863
fe22502d4ab1 [forms] add setFormsTarget() to the list of postAjaxLoad callbacks to have iframe on ajax-rendered forms
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3834
diff changeset
   555
function setFormsTarget(node) {
fe22502d4ab1 [forms] add setFormsTarget() to the list of postAjaxLoad callbacks to have iframe on ajax-rendered forms
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3834
diff changeset
   556
    var $node = jQuery(node || document.body);
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   557
    $node.find('form').each(function() {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   558
        var form = jQuery(this);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   559
        var target = form.attr('cubicweb:target');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   560
        if (target) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   561
            form.attr('target', target);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   562
            /* do not use display: none because some browsers ignore iframe
1419
7ff24154351d javascript + json refactoring
sylvain.thenault@logilab.fr
parents: 1314
diff changeset
   563
             * with no display */
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   564
            form.append(IFRAME({
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   565
                name: target,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   566
                id: target,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   567
                src: 'javascript: void(0)',
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   568
                width: '0px',
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   569
                height: '0px'
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   570
            }));
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   571
        }
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   572
    });
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   573
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   574
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   575
jQuery(document).ready(function() {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   576
    setFormsTarget();
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   577
});
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   578
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   579
/**
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   580
 * .. function:: validateForm(formid, action, onsuccess, onfailure)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   581
 *
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   582
 * called on traditionnal form submission : the idea is to try
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   583
 * to post the form. If the post is successful, `validateForm` redirects
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   584
 * to the appropriate URL. Otherwise, the validation errors are displayed
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   585
 * around the corresponding input fields.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   586
 */
1864
4ceaf8f2709b add onfailure fonction for validateForm, return formid on success
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1798
diff changeset
   587
function validateForm(formid, action, onsuccess, onfailure) {
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   588
    try {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   589
        var zipped = formContents(formid);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   590
        var args = ajaxFuncArgs('validate_form', null, action, zipped[0], zipped[1]);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   591
        var d = loadRemote('json', args);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   592
    } catch(ex) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   593
        log('got exception', ex);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   594
        return false;
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   595
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   596
    function _callback(result, req) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   597
        handleFormValidationResponse(formid, onsuccess, onfailure, result);
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   598
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   599
    d.addCallback(_callback);
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   600
    return false;
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   601
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   602
1419
7ff24154351d javascript + json refactoring
sylvain.thenault@logilab.fr
parents: 1314
diff changeset
   603
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   604
/**
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   605
 * .. function:: inlineValidateRelationFormOptions(rtype, eid, divid, options)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   606
 *
1759
61d026ced19f preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1713
diff changeset
   607
 * called by reledit forms to submit changes
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   608
 * * `rtype`, the attribute being edited
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   609
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   610
 * * `eid`, the eid of the entity being edited
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   611
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   612
 * * `options`, a dictionnary of options used by the form validation handler such
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   613
 *    as ``role``, ``onsuccess``, ``onfailure``, ``reload``, ``vid``, ``lzone``
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   614
 *    and ``default_value``:
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   615
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   616
 *     * `onsucess`, javascript function to execute on success, default is noop
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   617
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   618
 *     * `onfailure`, javascript function to execute on failure, default is noop
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   619
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   620
 *     * `default_value`, value if the field is empty
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   621
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   622
 *     * `lzone`, html fragment (string) for a clic-zone triggering actual edition
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   623
 */
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   624
function inlineValidateRelationFormOptions(rtype, eid, divid, options) {
1759
61d026ced19f preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1713
diff changeset
   625
    try {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   626
        var form = getNode(divid + '-form');
1798
cc86fe8efaaa pass default values along the whole call chain, fix hidden field update bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1760
diff changeset
   627
        var relname = rtype + ':' + eid;
cc86fe8efaaa pass default values along the whole call chain, fix hidden field update bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1760
diff changeset
   628
        var newtarget = jQuery('[name=' + relname + ']').val();
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   629
        var zipped = cw.utils.formContents(form);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   630
        var args = ajaxFuncArgs('validate_form', null, 'apply', zipped[0], zipped[1]);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   631
        var d = loadRemote(JSON_BASE_URL, args, 'POST')
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   632
    } catch(ex) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   633
        return false;
1759
61d026ced19f preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1713
diff changeset
   634
    }
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   635
    d.addCallback(function(result, req) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   636
        execFormValidationResponse(rtype, eid, divid, options, result);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   637
    });
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   638
    return false;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   639
}
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   640
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   641
function execFormValidationResponse(rtype, eid, divid, options, result) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   642
    options = $.extend({onsuccess: noop,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   643
                        onfailure: noop
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   644
                       }, options);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   645
    if (handleFormValidationResponse(divid + '-form', options.onsucess , options.onfailure, result)) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   646
        if (options.reload) {
3742
20f429eb5f46 kill separate attribute client-side handling #473636
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3545
diff changeset
   647
            document.location.reload();
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   648
        } else {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   649
            var args = {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   650
                fname: 'reledit_form',
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   651
                rtype: rtype,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   652
                role: options.role,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   653
                eid: eid,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   654
                divid: divid,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   655
                reload: options.reload,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   656
                vid: options.vid,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   657
                default_value: options.default_value,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   658
                landing_zone: options.lzone
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   659
            };
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   660
            jQuery('#' + divid + '-reledit').parent().loadxhtml(JSON_BASE_URL, args, 'post');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   661
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   662
    }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   663
1759
61d026ced19f preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1713
diff changeset
   664
}
61d026ced19f preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1713
diff changeset
   665
61d026ced19f preliminary support for inline edition of relations
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1713
diff changeset
   666
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   667
/**
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   668
 * .. function:: loadInlineEditionFormOptions(eid, rtype, divid, options)
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   669
 *
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   670
 * inline edition
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   671
 */
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   672
function loadInlineEditionFormOptions(eid, rtype, divid, options) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   673
    var args = {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   674
        fname: 'reledit_form',
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   675
        rtype: rtype,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   676
        role: options.role,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   677
        eid: eid,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   678
        divid: divid,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   679
        reload: options.reload,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   680
        vid: options.vid,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   681
        default_value: options.default_value,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   682
        landing_zone: options.lzone,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   683
        callback: function() {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   684
            showInlineEditionForm(eid, rtype, divid);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   685
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   686
    };
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   687
    jQuery('#' + divid + '-reledit').parent().loadxhtml(JSON_BASE_URL, args, 'post');
3744
767b5d0cd3cc reledit: load actual edition form on demand #471799
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3742
diff changeset
   688
}
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   689
function showInlineEditionForm(eid, rtype, divid) {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   690
    jQuery('#' + divid).hide();
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   691
    jQuery('#' + divid + '-value').hide();
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   692
    jQuery('#' + divid + '-form').show();
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   693
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   694
2371
76bf522c27be [reledit] simplify, fixing #344545
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2364
diff changeset
   695
function hideInlineEdit(eid, rtype, divid) {
3100
b0a583156d6d fix reledit validation error handling for relations #345477
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2859
diff changeset
   696
    jQuery('#appMsg').hide();
b0a583156d6d fix reledit validation error handling for relations #345477
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2859
diff changeset
   697
    jQuery('div.errorMessage').remove();
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   698
    jQuery('#' + divid).show();
3767
03924de0014d reledit: stuff the value into its own div and properly hide it when necessary (but dont lump it with the landingzone div for it switches the form on when one clicks on a value to traverse it)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3760
diff changeset
   699
    jQuery('#' + divid + '-value').show();
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   700
    jQuery('#' + divid + '-form').hide();
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   701
}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   702
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   703
CubicWeb.provide('edition.js');
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   704
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   705
// ======================= DEPRECATED FUNCTIONS ========================= //
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   706
inlineValidateRelationForm = cw.utils.deprecatedFunction(
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   707
    '[3.9] inlineValidateRelationForm() function is deprecated, use inlineValidateRelationFormOptions instead',
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   708
    function(rtype, role, eid, divid, reload, vid, default_value, lzone, onsucess, onfailure) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   709
        try {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   710
            var form = getNode(divid + '-form');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   711
            var relname = rtype + ':' + eid;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   712
            var newtarget = jQuery('[name=' + relname + ']').val();
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   713
            var zipped = formContents(form);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   714
            var d = asyncRemoteExec('validate_form', 'apply', zipped[0], zipped[1]);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   715
        } catch(ex) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   716
            return false;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   717
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   718
        d.addCallback(function(result, req) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   719
        var options = {role : role,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   720
                       reload: reload,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   721
                       vid: vid,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   722
                       default_value: default_value,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   723
                       lzone: lzone,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   724
                       onsucess: onsucess || $.noop,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   725
                       onfailure: onfailure || $.noop
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   726
                      };
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   727
            execFormValidationResponse(rtype, eid, divid, options);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   728
        });
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   729
        return false;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   730
    }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   731
);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   732
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   733
loadInlineEditionForm = cw.utils.deprecatedFunction(
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   734
    '[3.9] loadInlineEditionForm() function is deprecated, use loadInlineEditionFormOptions instead',
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   735
    function(eid, rtype, role, divid, reload, vid, default_value, lzone) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   736
        var args = {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   737
            fname: 'reledit_form',
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   738
            rtype: rtype,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   739
            role: role,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   740
            eid: eid,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   741
            divid: divid,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   742
            reload: reload,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   743
            vid: vid,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   744
            default_value: default_value,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   745
            landing_zone: lzone,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   746
            callback: function() {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   747
                showInlineEditionForm(eid, rtype, divid);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   748
            }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   749
        };
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   750
        jQuery('#' + divid + '-reledit').parent().loadxhtml(JSON_BASE_URL, args, 'post');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   751
    }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 5475
diff changeset
   752
);