PageSourceSearch

https://www.stadstheaterdebond.nl/js/bestelData.js

js stadstheaterdebond.nl collected 2026-10-04 00:30:49 UTC 21,478 bytes, 509 lines download raw bytes

1var seatSelectionSessionId = '';
2var seatSelectionObj = {
3    href: "#modal_stoelkeuze",
4    width: 600,
5    padding: 15,
6    margin: 0,
7    helpers: {
8      overlay: {
9        locked: true
10      }
11    },
12    // set an extra class here since we want to reposition
13    // the close-button for this kind of modal
14    beforeShow: function() {
15        $('body').addClass('modal-seats')
16    },
17    afterClose: function() {
18        $('body').removeClass('modal-seats')
19    }
20};
21
22var bmCounter = {
23    'bestel_app.booking.ranks.on add remove reset': { 'cnt': 0, 'time': 0 },
24    'show-pricecodes-loaded': { 'cnt': 0, 'time': 0 },
25    'bestel_app.on pricecodes': { 'cnt': 0, 'time': 0 },
26    'show-discounts-loaded': { 'cnt': 0, 'time': 0 },
27    'cart-loaded each.shows': { 'cnt': 0, 'time': 0 },
28}
29
30var ranks = new Array();
31
32$(document).ready(function() {
33
34    $('[data-hook="stoelkeuze_info"]').hide();
35
36    bestel_app.booking.ranks.on('add remove reset',function( rank ){
37        var $li = $('<li>')
38            .addClass('rank rank-' + rank.get('id'))
39            .html(rank.get('title'));
40        ranks.push( $li );
41        $('#legend ul').prepend( ranks );
42    });
43
44
45    $('.js_bestseat').click(function(){
46        $('#rang_amount').prop('readonly', false);
47        $('#rang_id').prop('disabled', false);
48        $('#rang_id_hidden').prop('disabled', true).val('');
49        itixCartController.selectedSeats = [];
50        itixCartController.removeSeatSelection();
51    });
52
53
54    bestel_app.on('booking',function(event, obj){
55        switch(event){
56            case 'change:totalAmount':
57                if ( obj.totalAmount > 0 ) {
58                    $('[data-action="submit"]').removeClass('hide');
59                } else {
60                    $('[data-action="submit"]').addClass('hide');
61                }
62                break;
63            case 'change:totalPrice':
64                $('[data-hook~="cart-price-total"]').html(formatPrice(bestel_app.booking.totalPrice));
65                break;
66        }
67    });
68
69
70    $('body').on('click', '[data-action="submit"]', function() {
71        $(this).addClass('hide');
72
73        var $show = $('[data-hook~="order-show"]');
74        bestel_app.booking.ranks.getSelected().id;
75
76        // Get selected pricecodes
77        var seatInfo = [];
78        var counter = 1;
79        var discountsObj = bestel_app.booking.discounts.getSelected();
80        var discounts = new Array();
81        _.each(discountsObj, function(dc){
82            discounts.push(dc.all);
83        });
84
85        _.each(bestel_app.booking.pricecodes.getSelected(), function (pricecode) {
86            for (i = 0; i < pricecode.amount; i++) {
87                var discountIndex = _.findIndex(discounts, {pricecodeId: pricecode.id});
88                if ( discountIndex > -1 ) {
89                    var pricecodeDiscount = discounts[discountIndex];
90                    discounts.splice(discountIndex, 1);
91                }
92                var ticketInfo = {seatNumber: counter, pricecode: pricecode.id};
93                if (pricecodeDiscount && pricecodeDiscount.amount > 0) {
94                    ticketInfo.discount = parseInt(pricecodeDiscount.id);
95                    pricecodeDiscount.amount -= 1;
96                } else {
97                    ticketInfo.discount = 0;
98                }
99                seatInfo.push(ticketInfo);
100                counter += 1;
101            }
102        });
103
104        var arrangementInfo = [];
105        _.each(bestel_app.booking.arrangements.getSelected(), function (arrangement) {
106            _.each(arrangement.pricecodes.getSelected(), function (pricecode) {
107                for (i = 0; i < pricecode.amount; i++) {
108                    arrangementInfo.push({arrangementId: arrangement.id, pricecode: pricecode.id});
109                }
110            });
111        });
112
113        var articleInfo = [];
114        _.each(bestel_app.booking.articles.getSelected(), function (article) {
115            articleInfo.push({articleId: article.id, amount: article.amount});
116        });
117
118        // If bestavailable, then remove any previously selected seats. This prevents an incompatability
119        // between the total amount of seats and the actual selection (loaded from the previous booking)
120        // TODO: move this to the bestel_app
121        if($('[data-hook="seatselection-bestavailable"]').hasClass('selected')) {
122            bestel_app.booking.selectedSeats = new Array;
123        }
124
125        // Send complete booking to server
126        // Triggers "cart-add-booking-success" or "cart-add-booking-failed"
127        messageService.clearErrors('');
128        itixCartController.addBooking({
129            show_id: $show.attr('data-showid'),
130            rank_id: bestel_app.booking.ranks.getSelected().id,
131            seat_options: seatInfo,
132            seats: bestel_app.booking.selectedSeats,
133            arrangement_options: arrangementInfo,
134            article_options: articleInfo,
135            overwrite_existing_booking: true,
136            success: function () {
137                if (typeof relatedSeries != 'undefined' && relatedSeries.length > 2) {
138                    if (Modernizr.localstorage) {
139                        localStorage.setItem('lastShowSeriesAlert', relatedSeries);
140                    }
141                }
142                document.location = '/winkelwagen/';
143            },
144            failed: function() {
145                $('[data-action="submit"]').removeClass('hide');
146            }
147        });
148    });
149
150
151    $('body').on('show-ranks-loaded',function(event, data){
152        bestel_app.booking.ranks.set(data.message);
153        stoelkeuze_app.settings.ranks = data.message;
154    });
155
156    $('[data-hook="stoelkeuze_message_totalamount"]').html(bestel_app.booking.totalAmount);
157    bestel_app.on('booking',function(event){
158        if ( event == 'change:totalAmount' ) {
159            // trigger om prijcodes op te halen
160            var $show = $('[data-hook~="order-show"]');
161            var itixShow = new ItixShow($show.attr('data-showid'), $show);
162            itixShow.getPriceCodes({
163                rank_id: bestel_app.booking.ranks.getSelected().id,
164                amount: bestel_app.booking.totalAmount
165            });
166
167            $('[data-hook="stoelkeuze_message_totalamount"]').html(bestel_app.booking.totalAmount);
168        }
169    });
170
171    bestel_app.on('ranks',function(event){
172        if ( event == 'change:selected' ) {
173            // trigger om prijcodes op te halen
174            var $show = $('[data-hook~="order-show"]');
175            var itixShow = new ItixShow($show.attr('data-showid'), $show);
176            itixShow.getPriceCodes({
177                rank_id: bestel_app.booking.ranks.getSelected().id,
178                amount: bestel_app.booking.totalAmount
179            });
180        }
181    });
182
183    $('body').on('show-pricecodes-loaded',function(event, data){
184        var pricecodes = [];
185        if( data.message.length > 0 ) {
186            _.each(data.message[0], function (item) {
187                var pricecode = {
188                    id: parseInt(item.id),
189                    title: item.label,
190                    defaultPrice: parseFloat(item.prijs),
191                    additionalPrice: isNaN(parseFloat(item.toeslag)) ? 0 : parseFloat(item.toeslag)
192                };
193
194                if (0 > $.inArray(pricecode, pricecodes)) {
195                    pricecodes.push(pricecode);
196                }
197            });
198            bestel_app.booking.pricecodes.set(pricecodes);
199
200            if (data.message[0].length > 1) {
201                bestel_app.view.viewSelectShowPricesBlock.viewPricecodes.views[0].noInput = true
202            }
203        }
204    });
205
206    bestel_app.on('pricecodes',function(event, object){
207        if ( event == 'change:totalPrice' || event == 'change:amount') {
208            if (parseInt(bestel_app.booking.totalAmount) == bestel_app.booking.totalAmountByPricecodes) {
209                var $show = $('[data-hook~="order-show"]');
210                var itixShow = new ItixShow($show.attr('data-showid'), $show);
211
212                var pcs = bestel_app.booking.pricecodes.filter(function (pc) {
213                    return pc.amount > 0;
214                });
215
216                var priceCodes = new Object();
217                var counter = 1;
218                _.each(pcs, function (pc) {
219                    for (i = 0; i < pc.amount; i++) {
220                        priceCodes[counter] = pc.id;
221                        counter++;
222                    }
223                });
224
225                itixShow.getDiscounts({
226                    rank_id: bestel_app.booking.ranks.getSelected().id,
227                    priceCodes: priceCodes
228                });
229            }
230        }
231    });
232
233    $body.on('show-discounts-loaded',function(event,data) {
234        var discounts = [];
235        _.each(data.message, function (ticketitem) {
236            _.each(ticketitem, function(item) {
237                if (item.korting > 0) {
238
239                    var found = false;
240                    _.each(discounts, function(loopDiscount) {
241                        if ( item.id == loopDiscount.discountId && item.pricecode_id == loopDiscount.pricecodeId ) {
242                            loopDiscount.maxAmount += 1;
243                            found = true;
244                        }
245                    });
246
247                    if ( !found ) {
248                        discounts.push({
249                            discountId: parseInt(item.id),
250                            pricecodeId: item.pricecode_id,
251                            discount: item.korting,
252                            price: item.prijs,
253                            label: item.label,
254                            credits: item.credits,
255                            maxAmount: 1
256                        });
257                    }
258                }
259            });
260        });
261        bestel_app.booking.discounts.reset();
262        bestel_app.booking.discounts.set(discounts);
263    });
264
265    $('body').on('cart-loaded',function(event,data) {
266        var shows = data.message.shows;
267        var arrangements = data.message.arrangements;
268        var articles = data.message.articles;
269
270        var bundles = data.message.bundles;
271
272        var bookingInfo = {
273            amount: 0,
274            rankId: 0,
275            pricecodes: {},
276            discounts: {},
277            arrangements: {},
278            articles: {}
279        }
280
281        _.each(shows, function(show){
282            if ( show.showid == currentShowId ) {
283                $('[data-hook="order-data-select"]').hide();
284                if ( show.seatInfo.length > 0 ) {
285
286                    $('[data-hook="stoelkeuze_info"]').show();
287                    $('[data-hook="stoelkeuze_info_seats"]').html('');
288
289                    _.each(show.seatInfo,function(seat){
290                        stoelkeuze_app.preSelectedSeats.add({
291                            id: seat.id,
292                            rank: seat.rang,
293                            seat: seat.stoel,
294                            row: seat.rij,
295                            lc: seat.vak,
296                            sa: true,
297                            occ: false
298                        });
299
300                        $('[data-hook="stoelkeuze_info_seats"]').append('Vak: '+seat.vak+', rij: '+seat.rij+', stoel: '+seat.stoel+'<br />');
301                    });
302
303                    bestel_app.booking.seatSelectionType = 'userdefined';
304                }
305                _.each(show.bookings, function(booking) {
306
307                    bestel_app.bookingIds.push(booking.booking_id);
308
309                    bookingInfo.amount += booking.amount;
310                    bookingInfo.rankId = booking.rank_id;
311                    if ( !bookingInfo.pricecodes[booking.pricecode_id] ) {
312                        bookingInfo.pricecodes[booking.pricecode_id] = 0;
313                    }
314                    bookingInfo.pricecodes[booking.pricecode_id] += booking.amount;
315
316                    _.each(booking.discounts, function(discount){
317                        if ( !bookingInfo.discounts[discount.discount_id+'_'+discount.pricecode_id] ) {
318                            bookingInfo.discounts[discount.discount_id+'_'+discount.pricecode_id] = 0;
319                        }
320                        bookingInfo.discounts[discount.discount_id+'_'+discount.pricecode_id] += discount.amount;
321                    });
322
323                    _.each(bundles,function(bundle){
324                        if (bundle.indexOf(booking.booking_id) > -1) {
325                            var found = false;
326                            _.each(articles,function(article){
327                                if ( bundle.indexOf(article.booking.booking_id) > -1 ) {
328                                    // add article to list
329                                    bookingInfo.articles[article.articleid] = article.booking.amount;
330                                }
331                            });
332
333                            _.each(arrangements, function(arrangement) {
334                                _.each(arrangement.bookings, function(booking){
335                                    if ( bundle.indexOf(booking.booking_id) > -1 ) {
336                                        if ( typeof bookingInfo.arrangements[arrangement.arrangementid] == 'undefined' ) {
337                                            bookingInfo.arrangements[arrangement.arrangementid] = {};
338                                        }
339                                        bookingInfo.arrangements[arrangement.arrangementid][booking.pricecode_id] = booking.amount;
340                                    }
341                                });
342                            });
343                        }
344                    });
345                });
346            }
347        });
348
349        if ( bookingInfo.amount > 0 ) {
350            var totalAmountIntervalCounter = 0;
351            var totalAmountInterval = setInterval(function () {
352                if (totalAmountIntervalCounter++ > 25) {
353                    clearInterval(totalAmountInterval);
354                }
355                if (bestel_app.booking.ranks.length) {
356                    bestel_app.autoAdjustAmounts = false;   // disable auto adjusting amount fields
357                    bestel_app.booking.totalAmount = bookingInfo.amount;
358                    stoelkeuze_app.maxSeats = bookingInfo.amount;
359                    bestel_app.booking.ranks.get(bookingInfo.rankId).selected = true;
360                    clearInterval(totalAmountInterval);
361
362                    var pricecodeIntervalCounter = 0;
363                    var pricecodeInterval = setInterval(function () {
364                        if (pricecodeIntervalCounter++ > 25) {
365                            clearInterval(pricecodeInterval);
366                        }
367                        if (bestel_app.booking.pricecodes.length) {
368                            clearInterval(pricecodeInterval);
369                            _.each(bookingInfo.pricecodes, function (pc_amount, pricecode_id) {
370                                bestel_app.booking.pricecodes.get(pricecode_id).set('amount', pc_amount);
371                            });
372
373                            bestel_app.autoAdjustAmounts = true;    // enable auto adjusting amount fields
374
375                            _.each(bookingInfo.arrangements, function (arrangement, arrangementId) {
376                                _.each(arrangement, function (amount, pc) {
377                                    bestel_app.booking.arrangements.get(arrangementId).totalAmount += amount;
378                                })
379                            });
380
381                            if (_.size(bookingInfo.discounts)) {
382                                var discountsIntervalCounter = 0;
383                                var discountsInterval = setInterval(function () {
384                                    if (discountsIntervalCounter++ > 25) {
385                                        clearInterval(discountsInterval);
386                                    }
387                                    if (bestel_app.booking.discounts.length) {
388                                        clearInterval(discountsInterval);
389                                        _.each(bookingInfo.discounts, function (dc_amount, code) {
390                                            bestel_app.booking.discounts.find({id: code}).amount = dc_amount;
391                                        });
392                                    }
393                                }, 100);
394                            }
395
396                        }
397                    }, 100);
398
399
400                }
401            }, 100);
402
403            // Artikelen toevoegen
404            _.each(bookingInfo.articles, function (amount, articleid) {
405                bestel_app.booking.articles.get(articleid).amount = amount;
406            });
407        }
408
409        var options = {};
410        options.bookingId = bestel_app.bookingIds;
411        options.success = function(data){
412            stoelkeuze_app.showId = currentShowId;
413            stoelkeuze_app.seatSelectionId = data.message.seatselectionid;
414
415            bestel_app.booking.selectedSeats = ( typeof data.message.seats == "undefined" ? [] : data.message.seats );
416
417//              stoelkeuze_samenvatting_app.showId = currentShowId;
418//              stoelkeuze_samenvatting_app.seats.fetchForShow();
419
420            $('[data-hook="seatselection-userdefined"]').on('click',function(){
421                if ( stoelkeuze_app.seats.length == 0 ) {
422                    $(this).addClass('is-loading').find('.load-default-text').html('&nbsp;');
423                    stoelkeuze_app.seats.fetchForShow();
424                } else {
425                    $.fancybox(seatSelectionObj);
426                }
427            });
428
429            $('[data-hook="stoelkeuze_message_selectedamount"]').html(stoelkeuze_app.getSelectedSeats().length);
430
431            stoelkeuze_app.seats.on('sync',function(){
432                if ( typeof data.message.seats != 'undefined' ) {
433                    _.each(data.message.seats,function(seat){
434                        stoelkeuze_app.seats.get(seat).occ = false;
435                        stoelkeuze_app.seats.get(seat).selected = true;
436                    })
437                }
438            });
439
440//              stoelkeuze_samenvatting_app.seats.on('sync',function(){
441//                  if ( typeof data.message.seats != 'undefined' ) {
442//                      _.each(data.message.seats,function(seat){
443//                          stoelkeuze_app.seats.get(seat).occ = false;
444//                          stoelkeuze_app.seats.get(seat).selected = true;
445//                      })
446//                  }
447//              });
448
449            stoelkeuze_app.on('error', function(error) {
450                $('[data-hook="stoelkeuze_messages"]').html(transError(error.message.code,stoelkeuzeErrors)).addClass('active');
451                $('[data-hook="seatselection-confirm"]').addClass('hide');
452            });
453
454            stoelkeuze_app.on('selectSeat',function(seats){
455                $('[data-hook="stoelkeuze_messages"]').html('').removeClass('active');
456                $('[data-hook="stoelkeuze_message_selectedamount"]').html(stoelkeuze_app.getSelectedSeats().length);
457                $('[data-hook="stoelkeuze_message_totalamount"]').html(bestel_app.booking.totalAmount);
458
459                if (bestel_app.booking.totalAmount == stoelkeuze_app.getSelectedSeats().length) {
460                    $('[data-hook="seatselection-confirm"]').removeClass('hide');
461                } else {
462                    $('[data-hook="seatselection-confirm"]').addClass('hide');
463                }
464
465                var selectedSeats = new Array();
466                _.each(seats, function(seat){
467                    selectedSeats.push(seat.id);
468                });
469                bestel_app.booking.selectedSeats = selectedSeats;
470
471                if ( seats.length > 0 ) {
472                    bestel_app.booking.ranks.get(seats[0].rank).selected = true;
473                }
474            });
475            bestel_app.on('booking',function(event,obj){
476                if ( event == 'change:totalAmount') {
477                    stoelkeuze_app.maxSeats = bestel_app.booking.totalAmount;
478                }
479            });
480        }
481
482        itixCartController.getSeatSelectionId(options);
483    });
484
485
486
487    stoelkeuze_app.on('selectSeat', function (seats) {
488        $('[data-hook="stoelkeuze_info_seats"]').html('');
489        _.each(seats, function (seat) {
490            $('[data-hook="stoelkeuze_info_seats"]').append('Vak: ' + seat.lc + ', rij: ' + seat.row + ', stoel: ' + seat.seat + '<br />');
491        });
492        if (seats.length > 0) {
493            $('[data-hook="stoelkeuze_info"]').show();
494        } else {
495            $('[data-hook="stoelkeuze_info"]').hide();
496        }
497    });
498
499
500    stoelkeuze_app.on('seatplan-loaded', function () {
501        var $obj = $('[data-hook="seatselection-userdefined"]');
502        $('.loading-message').hide();
503        $obj.find('.load-default-text').html($obj.attr('data-text'));
504        $obj.removeClass('is-loading');
505        $.fancybox(seatSelectionObj);
506    });
507
508
509});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.