Refresh widget when updating a record

Jonatan4
Giga Guru

I have a widget which displays records in a certain state, with a counter on top of how many there are (see image below). I want to update the counter when the user clicks on one of the buttons to reflect the current count.

Part of my HTML:

<div class="room-container" ng-if="selectedRoom.sys_id">
<div class="room-top-row">

<!-- THIS IS THE PART I WANT TO UPDATE WHEN CLICKING THE BUTTONS -->
  <div class="room-title"><b>{{selectedRoom.display}}</b> ({{currentInventory.length}})</div>

  <input class="form-control item-scan-input" type="text" placeholder="${Scan item to inventory}..." ng-model="scanInput" ng-model-options="{debounce: 200}" ng-change="updateInventoryScan(scanInput); scanInput='';">
</div>


<table class="table table-striped">
<thead>
  <tr>
    <th>${Inventory Number}</th>
    <th>${Inventory Type}</th>
    <th>${Action}</th>
  </tr>
</thead>

<tbody>
  <tr ng-repeat="inv in currentInventory">
    <td>{{inv.inventory.display}}</td>
    <td>{{inv.inventory.type}}</td>
    <td>
        <button ng-if="!inv.done" class="btn btn-xs btn-primary" ng-click="updateInventory(inv, 'inventoried', selectedRoom.sys_id)">${Inventoried}</button>
      <button ng-if="!inv.done" class="btn btn-xs btn-warning" ng-click="updateInventory(inv, 'missing', selectedRoom.sys_id)">${Missing}</button>
      <button ng-if="!inv.done" class="btn btn-xs btn-danger" ng-click="updateInventory(inv, 'will_be_scrapped', selectedRoom.sys_id)">${Will Be Scrapped}</button>
                
      <div ng-if="inv.done" style="color: green;">${Updated with state}: {{inv.state}}</div>
    </td>
  </tr>
</tbody>

 

Part of my Client Script:

function($scope, $uibModal) {
/* widget controller */
var c = this;

//----- Default Values -----
$scope.selectedRoom = {};
$scope.currentInventory = [];
//--------------------------

$scope.selectRoom = function(room){
    $scope.selectedRoom = room;
    c.server.get({action: 'getScheduledInventory', room: room.sys_id, task: c.data.current_task_id}).then(function(resp){
        $scope.currentInventory = resp.data.inventory;
    });
}

$scope.updateInventory = function(item, state, room){
    if($scope.modal){
        $scope.modal.close();
        
        $scope.currentInventory.push($scope.tempInvData.inventoryItem);
        $scope.modal = false;
    }
        
    c.server.get({action: 'updateInventory', id: item.sys_id, state: state , room: room }).then(function(resp){
        if(resp.data.wasUpdated){
            item.done = true;
            item.state = resp.data.newState;
            item.room = resp.data.room;
        }
    });
}
1 REPLY 1

palanikumar
Mega Sage

Add this line after "item.room = res.data.room" and see whether issue is resolved

$scope.selectRoom(item.room);

Thank you,
Palani