1(function(window, $) { 2 3 'use strict'; 4 5 /****************************/ 6 /* */ 7 /* SewobeProductTable */ 8 /* */ 9 /****************************/ 10 11 /* Constructor */ 12 var $overlay = null; 13 var SewobeProductTable = function(element, options) { 14 var _this = this; 15 this.el = element; 16 var $el = $(this.el); 17 this.$viewport = $el.find('.sewobe-product-table-detail'); 18 19 // Check if criteria for mobile apply. If they do, use SewobeOverlay and hide right column. 20 // if (('ontouchstart' in document.documentElement) || $(window).innerWidth() < 799) { 21 $el.find('.sewobe-accordion-list tr.product-row, .sewobe-accordion-list tr.product-row.amount-row, .sewobe-accordion-list tr.amount-row').each(function() { 22 var $this = $(this); 23 $this.on({ 24 'click': _this.onProductTouchstart.bind(_this) 25 }); 26 $this.find('.amount input, .weekly-amount input').on({ 27 /** 2019-07-18 - MW - Events erweitert für Keypresses */ 28 'change keyup mouseup': _this.onAmountChange.bind(_this) 29 }); 30 // $this.next('.amount-row').find('input').on({ 31 // /** 2019-07-18 - MW - Events erweitert für Keypresses */ 32 // 'change keyup mouseup': _this.onDailyAmountChange.bind(_this) 33 // }); 34 }); 35 $('.sewobe-product-table-detail').hide(); 36 _this.overlay = new SewobeOverlay(); 37 // } // else { 38 // $el.find('.sewobe-accordion-list tr.product-row, .sewobe-accordion-list tr.product-row.amount-row, .sewobe-accordion-list tr.amount-row').each(function() { 39 // var $this = $(this); 40 // $this.on({ 41 // 'mouseenter': _this.onProductMouseenter.bind(_this), 42 // 'mouseleave': _this.onProductMouseleave.bind(_this) 43 // }); 44 // $this.find('.amount input, .weekly-amount input').on({ 45 // /** 2019-07-18 - MW - Events erweitert für Keypresses */ 46 // 'change keyup mouseup': _this.onAmountChange.bind(_this) 47 // }); 48 // $this.next('.amount-row').find('input').on({ 49 // /** 2019-07-18 - MW - Events erweitert für Keypresses */ 50 // 'change keyup mouseup': _this.onDailyAmountChange.bind(_this) 51 // }); 52 // }); 53 // if ($('.sewobe-product-table-detail').length > 0) { 54 // this.$viewport.affix({ 55 // offset: { 56 // top: $('.sewobe-product-table-detail').offset().top 57 // } 58 // }); 59 // } 60 // 61 // this.$viewport.on({ 62 // 'affix.bs.affix': this.onViewportAffix.bind(this), 63 // 'affix-top.bs.affix': this.onViewportAffixTop.bind(this) 64 // }); 65 // } 66 67 if ($('#date-start').val() == '') { 68 $el.children('.empty-only').show(); 69 } else { 70 $el.children('.empty-only').hide(); 71 } 72 73 $el.find('table').each(function() { 74 var $table = $(this); 75 76 $table.find('tr.product-row').each(function() { 77 var $row = $(this); 78 79 if ($row.next('.amount-row').length) { 80 _this.updateWeeklyAmount($row); 81 } else { 82 _this.updateItemAmountPrice($row); 83 } 84 }); 85 }); 86 this.updateTotalPrice(); 87 }; 88 89 /* Class */ 90 91 SewobeProductTable.prototype = { 92 constructor: SewobeProductTable, 93 94 onCategoryOpen: function(e) { 95 var $target = $(e.target); 96 97 if ($target.find('.product-row .amount > .amount-table').length) { 98 $target.find('table tr.product-row').each(function() { 99 var $this = $(this); 100 var $amountRow = $('<tr class="amount-row"><td colspan="7"></td></tr>'); 101 $this.after($amountRow); 102 103 $amountRow.children('td').append($this.find('.amount-table')); 104 }) 105 } 106 }, 107 108 onProductTouchstart: function(e) { 109 if ($(e.target).is('input')) { 110 return 111 } else { 112 var $target = $(e.target).closest('tr.product-row'), 113 $detailContent = $target.find('.detail > *').clone(), 114 title = $target.find('.title').text(), 115 $target = $(e.target).closest('tr.product-row'); 116 var data = ""; 117 // 2018-01-17 MW: SC-26100 Ajaxcall fehlerhaft 118 //Sofern Mandant_Key vorhanden 119 if ($('#MANDANT_KEY').length > 0) { 120 data += "MANDANT_KEY="+$('#MANDANT_KEY').val()+"&"; 121 } 122 //Sofern Session vorhanden 123 if ($('#SESSION').length > 0) { 124 data += "SESSION="+$('#SESSION').val()+"&"; 125 } 126 data += "MODE=1&ARTIKEL_NR="+$target.find('#AID').val()+"&IS_AJAX=true",
127 $overlay = this.overlay; 128 $.post(appendSessionParams(swb.getBasisUrl() + "lieferdienst/getDeliveryContent"),data) 129 .done( function( result) { 130 var json = JSON.parse(result), 131 $viewport = $('.sewobe-product-table-detail'); 132 var $oDetail = $("<div></div>"); 133 if (typeof json.DATA !== 'undefined') { 134 if (typeof json.DATA.AJAX !== 'undefined') { 135 var $oImg = $("<img>"); 136 var $oDescription = $("<div></div>"); 137 var $oPriceChange = $("<div><b></b></div>"); 138 if (typeof json.DATA.AJAX.LABEL !== 'undefined') { 139 $overlay.setTitle(json.DATA.AJAX.LABEL); 140 } 141 if (typeof json.DATA.AJAX.IMAGE_PATH !== 'undefined') { 142 if (json.DATA.AJAX.IMAGE_PATH !== false){ 143 $($oDetail).append($oImg.attr({src: json.DATA.AJAX.IMAGE_PATH})); 144 } 145 } 146 if (typeof json.DATA.AJAX.DESCRIPTION !== 'undefined') { 147 $($oDetail).append($oDescription.addClass('description').html(json.DATA.AJAX.DESCRIPTION)); 148 } 149 if (typeof json.DATA.AJAX.PRICE_CHANGE_STATE !== false) { 150 $($oDetail).append($oPriceChange.addClass('pricechange').html(json.DATA.AJAX.PRICE_CHANGE_MESSAGE)); 151 } 152 } 153 } 154 $overlay.loadContent($oDetail); 155 $overlay.open(); 156 }); 157 } 158 }, 159 160 onViewportAffix: function(e) { 161 var $target = $(e.target); 162 $target.css({ 163 left: $target.offset().left, 164 width: $target.outerWidth() 165 }); 166 }, 167 168 onViewportAffixTop: function(e) { 169 var $target = $(e.target); 170 $target.css({ 171 left: 'auto', 172 width: '' 173 }); 174 }, 175 176 onProductMouseenter: function(e) { 177 var $target = $(e.target).closest('tr.product-row'); 178 179 $target.addClass('active'); 180 // 2019-11-12 - MW - SC-30993 - Bugfix: Bei Einzelbestellungen sind product-row und amount-row die gleiche, sonst wird das nächste Produkt mit gehovert 181 if (!$target.hasClass('amount-row')) { 182 $target.next('.amount-row').addClass('active'); 183 } 184 185 186 this.$viewport.children('.loader').show(); 187 this.$viewport.children('.info').hide(); 188 189 var data = ""; 190 if ($('#MANDANT_KEY').length > 0) { 191 data += "MANDANT_KEY="+$('#MANDANT_KEY').val()+"&"; 192 } 193 data += "MODE=1&ARTIKEL_NR="+$target.find('#AID').val()+"&IS_AJAX=true"; 194 $.post(appendSessionParams(swb.getBasisUrl() + "lieferdienst/getDeliveryContent"),data) 195 .done( function( result) { 196 var json = JSON.parse(result), 197 $viewport = $('.sewobe-product-table-detail'); 198 var $oDetail = $("<div></div>"); 199 if (typeof json.DATA !== 'undefined') { 200 if (typeof json.DATA.AJAX !== 'undefined') { 201 var $oLabel = $("<h3></h3>"); 202 var $oImg = $("<img>"); 203 var $oDescription = $("<div></div>"); 204 var $oPriceChange = $("<div><b></b></div>"); 205 if (typeof json.DATA.AJAX.LABEL !== 'undefined') { 206 $($oDetail).append($oLabel.text(json.DATA.AJAX.LABEL)); 207 } 208 if (typeof json.DATA.AJAX.IMAGE_PATH !== 'undefined') { 209 if (json.DATA.AJAX.IMAGE_PATH !== false){ 210 $($oDetail).append($oImg.attr({src: json.DATA.AJAX.IMAGE_PATH})); 211 } 212 } 213 if (typeof json.DATA.AJAX.DESCRIPTION !== 'undefined') { 214 $($oDetail).append($oDescription.addClass('description').html(json.DATA.AJAX.DESCRIPTION)); 215 } 216 if (typeof json.DATA.AJAX.PRICE_CHANGE_STATE !== false) { 217 $($oDetail).append($oPriceChange.addClass('pricechange').html(json.DATA.AJAX.PRICE_CHANGE_MESSAGE)); 218 } 219 } else { 220 $viewport.children('.loader').hide(); 221 $viewport.children('.info').show(); 222 } 223 } else { 224 $viewport.children('.loader').hide(); 225 $viewport.children('.info').show(); 226 } 227 $viewport.children('.updatable').html($oDetail); 228 $viewport.children('.loader').hide(); 229 $viewport.children('.info').hide(); 230 }) 231 .fail(function() { 232 var $viewport = $('.sewobe-product-table-detail'); 233 $viewport.children('.info').show(); 234 $viewport.children('.updatable').empty(); 235 $viewport.children('.loader').hide(); 236 }); 237 }, 238 onProductMouseleave: function(e) { 239 var $target = $(e.target).closest('tr.product-row'); 240 $target.removeClass('active'); 241 $target.next('.amount-row').removeClass('active'); 242 this.$viewport.children('.updatable').empty(); 243 this.$viewport.children('.info').show(); 244 }, 245 246 onAmountChange: function(e) { 247 var $target = $(e.target), 248 $el = $(this.el), 249 $td = $target.closest('td'), 250 $row = $td.closest('tr.product-row') || $td.closest('tr').prev('.product-row'); 251 if ($target.val() === '' || $target.val() <= 0) { 252 $target.val(''); 253 } else { 254 // Validiere Zahlen (Nur Ganzzahlen erlaubt 255 $target.val(Math.floor($target.val().replace(",","."))); 256 } 257 this.updateItemAmountPrice($row); 258 }, 259 260 onDailyAmountChange: function(e) { 261 var $target = $(e.target), 262 $productRow = $target.closest('tr.amount-row').prev('tr.product-row'); 263 264 this.updateWeeklyAmount($productRow); 265 }, 266 267 updateWeeklyAmount: function($productRow) { 268 var $weeklyInput = $productRow.find('.weekly-amount > input'), 269 $amountRow = $productRow.next('tr.amount-row'), 270 weeklyAmount = 0; 271 272 $amountRow.find('td tbody td').each(function() { 273 var $td = $(this), 274 $input = $td.find('input'); 275 276 if (!$input.hasClass('ignore') && $input.length) { 277 weeklyAmount += parseInt($input.val() === '' ? 0 :$input.val()); 278 279 } 280 }); 281 282 $weeklyInput 283 .attr('value', weeklyAmount); 284 this.updateItemAmountPrice($productRow); 285 }, 286 287 updateItemAmountPrice: function($row) { 288 // 2021-05-12 - KM - Mit MW Korrektur von Preisberechnung, welche einen Bug in den Scopes hatte 289 var $target = $row.find('.amount > input, .weekly-amount > input'), 290 $table = $target.closest('table.collapsible-content-wrapper'), 291 $pricerow = $row.prev('.price-row'), 292 amount = 0,
293 $pricetd = $pricerow.length > 0 ? $pricerow.find('.price') : $row.find('.price'), 294 $totaltd = $pricerow.length > 0 ? $pricerow.find('.row-total') : $row.find('.row-total'), 295 price = parseFloat($pricetd.attr('data-price')); 296 for (let item of $target) { 297 amount += parseFloat($(item).val() === '' ? 0 :$(item).val()) 298 } 299 let total = roundPrice(amount * price, 2); 300 $totaltd.text(total.replace('.', ',') + ' ' + $($(document).find('td[data-waehrung]')[0]).attr("data-waehrung")).attr('data-price', total); 301 302 this.updateCategoryPrice($table); 303 this.updateTotalPrice(); 304 }, 305 306 updateCategoryPrice: function($table) { 307 if ($table.is('.amount-table')) { 308 $table = $table.prev('.product-table'); 309 } 310 311 var $categoryPriceEl = $table.closest('li').find('.category-price'), 312 categoryPrice = 0; 313 $table.find('td.row-total').each(function() { 314 var $this = $(this); 315 categoryPrice = parseFloat(categoryPrice) + parseFloat( roundPrice($this.attr('data-price'), 2) ); 316 }); 317 318 if (categoryPrice == 0) { 319 $categoryPriceEl.children('.empty').show(); 320 $categoryPriceEl.children('.price-content').hide(); 321 } else { 322 $categoryPriceEl.children('.empty').hide(); 323 $categoryPriceEl.children('.price-content').show().html((roundPrice(categoryPrice, 2) + ' ' + $($(document).find('td[data-waehrung]')[0]).attr("data-waehrung")).replace('.', ',')); 324 } 325 326 $categoryPriceEl.attr('data-price', roundPrice(categoryPrice, 2)) 327 }, 328 329 updateTotalPrice: function() { 330 var $el = $(this.el); 331 var totalPrice = 0; 332 $el.find('.category-price').each(function() { 333 var $this = $(this); 334 totalPrice = parseFloat(totalPrice) + parseFloat( roundPrice($(this).attr('data-price'), 2)); 335 }); 336 // 2020-10-01 - MW - Scope auf das eigentliche Form angepasst 337 var edit_mode = $el.closest('form').find('input[name=EDIT_MODE]').val(); 338 var articles = $('input[name^="ARTIKEL"]'); 339 var blnCHECKOUT = false; 340 for(var i = 0; i < articles.length; i++) { 341 //2019-04-05 MW: Wenn Wert 0, dann Feld leeren fuer Folgecheck 342 if (articles[i].value === '0') { 343 articles[i].value = ''; 344 } 345 if (articles[i].value !== '') { 346 blnCHECKOUT = true; 347 } 348 } 349 if (totalPrice.toFixed(2) == 0.00 && !blnCHECKOUT) { 350 $('#total-price').children('.updatable').hide(); 351 $('#total-price').children('.total-empty').show(); 352 if (edit_mode > 0) { 353 $('.lieferdienst').find($('button.btn-primary:submit').prop("disabled", true)); 354 } 355 } else { 356 $('#total-price').children('.updatable').show(); 357 $('#total-price').children('.updatable').children('.price').html(formatPrice(totalPrice)); 358 $('#total-price').children('.total-empty').hide(); 359 if (edit_mode > 0 && blnCHECKOUT == true) { 360 $('.lieferdienst').find($('button.btn-primary:submit').prop("disabled", false)); 361 } 362 } 363 } 364 }; 365 366 $.fn.sewobeProductTable = function(option, val) { 367 return this.each(function() { 368 var options = {}; 369 new SewobeProductTable(this, $.extend({}, $.fn.sewobeProductTable.defaults, options)); 370 } 371 ); 372 }; 373 374 $.fn.sewobeProductTable.defaults = {}; 375 376 /* Init */ 377 378 $('.sewobe-product-table').each(function() { 379 $(this).closest('.input-grp').append('<i class="sewobe-icon-events"></i>'); 380 $(this).sewobeProductTable(); 381 }); 382})(window, jQuery); 383 384function formatPrice(value) { 385 return roundPrice(value, 2).replace('.', ',') + ' '+$($(document).find('td[data-waehrung]')[0]).attr("data-waehrung"); 386} 387 388function roundPrice(value, decimals) { 389 return Number(Math.round(value+'e'+decimals)+'e-'+2).toFixed(2); 390}
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.