Subversion-Projekte lars-tiefland.marine-sales.de

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
2 lars 1
//$Id: addresses.js 7148 2021-09-10 10:51:20Z erling $
2
$(document).ready(function()
3
{
4
 
5
    var name = $( "#vorname" ),
6
        lname = $( "#nachname" ),
7
        company = $( "#firma" ),
8
        street1 = $( "#street1" ),
9
        str_nr1 = $( "#str_nr1" ),
10
        postal = $( "#plz" ),
11
        city = $( "#ort" ),
12
        email=$('#email'),
13
        phone=$('#telefon'),
14
        allFields = $( [] ).add( name ).add( lname ).add( company ).add( street1 ).add( str_nr1 ).add( postal ).add( city ).add(email).add(phone),
15
        tips = $( "#validateTips" );
16
 
17
    $(".changeBillingAddressDialogAlt").delegate("input:button", "click", function(){
18
        $('#edit_addr_dialog_bill').dialog("open");
19
    });
20
    $(".changeShippingAddressDialogAlt").delegate("input:button", "click", function(){
21
        $('#edit_addr_dialog_ship').dialog("open");
22
    });
23
    $(".changeBillingAddressDialog, .changeShippingAddressDialog").delegate("input:button", "click", function(){
24
        $('#new_addr_dialog').dialog("open");
25
        $(".changeBillingAddressDialog, .changeShippingAddressDialog").dialog("close");
26
    });
27
 
28
    $(".addr_defaultBilling").click(function(){
29
        var addr_id = $(this).val();
30
        $('.addresses').load('/module/addr_saveDefault.php?type=billing&addr_id='+addr_id);
31
    });
32
    $(".addr_defaultShipping").click(function(){
33
        var addr_id = $(this).val();
34
        $('.addresses').load('/module/addr_saveDefault.php?type=shipping&addr_id='+addr_id);
35
    });
36
    $(".addr_defaultAccount").click(function(){
37
        var addr_id = $(this).val();
38
        $.ajax({
39
            url: "/get_land_id.php?a_id="+addr_id,
40
            success:function(land_id){
41
                $.ajax({
42
                    url: "/change_currency.php?l_id="+land_id
43
                });
44
            }
45
       });
46
       $('.addresses').load('/module/addr_saveDefault.php?type=account&addr_id='+addr_id);
47
    });
48
 
49
 
50
 
51
    function updateTips( t )
52
    {
53
        tips
54
            .html( t )
55
            .addClass( "ui-state-highlight" );
56
        setTimeout(function()
57
        {
58
            tips.removeClass( "ui-state-highlight", 1500 );
59
        }, 500 );
60
    }
61
 
62
    function checkLength( o, n, min, max )
63
    {
64
        if ( o.val().length > max || o.val().length < min )
65
        {
66
            o.addClass( "ui-state-error" ).focus();
67
            updateTips( "Length of " + n + " must be between " + min + " and " + max + "." );
68
            return false;
69
        }
70
        else
71
        {
72
            return true;
73
        }
74
    }
75
    function checkMinLength( o, n )
76
    {
77
        if ( o.val().length < 1 )
78
        {
79
            o.addClass( "ui-state-error" ).focus();
80
            updateTips( n + " darf nicht leer sein." );
81
            return false;
82
        }
83
        else
84
        {
85
            return true;
86
        }
87
    }
88
 
89
    function checkRegexp( o, regexp, n )
90
    {
91
        if ( !( regexp.test( o.val() ) ) )
92
        {
93
            o.addClass( "ui-state-error" ).focus();
94
            updateTips( n );
95
            return false;
96
        }
97
        else
98
        {
99
            return true;
100
        }
101
    }
102
    $('#new_addr_dialog,#new_shipping_addr_dialog,#new_billing_addr_dialog').dialog(
103
    {
104
        autoOpen:false,
105
        height: "auto",
106
        width: "auto",
107
        modal:true,
108
        resizable:false,
109
        show:"fade",
110
        hide:"fade",
111
        buttons:
112
        {
113
            'Abbrechen':function(){
114
                $(this).dialog("close");
115
            },
116
 
117
            'Adresse speichern': function()
118
            {
119
                var bValid = true;
120
//                allFields.removeClass( "ui-state-error" );
121
//                tips.text("");
122
//
123
//                bValid = bValid && checkMinLength(name,"First name");
124
//                bValid = bValid && checkMinLength(lname,"Last name");
125
//                bValid = bValid && checkMinLength(street1,"Street");
126
//                bValid = bValid && checkMinLength(str_nr1,"Street No");
127
//                bValid = bValid && checkMinLength(postal,"Postalcode");
128
//                bValid = bValid && checkMinLength(city,"City");
129
                //bValid = bValid && checkMinLength(email,"E-Mail");
130
 
131
 
132
                if ( bValid )
133
                {
134
                    daten=$('.edit_address').serializeArray();
135
                    //Shows which address was choosen true/false
136
                    $.ajax({
137
                        type: "POST",
138
                        url: "/edit_address.php?mode=save",
139
                        data: daten
140
                    }).done(function( html ){
141
                        resultArr=html.split("|");
142
                        resultCode=resultArr[0];
143
                        resultText=resultArr[1];
144
                        tips.html(resultText);
145
                        if(resultCode!=1)
146
                        {
147
                            $("#new_addr_dialog").dialog("close");
148
                            alert("Die Adresse wurde gespeichert und kann jetzt durch einen Klick auf 'Adresse wechseln' als Rechnungs- und/oder Lieferadresse verwendet werden.");
149
                            window.location.reload();
150
                        }
151
                    });
152
                }
153
            },
154
        }
155
    });
156
    $('#edit_addr_dialog_bill').dialog(
157
    {
158
        autoOpen:false,
159
        height: "auto",
160
        width: "auto",
161
        modal:true,
162
        resizable:false,
163
        show:"fade",
164
        hide:"fade",
165
        buttons:
166
        {
167
            'Adresse speichern': function()
168
            {
169
 
170
                daten=$('#edit_address').serializeArray();
171
                //Shows which address was choosen true/false
172
                $.ajax({
173
                    type: "POST",
174
                    url: "/edit_address.php?mode=save",
175
                    data: daten
176
                }).done(function( html ){
177
                    $(".changeBillingAddressDialogAlt").load("/edit_address.php?mode=showAdress");
178
                    $("#edit_addr_dialog_bill").dialog("close");
179
                });
180
 
181
            },
182
            'Abbrechen':function(){
183
                $(this).dialog("close");
184
            }
185
        }
186
    });
187
 
188
    $('#edit_addr_dialog_ship').dialog(
189
    {
190
        autoOpen:false,
191
        height: "auto",
192
        width: "auto",
193
        modal:true,
194
        resizable:false,
195
        show:"fade",
196
        hide:"fade",
197
        buttons:
198
        {
199
            'Adresse speichern': function()
200
            {
201
 
202
                daten=$('#edit_address').serializeArray();
203
                //Shows which address was choosen true/false
204
                $.ajax({
205
                    type: "POST",
206
                    url: "/edit_address.php?mode=save",
207
                    data: daten
208
                }).done(function( html ){
209
 
210
                    $(".changeShippingAddressDialogAlt").load("/edit_address.php?mode=showAdress&type=ship");
211
                    $("#edit_addr_dialog_ship").dialog("close");
212
                });
213
 
214
            },
215
            'Abbrechen':function(){
216
                $(this).dialog("close");
217
            }
218
        }
219
    });
220
 
221
    $('#del_address_dialog,.del_address_dialog').dialog({
222
        autoOpen: false,
223
        height: "auto",
224
        width: "auto",
225
        modal: true,
226
        resizable: false,
227
        show:"fade",
228
        hide:"fade",
229
        title: 'Adresse löschen',
230
        open: function() {
231
            $(this).html("Möchten Sie diese Adresse wirklich löschen?");
232
        },
233
        buttons:
234
        {
235
            'Nein': function(){
236
                $(this).dialog('close');
237
            },
238
            'Ja': function(){
239
                $('.addresses').load("/del_address.php", data);
240
                $(this).dialog('close');
241
            }
242
        }
243
    });
244
 
245
    $('.new_addr_basket').click(new_address);
246
 
247
    $('#edit_addr_basket').click(function(){
248
        idArray = $(this).attr("id").split("_");
249
        adressID = idArray[0];
250
 
251
        edit_address(adressID);
252
    });
253
 
254
    $('#my_address_book').click(function(){
255
        $(location).attr('href','/?mode=addresses&type=buy');
256
    });
257
    $('#continue_buy').click(function(){
258
        $(location).attr("href","bestellen_seite_1.html");
259
    });
260
 
261
 
262
    $('#change_address_billing').click(function(){
263
        $(location).attr("href","bestellen_seite_1.html");
264
    });
265
    $('#change_address_shipping').click(function(){
266
        $(location).attr("href","bestellen_seite_1.html");
267
    });
268
 
269
 
270
    //$('#list_billing_addr').change(upd_land);
271
    $('#list_shipping_addr').change(upd_land).change();
272
 
273
    $( "button",".new"  ).button({
274
        icons: {
275
            primary: "ui-icon-plus"
276
        }
277
    });
278
    $( "input:button" ).button();
279
 
280
    $( "#tabsBasket .trash" ).click(function(event){
281
        event.stopImmediatePropagation();
282
        event.preventDefault();
283
        var id = $(this).attr("id");
284
        var idsplit = id.split("_");
285
        var adressID = idsplit[1];
286
 
287
        del_address(adressID);
288
    });
289
 
290
    $( "#accordionBasket .trash" ).click(function(event){
291
        event.stopImmediatePropagation();
292
        event.preventDefault();
293
        var id = $(this).attr("id");
294
        var idsplit = id.split("_");
295
        var adressID = idsplit[1];
296
 
297
        del_address(adressID);
298
    });
299
 
300
 
301
    $( "#tabsBasket .edit" ).click(function(event){
302
        event.stopImmediatePropagation();
303
        event.preventDefault();
304
        var id = $(this).attr("id");
305
        var idsplit = id.split("_");
306
        var adressID = idsplit[1];
307
 
308
        edit_address(adressID);
309
    });
310
 
311
    $( "#accordionBasket .edit" ).click(function(event){
312
        event.stopImmediatePropagation();
313
        event.preventDefault();
314
        var id = $(this).attr("id");
315
        var idsplit = id.split("_");
316
        var adressID = idsplit[1];
317
 
318
        edit_address(adressID);
319
    });
320
 
321
 
322
});
323
function add_to_list(data)
324
{
325
    ret=data.split("|");
326
    code=ret[0];
327
    adresse=ret[1];
328
 
329
    if(code==0)
330
    {
331
        $('#list_billing_addr').append(adresse);
332
        $('#list_shipping_addr').append(adresse);
333
 
334
        $('#new_addr_dialog').dialog("close");
335
    }
336
    else
337
    {
338
        $( "#validateTips" ).html(adresse);
339
    }
340
}
341
function del_address(adressID)
342
{
343
    data = new Array();
344
 
345
    data.push({ name: "mode", value: "delete" });
346
    data.push({ name: "id", value: adressID });
347
 
348
    $('#del_address_dialog').dialog("open");
349
}
350
function edit_address(adressID)
351
{
352
    var data = new Array();
353
    data.push({ name: "mode", value: "edit" });
354
    data.push({ name: "id", value: adressID });
355
 
356
    $('.addresses').load("/edit_address.php",data);
357
}
358
function new_address()
359
{
360
    var data = new Array();
361
    data.push({ name: "mode", value: "edit" });
362
    data.push({ name: "id", value: '' });
363
 
364
    $('.addresses').load("edit_address.php",data);
365
}
366
 
367
function upd_land()
368
{
369
    addr_id=$(this).val();
370
    $.ajax({
371
        url: "/get_land_id.php?a_id="+addr_id,
372
        success:function(land_id){
373
            $('#liefer_Land').val(land_id).change();
374
            $.ajax({
375
                url: "/change_currency.php?l_id="+land_id
376
            });
377
        }
378
    });
379
}
380