How to set indeterminate state of checkbox in Jsgrid - jsgrid

I am using this library Lightweight Grid jQuery Plugin. One of my column has checkbox i want to show indeterminate state of checkbox if value is "". I tried to set the property of checkbox through jquery to true but its not working can any one show how to do it in this library.

Here is the fiddle link where i did it
$("#jsGrid").jsGrid({
height: 300,
width: "100%",
paging: true,
autoload: true,
pageSize: 5,
controller: {
loadData: function() {
return data;
}
},
fields: [{
name: "Name",
type: "textarea",
width: 150
}, {
name: "Married",
title: "Is Married",
align: "center",
itemTemplate: function(value, item) {
return $("<input>").attr("type", "checkbox")
.attr("checked", function() {
if (value === false) {
item.uncheck = true;
item.uncheck = item.indeterminate = false;
$(this).prop("checked", false);
} else if (value === true) {
$(this).prop("checked", true);
item.checked = true;
item.uncheck = item.indeterminate = false;
} else {
item.indeterminate = true;
item.checked = item.uncheck = false;
$(this).prop("indeterminate", true);
}
})
.on("click", function() {
if (item.uncheck === true && item.checked === false && item.indeterminate === false) {
item.indeterminate = true;
item.uncheck = item.checked = false;
$(this).prop("indeterminate", true);
} else if (item.uncheck === false && item.checked === false && item.indeterminate === true) {
item.checked = true;
item.uncheck = item.indeterminate = false;
$(this).prop("checked", true);
} else {
item.uncheck = true;
item.indeterminate = item.checked = false;
$(this).prop("checked", false);
}
});
}
}, {
type: "control"
}]
});
Solution

Related

Ajax with laravel Post returning

I am working with laravel and ajax. But when I register I see this error 302.
I know this may be a trivial question but I am just not able to get this ajax call to work.
Auth/RegisterController.php
protected function create(array $data, Request $request)
{
if ($request->hasFile('image')) {
$fileNameWithExt = $request->file('image')->getClientOriginalName();
$filename = pathinfo($fileNameWithExt, PATHINFO_FILENAME);
$extention = $request->file('image')->getClientOriginalExtension();
$fileNameToStore = $filename.'_'.time().'.'.$extention;
$path = $request->file('image')->storeAs('public/images', $fileNameToStore);
} else {
$fileNameToStore = 'noimage.jpg';
}
return User::create([
'firstname' => $data['firstـname'],
'lastname' => $data['lastـname'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'mobile' => $data['mobile'],
'nasional_code' => $data['national_code'],
'birthdate' => $data['birthـdate'],
'document' => $data['document'],
'educational' => $data['educational'],
'gender' => $data['gender'],
'side' => $data['side'],
$fileNameToStore => $data['image']
]);
}
My ajax is register.js file
How do I pass the "Accept'=>'application/json" in request when testing:
I want to add 'accept'=>'application/json' to my request header.
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
function scroll_to_class(element_class, removed_height) {
var scroll_to = $(element_class).offset().top - removed_height;
if($(window).scrollTop() != scroll_to) {
$('html, body').stop().animate({scrollTop: scroll_to}, 0);
}
}
function bar_progress(progress_line_object, direction) {
var number_of_steps = progress_line_object.data('number-of-steps');
var now_value = progress_line_object.data('now-value');
var new_value = 0;
if(direction == 'right') {
new_value = now_value + ( 100 / number_of_steps );
}
else if(direction == 'left') {
new_value = now_value - ( 100 / number_of_steps );
}
progress_line_object.attr('style', 'width: ' + new_value + '%;').data('now-value', new_value);
}
jQuery(document).ready(function() {
$('form fieldset:first').fadeIn('slow');
$('form input[type="text"], form input[type="password"], form textarea').on('focus', function() {
$(this).removeClass('input-error');
});
$('form .btn-next').on('click', function() {
var parent_fieldset = $(this).parents('fieldset');
var next_step = true;
var current_active_step = $(this).parents('form').find('.form-wizard.active');
var progress_line = $(this).parents('form').find('.progress-line');
parent_fieldset.find('input[type="text"], input[type="password"], input[type="email"], input[type="radio"]').each(function() {
if( $(this).val() == "" ) {
$(this).addClass('input-error');
next_step = false;
}
else {
$(this).removeClass('input-error');
}
});
parent_fieldset.find('input[type="checkbox"]').each(function() {
if( $(this).prop("checked") == false ) {
$('.form-check-label').css("color","red");
next_step = false;
}
else {
$('.form-check-label').css("color","black");
}
});
if( next_step ) {
parent_fieldset.fadeOut(400, function() {
current_active_step.removeClass('active').addClass('activated').next().addClass('active');
bar_progress(progress_line, 'right');
$(this).next().fadeIn();
scroll_to_class( $('form'), 20 );
});
}
});
// previous step
$('form .btn-previous').on('click', function() {
var current_active_step = $(this).parents('form').find('.form-wizard.active');
var progress_line = $(this).parents('form').find('.progress-line');
$(this).parents('fieldset').fadeOut(400, function() {
current_active_step.removeClass('active').prev().removeClass('activated').addClass('active');
bar_progress(progress_line, 'left');
$(this).prev().fadeIn();
scroll_to_class( $('form'), 20 );
});
});
$('form').on('submit', function(e) {
$(this).find('input[type="text"], input[type="password"], input[type="username"], input[type="email"], input[type="tel"], input[type="url"], textarea').each(function() {
if( $(this).val() == "" ) {
e.preventDefault();
$(this).addClass('input-error');
}
else {
$(this).removeClass('input-error');
}
});
});
});
Update your ajax header, according to this:
$.ajaxSetup({
headers: {
accepts: "application/json; charset=utf-8",
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
The possibilities of this issue is CSRF token and missing route.

How to change error 302 in laravel with ajax

I am working with laravel and ajax. But when I register I see this error 302.
I know this may be a trivial question but I am just not able to get this ajax call to work.
Auth/RegisterController.php
protected function create(array $data, Request $request)
{
if ($request->hasFile('image')) {
$fileNameWithExt = $request->file('image')->getClientOriginalName();
$filename = pathinfo($fileNameWithExt, PATHINFO_FILENAME);
$extention = $request->file('image')->getClientOriginalExtension();
$fileNameToStore = $filename.'_'.time().'.'.$extention;
$path = $request->file('image')->storeAs('public/images', $fileNameToStore);
} else {
$fileNameToStore = 'noimage.jpg';
}
return User::create([
'firstname' => $data['firstـname'],
'lastname' => $data['lastـname'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'mobile' => $data['mobile'],
'nasional_code' => $data['national_code'],
'birthdate' => $data['birthـdate'],
'document' => $data['document'],
'educational' => $data['educational'],
'gender' => $data['gender'],
'side' => $data['side'],
$fileNameToStore => $data['image']
]);
}
My ajax is register.js file
How do I pass the "Accept'=>'application/json" in request when testing:
I want to add 'accept'=>'application/json' to my request header.
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
function scroll_to_class(element_class, removed_height) {
var scroll_to = $(element_class).offset().top - removed_height;
if($(window).scrollTop() != scroll_to) {
$('html, body').stop().animate({scrollTop: scroll_to}, 0);
}
}
function bar_progress(progress_line_object, direction) {
var number_of_steps = progress_line_object.data('number-of-steps');
var now_value = progress_line_object.data('now-value');
var new_value = 0;
if(direction == 'right') {
new_value = now_value + ( 100 / number_of_steps );
}
else if(direction == 'left') {
new_value = now_value - ( 100 / number_of_steps );
}
progress_line_object.attr('style', 'width: ' + new_value + '%;').data('now-value', new_value);
}
jQuery(document).ready(function() {
$('form fieldset:first').fadeIn('slow');
$('form input[type="text"], form input[type="password"], form textarea').on('focus', function() {
$(this).removeClass('input-error');
});
$('form .btn-next').on('click', function() {
var parent_fieldset = $(this).parents('fieldset');
var next_step = true;
var current_active_step = $(this).parents('form').find('.form-wizard.active');
var progress_line = $(this).parents('form').find('.progress-line');
parent_fieldset.find('input[type="text"], input[type="password"], input[type="email"], input[type="radio"]').each(function() {
if( $(this).val() == "" ) {
$(this).addClass('input-error');
next_step = false;
}
else {
$(this).removeClass('input-error');
}
});
parent_fieldset.find('input[type="checkbox"]').each(function() {
if( $(this).prop("checked") == false ) {
$('.form-check-label').css("color","red");
next_step = false;
}
else {
$('.form-check-label').css("color","black");
}
});
if( next_step ) {
parent_fieldset.fadeOut(400, function() {
current_active_step.removeClass('active').addClass('activated').next().addClass('active');
bar_progress(progress_line, 'right');
$(this).next().fadeIn();
scroll_to_class( $('form'), 20 );
});
}
});
// previous step
$('form .btn-previous').on('click', function() {
var current_active_step = $(this).parents('form').find('.form-wizard.active');
var progress_line = $(this).parents('form').find('.progress-line');
$(this).parents('fieldset').fadeOut(400, function() {
current_active_step.removeClass('active').prev().removeClass('activated').addClass('active');
bar_progress(progress_line, 'left');
$(this).prev().fadeIn();
scroll_to_class( $('form'), 20 );
});
});
$('form').on('submit', function(e) {
$(this).find('input[type="text"], input[type="password"], input[type="username"], input[type="email"], input[type="tel"], input[type="url"], textarea').each(function() {
if( $(this).val() == "" ) {
e.preventDefault();
$(this).addClass('input-error');
}
else {
$(this).removeClass('input-error');
}
});
});
});

Joomla - Custom error message from form invalid fields

I am developing Custom Component for Joomla.
I did well in validating field by adding custom rule. But if entered value does not pass through my validation, it gives error as "Invalid Field: My Field Name"
I want to replace this with my own message.
I know I can use "JText::_('LANGUAGE_STRING'). But I'm not sure where do I need to add it.
I have custom rule called "validemails" which returns false in client side as well as server side validation.
My Client side Validation is: (components/com_helpdesk/models/forms/create.js)
jQuery(document).ready(function () {
document.formvalidator.setHandler('validemail', function (value) {
var emails = [value];
if (value.indexOf(';') !== -1) {
emails = value.split(';');
}
else if(value.indexOf(',') !== -1) {
emails = value.split(',');
}
regex = /^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+#[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
var result = false;
emails.each(function (value) {
result = regex.test(jQuery.trim(value));
if (result === false) {
return false;
}
});
return result;
});
});
My Server Side Validation is: (components/com_helpdesk/models/rules/validemail.php)
use Joomla\Registry\Registry;
JFormHelper::loadRuleClass('email');
class JFormRuleValidemail extends JFormRuleEmail {
public function test(SimpleXMLElement $element, $value, $group = null, Registry $input = null, JForm $form = null) {
$emails = array($value);
if (strpos($value, ';') !== false) {
$emails = explode(';', $value);
}
else if (strpos($value, ',') !== false) {
$emails = explode(',', $value);
}
foreach ($emails as $email) {
if (!parent::test($element, trim($email))) {
return false;
continue;
}
}
return true;
}
}
Please note that I'm developing Front-end view of Component not back-end.
Well fortunately, I got my server side validation working by this way:
use Joomla\Registry\Registry;
JFormHelper::loadRuleClass('email');
class JFormRuleValidemail extends JFormRuleEmail {
public function test(SimpleXMLElement $element, $value, $group = null, Registry $input = null, JForm $form = null) {
$emails = array($value);
if (strpos($value, ';') !== false) {
$emails = explode(';', $value);
}
else if (strpos($value, ',') !== false) {
$emails = explode(',', $value);
}
foreach ($emails as $email) {
if (!parent::test($element, trim($email))) {
***$element->addAttribute('message', JText::_('COM_HELPDESK_ERROR_EMAIL').' '.$value);***
return false;
continue;
}
}
return true;
}
}
I got the solution. May be it will be useful for other googlers. Below is a code snippet for client side validation. Put below code in your custom JS:
jQuery('.validate').click(function (e) {
var fields, invalid = [], valid = true, label, error, i, l;
fields = jQuery('form.form-validate').find('input, textarea, select');
if (!document.formvalidator.isValid(jQuery('form'))) {
for (i = 0, l = fields.length; i < l; i++) {
if (document.formvalidator.validate(fields[i]) === false) {
valid = false;
invalid.push(fields[i]);
}
}
// Run custom form validators if present
jQuery.each(document.formvalidator.custom, function (key, validator) {
if (validator.exec() !== true) {
valid = false;
}
});
if (!valid && invalid.length > 0) {
error = {"error": []};
for (i = invalid.length - 1; i >= 0; i--) {
label = jQuery.trim(jQuery(invalid[i]).data("label").text().replace("*", "").toString());
if (label) {
if(label === 'Subject') {
error.error.push('Please Enter Subject');
}
if(label === 'Description') {
error.error.push('Please Enter Description');
}
if(label === 'Priority') {
error.error.push('Please Select Priority');
}
if(label === 'Email CCs') {
error.error.push('Please Enter proper Emails in CC section');
}
if(label === 'Email BCCs') {
error.error.push('Please Enter proper Emails in BCC section');
}
}
}
}
Joomla.renderMessages(error);
}
e.preventDefault();
});

Autocomplete up-down key navigation in JqGrid

I got JqGrid with modified cellEdit ( full up-down-left-right cell navigation ).
Here is bits of jqgrid.src:
if (e.keyCode === 37) {
if(!$t.grid.hDiv.loading ) {
{$($t).jqGrid("prevCell",iRow,iCol);} //left
} else {
return false;
}
}
if (e.keyCode === 39) {
if(!$t.grid.hDiv.loading ) {
{$($t).jqGrid("nextCell",iRow,iCol);} //right
} else {
return false;
}
}
if (e.keyCode === 38) {
if(!$t.grid.hDiv.loading ) {
{$($t).jqGrid("prevRow",iRow,iCol);} //up
} else {
return false;
}
}
if (e.keyCode === 40) {
if(!$t.grid.hDiv.loading ) {
{$($t).jqGrid("nextRow",iRow,iCol);} //down
} else {
return false;
}
}
and others
nextCell : function (iRow,iCol) {
return this.each(function (){
var $t = this, nCol=false, i;
if (!$t.grid || $t.p.cellEdit !== true) {return;}
// try to find next editable cell
for (i=iCol+1; i<$t.p.colModel.length; i++) {
if ($t.p.colModel[i].editable ===true && $t.p.colModel[i].hidden !== true ) {
//alert($t.p.colModel[i-1].hidden);
nCol = i; break;
}
}
if(nCol !== false) {
$($t).jqGrid("editCell",iRow,nCol,true);
} else {
if ($t.p.savedRow.length >0) {
$($t).jqGrid("saveCell",iRow,iCol);
}
}
});
},
prevCell : function (iRow,iCol) {
return this.each(function (){
var $t = this, nCol=false, i;
if (!$t.grid || $t.p.cellEdit !== true) {return;}
// try to find next editable cell
for (i=iCol-1; i>=0; i--) {
if ($t.p.colModel[i].editable ===true && $t.p.colModel[i].hidden !== true ) {
nCol = i; break;
}
}
if(nCol !== false) {
$($t).jqGrid("editCell",iRow,nCol,true);
} else {
if ($t.p.savedRow.length >0) {
$($t).jqGrid("saveCell",iRow,iCol);
}
}
});
},
prevRow : function (iRow,iCol) {
return this.each(function (){
var $t = this, nCol=false, i;
if (!$t.grid || $t.p.cellEdit !== true) {return;}
// try to find next editable cell
iRow--;
iCol++;
for (i=iCol-1; i>=0; i--) {
if ( $t.p.colModel[i].editable ===true) {
nCol = i; break;
}
}
if(nCol !== false) {
$($t).jqGrid("editCell",iRow,nCol,true);
} else {
if ($t.p.savedRow.length >0) {
$($t).jqGrid("saveCell",iRow,iCol);
}
}
});
},
nextRow : function (iRow,iCol) {
return this.each(function (){
var $t = this, nCol=false, i;
if (!$t.grid || $t.p.cellEdit !== true) {return;}
// try to find next editable cell
iRow++;
iCol++;
for (i=iCol-1; i>=0; i--) {
if ( $t.p.colModel[i].editable ===true) {
nCol = i; break;
}
}
if(nCol !== false) {
$($t).jqGrid("editCell",iRow,nCol,true);
} else {
if ($t.p.savedRow.length >0) {
$($t).jqGrid("saveCell",iRow,iCol);
}
}
});
}
Also i got autocomplete working with JqGrid event afterEditCell:
getautocompl = function(rowid,cellname,value,iRow,iCol){
setTimeout(function() { $("#"+iRow+"_"+cellname).select().focus();},10);
if(cellname!=='date_factory' || cellname!=='date_otgr_factory' || cellname!=='date_shipment' || cellname!=='date_sklad' || cellname!=='kolinkor'
|| cellname!=='kolkor' || cellname!=='kol_quantity' || cellname!=='description') {
$("#"+iRow+"_"+cellname).autocomplete({
source:"../../phpmon/autocomplete.php?fname="+cellname,
delay:250,
minLength: 2});
}
}
Problem here is that i cant manage autocomplete hotkeys to work, when i hit "down" button it just goes to next cell, rather then to any of the autocomplete options.
you could suppress jqgrid navigation when autocomplete element is visible. something like:
$(document).keydown(function( fn ){
var key = fn.keyCode;
if( $("#autocomplete") && key == 40)
/* your autocomplete action*/
});
Its not quite what i needed, but it helped me to make it.
I just modified jqgrid source code like this :
if (e.keyCode === 40) {
if(!$t.grid.hDiv.loading ) {
if ($('.ui-menu-item').length < 1) {
{$($t).jqGrid("nextRow",iRow,iCol);} //down
}
} else {
return false;
}
}
Where .ui-menu-item is class of autocomplete widget.
thk a lot

How to utilize the browser back button with AJAX requested dynamic content

I have asked a question like this before, and the answer was great but the more I looked at my code the more confused I got, and after 10hrs my brain is shot and I'm in need of help. So all my content is loaded dynamically via Jquery's $.post and loaded into #content-container. Now I included my entire Jquery file to show you why I am getting so confused as how to get this to work without re-writing all the code. As you can see, and what I'm thinking, is that the history plugins such as BBQ, and history.js seem to be out of the question because I don't use anchor tags and the multitude of .live('click', funcition() { I have use different classes and id's for various reasons. I also believe that rules out using the hash and linking it to a single class via .trigger(), executing the AJAX(hope that makes sense). The only option I have left is actually kinda my question. Would it be possible to load the dynamic content into #content-container still using the $.post with $.load() or window.location and actually have the previous content loaded when the browser back button is clicked.
I greatly appreciate the help, really.....
$(document).ready(function() {
$(window).load(function () {
});
$('#map').hide();
$('#informational-container').hide();
$('.clickable').click(function(){
$('#map').hide();
});
function getTotalDealCount() {
$.post('../service/service.getTotalDealCount.php', {}, function(data) {
if(data.success) $('#deal-counter').append(data.results);
}, 'json');
return false;
}
function loadMap(lat, lon) {
var latlng = new google.maps.LatLng(lat, lon);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map'), myOptions);
var marker = new google.maps.Marker({
position: latlng,
map: map
});
}
function getLatLon(address, zipcode) {
$.post('../service/service.getLatLon.php', { address: address, zipcode: zipcode }, function(data) {
if(data.success) {
var res = data.results;
var coordinates = res.split('_');
loadMap(coordinates[0], coordinates[1]);
} else {
return false;
}
}, 'json');
return false;
}
function getAddressZipcode(id) {
$.post('../service/service.getAddressZipcode.php', { id: id }, function(data) {
if(data.success) {
var res = data.results;
var location = res.split('_');
getLatLon(location[0], location[1]);
} else {
return -1;
}
}, 'json');
return false;
}
$('#how-it-works').live('click', function() {
$('#content-container').load('../module/module.string.php #string-m1');
});
$('#why-post-a-deal').live('click', function() {
$('#content-container').load('../module/module.string.php #string-m2');
});
$('#who-are-we').live('click', function() {
$('#content-container').load('../module/module.string.php #string-m3');
});
$('#contact-us').live('click', function() {
$('#content-container').load('../module/module.string.php #string-m4');
});
$('#post-deal-img').live('click', function() {
$('#content-container').load('post.php');
});
$('.post-deal-inputs').live('click', function() {
$('.post-deal-inputs').live('click', function(e) {
$(this).val('');
$(this).removeClass('post-deal-inputs')
.addClass('post-deal-inputs-clicked');
});
});
$('#df5').live('click', function() {
$('#df7').val('');
$('#df7').hide();
});
$('#df6').live('click', function() {
$('#df7').show();
});
$('#post-how-to-link').live('click', function() {
apprise();
});
$('#terms').live('click', function() {
$('#content-container').load('../module/module.string.php #string-m5');
});
$('#disclaimer').live('click', function() {
$('#content-container').load('../module/module.string.php #string-m6');
});
$('#post-deal-button').live('click', function() {
var dealForm = $('#deal-form').serialize();
var company = $('#df1').val();
var description = $('#df2').val();
var zipcode = $('#df4').val();
var starts = $('#df7').val();
var ends = $('#df8').val();
if(company == '' || company == 'Company') {
apprise('A company name is required!');
return false;
}
if(description == '' || description == 'Deal') {
apprise('A deal is required!');
return false;
}
var swear = swearFilter(description);
if(swear != false) {
apprise('Please remove the naughty word `' + swear + '` from your deal.');
return false;
}
if(zipcode == '' || zipcode == 'Zipcode') {
apprise('A zipcode is required!');
return false;
}
if($('#df7').is(':visible') && typeof(ends) != 'undefined') {
var res = validateDate(starts);
if(res == false) {
apprise('Please select a valid start date!');
return false;
}
}
if(typeof(ends) != 'undefined') {
var res = validateDate(ends);
if(res == false) {
apprise('Please select a valid end date!');
return false;
}
}
if(ends == '') {
apprise('A deal end date is required!');
return false;
}
if($('#df7').is(':visible') && $('#df7').val() == '') {
apprise('If its not a one day sale a start date is required!');
return false
}
$.post('../service/service.postDeal.php', { dealForm: dealForm }, function(data) {
if(data.success == true) {
apprise('Your deal has been posted, thank you!');
window.location = '../root/index.php';
return true;
}
if(data.success == false) {
if(data.fail == 1) {
apprise('An error has occured and your deal has not been posted. ' +
'The error has been emailed to our support department to have the issue fixed, we apologize :(');
return false;
}
if(data.fail == 2) {
apprise('The zipcode you supplied was not in our database. Please enter the city ' +
'and state/province in the following prompts to add your location.' , {'confirm':true}, function() {
insertNewLocation(zipcode);
});
}
if(data.fail == 3) {
apprise('A zipcode is required!');
}
}
}, 'json');
return false;
});
function validateDate(string) {
if(string.toLowerCase().indexOf('-') >= 0) {
var dateArray = string.split('-');
var year = dateArray[0], month = dateArray[1], day = dateArray[2];
if(year.length == 4 && month.length == 2 && day.length == 2) return true;
else return false;
}
return false;
}
function swearFilter(string) {
var ret = false;
var filter = [];
var stringArray = string.split(' ');
for(var i = 0; i < stringArray.length; i++) {
if(jQuery.inArray(stringArray[i], filter) > -1) {
ret = stringArray[i];
break;
}
}
return ret;
}
function insertNewLocation(zipcode) {
var city = '';
var state = '';
if (/[^a-zA-Z 0-9]+/g.test(zipcode)) {
apprise('The zipcode should contain only numbers, letters or both!');
return false;
}
apprise('Enter the name of the city:', {'input':true}, function(_city_) {
if(/[^a-zA-Z]+/g.test(_city_)) {
apprise('The city should contain only letters!');
return false;
}
city = _city_;
apprise('Enter the state in 2 letter abbreviated format:', {'input':true}, function(_state_) {
if (/[^a-zA-Z]+/g.test(_state_)) {
apprise('The state should contain only letters');
return false;
}
if(_state_.length > 2) {
apprise('The state should only be 2 letters in length');
}
state = _state_;
$.post('../service/service.insertNewLocation.php', { city: city, state: state, zipcode: zipcode }, function(data) {
if(data.success == true) {
apprise('Thank you, you may now submit you deal!');
return true;
}
if(data.success == false) {
if(data.fail == 1) {
apprise('An error has occured and your location has not been added to our database. ' +
'The error has been emailed to our support department to have the issue fixed, we apologize :(');
return false;
}
if(data.fail == 2) {
apprise('A zipcode is required!');
return false;
}
}
}, 'json');
return false;
});
});
}
$('#search-type-button').live('click', function() {
var search = $('#search-type-text').val();
var keyword = $('#keyword-type-text').val();
if(search == '') {
apprise('A zipcode or city and state combo to search for deals in your area!');
return false;
}
if(keyword == 'Keyword') {
apprise('If you want to add a keyword to you deal, make sure its unique!');
return false;
}
$.post('../service/service.loadDealsByCityOrZipcode.php', { search: search, keyword: keyword }, function(data) {
if(data.success) {
$('#content-container').html(data.results);
return true;
}
if(data.success == false) {
if(data.fail == 1) {
apprise('An error has occured locating the deals. ' +
'The error has been emailed to our support department to have the issue fixed, we apologize :(');
return false;
}
if(data.fail == 2) {
apprise('There are no deals within the zipcode you provided, be the first to add one!');
return false;
}
if(data.fail == 3) {
apprise('There are no deals matching the tag you supplied!');
return false;
}
if(data.fail == 4) {
apprise('A zipcode or city and state combo to search for deals in your area!');
return false;
}
}
}, 'json');
return false;
});
$('.deals-queried-deal').live('click', function() {
var id = this.id;
$('#comment-link').show();
$.post('../service/service.loadDealDescription.php', { id: id }, function(data) {
if(data.success == true) {
$('#content-container').html(data.results);
var res = getAddressZipcode(id);
if(res != -1) $('#map').show();
}
if(data.success == false) {
if(data.fail == 1) {
apprise('An error has occured loading the deal you selected. ' +
'The error has been emailed to our support department to have the issue fixed, we apologize :(');
} else if(data.fail == 2) {
apprise('The deal you selected does not exist! ' +
'The error has been emailed to our support department to have the issue fixed, we apologize :(');
} else if(data.fail == 3) {
apprise('An error has occured loading the deal you selected. ' +
'The error has been emailed to our support department to have the issue fixed, we apologize :(');
}
}
}, 'json');
return false;
});
$('.vote-down').live('click', function() {
var id = this.id;
var vote = 0;
$.post('../service/service.tallyVote.php', { id: id, vote: vote }, function(data) {
if(data.success == true) {
apprise('Thank you for your vote!');
return true;
}
if(data.success == false) {
if(data.fail == 1) {
apprise('An error has occured when voting for this deal. ' +
'The error has been emailed to our support department to have the issue fixed, we apologize :(');
return false;
}
if(data.fail == 2) {
apprise('You have already voted for this deal!');
return false;
}
}
}, 'json');
return false;
});
$('.vote-up').live('click', function() {
var id = this.id;
var vote = 1;
$.post('../service/service.tallyVote.php', { id: id, vote: vote }, function(data) {
if(data.success == true) {
apprise('Thank you for your vote!');
return true;
}
if(data.success == false) {
if(data.fail == 1) {
apprise('An error has occured when voting for this deal. ' +
'The error has been emailed to our support department to have the issue fixed, we apologize :(');
return false;
}
if(data.fail == 2) {
apprise('You have already voted for this deal!');
return false;
}
}
}, 'json');
return false;
});
$('#email-button').live('click', function() {
var emailAddress = $('.email-textbox').val();
var from = $('#from-textbox').val();
var message = $('#email-div').html();
var atpos = emailAddress.indexOf("#");
var dotpos = emailAddress.lastIndexOf(".");
if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= emailAddress.length) {
apprise('Please enter a valid email address!');
return false;
}
if(emailAddress == '') {
apprise('An email address is required!');
return false;
}
if(from == '') {
apprise('Your name is required!');
return false;
}
$.post('../service/service.emailDeal.php', { emailAddress: emailAddress, from: from, message: message}, function(data) {
if(data.success == true) {
apprise('The deal has been sent, we hope they enjoy it!');
return true;
}
if(data.success == false) {
if(data.fail == 1) {
apprise('An error has occured sending the email. ' +
'The error has been emailed to our support department to have the issue fixed, we apologize :(');
return false;
}
if(data.fail == 2) {
apprise('An email address is required!');
return false;
}
}
}, 'json');
return false;
});
$('.comment-link').live('click', function() {
var id = this.id;
$.post('../service/service.loadComments.php', { id: id }, function(data) {
if(data.success == true) {
$('#content-container').html(data.results);
return true;
}
if(data.success == false) {
apprise('An error has occured retrieving the comments for this deal. ' +
'The error has been emailed to our support department to have the issue fixed, we apologize :(');
return false;
}
}, 'json');
return false;
});
$('.post-comment-button').live('click', function() {
var id = this.id;
var comment = $('#comment-textarea').val();
var author = $('#post-comment-whois').val();
var swear = swearFilter(comment);
if(swear == true) {
apprise('Please remove the word "' + swear + '" from your comment.');
return false;
}
if(comment == '') {
apprise('Please fill out a comment first!');
return false;
}
$.post('../service/service.postComment.php', { id: id, comment: comment, author: author }, function(data) {
if(data.success == true) {
$.post('../service/service.loadComments.php', { id: id }, function(data) {
if(data.success == true) {
$('#content-container').html(data.results);
return true;
}
if(data.success == false) {
apprise('An error has occured retrieving the comments for this deal. ' +
'The error has been emailed to our support department to have the issue fixed, we apologize :(');
return false;
}
}, 'json');
return false;
}
if(data.success == false) {
if(data.fail == 1) {
apprise('An error has occured while attempting to post your comment. ' +
'The error has been emailed to our support department to have the issue fixed, we apologize :(');
return false;
}
if(data.fail == 2) {
apprise('Please fill out a comment first!');
return false;
}
}
}, 'json');
return false;
});
});`
Use history.js to pushState and then window.history.back()

Resources