Function that already running don't call it next time - php

I am working on AngularJS project I am using ng-repeat to show data, There is a Edit button that enable editing for particular row. On edit button click there is Save and Cancel button shows. On save button click it call $http.post to update data in database. Data are shown in gal unit and store as liter so when I click on save button it first convert to liter and then store in db.
Now the problem is when I click on Save button for once it work correctly, But when I click twice on Save button it convert gal -> liter -> liter and then save to db.
So I want to do is if $http request is already in process then do not accept another $http request.
I have tried to disable the button but still it is clickable.
HTML:
<div class="taxi_output" ng-repeat="item in vmDosings.data track by $index" >
<div class="row">
<div class="col-lg-4 text-center one" ng-bind="item.dos_nr"></div>
<div class="col-lg-4 text-center two">
<div ng-if="item.enableContent">
<input id="{{$index}}" class="font-size input-{{$index}}" ng-class="{ 'error' : vmDosings.error.level || vmDosings.error.undef || vmDosings.error.exist }" type="text" ng-model="item.level" ng-change="itemChanges(item)" ng-disabled="!item.enableContent"/> {{::$root.getEinheiten($root.GlobalData.config.volumemessurement)}}
</div>
<div ng-if="!item.enableContent" >
<p class=""> {{ item.level + ' ' + $root.getEinheiten($root.GlobalData.config.volumemessurement)}} </p>
</div>
</div>
<div class="col-lg-4" ng-if="item.enableContent == false" style="vertical-align: middle">
<a class="btn" ng-click="enableContent(item, $index)" event-focus="click" event-focus-id="{{$index}}" tooltip-placement="bottom" tooltip="{{::$root.getLabel('edit')}}">
<i style="cursor:pointer;" class="fa fa-edit fa-2x"></i>
</a>
<a class="btn" ng-if="vmDosings.data.length > 1" ng-click="removeFromList(item, $index)" tooltip-placement="bottom" tooltip="{{::$root.getLabel('delete')}}">
<i style="cursor:pointer;" class="fa fa-trash fa-2x"></i>
</a>
</div>
<div class="col-lg-4" ng-if="item.enableContent == true">
<a class="btn" ng-click="saveChanges(item, $index)" tooltip-placement="bottom" tooltip="{{::$root.getLabel('save')}}">
<i style="cursor:pointer;" class="fa fa-save fa-2x"></i>
</a>
<a class="btn" ng-click="removeFromList(item, $index)" tooltip-placement="bottom" tooltip="{{::$root.getLabel('delete')}}">
<i style="cursor:pointer;" class="fa fa-trash fa-2x"></i>
</a>
<a class="btn" ng-click="restoreChanges(item)" tooltip-placement="bottom" tooltip="{{::$root.getLabel('reset')}}">
<i style="cursor:pointer;" class="fa fa-remove fa-2x"></i>
</a>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div ng-if="item.enableContent && vmDosings.validate == false">
<div class="panel panel-danger" style="margin-top:5px; margin-bottom:0px;">
<div class="panel-heading" style="padding:0">
<ul style="padding: 5px 0px 5px 30px;">
<li ng-if="vmDosings.error.level" ng-bind="getLabel('only_floats_with_one_digit')"></li>
<li ng-if="vmDosings.error.undef" ng-bind="getLabel('inputs_empty_not_allowed')"></li>
<li ng-if="vmDosings.error.exist" ng-bind="getLabel('data_already_exist')"></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="hr-line-dashed"></div>
</div>
AngulrJS:
Enable Edit Mode:
$scope.enableContent = function(data, $index) {
angular.forEach(vmDosings.data, function(value, key) {
vmDosings.data[key].enableContent = (value.id == data.id ? true : false );
});
$timeout(function () {
$('.input-'+ $index).focus();
$('.input-'+ $index).val($('.input-'+ $index).val());
});
}
save button click:
$rootScope.GlobalData.config.volumemessurement get the id of unit
$rootScope.calcunits(9, id, data['level']); is a function for convert
$scope.saveChanges = function(data) {
var id = $rootScope.GlobalData.config.volumemessurement;
data['level'] = $rootScope.calcunits(id, 9, data['level']);
checkValues(data);
var checked = true;
for (i in vmDosings.error) {
if (vmDosings.error[i]) {
checked = false;
vmDosings.validate = false;
break;
}
}
if(checked == true) {
DosingsServices.saveChanges(data).then(function (result) {
if( result.data.message == 'success' && result.data.status == 200) {
DosingsServices.getDosings($stateParams.taxi_id).then(function (result) {
//vmDosings.data = result.data.dosings
var data = result.data.dosings;
var id = $rootScope.GlobalData.config.volumemessurement;
var i = 0;
for(i = 0; i <= data.length; i++) {
angular.forEach(data[i], function(value, key){
if(key == "level")
data[i][key] = $rootScope.calcunits(9, id, value)
});
}
vmDosings.data = data;
});
}
else if( result.data.message == 'Data Already Exist') {
data['level'] = $rootScope.calcunits(9, id, data['level']);
vmDosings.error.exist = true;
vmDosings.validate = false;
}
});
}
}

What you need is interceptors method of $httpProvider. It give you full control over any http call within Angular scope ( request,requestError,response,responseError methods).
If service call is already in progress you can skip next call or put it in a queue to call once you get response from previous call any other thing you want to do
// register the interceptor as a service
$provide.factory('myHttpInterceptor', function($q, dependency1, dependency2) {
return {
// optional method
'request': function(config) {
// do something on success
return config;
},
// optional method
'requestError': function(rejection) {
// do something on error
return $q.reject(rejection);
},
// optional method
'response': function(response) {
// do something on success
return response;
},
// optional method
'responseError': function(rejection) {
// do something on error
return $q.reject(rejection);
}
};
});
$httpProvider.interceptors.push('myHttpInterceptor');

Set a flag var inProgress = true; before your post method. Check on if this flag is set before you post. Set flag to false when post method is finished (finally).
You can also use this flag to enable/disable save button.

Related

Reset alpine component to initial state

I'm starting with Alpine js and I use a component with plus and minus buttons to add or remove items, however this is used in a modal that when invoked brings a specific product, the problem is that when closing the modal and opening it again with another product the component values ​​do not update, is there a way to reset to the initial state?
<div wire:model.defer='{{ $wiremodel }}'
class="input-group input-group-sm {{$size == 'l' ? 'input-group-lg': ''}} {{$size == 's' ? 'input-group-sm': ''}}"
x-data="{ count: {{ $min }}, max:{{ $max }}, min:{{ $min }}, price:{{ $price }},
increment(){
var incre;
if(this.max == 0){
incre = true;
this.count ++;
}else{
this.count == this.max ? incre = false : incre = true;
this.count == this.max ? this.count : this.count++;
}
if(incre){
var oldprice;
var newprice;
oldprice = $('#price_product_button').attr('data-price');
newprice = parseFloat(this.price) + parseFloat(oldprice);
$('#price_product_button').attr('data-price', newprice);
$('#price_product_button').html(newprice.toLocaleString('pt-BR', { style: 'currency' , currency:'BRL'}));
}
},
decrement(){
var decre;
this.count == this.min ? decre = false : decre = true;
this.count == this.min ? this.count : this.count--;
console.log(this.count);
if(decre){
var oldprice;
var newprice;
oldprice = $('#price_product_button').attr('data-price');
newprice = parseFloat(oldprice) - parseFloat(this.price) ;
$('#price_product_button').attr('data-price', newprice);
$('#price_product_button').html(newprice.toLocaleString('pt-BR', { style: 'currency' , currency:'BRL'}));
}
}
}">
<div class="input-group-prepend">
<button #click="decrement() ; $dispatch('input', count)" class="btn btn-outline-light bg-white text-danger" data-price="">
<i class="fas fa-minus"></i>
</button>
</div>
<input readonly x-model.number="count" class="form-control border-0 text-center input-btn-add-remove"
placeholder="{{ $min }}" />
<div class="input-group-append">
<button #click="increment() ; $dispatch('input', count)" class="btn btn-outline-light bg-white text-danger">
<i class="fas fa-plus"></i>
</button>
</div>
</div>```
If the x-data object of a component contains an init() method, it will be called automatically. For example:
<div x-data="{
init() {
this.count = {{ $min }};
this.max = {{ $max }};
this.min = {{ $min }};
this.price = {{ $price }};
}
}">
...
</div>
You can use that fact for your advantage and everytime the modal opens, the init method can be called to reset the values to its original state. Also it will be called automatically on the first init.

How to i use id from a selected item in datatable for a button?

I have a problem with PHP and Codeigniter. In this datatable, you can select rows from it. What I need to do, is that when I select a row, I have to use it's id to press the yellow button call 'editar' at right and be available to edit that row.
enter image description here
this is my HTML:
<div class="row">
<div class="col-lg-9">
<?=$tablaObrasSociales?>
</div>
<div class="col-lg-3">
<div class="ibox">
<div class="ibox-content" style="text-align: center;">
<h3>Acciones</h3>
<p><button class="btn btn-w-m btn-primary" data-toggle="modal" data-target="#modalNuevaOS" ><i class="fa fa-plus"></i> Obra Social</button></p>
<p><button id="btnEditarOs" onclick="accionClickObrasSociales();" class="btn btn-w-m btn-warning" disabled data-toggle="modal" data-target="#modalEditarOS"><i class="fa fa-trash"></i> Editar</button></p>
<p><button id="btnBajaOs" class="btn btn-w-m btn-danger" disabled><i class="fa fa-times"></i> Dar de baja</button></p>
</div>
</div>
</div>
</div>
and this my Javascript:
function accionClickObrasSociales(){
var id_fila=$(this).attr('id');
$('#tablaObrasSociales tr').removeClass("filaResaltada"); //Limpia el estilo de fila resaltada
$(this).addClass("filaResaltada"); //Resalta la fila seleccionada
if (id_fila != null) {
document.getElementById("btnEditarOs").disabled = false;
document.getElementById("btnBajaOs").disabled = false;
}
editar(id_fila);
}
function editar(idFila){
debugger;
$.ajax({
type: "POST",
url: "<?= BASEURL?>" + "/obraSocial/editar/"+idFila,
});
}
You could iterate over the row data to get the selected row id :
var table = $('#example').DataTable();
function accionClickObrasSociales(){
var id_fila=$(this).attr('id');
$('#tablaObrasSociales tr').removeClass("filaResaltada"); //Limpia el estilo de fila resaltada
$(this).addClass("filaResaltada"); //Resalta la fila seleccionada
if (id_fila != null) {
document.getElementById("btnEditarOs").disabled = false;
document.getElementById("btnBajaOs").disabled = false;
}
editar(id_fila);
var selected_id = $.map(table.rows('.selected').data(), function (item) {
return item[0] // return first column value, which is ID column
});
console.log('the row id is : ', selected_id)
}

How to fix POST data not properly set from ajax request?

I have a problem in getting the POST data from a page using ajax. In the jquery code the data is running smoothly and it will display when i alert the data. In the ajax request code the data from jquery has been successfully pass into showpercent.php file. Now the problem about showpercent.php, the data POST index percentage_id is unidentified. How can i fix this problem in getting the value of POST?
Below is the table list with button when the data is coming from.
<table>
<tr>
<td>
<button class="btn btn-info show-percentage" title="Click to add view percentages!" data-percentage_id="'.$row['hidden_id'] .'" data-toggle="show-percentage"><i class="glyphicon glyphicon-time"></i></button>
</td>
</tr>
</table>
Below is the ajax request sending the data into showpercent.php file. When I alert the percentage_id from button click the data will show in the alert and the ajax was successfully pass into specific php file which is showpercent.php.
<script>
$(document).ready(function(){
$(".show-percentage").click(function(){
var percentage_id = $(this).data('percentage_id');
alert("Ajax Landing ID "+landing_id);
$.ajax({
url: 'ajax/showpercent.php',
type: 'POST',
cache: false,
data: { percentage_id : percentage_id },
success: function(data) {
alert(data);
$('#add-percentage').modal('show');
readRecords();
},
error: function(request, status, error){
alert("Error!! "+error);
}
});
// READ recods when the button is click
readRecords();
});
function readRecords() {
$.get("ajax/showpercent.php", {}, function (data, status) {
$(".display_percentage").html(data);
});
}
});
</script>
Below is the modal having a tab will display the data from ajax request. The class display_percentage will display the current data from showpercentage.
<div id="add-percentage" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Fish Landing Percentage</h4>
</div>
<div class="modal-body">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#menu1">Add Percentage</a></li>
</ul>
<div class="tab-content">
<div id="menu1" class="tab-pane fade in active">
<br>
<div class="display_percentage"></div>
</div>
</div>
<div class="modal-footer">
<button type="button" id="primary" class="btn btn-primary" onclick="AddPercentage()"> Add Percentage </button>
<button type="button" id="danger" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
showpercent.php
This file will read by readRecords() function to display into the modal with tab class display_percentage when the button click is triggered.
This is now the problem comes, when the data was successfully pass from ajax request the data POST in the showpercent.php is not properly set and cannot proceed to the mysql process because the POST is not set.
<?php
include 'db.php';
$data = '
<table">
<thead>
<tr class="success">
<th ><center>No.</center></th>
<th ><center>Percentage ID</center></th>
<th ><center>Landing ID</center></th>
<th><center>Percentage</center></th>
<th><center>Date Added</center></th>
</tr>
</thead>';
if(isset($_POST['percentage_id'])){
$landing_id = $_POST['percentage_id'];
$query = mysqli_query($conn, "SELECT
percentage.percent_id,
percentage.landing_id,
percentage.percentage,
percentage.date_recorded
FROM
percentage
WHERE percentage.landing_id = '$landing_id'");
$number = 1;
while($row = mysqli_fetch_array($query)) {
$data .= '
<tr>
<td><center>' . $number . '</center></td>
<td><center>' . $row['percent_id'] . '</center></td>
<td><center>' . $row['landing_id'] . '</center></td>
<td><center>' . $row['percentage'] . '%</center></td>
<td><center>' . date("M. d, Y", strtotime($row['date_recorded'])) . '</center></td>
</tr>';
$number++;
}
}else{
echo 'Percentage id is not set!';
}
$data .= '
</table>';
echo $data;
?>
But in the console the ajax passing data will run smoothly.
I wish anybody will help me to fix this problem.
I read your code your showpercent.php, javascript and html and soo far and notice this
<button class="btn btn-info show-percentage" title="Click to add view percentages!" data-percentage_id="'.$row['hidden_id'] .'" data-toggle="show-percentage"><i class="glyphicon glyphicon-time"></i></button>
and check this
data-percentage_id="'.$row['hidden_id'] .'"
you're doing it wrong this is not how you put php value into html value, this will return undefined in javascript if you try to get its value so
This is why
var percentage_id = $(this).data('percentage_id');
returns undefined in javascript and php
So replace it with this
data-percentage_id="<?php echo $row['hidden_id']; ?>"
So replace your button into like this
<button class="btn btn-info show-percentage" title="Click to add view percentages!" data-percentage_id="<? echo $row['hidden_id']; ?>" data-toggle="show-percentage"><i class="glyphicon glyphicon-time"></i></button>
thanks to #Keval Mangukiya
try:
add this in your html
<button id="percentage_id" class="btn btn-info show-percentage" title="Click to add view percentages!" data-percentage_id="<?=$row['hidden_id'] ?>" data-toggle="show-percentage"><i class="glyphicon glyphicon-time"></i></button>
set the value of your percentage_id before getting it
add to your JavaScript with
$("#percentage_id]").data('percentage_id',loading_id); //setter
var percentage_id = $(this).data('percentage_id'); //getter

my website shows 500 internal server error , when receiving ajax response

It shows 500 internal server error when retrieving data through ajax. But the whole code works well in my localhost. And i am facing this error for the first time, so i am not sure whether this error is caused due to fetching data through AJAX. If it is not the correct reason please get me the correct reason.
this is my coding
$.ajax({
type:"POST",
url:"api_fle/get_post",
data:{u_id:u_id,type:'all13'},
success:function(response){
if(response!=0){
var parsed = $.parseJSON(response);
date = new Array();
events = new Array();
$.each(parsed,function(i,parsed){
if(parsed.shred.length>15){var shred=jQuery.trim(parsed.shred).substring(0, 14) + '...';} else{var shred=parsed.shred;}
if(parsed.cmpny_name == parsed.shred){var sharedd=parsed.cmpny_name; var sha=""; var pic=parsed.pro_pic;}else{var sharedd=shred; var sha=' shared <input type="hidden" id="who_hid_id" value="'+parsed.id+'">'+parsed.cmpny_name+"'s Event"; var pic=parsed.pic;}
date[i]=parsed.SharedDate;
events[i]='<div class="col-md-10 post" style="background:#FFF"><span class="company-logo-small"><img src="'+pic+'" style=" width: 60px; height: 60px;"></span>'
+'<span class="fullhead"><span class="posted-name"><a id="who_shred" style="color:#fff;cursor:pointer;"><input type="hidden" id="who_hid_id" value="'+parsed.id+'"><span itemprop="hiringOrganization">'+sharedd+'</span></a>'+sha+'</span></span>'
+'<span class="post-status" style="color:#fff;">'+prettyDate(parsed.SharedDate)+'</span><div class="post-inner"><div class="col-md-12"><div class="panel panel-default event">'
+'<div class="panel-heading title">'+parsed.name+'</div><ul class="list-group"><li class="list-group-item"><i class="fa fa-globe"></i>'+parsed.location+'</li>'
+'<li class="list-group-item"><i class="fa fa-calendar-o"></i>'+parsed.date+'</li><li class="list-group-item"><i class="fa fa-clock-o"></i>'+parsed.time+'</li>'
+'<li class="list-group-item"><i class="fa fa-users"></i>Attendees '+parsed.attendies+'</li></ul><ul class="list-group"><div class="panel-body"><p>'+parsed.decs+'</p>'
+'<a class="btn btn-xs btn-info pull-left" target="_blank" href="eventview?evnt_id='+parsed.evnt_id+'">View</a>&nbsp&nbsp'
+'<i class="fa fa-fw fa-facebook-square" style="font-size:20px;"></i>'
+'<a class="twitter popup" href="pagelink?evnt_id='+parsed.evnt_id+'" target="_blank"><i class="fa fa-fw fa-twitter-square " style="font-size:20px;"></i></a>'
+'<a class="twitter popup" href="pagelink?evnt_id='+parsed.evnt_id+'" target="_blank">'
+'<i class="fa fa-fw fa-linkedin-square" style="font-size:20px;"></i></a><a class="twitter popup" href="pagelink?evnt_id='+parsed.evnt_id+'" target="_blank">'
+'<i class="fa fa-fw fa-google-plus" style="font-size:20px;"></i></a></div></ul><div id="img"></div><div class="clearfix"></div></div></div></div></div>';
});
}
});
-------------------------
page : get_post
--------------------
if($_POST['type']=='all13'){
$update_time=mysql_query("UPDATE `share_post` SET `sharedDate`='".$_POST['time']."' WHERE `frm_id` = 'U005114608238'");
$sql=select_query("SELECT s.id,e.u_id,e.cmpny_name,n.pro_pic as pic,l.pro_pic,l.level as lv,m.evnt_id,m.name,m.location,m.decs,m.time,
m.date,m.attendies,s.frm_id,s.is_important,s.shred,s.SharedDate,s.lvl FROM employer_info e,login l,login n,`event` m, share_post s WHERE n.u_id=s.frm_id and e.u_id=l.u_id and m.u_id=l.u_id and m.evnt_id=s.post_id and s.to_id='".$_POST['u_id']."' order by s.id desc");
$count=count($sql);
$response=array();
for($i=0;$i<$count;$i++){
array_push($response,$sql[$i]);
}
echo json_encode($response);
}
when i have inspected the error , i got something like in this screenshot

React - "setState" is not a function

I have a view which shows a table with rows of data from a local wamp database. Each row has a View, Edit and Delete button which allows a user to View, Edit and Delete records respectively.
Clicking on a row's Delete button will bring up a confirmation modal and is deleted when the modal's Delete button is clicked.
Right now, clicking on the Delete button throws up these errors:
Warning: setState(...): You passed an undefined or null state object; instead, use forceUpdate().
Uncaught TypeError: this.setState(...) is not a function
I also get a warning when trying to bind a variable:
Warning: bind(): React component methods may only be bound to the component instance. See GamePlatformTable
I've tried using forceUpdate in place of setState from stuff I've been searching, but I get the same 2nd errors. If it helps, I'm using php, CodeIgniter 3.0.3 and native React 0.14.3. I'm still relatively new to React, and thanks for helping.
Here's my code:
View:
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php
$this->load->view("templates/meta_common");
$this->load->view("templates/css_common");
?>
<title>Video Game Portal Admin</title>
</head>
<body>
<div class="container">
<?php $this->load->view("admin/admin_navbar"); ?>
<div class="page-header">
<h1>
<i class="text-info fa fa-file-text-o"></i> Browse Game Platforms
<span class="badge">REACT JS</span>
<button onclick="window.location.replace('<?= site_url("admin/game_platform/add_game_platform/") ?>')" type="button"
class="btn btn-danger"><i class="fa
fa-plus"></i> Add Game Platform
</button>
</h1>
</div>
<?php $this->load->view("admin/template_user_message"); ?>
<div id="GamePlatformTable">
</div>
<?php $this->load->view("admin/admin_footer"); ?>
</div>
<?php $this->load->view("templates/js_common"); ?>
<script src="<?=RESOURCES_FOLDER?>js/react.js"></script>
<script src="<?=RESOURCES_FOLDER?>js/react-dom.js"></script>
<script src="<?=RESOURCES_FOLDER?>js/JSXTransformer.js"></script>
<script src="<?=RESOURCES_FOLDER?>jsx/BrowseGamePlatform.js" type="text/jsx;harmony=true"></script>
<script type="text/jsx">
var gamePlatforms = <?=json_encode($game_platforms)?>;
ReactDOM.render(
<GamePlatformTable
gamePlatforms = {gamePlatforms}
siteUrl = "<?=site_url()?>"
/>,
document.getElementById("GamePlatformTable")
);
</script>
External React:
The error occurs in the deleteButtonClicked function of GamePlatformTable.
var rowIndex = 0;
var GamePlatformRow = React.createClass({
render: function () {
++rowIndex;
var developer = !this.props.gamePlatform.developer || this.props.gamePlatform.developer == "none" ?
<span className="text-placeholder">none</span> : this.props.gamePlatform.developer;
var year_intro = !this.props.gamePlatform.year_intro || this.props.gamePlatform.year_intro == "0" ?
<span className="text-placeholder">0</span> : this.props.gamePlatform.year_intro;
var logo_img = this.props.gamePlatform.logo_url ?
<img className="img-rounded" src={this.props.siteUrl + "/uploads/" + this.props.gamePlatform.logo_url}
alt={this.props.gamePlatform.abbr} width="50px" height="50px"/> :
<span className="text-placeholder">no logo</span>;
var view_action = <a
href={this.props.siteUrl + "/admin/game_platform/view_game_platform/" + this.props.gamePlatform.platform_id}
type="button" className="btn btn-default"><i className="fa fa-eye"></i> View</a>;
var edit_action = <a
href={this.props.siteUrl + "/admin/game_platform/view_game_platform/" + this.props.gamePlatform.platform_id}
type="button" className="btn btn-default"><i className="fa fa-file-text-o"></i> Edit</a>;
return (
<tr>
<td>{rowIndex}</td>
<td>{this.props.gamePlatform.platform_name}</td>
<td><span className="badge">{this.props.gamePlatform.abbr}</span></td>
<td>{logo_img}</td>
<td>{developer}</td>
<td>{year_intro}</td>
<td>
{view_action}
{edit_action}
<button type="button" className="btn btn-default"
onClick={this.props.deleteButtonClicked.bind(this, this.props.gamePlatform.platform_id)}><i
className="fa fa-trash"></i> Delete
</button>
</td>
</tr>
);
}
}); //end GamePlatformRow
var GamePlatformTable = React.createClass({
getInitalState: function () {
return {
gamePlatforms: this.props.gamePlatforms,
deletePlatformId: null
};
},
refreshTableData: function () {
var data = {
"gamePlatforms": this.props.gamePlatforms
};
$.ajax({
url: this.props.siteUrl + "game_platform/json_get_all_platforms",
dataType: "json",
data: data,
cache: false,
success: function (data) {
this.setState({gamePlatforms: data.gamePlatforms});
}.bind(this),
error: function (xhr, status, err) {
console.error(this.props.siteUrl + "game_platform/json_get_by_platform_id", status, err.toString());
}.bind(this)
});
},
confirmDeleteClicked: function () {
var data = {
"platform_id": this.state.deletePlatformId
}
$.ajax({
type: "POST",
url: this.props.siteUrl + "game_platform/json_delete_by_platform_id",
dataType: "json",
data: data,
success: function (data) {
this.refreshTableData();
}.bind(this),
error: function (xhr, status, err) {
this.refreshTableData();
}.bind(this)
});
},
deleteButtonClicked: function (platform_id) {
console.log("GamePlatformTable.deleteButtonClicked\nplatform_id: " + platform_id);
$("#ConfirmDeleteModal").modal("show");
this.setState()({
deletePlatformId: platform_id
}).bind(this);
},
render: function () {
var rows = [];
this.props.gamePlatforms.forEach(
function (gamePlatform) {
rows.push(<GamePlatformRow gamePlatform={gamePlatform} key={gamePlatform.platform_id}
siteUrl={this.props.siteUrl}
deleteButtonClicked={this.deleteButtonClicked}/>);
}.bind(this)
);
return (
<div className="table-responsive">
<table className="table table-hover" id="GamePlatformTable">
<thead>
<tr>
<th>#</th>
<th>Platform Name</th>
<th>Platform Abbr</th>
<th>Platform Logo</th>
<th>Platform Developer</th>
<th>First Release Year</th>
<th> </th>
</tr>
</thead>
<tbody>{rows}</tbody>
</table>
<div className="modal fade" id="ConfirmDeleteModal">
<div className="modal-dialog">
<div className="modal-content">
<div className="modal-header">
<button type="button" className="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">×</span></button>
<h4 className="modal-title">Delete Game Platform</h4>
</div>
<div className="modal-body">
<p>Are you sure?</p>
<p>This action <strong className="text-danger">cannot</strong> be undone.</p>
</div>
<div className="modal-footer">
<button type="button" onclick={this.confirmDeleteClicked} className="btn btn-danger"
data-dismiss="modal"><i className="fa fa-trash"></i> Delete
</button>
<button type="button" className="btn btn-default" data-dismiss="modal"><i
className="fa fa-ban"></i> Cancel
</button>
</div>
</div>
</div>
</div>
</div>
);
}
}); // end GamePlatformTable
Edit 1:
Removing the .bind(this) removed the bind warning.
Edit 2:
I forgot to add, the console.logs() are showing the correct IDs.
Eh, I solved the prob.
I had parenthesis in front of setState.... like setState()({}) instead of setState({}).

Categories