Homparty dev

This commit is contained in:
Kevin Adametz 2020-12-16 20:03:51 +01:00
parent 9252094a04
commit ac0d5b781e
60 changed files with 3443 additions and 293 deletions

284
public/js/iq-homeparty-cart.js Executable file
View file

@ -0,0 +1,284 @@
var IqHomepartyCart = {
form: "#homeparty-order-form",
btn_modal_add: '.add-product-basket',
btn_add: '.add-from-basket',
btn_remove: '.remove-from-basket',
table_input: '.table-input-event-onchange',
oTable: null,
cart_holder: '#insert_show_products_order_',
cart_holders: '.insert_show_products_order',
modal: '#modals-load-content',
remove_item_cart: '.remove_item_form_cart',
insert_show_total_order: '#insert_show_total_order',
insert_show_bonus: '#insert_show_bonus',
insert_show_bonus_host: '#insert_show_bonus_host',
/*
comp_holder: '#holder_html_view_comp_product',
is_for: null,
url: null,
btn_clear: '#clear-products-basket',
cart_input: '.cart-input-event-onchange',
remove_item: '.remove_item_form_cart',
shipping_state: '#change_shipping_state',
comp_products: 'switchers-comp-product',
count_comp_products: 'count_comp_products',
shipping_is_for: 'shipping_is_for',*/
_log: function ($msg){
console.log($msg);
},
init: function () {
var _self = this;
_self.url = $(_self.form).attr('action');
_self._log(_self.url);
$(_self.cart_holders).each(function (key, obj){
_self.reInit($(obj));
});
//_self.showInit();
/*$(_self.shipping_state).on('change', function(){
_self.update_shipping_state($(this));
});*/
return _self;
},
setDatabase: function (oTable){
var _self = this;
_self._log($(oTable));
_self.oTable = oTable;
},
reInitModal: function (){
var _self = this;
$(_self.oTable).find(_self.btn_modal_add).on('click', function(){
_self.add_product_modal($(this))
});
},
add_product_modal: function (_obj){
var _self = this;
_self.performRequest({
product_id: _obj.data('product-id'),
homeparty_id: $(_self.oTable).data('homeparty-id'),
homeparty_user_id: $(_self.oTable).data('homeparty-user-id'),
qty: 1,
action: 'addProduct'
}).done(_self.refreshView);
},
reInit: function (obj){
var _self = this;
var _obj = obj;
obj.find(_self.btn_add).off('click').on('click', function(){
_self.add_product($(this), _obj)
});
obj.find(_self.btn_remove).off('click').on('click', function(){
_self.remove_product($(this), _obj)
});
obj.find(_self.table_input).off('change').on('change', function(){
_self._log($(this));
_self.update_input_table($(this), _obj);
});
obj.find(_self.remove_item_cart).off('click').on('click', function(){
_self.remove_from_cart($(this), _obj);
});
},
add_product: function (_obj, _holder){
var _self = this;
var input = _holder.find('input[name="product_qty_'+_obj.data('order-item-id')+'"]');
var qty = parseInt(input.val()) + 1;
qty = _self.checkNumber(qty);
input.val(qty);
_self.update_cart(_holder, _obj, qty);
},
remove_product: function (_obj, _holder){
var _self = this;
var input = _holder.find('input[name="product_qty_'+_obj.data('order-item-id')+'"]');
var qty = parseInt(input.val()) - 1;
qty = _self.checkNumber(qty);
input.val(qty);
_self.update_cart(_holder, _obj, qty);
},
update_input_table: function (_obj, _holder){
var _self = this;
var qty = parseInt(_obj.val());
qty = _self.checkNumber(qty);
_obj.val(qty);
_self.update_cart(_holder, _obj, qty);
},
update_cart: function (_holder, _obj, qty){
var _self = this;
_self.performRequest({
product_id: _obj.data('product-id'),
order_item_id: _obj.data('order-item-id'),
homeparty_id: _holder.data('homeparty-id'),
homeparty_user_id: _holder.data('homeparty-user-id'),
qty: qty,
action: 'updateCart'
}).done(_self.refreshView);
},
remove_from_cart: function (_obj, _holder){
var _self = this;
_self.performRequest({
product_id: _obj.data('product-id'),
order_item_id: _obj.data('order-item-id'),
homeparty_id: _holder.data('homeparty-id'),
homeparty_user_id: _holder.data('homeparty-user-id'),
action: 'removeFromCart'
}).done(_self.refreshView);
},
refreshView: function (data) {
var _self = IqHomepartyCart;
var obj = $(_self.cart_holder+data.data.homeparty_user_id)
obj.html(data.html_user_cart);
$(_self.insert_show_total_order).html(data.html_total);
$(_self.insert_show_bonus).html(data.html_bonus);
$(_self.insert_show_bonus_host).html(data.html_host_bonus);
$(_self.modal).modal('hide');
_self.reInit(obj);
//$(_self.comp_holder).html(data.html_comp);
// var input = $(_self.table).find('input[name="product_qty_'+data.data.product_id+'"]');
// input.val(data.data.qty);
// _self.showInit();
},
performRequest : function(data) {
var _self = this;
var url = _self.url,
contentType = 'application/x-www-form-urlencoded; charset=UTF-8';
console.log(data);
console.log(url);
return $.ajax({
url: url,
data: data,
type: "POST",
dataType: "json",
cache: false,
contentType: contentType,
encode: true,
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
})
.done(function (data) {
console.log('performRequest');
console.log(data);
}).fail(function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
console.log(jqXHR.responseText);
console.log(textStatus);
console.log(errorThrown);
console.log("Sorry, there was a problem!");
});
},
checkNumber : function(number){
if(number < 1 || isNaN(number)){
return 1;
}
if(number >= 100){
return 100;
}
return number;
},
/*
showInit: function (){
var _self = this;
$(_self.btn_clear).on('click', function (){
_self.performRequest({action: 'clearCart'})
.done(_self.refreshDatabaseRefreshAndView)
});
$(_self.cart_input).on('change', function(){
_self.update_input_cart($(this));
});
$(_self.remove_item).on('click', function(event){
event.preventDefault();
_self.update_cart_database($(this).data('product-id'), 0);
});
if(_self.is_for === 'me'){
$('input[name^="'+_self.comp_products+'"]').on('change', function(){
_self.update_comp_product($(this));
});
}
},
update_shipping_state : function (_obj){
var _self = this;
var id = parseInt(_obj.val());
var is_for = _obj.data('is-for');
_self.performRequest({shipping_country_id: id, shipping_is_for: is_for, action: 'updateShippingCountry'})
.done(_self.refreshItemsAndView);
},
update_input_table: function (_obj){
var _self = this;
var qty = parseInt(_obj.val());
qty = _self.checkNumber(qty);
_obj.val(qty);
_self.update_cart(_obj.data('product-id'), qty);
},
update_input_cart: function (_obj){
var _self = this;
var qty = parseInt(_obj.val());
qty = _self.checkNumber(qty);
_obj.val(qty);
_self.update_cart_database(_obj.data('product-id'), qty);
},
update_comp_product: function (_obj){
var _self = this;
_self.performRequest({comp_product_id: _obj.val(), comp_num: _obj.data('comp_num'), count_comp_products: $('input[name="'+_self.count_comp_products+'"]').val(), action: 'updateCompProduct'})
.done(_self.refreshItemsAndView);
},
update_cart_database: function (product_id, qty){
var _self = this;
_self.performRequest({product_id: product_id, qty: qty, action: 'updateCart'})
.done(_self.refreshDatabaseAndView);
},
update_cart: function (product_id, qty){
var _self = this;
_self.performRequest({product_id: product_id, qty: qty, action: 'updateCart'})
.done(_self.refreshItemsAndView);
},
refreshItemsAndView: function (data){
var _self = IqShoppingCart;
$(_self.cart_holder).html(data.html_cart);
$(_self.comp_holder).html(data.html_comp);
_self.showInit();
},
refreshDatabaseAndView: function (data) {
var _self = IqShoppingCart;
$(_self.cart_holder).html(data.html_cart);
$(_self.comp_holder).html(data.html_comp);
var input = $(_self.table).find('input[name="product_qty_'+data.data.product_id+'"]');
input.val(data.data.qty);
_self.showInit();
},
refreshDatabaseRefreshAndView : function (data){
var _self = IqShoppingCart;
$(_self.cart_holder).html(data.html_cart);
$(_self.comp_holder).html(data.html_comp);
_self.showInit();
_self.oTable.draw();
},
checkNumber : function(number){
if(number < 0 || isNaN(number)){
return 0;
}
if(number >= 100){
return 100;
}
return number;
},
*/
};

178
public/js/summernote-cleaner.js Executable file
View file

@ -0,0 +1,178 @@
/* https://github.com/DiemenDesign/summernote-cleaner */
(function (factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery'], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory(require('jquery'));
} else {
factory(window.jQuery);
}
}
(function ($) {
$.extend(true, $.summernote.lang, {
'en-US': {
cleaner: {
tooltip: 'Cleaner',
not: 'Text has been Cleaned!!!',
limitText: 'Text',
limitHTML: 'HTML'
}
}
});
$.extend($.summernote.options, {
cleaner: {
action: 'both', // both|button|paste 'button' only cleans via toolbar button, 'paste' only clean when pasting content, both does both options.
newline: '<br>', // Summernote's default is to use '<p><br></p>'
notStyle: 'position:absolute;top:0;left:0;right:0',
icon: '<i class="note-icon"><svg xmlns="http://www.w3.org/2000/svg" id="libre-paintbrush" viewBox="0 0 14 14" width="14" height="14"><path d="m 11.821425,1 q 0.46875,0 0.82031,0.311384 0.35157,0.311384 0.35157,0.780134 0,0.421875 -0.30134,1.01116 -2.22322,4.212054 -3.11384,5.035715 -0.64956,0.609375 -1.45982,0.609375 -0.84375,0 -1.44978,-0.61942 -0.60603,-0.61942 -0.60603,-1.469866 0,-0.857143 0.61608,-1.419643 l 4.27232,-3.877232 Q 11.345985,1 11.821425,1 z m -6.08705,6.924107 q 0.26116,0.508928 0.71317,0.870536 0.45201,0.361607 1.00781,0.508928 l 0.007,0.475447 q 0.0268,1.426339 -0.86719,2.32366 Q 5.700895,13 4.261155,13 q -0.82366,0 -1.45982,-0.311384 -0.63616,-0.311384 -1.0212,-0.853795 -0.38505,-0.54241 -0.57924,-1.225446 -0.1942,-0.683036 -0.1942,-1.473214 0.0469,0.03348 0.27455,0.200893 0.22768,0.16741 0.41518,0.29799 0.1875,0.130581 0.39509,0.24442 0.20759,0.113839 0.30804,0.113839 0.27455,0 0.3683,-0.247767 0.16741,-0.441965 0.38505,-0.753349 0.21763,-0.311383 0.4654,-0.508928 0.24776,-0.197545 0.58928,-0.31808 0.34152,-0.120536 0.68974,-0.170759 0.34821,-0.05022 0.83705,-0.07031 z"/></svg></i>',
keepHtml: true, //Remove all Html formats
keepOnlyTags: [], // If keepHtml is true, remove all tags except these
keepClasses: false, //Remove Classes
badTags: ['style', 'script', 'applet', 'embed', 'noframes', 'noscript', 'html'], //Remove full tags with contents
badAttributes: ['style', 'start'], //Remove attributes from remaining tags
limitChars: 0, // 0|# 0 disables option
limitDisplay: 'both', // none|text|html|both
limitStop: false // true/false
}
});
$.extend($.summernote.plugins, {
'cleaner': function (context) {
var self = this,
ui = $.summernote.ui,
$note = context.layoutInfo.note,
$editor = context.layoutInfo.editor,
options = context.options,
lang = options.langInfo;
var cleanText = function (txt, nlO) {
var out = txt;
if (!options.cleaner.keepClasses) {
var sS = /(\n|\r| class=(")?Mso[a-zA-Z]+(")?)/g;
out = txt.replace(sS, ' ');
}
var nL = /(\n)+/g;
out = out.replace(nL, nlO);
if (options.cleaner.keepHtml) {
var cS = new RegExp('<!--(.*?)-->', 'gi');
out = out.replace(cS, '');
var tS = new RegExp('<(/)*(meta|link|\\?xml:|st1:|o:|font)(.*?)>', 'gi');
out = out.replace(tS, '');
var bT = options.cleaner.badTags;
for (var i = 0; i < bT.length; i++) {
tS = new RegExp('<' + bT[i] + '\\b.*>.*</' + bT[i] + '>', 'gi');
out = out.replace(tS, '');
}
var allowedTags = options.cleaner.keepOnlyTags;
if (typeof(allowedTags) == "undefined") allowedTags = [];
if (allowedTags.length > 0) {
allowedTags = (((allowedTags||'') + '').toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join('');
var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi;
out = out.replace(tags, function($0, $1) {
return allowedTags.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : ''
});
}
var bA = options.cleaner.badAttributes;
for (var ii = 0; ii < bA.length; ii++ ) {
//var aS=new RegExp(' ('+bA[ii]+'="(.*?)")|('+bA[ii]+'=\'(.*?)\')', 'gi');
var aS = new RegExp(' ' + bA[ii] + '=[\'|"](.*?)[\'|"]', 'gi');
out = out.replace(aS, '');
aS = new RegExp(' ' + bA[ii] + '[=0-9a-z]', 'gi');
out = out.replace(aS, '');
}
}
return out;
};
if (options.cleaner.action == 'both' || options.cleaner.action == 'button') {
context.memo('button.cleaner', function () {
var button = ui.button({
contents: options.cleaner.icon,
tooltip: lang.cleaner.tooltip,
container: 'body',
click: function () {
if ($note.summernote('createRange').toString())
$note.summernote('pasteHTML', $note.summernote('createRange').toString());
else
$note.summernote('code', cleanText($note.summernote('code')));
if ($editor.find('.note-status-output').length > 0)
$editor.find('.note-status-output').html('<div class="alert alert-success">' + lang.cleaner.not + '</div>');
}
});
return button.render();
});
}
this.events = {
'summernote.init': function () {
if ($.summernote.interface === 'lite') {
$("head").append('<style>.note-statusbar .pull-right{float:right!important}.note-status-output .text-muted{color:#777}.note-status-output .text-primary{color:#286090}.note-status-output .text-success{color:#3c763d}.note-status-output .text-info{color:#31708f}.note-status-output .text-warning{color:#8a6d3b}.note-status-output .text-danger{color:#a94442}.alert{margin:-7px 0 0 0;padding:7px 10px;border:1px solid transparent;border-radius:0}.alert .note-icon{margin-right:5px}.alert-success{color:#3c763d!important;background-color: #dff0d8 !important;border-color:#d6e9c6}.alert-info{color:#31708f;background-color:#d9edf7;border-color:#bce8f1}.alert-warning{color:#8a6d3b;background-color:#fcf8e3;border-color:#faebcc}.alert-danger{color:#a94442;background-color:#f2dede;border-color:#ebccd1}</style>');
}
if (options.cleaner.limitChars != 0 || options.cleaner.limitDisplay != 'none') {
var textLength = $editor.find(".note-editable").text().replace(/(<([^>]+)>)/ig, "").replace(/( )/, " ");
var codeLength = $editor.find('.note-editable').html();
var lengthStatus = '';
if (textLength.length > options.cleaner.limitChars && options.cleaner.limitChars > 0)
lengthStatus += 'text-danger">';
else
lengthStatus += '">';
if (options.cleaner.limitDisplay == 'text' || options.cleaner.limitDisplay == 'both') lengthStatus += lang.cleaner.limitText + ': ' + textLength.length;
if (options.cleaner.limitDisplay == 'both') lengthStatus += ' / ';
if (options.cleaner.limitDisplay == 'html' || options.cleaner.limitDisplay == 'both') lengthStatus += lang.cleaner.limitHTML + ': ' + codeLength.length;
$editor.find('.note-status-output').html('<small class="pull-right ' + lengthStatus + '&nbsp;</small>');
}
},
'summernote.keydown': function (we, e) {
if (options.cleaner.limitChars != 0 || options.cleaner.limitDisplay != 'none') {
var textLength = $editor.find(".note-editable").text().replace(/(<([^>]+)>)/ig, "").replace(/( )/, " ");
var codeLength = $editor.find('.note-editable').html();
var lengthStatus = '';
if (options.cleaner.limitStop == true && textLength.length >= options.cleaner.limitChars) {
var key = e.keyCode;
allowed_keys = [8, 37, 38, 39, 40, 46]
if ($.inArray(key, allowed_keys) != -1) {
$editor.find('.cleanerLimit').removeClass('text-danger');
return true;
} else {
$editor.find('.cleanerLimit').addClass('text-danger');
e.preventDefault();
e.stopPropagation();
}
} else {
if (textLength.length > options.cleaner.limitChars && options.cleaner.limitChars > 0)
lengthStatus += 'text-danger">';
else
lengthStatus += '">';
if (options.cleaner.limitDisplay == 'text' || options.cleaner.limitDisplay == 'both')
lengthStatus += lang.cleaner.limitText + ': ' + textLength.length;
if (options.cleaner.limitDisplay == 'both')
lengthStatus += ' / ';
if (options.cleaner.limitDisplay == 'html' || options.cleaner.limitDisplay == 'both')
lengthStatus += lang.cleaner.limitHTML + ': ' + codeLength.length;
$editor.find('.note-status-output').html('<small class="cleanerLimit pull-right ' + lengthStatus + '&nbsp;</small>');
}
}
},
'summernote.paste': function (we, e) {
if (options.cleaner.action == 'both' || options.cleaner.action == 'paste') {
e.preventDefault();
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
msie = msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./);
var ffox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
if (msie)
var text = window.clipboardData.getData("Text");
else
var text = e.originalEvent.clipboardData.getData(options.cleaner.keepHtml ? 'text/html' : 'text/plain');
if (text) {
if (msie || ffox)
setTimeout(function () {
$note.summernote('pasteHTML', cleanText(text, options.cleaner.newline));
}, 1);
else
$note.summernote('pasteHTML', cleanText(text, options.cleaner.newline));
if ($editor.find('.note-status-output').length > 0)
$editor.find('.note-status-output').html('<div class="summernote-cleanerAlert alert alert-success">' + lang.cleaner.not + '</div>');
}
}
}
}
}
});
}));