Browse Source

Improves start_shop, gets contacts ready for processing.

1) Slight improvements in UI with start_shop .. the date.
2) Adds deferred promise for contact.js.
devel
Jonathan Rosenbaum 10 years ago
parent
commit
4cd269fd06
  1. 1
      include_header.html
  2. 135
      js/contact.js
  3. 31
      js/shop.js
  4. 2
      js/transaction.js
  5. 3
      start_shop.php

1
include_header.html

@ -31,6 +31,7 @@ function resetTimer()
<script src="js/jquery-2.1.1.js"></script>
<script src="js/transaction.js"></script>
<script src="js/contact.js"></script>
<script src="js/shop.js"></script>
<script src="js/jquery.mask.js"></script>
<script src="js/jquery.jeditable.js"></script>
<script src="js/jquery.nouislider.js"></script>

135
js/contact.js

@ -25,62 +25,89 @@ $(function(){
var email_list_choice;
$("select[name='contact_id']").chosen();
$("#submit_contact").on("click keypress", function(e) {
function save_contact() {
// Deferred Promise, since we don't know when the click will be made,
// it is an asynchronous function, and we need to know the returned result.
// Provides a clean separation of code.
var dfd = $.Deferred();
$("#submit_contact").on("click keypress", function(e) {
// check for errors
//error_handler(input,error_span,error,error_text,event);
var err0 = 0, err1 = 0, err2 = 0, err3 = 0, err4 = 0, err5 = 0;
// if it is showing
$("#email_list_error").hide();
// check for errors
//error_handler(input,error_span,error,error_text,event);
// first name & last name input
err0 = error_handler(first_name.val(), first_name_error, "","*Required",e);
err1 = error_handler(last_name.val(), last_name_error, "","*Required",e);
// email and phone input
if (email.val() === "" && phone.val() === "") {
err2 = error_handler(email.val(), email_error, "","*Required - email address and/or phone number",e);
err3 = error_handler(phone.val(), phone_error, "","*Required - email address and/or phone number",e);
} else if (email.val() === "" && phone.val() !== "") {
email_error.hide();
phone_error.hide();
var r = phone_validator(phone.val(),e);
var email_list_toggle = $("#email_list_toggle");
var email_list_error = $("#email_list_error");
if (r) {
if(email_list_toggle.val() == 1) {
err4 = error_handler(1, email_list_error, 1,"*Email address required for email list",e);
email_list_choice = 1;
}
}
} else if (email.val() !== "" && phone.val() === "") {
var err0 = 0, err1 = 0;
email_error.hide();
phone_error.hide();
email_validator(email.val(),e);
// if it is showing
$("#email_list_error").hide();
// first name & last name input
error_handler(first_name.val(), first_name_error, "","*Required",e);
error_handler(last_name.val(), last_name_error, "","*Required",e);
} else if (email.val() && phone.val() ) {
// email and phone input
if (email.val() === "" && phone.val() === "") {
error_handler(email.val(), email_error, "","*Required - email address and/or phone number",e);
error_handler(phone.val(), phone_error, "","*Required - email address and/or phone number",e);
} else if ( (email.val() === "" && phone.val() !== "") ) {
email_error.hide();
phone_error.hide();
var r = phone_validator(phone.val(),e);
var email_list_toggle = $("#email_list_toggle");
var email_list_error = $("#email_list_error");
if (r) {
if(email_list_toggle.val() == 1) {
error_handler(1, email_list_error, 1,"*Email address required for email list",e);
email_list_choice = 1;
}
}
} else if ( (email.val() !== "" && phone.val() === "") ) {
email_error.hide();
phone_error.hide();
email_validator(email.val(),e);
} else if ( email.val() && phone.val() ) {
email_error.hide();
phone_error.hide();
phone_validator(phone.val(),e);
email_validator(email.val(),e);
email_error.hide();
phone_error.hide();
phone_validator(phone.val(),e);
email_validator(email.val(),e);
}
// waiver checkbox
err5 = error_handler(waiver_checkbox.prop("checked"),waiver_error,false,"*Required",event);
}
// waiver checkbox
error_handler(waiver_checkbox.prop("checked"),waiver_error,false,"*Required",event);
} );
if ((err0 + err1 + err2 + err3 + err4 + err5) > 0 ) {
} else {
e.preventDefault();
dfd.resolve("Success");
}
}); // end submit_contact
return dfd.promise();
} // end save_contact
save_contact().done(function(success) {
if (success === "Success") {
var name = first_name.val() + " " + last_name.val() + " " + email.val() + " " + $("#email_list_toggle").val();
console.log(name);
}
} );
// waiver slideup/slidedown
$('#waiver').hide();
var c=0;
@ -94,11 +121,9 @@ $(function(){
$('#waiver').slideUp();
$(this).attr("value","Show Waiver");
c--;
}
}); // end submit_contact
}
} );
$("#email_list_toggle").on("set",function() {
if ($(this).val() == 0 && email_list_choice) {
$("#email_list_error").hide();

31
js/shop.js

@ -0,0 +1,31 @@
$(function(){
"use strict";
// sensible defaults
$("#shop_date").mask("0000-00-00", {placeholder: "yyyy-mm-dd" });
// error handler for shops with a popup dialog
function error_handler(input,error_span,error,error_text,event) {
var trans_error = 0;
if ( input == error ) {
if ( !error_span.is(":visible") ) {
error_span.show();
}
error_span.html(error_text);
trans_error = 1;
} else {
trans_error = 0;
error_span.hide();
}
if (trans_error) {
event.preventDefault();
}
return trans_error;
} // end error_handling function
});

2
js/transaction.js

@ -549,7 +549,7 @@ $(function() {
});
return dfd.promise()
return dfd.promise();
} // end function save_or_close

3
start_shop.php

@ -135,7 +135,7 @@ if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "ChangeDate")) {
<form action="<?php echo $editFormAction; ?>" method="post" name="form_new" id="form_new">
<tr>
<td height="30"><span class="yb_heading3red">Start New Shop:</span></td>
<td><input name="ctrl_date" type="text" class="yb_standard" value="<?php echo current_date(); ?>" /></td>
<td><input id="ctrl_date" name="ctrl_date" type="text" class="yb_standard" value="<?php echo current_date(); ?>" /></td>
<td><?php list_shop_locations($ctrl_shoplocation,"Treasure City") ?></td>
<td><?php list_shop_types($ctrl_shoptype) ?></td>
<td>&nbsp;</td>
@ -194,7 +194,6 @@ if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "ChangeDate")) {
<option value="Sunday">Sunday</option>
</select>
<input type="submit" name="Submit" value="Submit" />
(date format YYYY-MM-DD)
<input type="hidden" name="MM_insert" value="ChangeDate" />
</form></td>
</tr>

Loading…
Cancel
Save