Browse Source

Front-end shop basket progress

Vova Tkach 5 years ago
parent
commit
76f472bdab

+ 1 - 1
assets/cp.scripts.js

@@ -7073,7 +7073,7 @@
 				}).done(function(data) {
 					FormDataWasChanged = false;
 					if(IsDebugMode()) console.log('done', data);
-					AjaxDone(data)
+					AjaxDone(data);
 				}).fail(function(xhr, status, error) {
 					if(IsDebugMode()) console.log('fail', xhr, status, error);
 					AjaxFail(xhr.responseText, status, error);

File diff suppressed because it is too large
+ 0 - 0
assets/cp.scripts.js.go


+ 3 - 0
assets/template/header_html_file.go

@@ -31,6 +31,9 @@ var VarHeaderHtmlFile = []byte(`<!doctype html>
 			var ShopBasketBtnContinue = 'Continue Shopping';
 			var ShopBasketBtnOrder = 'Make order';
 			var ShopBasketEmpty = 'Your basket currently empty...';
+			var ShopOrderSuccess = 'Thank you for your order! We will call you shortly';
+			var ShopOrderErrorMobilePhone = 'Mobile phone number is invalid';
+			var ShopOrderErrorEmailAddress = 'Email address is invalid';
 		</script>
 	</head>
 	<body id="body" class="fixed-top-bar">

+ 78 - 5
assets/template/scripts_js_file.go

@@ -179,7 +179,8 @@ var VarScriptsJsFile = []byte(`(function(window, $) {
 								<div class="modal-body text-left" style="position:relative;"> \
 									<div class="blocker" style="position:absolute;left:0px;top:0px;width:100%;height:100%;background:#fff;opacity:0.5;display:none;"></div> \
 									<div class="data"></div> \
-									<div class="order-form mt-4" style="display:none;"> \
+									<div class="order-form mt-3" style="display:none;"> \
+									<hr class="mb-4"> \
 									<form class="data-form" action="/" method="post" autocomplete="off"> \
 										<div class="hidden"><input type="hidden" name="action" value="shop-order"></div> \
 										<div class="form-group"> \
@@ -263,6 +264,61 @@ var VarScriptsJsFile = []byte(`(function(window, $) {
 						</div> \
 					</div>';
 					$('#sys-modal-shop-basket-placeholder').html(html);
+
+					// ---
+					// var OrderForm = $('#sys-modal-shop-basket .modal-body .order-form form');
+					// OrderForm.submit(function(e) {
+					// 	if(OrderForm.hasClass('loading')) {
+					// 		e.preventDefault();
+					// 		return;
+					// 	}
+
+					// 	// Block send button
+					// 	OrderForm.addClass('loading').addClass('alert-here');
+					// 	var button = OrderForm.find('button[type=submit]');
+					// 	button.addClass('progress-bar-striped')
+					// 		.addClass('progress-bar-animated');
+
+					// 	// Another button
+					// 	if(button.attr('data-target') != '') {
+					// 		$('#' + button.attr('data-target')).addClass('progress-bar-striped')
+					// 			.addClass('progress-bar-animated');
+					// 	}
+
+					// 	// Clear form messages
+					// 	form.find('.sys-messages').html('');
+
+					// 	$.ajax({
+					// 		type: "POST",
+					// 		url: form.attr('action'),
+					// 		data: form.serialize()
+					// 	}).done(function(data) {
+					// 		FormDataWasChanged = false;
+					// 		if(IsDebugMode()) console.log('done', data);
+					// 		AjaxDone(data)
+					// 	}).fail(function(xhr, status, error) {
+					// 		if(IsDebugMode()) console.log('fail', xhr, status, error);
+					// 		AjaxFail(xhr.responseText, status, error);
+					// 	}).always(function() {
+					// 		// Add delay for one second
+					// 		setTimeout(function() {
+					// 			form.removeClass('loading').removeClass('alert-here');
+					// 			button.removeClass('progress-bar-striped')
+					// 				.removeClass('progress-bar-animated');
+					// 			// Another button
+					// 			if(button.attr('data-target') != '') {
+					// 				$('#' + button.attr('data-target'))
+					// 					.removeClass('progress-bar-striped')
+					// 					.removeClass('progress-bar-animated');
+					// 			}
+					// 		}, 100);
+					// 	});
+
+					// 	// Prevent submit action
+					// 	e.preventDefault();
+					// });
+					// ---
+
 					$("#sys-modal-shop-basket").modal({
 						backdrop: 'static',
 						keyboard: true,
@@ -372,9 +428,6 @@ var VarScriptsJsFile = []byte(`(function(window, $) {
 					var OrderFormBlock = $('#sys-modal-shop-basket .modal-body .order-form');
 					if(OrderFormBlock.css('display') == 'none') {
 						OrderFormBlock.css('display', 'block');
-						// ---
-						// $('#navbar-top').css('margin-right', $('#body').css('padding-right'));
-						// ---
 						setTimeout(function() { OrderFormBlock.find('input.form-control').first().focus(); }, 500);
 						return;
 					}
@@ -382,7 +435,27 @@ var VarScriptsJsFile = []byte(`(function(window, $) {
 					// Send form
 					ShopBasketBlockObject(object);
 					console.log('Order action');
-					// ShopBasketUnBlockObject(object);
+					var OrderForm = $('#sys-modal-shop-basket .modal-body .order-form form');
+					$.ajax({
+						type: "POST",
+						url: OrderForm.attr('action'),
+						data: OrderForm.serialize()
+					}).done(function(data) {
+						// FormDataWasChanged = false;
+						// if(IsDebugMode()) console.log('done', data);
+						// AjaxDone(data);
+						// ---
+						// ShopOrderSuccess
+						// ShopOrderErrorMobilePhone
+						// ShopOrderErrorEmailAddress
+						console.log('Order action done', data);
+					}).fail(function(xhr, status, error) {
+						// if(IsDebugMode()) console.log('fail', xhr, status, error);
+						// AjaxFail(xhr.responseText, status, error);
+						console.log('Order action fail', xhr, status, error);
+					}).always(function() {
+						ShopBasketUnBlockObject(object);
+					});
 				}
 			},
 		};

+ 3 - 0
hosts/localhost/template/header.html

@@ -29,6 +29,9 @@
 			var ShopBasketBtnContinue = 'Continue Shopping';
 			var ShopBasketBtnOrder = 'Make order';
 			var ShopBasketEmpty = 'Your basket currently empty...';
+			var ShopOrderSuccess = 'Thank you for your order! We will call you shortly';
+			var ShopOrderErrorMobilePhone = 'Mobile phone number is invalid';
+			var ShopOrderErrorEmailAddress = 'Email address is invalid';
 		</script>
 	</head>
 	<body id="body" class="fixed-top-bar">

+ 76 - 5
hosts/localhost/template/scripts.js

@@ -262,6 +262,61 @@
 						</div> \
 					</div>';
 					$('#sys-modal-shop-basket-placeholder').html(html);
+
+					// ---
+					// var OrderForm = $('#sys-modal-shop-basket .modal-body .order-form form');
+					// OrderForm.submit(function(e) {
+					// 	if(OrderForm.hasClass('loading')) {
+					// 		e.preventDefault();
+					// 		return;
+					// 	}
+
+					// 	// Block send button
+					// 	OrderForm.addClass('loading').addClass('alert-here');
+					// 	var button = OrderForm.find('button[type=submit]');
+					// 	button.addClass('progress-bar-striped')
+					// 		.addClass('progress-bar-animated');
+
+					// 	// Another button
+					// 	if(button.attr('data-target') != '') {
+					// 		$('#' + button.attr('data-target')).addClass('progress-bar-striped')
+					// 			.addClass('progress-bar-animated');
+					// 	}
+
+					// 	// Clear form messages
+					// 	form.find('.sys-messages').html('');
+
+					// 	$.ajax({
+					// 		type: "POST",
+					// 		url: form.attr('action'),
+					// 		data: form.serialize()
+					// 	}).done(function(data) {
+					// 		FormDataWasChanged = false;
+					// 		if(IsDebugMode()) console.log('done', data);
+					// 		AjaxDone(data)
+					// 	}).fail(function(xhr, status, error) {
+					// 		if(IsDebugMode()) console.log('fail', xhr, status, error);
+					// 		AjaxFail(xhr.responseText, status, error);
+					// 	}).always(function() {
+					// 		// Add delay for one second
+					// 		setTimeout(function() {
+					// 			form.removeClass('loading').removeClass('alert-here');
+					// 			button.removeClass('progress-bar-striped')
+					// 				.removeClass('progress-bar-animated');
+					// 			// Another button
+					// 			if(button.attr('data-target') != '') {
+					// 				$('#' + button.attr('data-target'))
+					// 					.removeClass('progress-bar-striped')
+					// 					.removeClass('progress-bar-animated');
+					// 			}
+					// 		}, 100);
+					// 	});
+
+					// 	// Prevent submit action
+					// 	e.preventDefault();
+					// });
+					// ---
+
 					$("#sys-modal-shop-basket").modal({
 						backdrop: 'static',
 						keyboard: true,
@@ -371,17 +426,33 @@
 					var OrderFormBlock = $('#sys-modal-shop-basket .modal-body .order-form');
 					if(OrderFormBlock.css('display') == 'none') {
 						OrderFormBlock.css('display', 'block');
-						// ---
-						// $('#navbar-top').css('margin-right', $('#body').css('padding-right'));
-						// ---
 						setTimeout(function() { OrderFormBlock.find('input.form-control').first().focus(); }, 500);
 						return;
 					}
 					// Validate
 					// Send form
 					ShopBasketBlockObject(object);
-					console.log('Order action');
-					// ShopBasketUnBlockObject(object);
+					var OrderForm = $('#sys-modal-shop-basket .modal-body .order-form form');
+					$.ajax({
+						type: "POST",
+						url: OrderForm.attr('action'),
+						data: OrderForm.serialize()
+					}).done(function(data) {
+						// FormDataWasChanged = false;
+						// if(IsDebugMode()) console.log('done', data);
+						// AjaxDone(data);
+						// ---
+						// ShopOrderSuccess
+						// ShopOrderErrorMobilePhone
+						// ShopOrderErrorEmailAddress
+						console.log('Order action done', data);
+					}).fail(function(xhr, status, error) {
+						// if(IsDebugMode()) console.log('fail', xhr, status, error);
+						// AjaxFail(xhr.responseText, status, error);
+						console.log('Order action fail', xhr, status, error);
+					}).always(function() {
+						ShopBasketUnBlockObject(object);
+					});
 				}
 			},
 		};

+ 57 - 0
modules/module_shop_order.go

@@ -0,0 +1,57 @@
+package modules
+
+import (
+	"golang-fave/engine/wrapper"
+	// "golang-fave/utils"
+)
+
+func (this *Modules) RegisterAction_ShopOrder() *Action {
+	return this.newAction(AInfo{
+		WantDB:    true,
+		Mount:     "shop-order",
+		WantAdmin: false,
+	}, func(wrap *wrapper.Wrapper) {
+		// pf_id := wrap.R.FormValue("id")
+
+		// pf_client_last_name := wrap.R.FormValue("client_last_name")
+		// pf_client_first_name := wrap.R.FormValue("client_first_name")
+		// pf_client_second_name := wrap.R.FormValue("client_second_name")
+		// pf_client_phone := wrap.R.FormValue("client_phone")
+		// pf_client_email := wrap.R.FormValue("client_email")
+		// pf_client_delivery_comment := wrap.R.FormValue("client_delivery_comment")
+		// pf_client_order_comment := wrap.R.FormValue("client_order_comment")
+
+		wrap.MsgError(`OK!`)
+		return
+
+		// if !utils.IsNumeric(pf_id) {
+		// 	wrap.MsgError(`Inner system error`)
+		// 	return
+		// }
+
+		// if err := wrap.DB.Transaction(func(tx *wrapper.Tx) error {
+		// 	if _, err := tx.Exec(`
+		// 		UPDATE shop_products SET
+		// 			parent_id = NULL,
+		// 			active = 0
+		// 		WHERE
+		// 			id = ?
+		// 		;`,
+		// 		utils.StrToInt(pf_id),
+		// 	); err != nil {
+		// 		return err
+		// 	}
+		// 	return nil
+		// }); err != nil {
+		// 	wrap.MsgError(err.Error())
+		// 	return
+		// }
+
+		// wrap.RecreateProductXmlFile()
+
+		// wrap.ResetCacheBlocks()
+
+		// // Reload current page
+		// wrap.Write(`window.location.reload(false);`)
+	})
+}

Some files were not shown because too many files changed in this diff