ajax only works once a refresh - ajax

I was doing a cart section where you can change your product quantity, at first i did it with a normal form, but i change it to ajax because i want to the page doesn´t need to refresh at all to show you your new quantity with your new price and your new total, so i did the following:
$('.actform').on('submit', function(ev) {
var id2 = $(this);
$.ajax({
type: $(id2).attr('method'),
url: $(id2).attr('action'),
data: $(id2).serialize(),
success: function(data) {
$('.container').load(' .container');
},
error: function() {
alert('Ha ocurrido un error');
}
});
ev.preventDefault();
});
It was all okay when you change 1 product for first time, but the second time the forms submits like it doesn´t have ajax, to fix this problem i replaced $('.container').load(' .container'); to $('.container').load(window.location.reload(false)); and it works, but i wanna know if there is another way to do it because this reload stutters a bit the page reload and it looks weird
cart.php whithout ajax (if you need to see):
<main id="main" class="main">
<?php if(!empty($_SESSION['cart'])){ ?>
<div class="container">
<h2 class="carrito-title">Mi Carrito</h2>
<div class="container2">
<div class="container-cart">
<table>
<thead>
<tr>
<th class="product-image">Imagen</th>
<th class="product-name">Producto</th>
<th class="product-price">Precio</th>
<th class="product-quantity">Cantidad (Modificar)</th>
<th class="product-total">Total</th>
<th class="product-remove">Eliminar</th>
</tr>
</thead>
<tbody>
<?php
$total= 0;
foreach($_SESSION['cart'] as $indice=>$producto){
$ID = $producto['ID'];
$select_products = $connect->prepare("SELECT * FROM `productos` WHERE id=$ID") or die('query failed');
$select_products->execute();
$list_products = $select_products->fetchAll(PDO::FETCH_ASSOC);
foreach($list_products as $product){
$nombre= $product['nombre'];
$precio= $product['precio'];
$codigo = $product['codigo'];
$imagen = "media/productos/$codigo.png";
?>
<tr>
<td class="product-image">
<img src="<?php echo $imagen?>" alt="<?php $nombre?>">
</td>
<td class="product-name">
<h2 class="name"><?php echo $nombre?></h2>
</td>
<td class="product-price"><h2 class="precio">$<?php echo number_format($precio, 0, ',', '.') ; ?></h2></td>
<td class="product-quantity">
<form action="backend/actProduct.php" method="post" class="actform" id="<?php echo $ID ?>">
<div class="cantidad">
<div class="cantidad-container">
<input type="hidden" name="id" min="1" value="<?php echo openssl_encrypt($ID,COD,KEY);?>">
<input type="number" class="nro updateCant" onchange="btnCart.click()" name="cantidadupd" value="<?php echo $producto['CANTIDAD'];?>">
<button name="btnCart" value="Update" type="submit" class="actualizar"><i class="fa-solid fa-rotate"></i></button>
</div>
</div>
</form>
</td>
<?php
$sub_total = $precio * $producto['CANTIDAD'];
$total = $total + $sub_total;
?>
<td><h2 class="subtotal">$<?php echo number_format($sub_total, 0, ',', '.'); ?></h2></td>
<td>
<form action="backend/deleteProduct.php" method="post">
<input type="hidden" name="id" value="<?php echo openssl_encrypt($ID,COD,KEY);?>">
<button class="delete" name="btnCart" type="submit" value="Remove" onclick="return confirm('Seguro que quieres eliminar este artículo?');">X</button>
</form>
</td>
</tr>
<?php
}};
?>
</tbody>
</table>
</div>
<?php if(isset($_SESSION['cart'])){ ?>
<div class="nocart">
<div class="final">
<h5 class="final-price preciofinal">Precio sin Impuestos: $<?php echo number_format($total, 0, ',', '.');?></h5>
<form action="backend/emptyCart.php" method="post" class="emptyform" id="<?php echo $ID ?>">
<input type="hidden" name="empty">
<button name="btnCart" type="submit" class ="vaciar" value="Empty" onclick="return confirm('¿Desea vaciar el carrito?');">Vaciar carrito</button>
</form>
</div>
<?php
if ($rol=='representante'){
?>
<div class="checkout">
<form action="productos.php">
<button name="btnFinCart" class="seguircomprando-btn">Seguir comprando</button>
</form>
<a class="checkout-btn" href="clientes.php">Seleccionar cliente</a>
</div>
<?php
}else{?>
<div class="checkout">
<form action="productos.php">
<button name="btnFinCart" class="seguircomprando-btn">Seguir comprando</button>
</form>
<form action="backend/fincompra.php" method="post" onsubmit="showLoad()">
<button name="btnFinCart" class ="checkout-btn" onclick="return confirm('¿Está seguro que desea finalizar la compra?');" value="Fin" >Finalizar compra</button>
</form>
</div>
<?php
}
?>
</div>
</div>
<?php }?>
</div>
<?php }else{
echo '
<div class="nosesion">
<h2 class="cartvacio">El carrito esta vacío</h2>
<a class="comprar-btn" href="productos.php">Comprar ahora</a>
</div>
';
}?>
</main>

Related

how to make ajax call inside a edit form view in laravel

i have created a form for editing the record from db there is different time slots and i want to make delete function for them so i made a ajax call but am confused in URL www.hostname.com/dental/public/admin/manageschedule/1/api/ajax 404 (Not Found)
how to call ajax inside a laravel edit form
here is what i have done:
#extends('admin.layouts.app_inner')
#section('htmlheader_title')
Home
#endsection
#section('content')
#if (count($errors))
#foreach($errors->all() as $error)
<div class="alert alert-danger"><i class="fa fa-fw fa-close"></i> {{ $error }}</div>
#endforeach
#endif
#if ($message = Session::get('success'))
<div class="alert alert-success alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-check"></i>Success</h4>
{{ $message }}
</div>
#endif
<div class="box box-info">
<div class="box-header with-border">
<h3 class="box-title text-green"><b>Add Schedule</b></h3>
</div>
<!-- /.box-header -->
<!-- form start -->
<div class="box-body">
{!! Form::model($doctors, ['method' => 'PATCH','route' => ['manageschedule.update', $doctors->doctor_id],'class' => 'form-horizontal','files'=>true]) !!}
<div class="form-group">
<label class="col-md-3 control-label"> Select Doctor :</label>
<div class="col-md-5">
<select class="form-control" required name="doctor_name">
<?php $results = DB::select(DB::raw("SELECT day FROM schedule_times where doctor_id='" . $doctors->doctor_id . "' Order BY id DESC ")); ?>
<option value="{{$doctors->doctor_name}}" SELECTED="YES">{{$doctors->doctor_name}}</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" required> Day :</label>
<div class="col-md-5">
<div class="md-checkbox-inline">
<?php $day = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'); ?>
#foreach($day as $days)
<input name="day[]" value="<?php echo $days; ?>" type="checkbox" class="md-checkbox" <?php
foreach ($results as $row) {
if ($row->day == $days) {
echo 'checked="checked"';
} else {
}
}
?> >
<label for="checkbox7"> <?php echo $days; ?> </label>
#endforeach
</div>
</div>
</div>
<?php foreach ($results as $row) { $d=$row->day;}
$result= DB::select(DB::raw("SELECT * FROM schedule_times where doctor_id='" . $doctors->doctor_id . "' And day='".$d."' "));
?>
<div class="form-group">
<label class="col-md-3 control-label" required>Time slots</label>
<div class="col-md-6">
<table class="table table-bordered" id="employee_table" width="50%" >
<th>Start Time</th>
<th>End Time</th>
<th>Manage</th>
<?php foreach ($result as $key=>$vari) {
$id = $vari->id;
?>
<tr id="row1">
<td><div class="input-group ">
<input type="text" class="form-control" id="time" placeholder="Start Time" name="s_time[]" value="<?php echo $vari->start_time; ?>" >
<span class="input-group-addon">
<span class="glyphicon glyphicon-time"></span>
</span>
</div></td>
<td><div class="input-group ">
<input type="text" class="form-control" id="time1" placeholder="Start Time" name="e_time[]" value="<?php echo $vari->end_time; ?>" >
<span class="input-group-addon">
<span class="glyphicon glyphicon-time"></span>
</span>
</div></td>
<?php if ($key == 0) { ?>
<td><input type='button' class='fa fa-plus fa-4 btn btn-primary' value='DELETE' disabled></td>
<?php } else { ?>
<td><span class='delete' id='del_<?php echo $id; ?>'><input type='button' class='fa fa-plus fa-4 btn btn-primary' value='DELETE' id='del_<?php echo $id; ?>' ></td>
</tr>
<?php }
}
?>
</table>
<a type="button" onclick="add_rows();" class="fa fa-plus-circle btn btn-primary"> Add More Time Slots</a>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label"> Per Patient Time :</label>
<div class="col-md-5">
<div class=" input-daterange">
<input type="text" name="p_time" class="form-control" placeholder="Set per patient time" id="time1" value="<?php
echo $result[0]->p_time; ?>">
<span class="help-block"> You can set only minute </span>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Visibility :</label>
<div class="col-md-5">
<input type="radio" id="checkbox2_5" value="Yes" name="visible" class="md-radiobtn" <?php
foreach($result as $check)
{
if($check->visibility=='Yes'){ echo 'checked="checked"';}else{}
} ?> >
<label for="checkbox2_5"> Yes </label>
<input type="radio" id="checkbox2_10" value="No" name="visible" class="md-radiobtn" <?php foreach($result as $check)
{
if($check->visibility=='No'){ echo 'checked="checked"';}else{}
} ?>>
<label for="checkbox2_10"> No </label>
</div>
</div>
<br><br>
<div class="box-footer">
<button type="submit" class="btn btn-info pull-right"id="submit">Update Schedule </button>
</div>
{!! Form::close() !!}
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$(function () {
$('#time').timepicker();
})
});
</script>
<script type="text/javascript">
$(document).ready(function () {
$(function () {
$('#time1').timepicker();
})
});
</script>
<script type="text/javascript">
function add_rows()
{
$rowno = $("#employee_table tr").length;
$rowno = $rowno + 1;
$("#employee_table tr:last").after("<tr id='row" + $rowno + "'><td><div class='input-group '><input type='text' class='form-control' placeholder='Start Time' name='s_time[]' onclick=showtime('row" + $rowno + "')><span class='input-group-addon'><span class='glyphicon glyphicon-time'></span></span></div> </td><td><div class='input-group '><input type='text' class='form-control' id='time1' placeholder='End Time' name='e_time[]'><span class='input-group-addon'><span class='glyphicon glyphicon-time'></span></span></div> </td><td><input type='button' class='fa fa-plus fa-4 btn btn-primary' value='DELETE' onclick=delete_row('row" + $rowno + "')></td></tr>");
}
function delete_row(rowno)
{
$('#' + rowno).remove();
}
</script>
<script type="text/javascript">
//Variant Deleting script///
$(document).ready(function () {
// Delete
$('.delete').click(function () {
var el = this;
var id = this.id;
var splitid = id.split("_");
// Delete id
var deleteid = splitid[1];
alert('Are you sure you want to delete?');
$.ajax({
url: 'api/ajax',
type: 'delete',
data: {id: deleteid},
success: function (response) {
// Removing row from HTML Table
$(el).closest('tr').css('background', 'tomato');
$(el).closest('tr').fadeOut(800, function () {
$(this).remove();
});
}
});
});
});
</script>
<meta name="_token" content="{!! csrf_token() !!}" />
#endsection
here is my controller of api
Route::post('ajax','Controller#ajax')->name('ajax');
here is my web route:
Route::get('/', function () {
return view('auth.login');
});
Route::post('/', function () {
return view('auth.login')->with('successMsg','Please Select A role .');
});
Route::prefix('admin')->group(function() {
Route::get('/login', 'Auth\AdminLoginController#showLoginForm')->name('admin.login');
Route::post('/login', 'Auth\AdminLoginController#login')->name('admin.login.submit');
Route::get('/', 'AdminController#index')->name('admin.home');
Route::resource('managedoctor', 'AddDocController');
Route::resource('managefront', 'AddFrontController');
Route::resource('managepatient', 'AddPatientController');
Route::resource('manageschedule', 'AddScheduleController');
Route::get('/logout', 'Auth\AdminLoginController#logout')->name('admin.logout');
});
Route::prefix('doctor')->group(function() {
Route::get('/login', 'Auth\DoctorLoginController#showLoginForm')->name('doctor.login');
Route::post('/login', 'Auth\DoctorLoginController#login')->name('doctor.login.submit');
Route::get('/', 'DoctorController#index')->name('doctor.home');
Route::get('/logout', 'Auth\DoctorLoginController#logout')->name('doctor.logout');
});
Route::prefix('frontdesk')->group(function() {
Route::get('/login', 'Auth\FrontdeskLoginController#showLoginForm')->name('frontdesk.login');
Route::post('/login', 'Auth\FrontdeskLoginController#login')->name('frontdesk.login.submit');
Route::get('/', 'FrontdeskController#index')->name('frontdesk.home');
Route::get('/logout', 'Auth\FrontdeskLoginController#logout')->name('frontdesk.logout');
});
my issue is resolved now the mistake i have done is i was not using the same route group in which am calling the controller with AUTH method

Banner Images not being reinserted correct to database

When I update my banner_image it should delete the ones from the database Then re insert the ones that are set.
Currently what it does is deletes the banner image but then re inserts blank banner_image
But should remove that enitre row.
Question How to make sure when I update it that will remove the images rows that are no longer selected and not re insert them
public function update($bid = NULL, $data = array()) {
$banner_update = array('banner_title' => $data['banner_title'], 'banner_status' => $data['banner_status']);
$this->db->where('bid', $bid);
$this->db->update('banner', $banner_update);
$this->db->where('bid', $bid)->delete('banner_image');
if (isset($data['banner_image'])) {
$banner_images = array();
$i = 0;
foreach ($data['banner_image'] as $image) {
$banner_images[$i] = array(
'bid' => $bid,
'banner_image' => $image['image'],
);
$i++;
}
$this->db->insert_batch('banner_image', $banner_images);
}
}
View
<?php echo form_open($action);?>
<div class="container">
<div class="card mt-3">
<div class="card-body">
<?php if (validation_errors()) {?>
<?php unset($_POST);?>
<div class="bg-error-warning">
<ul>
<?php echo validation_errors('<li>', '</li>');?>
</ul>
</div>
<?php }?>
<div class="row">
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12">
<p>Banner Title</p>
<div class="form-group">
<input type="text" name="banner_title" value="<?php echo $banner_title;?>" placeholder="Enter Banner Title" class="form-control">
</div>
</div>
</div>
<div class="row">
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12">
<table id="images" class="table table-striped table-bordered">
<tbody>
<tr>
<td>
<button type="button" onclick="addImage();" data-toggle="tooltip" title="Add Banner!" class="btn btn-primary"><i class="fa fa-plus-circle"></i></button>
</td>
</tr>
<?php $image_row = 0; ?>
<?php foreach ($banner_images as $banner_image) { ?>
<tr id="image-row<?php echo $image_row; ?>">
<td>
<a href="" id="thumb-image<?php echo $image_row; ?>" data-toggle="image">
<img src="<?php echo $banner_image['thumb']; ?>" alt="" title="" data-placeholder="<?php echo $placeholder; ?>" class="img-thumbnail"/></a>
<input type="hidden" name="banner_image[<?php echo $image_row; ?>][image]" value="<?php echo $banner_image['image']; ?>" id="input-image<?php echo $image_row; ?>" />
</td>
</tr>
<?php $image_row++; ?>
<?php } ?>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12">
<p>Banner Status</p>
<div class="form-group">
<?php $options = array('0' => 'Disabled', '1' => 'Enabled'); echo form_dropdown('banner_status', $options, $banner_status, array('class' => 'form-control'));?>
</div>
</div>
</div>
<div class="row">
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="form-group">
<button type="submit" class="btn btn-block btn-dark">Create Banner</button>
</div>
</div>
</div>
</div>
</div>
</div>
<?php echo form_close();?>
<script type="text/javascript">
var image_row = <?php echo $image_row; ?>;
function addImage() {
html = '<tr id="image-row' + image_row + '">';
html += '<td class="text-left">';
html += '<a href="" id="thumb-image' + image_row + '" data-toggle="image" >';
html += '<img src="<?php echo $placeholder; ?>" width="100" height="100" class="img-thumbnail" data-placeholder="<?php echo $placeholder; ?>"/>';
html += '<input type="hidden" name="banner_image[' + image_row + '][image]" value="" id="input-image' + image_row + '" />'
html += '</a>';
html += '</td>';
html += '<td class="text-left">';
html += '<button type="button" onclick="$(\'#image-row' + image_row + '\').remove();" data-toggle="tooltip" title="Remove Banner!" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button>'
html += '</td>';
html += '<script>';
html += '$(document).ready(function(){';
html += '$(\'[data-toggle="tooltip"]\').tooltip();';
html += '});';
html += '<\/script>';
$('#images tbody').append(html);
image_row++;
}
</script>
Have got it working just had to put empty in the foreach loop
public function update($bid = NULL, $data = array()) {
$banner_update = array('banner_title' => $data['banner_title'], 'banner_status' => $data['banner_status']);
// Updates the main banner table
$this->db->where('bid', $bid);
$this->db->update('banner', $banner_update);
// Removes banners so can have clean insert of new banners selected
$this->db->where('bid', $bid);
$this->db->delete('banner_image');
// Inserts new banner images & saved ones.
if ($this->input->post('banner_image')) {
foreach ($this->input->post('banner_image') as $image) {
if (!empty($image['image'])) {
$this->db->insert('banner_image', array('bid' => $bid, 'banner_image' => $image['image']));
}
}
}
}

What Script, Ajax , Controller codes are responsible for saving quantity

Below code we are using to display quantity text field and update quantity.
I want to know what all code is there in behind to update this quantity.
Means what script, ajax, contoller codes are responsible for saving this quantity.
<li class="fields">
<div class="customer-name">
<div class="field">
<label class="required" for="qty"><em>*</em><?php echo $helper->__('Quantity')?></label>
<div class="input-box">
<input type="text" name="qty" id="qty" value="<?php echo intval($mpAssignProductModel->getQty()) ?>" class="required-entry validate-zero-or-greater input-text"/>
</div>
</div>
</div>
</li>
because when i used above code in another file. It didt worked for me.
another page was displaying like this before :
After i replaced above code in another phtml file, its displaying like this :
This is complete code of file where updating quantity is not working :
phtml code :
<?php
$helper=Mage::helper('mpassignproduct');
$isPartner= Mage::getModel('marketplace/userprofile')->isPartner();
if($isPartner==1){ ?>
<script type="text/javascript">
if (typeof jQuery == 'undefined'){
document.write(unescape("%3Cscript src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>
<script src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<div>
<div class="page-title">
<h1><?php echo $helper->__('My Assign Product List') ?></h1>
</div>
<div class="wk_mp_design">
<div class="block block-account">
<div class="block-title">
<strong><span><h4><?php echo $helper->__('My Assign Product List'); ?></h4></span></strong>
</div>
</div>
<div class="fieldset wk_mp_fieldset">
<div class="grid">
<div class="hor-scroll">
<?php
if(count($this->getCollection())==0): ?>
<div class="fieldset wk_mp_fieldset">
<div class="wk_emptymsg">
<?php echo $helper->__('No Product Available') ?>
</div>
</div>
<?php else: ?>
<form action="<?php echo Mage::helper('core/url')->getCurrentUrl();?>" method="post">
<table cellspacing="0" class="border wk_mp_list_table">
<thead>
<tr id="wk_mp_tr_heading">
<th><span><?php echo $helper->__('Product Name') ?></span></th>
<th><span><?php echo $helper->__('Date') ?></span></th>
<th><span><?php echo $helper->__('Product Status') ?></span></th>
<th><span> </span></th>
</tr>
</thead>
<tbody class="wk_mp_body">
<tr>
<td>
<input type="text" class="input-text" name="s" placeholder='<?php echo $helper->__('Search by product name') ?>' value="<?php echo $this->getRequest()->getParam('s')?>"/>
</td>
<td>
<span class="wk_mp_td_span">
<?php echo $helper->__('From: ') ?>
<input name="from_date" id="special_from_date" class="input-text" value="<?php echo $this->getRequest()->getParam('from_date')?>" />
</span>
<span class="wk_mp_td_span">
<?php echo $helper->__('To: ') ?>
<input name="to_date" id="special_to_date" class="input-text" value="<?php echo $this->getRequest()->getParam('to_date')?>" />
</span>
</td>
<td>
<select name="prostatus" class="input-text">
<option value=""><?php echo $helper->__('All') ?></option>
<option value="1" <?php if($this->getRequest()->getParam('prostatus') == 1) echo 'selected="selected"'?>>
<?php echo $helper->__('Approved') ?>
</option>
<option value="2" <?php if($this->getRequest()->getParam('prostatus') == 2) echo 'selected="selected"'?>>
<?php echo $helper->__('Unapproved') ?>
</option>
</select>
</td>
<td>
<button class="button" title="Save" type="submit">
<span><span><span><?php echo $helper->__('Submit') ?></span></span></span>
</button>
</td>
</tr>
</tbody>
</table>
</form>
<form name="formmassdelete" id="form-customer-product-delete" method="post" action="<?php echo $this->getUrl('mpassignproduct/index/massdeletepro') ?>">
<input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" />
<button id="mass_delete_butn" style="float: left;padding: 5px 5px 5px 0;" type="submit" title="Delete Sellers" class="button">
<span><span>Delete Products</span></span>
</button>
<table cellspacing="0" class="border wk_mp_list_table wk_mp_list_container_table">
<thead>
<tr class="wk_content">
<th class="wk_check_first_td">
<span><input type="checkbox" id="mpselecctall" value="all" name="mpselecctall"></span>
</th>
<th class="wk_first_td">
<span class="label "><?php echo $helper->__('Product Name')?></span>
</th>
<th>
<span class="label name"><?php echo $helper->__('Price')?></span>
</th>
<th>
<span class="label name"><?php echo $helper->__('SKU')?></span>
</th>
<th>
<span class="label name"><?php echo $helper->__('Delivery Time')?></span>
</th>
<th>
<span class="label name"><?php echo $helper->__('Replacement Guarantee')?></span>
</th>
<th>
<span class="label qty"><?php echo $helper->__('Status')?></span>
</th>
<th>
<span class="label qty"><?php echo $helper->__('Qty.')?></span>
</th>
<th>
<span class="label qty"><?php echo $helper->__('Condition')?></span>
</th>
<th>
<span class="label"><?php echo $helper->__('Action')?></span>
</th>
</tr>
</thead>
<tbody>
<?php foreach($this->getCollection() as $assinproducts): ?>
<?php $products=Mage::getModel('catalog/product')->load($assinproducts->getProductId()); ?>
<tr class="wk_row_view ">
<td class="wk_check_first_td">
<span>
<input type="checkbox" value="<?php echo $assinproducts->getMpassignproductId(); ?>" class="mpcheckbox" name="product_mass_delete[]">
</span>
</td>
<td class="wk_first_td">
<span class="label name" title="<?php echo $products->getName(); ?>">
<?php
$productname=strlen($products->getName())>7?substr($products->getName(),0,7)."..":$products->getName();
echo $products->getName();
?>
</span>
</td>
<td>
<span class="label price">
<?php echo Mage::helper('core')->currency($assinproducts->getPrice(), true, false);?>
</span>
</td>
<td>
<span class="label sku">
<?php echo $assinproducts->getsku() ?>
</span>
</td>
<td>
<span class="label replacement">
<?php echo $assinproducts->getdeliverytime() ?>
</span>
</td>
<td>
<span class="label delivery">
<?php echo $assinproducts->getreplacement() ?>
</span>
</td>
<td>
<span class="label pro_status">
<?php if($assinproducts['flag']==1): ?>
<?php echo Mage::helper('mpassignproduct')->__('Approved')?>
<?php else: ?>
<?php echo Mage::helper('mpassignproduct')->__('Un-Approved')?>
<?php endif; ?>
</span>
</td>
<td>
<li class="fields">
<div class="customer-name">
<div class="field">
<label class="required" for="qty"><em>*</em><?php echo $helper->__('Quantity')?></label>
<div class="input-box">
<input type="text" name="qty" id="qty" value="<?php echo intval($mpAssignProductModel->getQty()) ?>" class="required-entry validate-zero-or-greater input-text"/>
</div>
</div>
</div>
</li>
</td>
<td>
<span class="label">
<?php
if($assinproducts['product_condition']=='new')
echo Mage::helper('mpassignproduct')->__('New');
else
echo Mage::helper('mpassignproduct')->__('Used');
?>
</span>
</td>
<td>
<span class="label wk_action">
<img src="<?php echo $this->getSkinUrl('marketplace/images/icon-edit.png'); ?>" data-type="<?php echo $assinproducts->getMpassignproductId(); ?>" alt="<?php echo $helper->__('Edit')?>" title="<?php echo $helper->__('Edit')?>" class="mp_edit"/>
<img data-type="<?php echo $assinproducts->getMpassignproductId(); ?>" src="<?php echo $this->getSkinUrl('marketplace/images/icon-trash.png'); ?>" alt="<?php echo $helper->__('Delete')?>" title="<?php echo $helper->__('Delete')?>" class="mp_delete"/>
</span>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</form>
<?php endif; ?>
</div>
</div>
<?php echo $this->getPagerHtml(); ?>
</div>
</div>
<div class="buttons-set">
<p class="back-link">
« <?php echo Mage::helper('marketplace')->__('Back') ?>
</p>
</div>
</div>
<?php }else{
echo "<h2 class='wk_new_msg'>".$helper->__("To BECOME SELLER PLEASE CONTACT TO ADMIN.")."</h2>";
}?>
<script>
function validateNumbers(e)
{
if (jQuery.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
// Allow: Ctrl+A, Command+A
(e.keyCode == 65 && ( e.ctrlKey === true || e.metaKey === true ) ) ||
// Allow: home, end, left, right, down, up
(e.keyCode >= 35 && e.keyCode <= 40)) {
// let it happen, don't do anything
return;
}
// Ensure that it is a number and stop the keypress
if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
e.preventDefault();
}
}
var $wk_jq = jQuery.noConflict();
(function($wk_jq){
$wk_jq( "#special_from_date" ).datepicker({dateFormat: "yy-mm-dd"});
$wk_jq( "#special_to_date" ).datepicker({dateFormat: "yy-mm-dd"});
$wk_jq('#mpselecctall').click(function(event) {
if(this.checked) {
$wk_jq('.mpcheckbox').each(function() {
this.checked = true;
});
}else{
$wk_jq('.mpcheckbox').each(function() {
this.checked = false;
});
}
});
$wk_jq('body').delegate('.mp_edit','click',function(){
var id=$wk_jq(this).attr("data-type");
var dicision=confirm('<?php echo $helper->__(" Are you sure you want to edit this product ? ")?>');
if(dicision==true){
var $type_id=$wk_jq(this).attr('data-type');
window.location = "<?php echo $this->getUrl('mpassignproduct/index/edit/') ?>".concat("id/",id);
}
});
$wk_jq('.mp_delete').click(function(){
var id=$wk_jq(this).attr("data-type");
var dicisionapp=confirm('<?php echo $helper->__(" Are you sure you want to delete this product ? ")?>');
if(dicisionapp==true)
window.location = "<?php echo $this->getUrl('mpassignproduct/index/delete/') ?>".concat("id/",id);
});
$wk_jq('#mass_delete_butn').click(function(e){
var flag =0;
$wk_jq('.mpcheckbox').each(function(){
if (this.checked == true){
flag =1;
}
});
if (flag == 0){
alert("<?php echo $helper->__(' No Checkbox is checked') ?>");
return false;
}
else{
var dicisionapp=confirm('<?php echo $helper->__(" Are you sure you want to delete these product ? ")?>');
if(dicisionapp==true){
$wk_jq('#form-customer-product-delete').submit();
}else{
return false;
}
}
});
})($wk_jq);
function hideReset(product_id)
{
var qtyId='#qty_'+ product_id;
var editLink="#edit_link_"+ product_id;
var updateButton="#update_button_"+ product_id;
var resetButton="#reset_button_"+ product_id;
$wk_jq(qtyId).hide();
$wk_jq(editLink).show();
$wk_jq(updateButton).hide();
$wk_jq(resetButton).hide();
}
function showField(product_id)
{
var qtyId = '#qty_'+ product_id;
var editLink = "#edit_link_"+ product_id;
var updateButton = "#update_button_"+ product_id;
var resetButton = "#reset_button_"+ product_id;
$wk_jq(qtyId).show();
$wk_jq(editLink).hide();
$wk_jq(updateButton).show();
$wk_jq(updateButton).prop('disabled', false);//just in case
$wk_jq(resetButton).show();
return false;
}
function updateField(product_id,assignqty)
{
// alert("Hello! I am an alert box!!");
var qtyId = '#qty_'+ product_id;
var valueId = '#valueqty_'+ product_id;
var updatedqty = '#updatedqty_'+ product_id;
var editLink = "#edit_link_"+ product_id;
var updateButton = "#update_button_"+ product_id;
var resetButton = "#reset_button"+ product_id;
var url = '<?php echo Mage::getUrl('marketplace/marketplaceaccount/updateField/')?>';
$wk_jq(qtyId).toggle();
$wk_jq(editLink).hide();
$wk_jq(updateButton).show();
$wk_jq(resetButton).show();
$qty = $wk_jq(qtyId).val();
jQuery(valueId).html($qty);
hideReset(product_id);
var tmpQty = assignqty+parseInt($qty) ;
new Ajax.Request(url, {
method: 'post',
parameters: {id: product_id, qty: tmpQty},
onComplete: function (transport) {
// alert(tmpQty);
jQuery(priceId).val($price);
jQuery(updatedqty).show().delay(2000).fadeOut();
$updateButton.prop('disabled', false);
}
});
}
</script>
Quantity is working in this file = http://pastebin.com/mByVn3ax

data tables couldnt work when thereis an bootstrap modal inside

I have a BIG PROBLEM, my data tables coundt work when i put a Bootstrap Modal in, the Bootstrap Modal is in the tr for Edit data for Looping.
here's my table and modal within
<table id="data" class="table table-bordered table-striped">
<thead>
<tr>
<th>No</th>
<th><center>Foto</center></th>
<th><center>Nip</center></th>
<th><center>Nama</center></th>
<th><center>Action</center></th>
</tr>
</thead>
<tbody>
<?php include( "../koneksi.php"); $no=1 ; $data_pegawai=m ysql_query( 'select * from data_pegawai'); while($data=m ysql_fetch_array($data_pegawai)){ ?>
<tr>
<td>
<?php echo $no; ?>
</td>
<td>
<?php echo $data[ 'foto']; ?>
</td>
<td>
<?php echo $data[ 'nip']; ?>
</td>
<td>
<?php echo $data[ 'nama']; ?>
</td>
<td>
<a class="btn btn-warning btn-md" data-toggle="modal" data-target="#myModalEdit<?php echo $data['id']; ?>"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a>
<a class="btn btn-danger btn-md"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>
</td>
<td>
<!-- Dialog Modal Edit -->
<div class="modal fade" id="myModalEdit<?php echo $data['id']; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel<?php echo $data['id']; ?>" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel<?php echo $data['id']; ?>">Edit Data</h4>
</div>
<div class="modal-body">
<form role="form" action="../master-pegawaiSimpan.php" method="post" enctype="multipart/form-data">
<div class="box-body">
<div class="form-group">
<div class="col-lg-12">
<label for="agama">Nip</label>
<input type="text" class="form-control" name="nip" placeholder="Nip" value="<?php echo $data['nip']; ?>">
<label for="agama">Nama</label>
<input type="text" class="form-control" name="nama" placeholder="Nama" value="<?php echo $data['nama']; ?>">
<br>
<label for="agama">Foto</label>
<input type="file" class="form-control" name="foto">
<br>
</div>
</div>
<div class="box-footer">
<button type="submit" value="Simpan" name="Simpan" class="btn btn-primary">Save</button>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</td>
</tr>
<?php $no++; } ?>
</tbody>
</table>
and i confused with the order of javascripts, did it make an effect?
So, if i delete the modal inside the table, data tables were fine
Your problem is a mismatch between the number of header <th> elements and the number column <td> elements. They must match exactly.
So you have two options :
Add an extra <th> element, or
Place the modal outside of the table. This is what you should do in my opinion. There is no reason what so ever for replicating the popover markup over and over, you could do something like this instead :
<a class="btn btn-warning btn-md" data-toggle="modal" data-target="#myModalEdit" edit-id="<?php echo $data['id']; ?>"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a>
remove id from the modal as well
<div class="modal fade" id="myModalEdit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
and add a click event to populate data from the row when the modal is about to be shown:
$('a[data-toggle="modal"]').on('click', function() {
$tr = $(this).closest('tr');
$('[name="nip"]').val($tr.find('td:eq(2)'));
$('[name="nama"]').val($tr.find('td:eq(3)'));
//etc
})

Magento admin block does not appear

I am experiencing very strange issue:
i have a module and it works in magento 1.4.0.0 - 1.7
recently i have someone that this module does not show in backend.
this the xml layout code
<reference name="content">
<block output="toHtml" type="syncer/adminhtml_mapping" template="wisepricer/mapping.phtml" name="wisepricer.mapping" />
</reference>
another peace of xml layout which goes to head - does appear.
i saw that it finds the block class (if you put die in the block constructor - it works).
But if you put die in the template - nothing. No logging about this.
the path to the template adminhtml/default/default/template/wisepricer/mapping.phtml
any ideas?
thanks
edit:
thanks for the reply guys, here is the additional info:
block declaration in config.xml
<blocks>
<syncer>
<class>Wisepricer_Syncer_Block</class>
</syncer>
</blocks>
part of the block class
<?php
/******************************************
* wisepricer *
******************************************/
class Wisepricer_Syncer_Block_Adminhtml_Mapping extends Mage_Adminhtml_Block_Template
{
function __construct() {
$this->setTemplate("wisepricer/mapping.phtml");
}
public function getHeader(){
$header = "Wisepricer Mapping";
return $header;
}
layout.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<adminhtml_syncer_mapping>
<reference name="head">
<action method="addItem"><type>skin_js</type> <name>wisepricer/prototype17.js</name></action>
<action method="addItem"><type>skin_js</type> <name>wisepricer/chosen.proto.js</name></action>
<action method="addCss"><stylesheet>wisepricer/wisepricer.css</stylesheet> </action>
<action method="addCss"><stylesheet>wisepricer/chosen.css</stylesheet> </action>
<action method="addItem"><type>skin_js</type> <name>wisepricer/chosen.proto.js</name></action>
</reference>
<reference name="content">
<block output="toHtml" type="syncer/adminhtml_mapping" template="wisepricer/mapping.phtml" name="wisepricer.mapping" />
</reference>
</adminhtml_syncer_mapping>
</layout>
template
<?php
$adminobj= new Mage_Adminhtml_Block_Template();
$formkey=$adminobj->getFormKey();
$licenseData=Mage::getModel('wisepricer_syncer/config')->load(1);
?>
<form id="mapping_form" name="mapping_form" method="post" action="<?php echo $this->getUrl('*/*/savemapping')?>">
<input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
<input name="mapping_form[stock]" type="hidden" value="qty" />
<div class="top_block">
<div class="top_block_left">
<div class="inner-cont">
<img src="<?php echo $this->getSkinUrl('images/wisepricer/wp-logo.png'); ?>"/>
</div>
</div>
<div class="top_block_right">
<button class="wp-save-btn" onclick="return beforeSubmit()"></button>
</div>
</div>
<div class="mid_block">
<div class="mid_block_left">
<div class="guidelines">
<div class="guidelines-block">
<p><?php echo $this->__('Enter your WisePricer license key you received from WisePricer. This will link this store with your WisePricer account.')?></p>
</div>
<div class="guidelines-block import-guidelines">
<p><?php echo $this->__('Choose which products to import to WisePricer.')?></p>
</div>
<div class="guidelines-block mapping-guidelines">
<h4><?php echo $this->__('Wisepricer mapping guidelines:')?></h4>
<ul>
<li id="rule1"><?php echo $this->__('If you have <span class="field">UPC</span> or <span class="field">ASIN</span> then fields <span class="field">BRAND</span>,<span class="field">MODEL</span>,<span class="field">MPN</span> are not required.')?></li>
<li id="rule2"><?php echo $this->__('If you don\'t have <span class="field">UPC</span> or <span class="field">ASIN</span>, then you should have at least one of the following combinations: <span class="field">BRAND+MODEL</span> or <span class="field">BRAND+MPN</span>')?></li>
<li id="rule3"><?php echo $this->__('You must have either <span class="field">COST</span> or <span class="field">MINPRICE</span> or, you can set fixed rule for <span class="field">MINPRICE</span>')?></li>
<li><?php echo $this->__('<span class="field">NAME</span>, <span class="field">SKU</span>, and <span class="field">PRICE</span> fields are required')?></li>
<li><?php echo $this->__('Other fields are not required, but having them will increase your ability to interact with them within WisePricer(e.g. setting advanced rules, better matching and more)')?></li>
</ul>
</div>
</div>
</div>
<div class="mid_block_right">
<div class="values-block">
<div class="license-block">
<div class="label-block"><label><?php echo $this->__('Enter your License key')?> <span class="required">*</span></label></div>
<input type="text" value="<?php echo $licenseData->getLicensekey()?>" class="input-text required-entry" name="register_form[licensekey]" />
</div>
</div>
<div class="values-block">
<div class="license-block import-settings">
<div class="values-block-sub b10">
<div class="label-block"><label><?php echo $this->__('Import:')?></label></div>
<?php echo $this->renderWebsitesSelect($licenseData->getWebsite())?>
</div>
<div class="values-block-sub b10">
<div class="label-block"><label><?php echo $this->__('Product types:')?></label></div>
<?php echo $this->renderTypesSelect($licenseData->getProduct_type())?>
</div>
<div class="values-block-sub b10 check-block">
<div class="label-block b0"><label><?php echo $this->__('Do not import out of stock items')?></label></div>
<input type="checkbox" name="register_form[import_outofstock]" <?php echo $this->getImportOutStockSet();?>/>
</div>
<div class="values-block-sub check-block">
<div class="label-block b0"><label><?php echo $this->__('Reprice Configurable')?></label></div>
<input type="checkbox" name="register_form[reprice_configurable]" <?php if($licenseData->getReprice_configurable()){ echo 'checked';}?>/>
<p class="wptip"><?php echo $this->__('The Configurable product will be assigned to the price of his cheapest child')?></p>
</div>
</div>
</div>
<p><?php echo $this->__('Please make sure the following fields are assigned correctly:');?></p>
<div class="values-block">
<table cellspacing="0" class="form-list">
<tr class="t-header">
<td><strong><?php echo $this->__('Required Fields')?></strong></td><td><strong><?php echo $this->__('Detected field')?></strong></td>
</tr>
<tr>
<td class="label firstcol"><span><?php echo $this->__('Title')?><span class="required">*</span></span></td>
<td class="input-ele"><?php echo $this->renderAttributesSelect('mapping_form[title]','title','name','required-entry chzn-select')?></td>
<td></td>
</tr>
<tr>
<td class="label firstcol"><span><?php echo $this->__('SKU')?><span class="required">*</span></span></td>
<td class="input-ele"><?php echo $this->renderSkuIdSelect('mapping_form[sku]','sku','sku','required-entry chzn-select')?></td>
<td></td>
</tr>
<tr>
<td class="label firstcol"><span><?php echo $this->__('UPC')?></span></td>
<td class="input-ele">
<?php echo $this->renderAttributesSelect('mapping_form[upc]','upc','upc','chzn-select')?>
</td>
<td class="desc"><p><span><?php echo $this->__('Universal Product Code')?></span></p></td>
</tr>
<tr>
<td class="label firstcol"><span><?php echo $this->__('Brand')?></span></td>
<td class="input-ele"><?php echo $this->renderAttributesSelect('mapping_form[brand]','brand','brand','chzn-select')?></td>
<td></td>
</tr>
<tr>
<td class="label firstcol"><span><?php echo $this->__('Model')?></span></td>
<td class="input-ele"><?php echo $this->renderAttributesSelect('mapping_form[model]','model','model','chzn-select')?></td>
<td></td>
</tr>
<tr>
<td class="label firstcol"><span><?php echo $this->__('MPN')?></span></td>
<td class="input-ele"><?php echo $this->renderAttributesSelect('mapping_form[mpn]','mpn','mpn','chzn-select')?></td>
<td></td>
</tr>
<tr>
<td class="label firstcol"><span><?php echo $this->__('ASIN')?></span></td>
<td class="input-ele">
<?php echo $this->renderAttributesSelect('mapping_form[asin]','asin','asin','chzn-select')?>
</td>
<td class="desc"><p><span><?php echo $this->__('Amazon Standard Identification Number')?></span></p></td>
</tr>
<tr>
<td class="label firstcol"><span><?php echo $this->__('Price')?> <span class="required">*</span></span></td>
<td class="input-ele"><?php echo $this->renderPriceAttributesSelect('mapping_form[price]','price','price','required-entry chzn-select')?></td>
<td></td>
</tr>
<tr>
<td class="label firstcol"><span><?php echo $this->__('Cost')?></span></td>
<td class="input-ele"><?php echo $this->renderAttributesSelect('mapping_form[cost]','cost','0','chzn-select')?></td>
<td></td>
</tr>
<tr>
<td class="label firstcol"><span><?php echo $this->__('Product image')?></span></td>
<td class="input-ele"><?php echo $this->renderAttributesSelect('mapping_form[productimage]','productimage','image','chzn-select')?></td>
<td></td>
</tr>
<tr class="special-opt-cont">
<td colspan="2">
<div class="ship-price-cont minprice">
<div class="ship-price-cont-top">
<div class="label"><?php echo $this->__('MinPrice')?></div>
<div class="value"><?php echo $this->renderAttributesSelect('mapping_form[minprice]','minprice','cost','chzn-select')?></div>
</div>
<div class="ship-price-cont-mid"><span><?php echo $this->__('-Or-')?></span></div>
<div class="ship-price-cont-bott">
<div class="label"><?php echo $this->__('Set a minimum price:')?></div>
</div>
<div class="ship-price-cont-bott desc">
<p><span><?php echo $this->__('this will manually override the choosen attribute.')?></span></p>
</div>
<div class="ship-price-cont-bott">
<div class="label">
<input id="minprice_man" type="text" name="mapping_form[minprice_man]" value="<?php echo $this->getFixedMinPrice()?>"/>
<?php echo $this->renderMinPriceRuleSelects();?>
</div>
</div>
</div>
</td>
<td class="desc"><p><span><?php echo $this->__('Wisepricer will never price below the minimum price you set.')?></span></p></td>
</tr>
<tr>
<td colspan="2">
<div class="ship-price-cont">
<div class="ship-price-cont-top">
<div class="label"><?php echo $this->__('Shipping price')?></div>
<div class="value"><?php echo $this->renderAttributesSelect('mapping_form[shipping]','shipping','0','chzn-select')?></div>
</div>
<div class="ship-price-cont-mid"><span><?php echo $this->__('-Or-')?></span></div>
<div class="ship-price-cont-bott">
<div class="label"><?php echo $this->__('Enter fixed shipping price')?></div>
<div class="value"><input type="text" name="mapping_form[shipping_man]" value="<?php echo $this->getShippingFixedRate()?>"/></div>
</div>
<div class="ship-price-cont-bott desc">
<p><span><?php echo $this->__('this will manually override the choosen attribute.')?></span></p>
</div>
</div>
</td>
<td></td>
</tr>
</table>
</div>
</div>
</div>
<div class="bott_block">
<div class="bott_block_left"></div>
<div class="bott_block_right">
<button class="wp-save-btn" onclick="return beforeSubmit()"></button>
</div>
</div>
</form>
<style>
#wsp-mapping td{
line-height: 20px;
overflow: hidden;
padding: 0 0 20px;
vertical-align: top;
width: 230px;
}
#wsp-mapping td.second-val{
padding-left: 20px
}
#wsp-mapping{
padding-top: 20px
}
</style>
<script type="text/javascript">
document.observe('dom:loaded', function(evt) {
var select, selects, _i, _len, _results;
if (Prototype.Browser.IE && (Prototype.BrowserFeatures['Version'] === 6 || Prototype.BrowserFeatures['Version'] === 7)) {
return;
}
selects = $$(".chzn-select");
_results = [];
for (_i = 0, _len = selects.length; _i < _len; _i++) {
select = selects[_i];
_results.push(new Chosen(select,{disable_search_threshold: 50}));
}
deselects = $$(".chzn-select-deselect");
for (_i = 0, _len = deselects.length; _i < _len; _i++) {
select = deselects[_i];
_results.push(new Chosen(select,{allow_single_deselect:true}));
}
return _results;
});
var editForm = new varienForm('mapping_form');
function beforeSubmit(){
$('rule2').setStyle('border:none');
$('rule1').setStyle('border:none');
$('rule3').setStyle('border:none');
var upc=$('upc').value;
var brand=$('brand').value;
var model=$('model').value;
var asin=$('asin').value;
var mpn=$('mpn').value;
var minprice=$('minprice').value;
var cost=$('cost').value;
var minprice_man=$('minprice_man').value;
var isValid=false;
var failedRule=0;
if(upc!=''||asin!=''){
if(minprice!=''||(cost!=''&&minprice_man!='')){
editForm.submit();
return;
}else{
failedRule=3;
}
}
if((brand!=''&&model!='')||(brand!=''&&mpn!='')){
if(minprice!=''||(cost!=''&&minprice_man!='')){
editForm.submit();
return;
}else{
failedRule=3;
}
}
if(failedRule==3){
$('rule3').setStyle('border:red solid 1px');
}else{
$('rule2').setStyle('border:red solid 1px');
$('rule1').setStyle('border:red solid 1px');
}
alert(Translator.translate('Please follow instructions in your mapping listed on the left.'));
window.location.hash='rule1';
return false;
}
</script>

Resources