IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

jQuery Discussion :

Changer le window.confirm de deleteItem en modal ou dialog de jsgrid


Sujet :

jQuery

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    131
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 131
    Points : 64
    Points
    64
    Par défaut Changer le window.confirm de deleteItem en modal ou dialog de jsgrid
    Bonjour,
    je cherche a changer le "window.confirm" de "deleteItem" en fenêtre modal ou dialog
    voici le code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    <!DOCTYPE html>
    <html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>jsGrid - Data Manipulation</title>
        <link rel="stylesheet" type="text/css" href="demos.css" />
        <link href='http://fonts.googleapis.com/css?family=Open+Sans:300,600,400' rel='stylesheet' type='text/css'>
     
        <link rel="stylesheet" type="text/css" href="../css/jsgrid.css" />
        <link rel="stylesheet" type="text/css" href="../css/theme.css" />
     
        <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.2/themes/cupertino/jquery-ui.css">
        <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
        <script src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
        <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
     
        <script src="db.js"></script>
     
        <script src="../src/jsgrid.core.js"></script>
        <script src="../src/jsgrid.load-indicator.js"></script>
        <script src="../src/jsgrid.load-strategies.js"></script>
        <script src="../src/jsgrid.sort-strategies.js"></script>
        <script src="../src/jsgrid.field.js"></script>
        <script src="../src/fields/jsgrid.field.text.js"></script>
        <script src="../src/fields/jsgrid.field.number.js"></script>
        <script src="../src/fields/jsgrid.field.select.js"></script>
        <script src="../src/fields/jsgrid.field.checkbox.js"></script>
        <script src="../src/fields/jsgrid.field.control.js"></script>
     
        <style>
            .ui-widget *, .ui-widget input, .ui-widget select, .ui-widget button {
                font-family: 'Helvetica Neue Light', 'Open Sans', Helvetica;
                font-size: 14px;
                font-weight: 300 !important;
            }
     
            .details-form-field input,
            .details-form-field select {
                width: 250px;
                float: right;
            }
     
            .details-form-field {
                margin: 30px 0;
            }
     
            .details-form-field:first-child {
                margin-top: 10px;
            }
     
            .details-form-field:last-child {
                margin-bottom: 10px;
            }
     
            .details-form-field button {
                display: block;
                width: 100px;
                margin: 0 auto;
            }
     
            input.error, select.error {
                border: 1px solid #ff9999;
                background: #ffeeee;
            }
     
            label.error {
                float: right;
                margin-left: 100px;
                font-size: .8em;
                color: #ff6666;
            }
        </style>
    </head>
    <body>
        <h1>Data Manipulation</h1>
        <div id="jsGrid"></div>
     
        <div id="detailsDialog">
            <form id="detailsForm">
                <div class="details-form-field">
                    <label for="name">Name:</label>
                    <input id="name" name="name" type="text" />
                </div>
                <div class="details-form-field">
                    <label for="age">Age:</label>
                    <input id="age" name="age" type="number" />
                </div>
                <div class="details-form-field">
                    <label for="age">Address:</label>
                    <input id="address" name="address" type="text" />
                </div>
                <div class="details-form-field">
                    <label for="country">Country:</label>
                    <select id="country" name="country">
                        <option value="">(Select)</option>
                        <option value="1">United States</option>
                        <option value="2">Canada</option>
                        <option value="3">United Kingdom</option>
                        <option value="4">France</option>
                        <option value="5">Brazil</option>
                        <option value="6">China</option>
                        <option value="7">Russia</option>
                    </select>
                </div>
                <div class="details-form-field">
                    <label for="married">Is Married</label>
                    <input id="married" name="married" type="checkbox" />
                </div>
                <div class="details-form-field">
                    <button type="submit" id="save">Save</button>
                </div>
            </form>
        </div>
        <div id="detailsDialog2">
     
            <form id="detailsForm2">
                <h1>The client  will be removed. Are you sure?</h1>
                <div class="details-form-field">
                    <button type="submit" id="save2">Save</button>
                </div>
            </form>
        </div>
        <script>
            $(function() {
     
                $("#jsGrid").jsGrid({
                    height: "70%",
                    width: "100%",
                    editing: true,
                    autoload: true,
                    paging: true,
    //                deleteConfirm: function(item) {
    //                    return showDetailsDialog2("Del", item);
    //                },
                  deleteConfirm: function(item, e, a) {
                      console.log(e)
                      console.log(a)
                        return "The client \"" + item.Name + "\" will be removed. Are you sure?";
                    },
                    rowClick: function(args) {
                        showDetailsDialog("Edit", args.item);
                    },
                    controller: db,
                    fields: [
                        { name: "Name", type: "text", width: 150 },
                        { name: "Age", type: "number", width: 50 },
                        { name: "Address", type: "text", width: 200 },
                        { name: "Country", type: "select", items: db.countries, valueField: "Id", textField: "Name" },
                        { name: "Married", type: "checkbox", title: "Is Married", sorting: false },
                        {
                            type: "control",
                            modeSwitchButton: false,
                            editButton: false,
                            headerTemplate: function() {
                                return $("<button>").attr("type", "button").text("Add")
                                    .on("click", function () {
                                        showDetailsDialog("Add", {});
                                    });
                            }
                        }
                    ]
                });
     
                $("#detailsDialog").dialog({
                    autoOpen: false,
                    width: 400,
                    close: function() {
                        $("#detailsForm").validate().resetForm();
                        $("#detailsForm").find(".error").removeClass("error");
                    }
                });
                $("#detailsDialog2").dialog({
                    autoOpen: false,
                    width: 400,
                    close: function() {
                        $("#detailsForm").validate().resetForm();
                        $("#detailsForm").find(".error").removeClass("error");
                    }
                });
                $("#detailsForm").validate({
                    rules: {
                        name: "required",
                        age: { required: true, range: [18, 150] },
                        address: { required: true, minlength: 10 },
                        country: "required"
                    },
                    messages: {
                        name: "Please enter name",
                        age: "Please enter valid age",
                        address: "Please enter address (more than 10 chars)",
                        country: "Please select country"
                    },
                    submitHandler: function() {
                        formSubmitHandler();
                    }
                });
     
                var formSubmitHandler = $.noop;
                var showDetailsDialog2 = function(dialogType, client) {
     
                    $("#detailsDialog2").dialog("option", "title", dialogType + " Client")
                            .dialog("open");
                }
                var showDetailsDialog = function(dialogType, client) {
                    $("#name").val(client.Name);
                    $("#age").val(client.Age);
                    $("#address").val(client.Address);
                    $("#country").val(client.Country);
                    $("#married").prop("checked", client.Married);
     
                    formSubmitHandler = function() {
                        saveClient(client, dialogType === "Add");
                    };
     
                    $("#detailsDialog").dialog("option", "title", dialogType + " Client")
                        .dialog("open");
                };
     
     
                var saveClient = function(client, isNew) {
                    $.extend(client, {
                        Name: $("#name").val(),
                        Age: parseInt($("#age").val(), 10),
                        Address: $("#address").val(),
                        Country: parseInt($("#country").val(), 10),
                        Married: $("#married").is(":checked")
                    });
     
                    $("#jsGrid").jsGrid(isNew ? "insertItem" : "updateItem", client);
     
                    $("#detailsDialog").dialog("close");
                };
     
                var theHREF;
     
                $( "#detailsDialog2" ).dialog({
                    resizable: false,
                    height:160,
                    width:500,
                    autoOpen: false,
                    modal: true,
                    buttons: {
                        "Oui": function() {
                            $( this ).dialog( "close" );
                            window.location.href = theHREF;
                        },
                        "Annuler": function() {
                            $( this ).dialog( "close" );
                        }
                    }
                });
     
                $(".jsgrid-button jsgrid-delete-button").on( "click", function(e) {
                    e.stopPropagation();
                    console.log(e)
                    theHREF = $(this).attr("href");
                    $("#detailsDialog2").dialog("open");
                });
     
            });
        </script>
    </body>
    </html>
    jsqrid met son bouton dans un input:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <td class="jsgrid-control-field jsgrid-align-center" style="width: 50px;"><input class="jsgrid-button jsgrid-delete-button" type="button" title="Delete"></td>
    preventDefault() ne marche pas non plus.

    dans le plugin jsgrid le code de deleteItem est :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
     deleteItem: function(item) {
                var $row = this._rowByItem(item);
     
                if(!$row.length)
                    return;
     
                 if(this.confirmDeleting && !window.confirm(getOrApply(this.deleteConfirm, this, $row.data(JSGRID_ROW_DATA_KEY))))
                    return;
     
                return this._deleteRow($row);
            },
     
            _deleteRow: function($row) {
                var deletingItem = $row.data(JSGRID_ROW_DATA_KEY),
                    deletingItemIndex = this._itemIndex(deletingItem);
     
                var args = this._callEventHandler(this.onItemDeleting, {
                    row: $row,
                    item: deletingItem,
                    itemIndex: deletingItemIndex
                });
     
                return this._controllerCall("deleteItem", deletingItem, args.cancel, function() {
                    this._loadStrategy.finishDelete(deletingItem, deletingItemIndex);
     
                    this._callEventHandler(this.onItemDeleted, {
                        row: $row,
                        item: deletingItem,
                        itemIndex: deletingItemIndex
                    });
                });
            }
    si qqun a le solution c'est super !!!

  2. #2
    Expert éminent sénior
    Avatar de mathieu
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    10 235
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 10 235
    Points : 15 532
    Points
    15 532
    Par défaut
    il est possible d'annuler l'édition (et donc de personnaliser la suppression) dans onItemDeleting
    http://js-grid.com/docs/#onitemdeleting

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    131
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 131
    Points : 64
    Points
    64
    Par défaut
    non il est cablé sur ok du window.confirm.

  4. #4
    Expert éminent sénior
    Avatar de mathieu
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    10 235
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 10 235
    Points : 15 532
    Points
    15 532
    Par défaut
    je n'ai pas compris ce dont vous parlez.
    vous pouvez nous montrer le code que vous avez essayé ?

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    131
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 131
    Points : 64
    Points
    64
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    onItemDeleting: function(args) {
     
                args.grid.preventDefault();
                args.item.preventDefault();
                args.deleteItem.preventDefault();
                args.items.preventDefault();
                args.value.preventDefault();
                args.start.preventDefault();
                args.deleteConfirm.preventDefault();
                args.data.preventDefault();
     
            },

  6. #6
    Expert éminent sénior
    Avatar de mathieu
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    10 235
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 10 235
    Points : 15 532
    Points
    15 532
    Par défaut
    la documentation indique d'utiliser args.cancel, essayez cela :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    onItemDeleting : function (args) {
        args.cancel = !window.confirm("Supprimer l'élément ?");
    },

  7. #7
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    131
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 131
    Points : 64
    Points
    64
    Par défaut
    non sa marche pas.

  8. #8
    Modérateur

    Avatar de NoSmoking
    Homme Profil pro
    Inscrit en
    Janvier 2011
    Messages
    16 959
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 16 959
    Points : 44 125
    Points
    44 125
    Par défaut
    Bonjour,
    un peu léger comme réponse !

    As tu essayé l'approche de cet exemple http://js-grid.com/demos/batch-delete.html

Discussions similaires

  1. Changer un javascript confirm en alert
    Par Tidus159 dans le forum ASP.NET
    Réponses: 5
    Dernier message: 23/05/2008, 09h30
  2. Window.Confirm dans du code php
    Par god_enel dans le forum Général JavaScript
    Réponses: 24
    Dernier message: 18/01/2007, 15h59
  3. window.confirm pour ouvrir une nouvelle page
    Par Are-no dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 15/08/2006, 17h50
  4. Utiliser "window.status" avec une fenêtre modale
    Par Giill dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 28/11/2005, 14h23
  5. Réponses: 4
    Dernier message: 18/05/2005, 14h08

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo