Add items to the local database, as you select from the list

1

I want to make a list of products and as the person is clicking Add (+) or Diminuir (-) go showing the quantity in (+) or (-) and when clicking on "Continue Ordering" items listed in a WebSQL (LocalStorage) and move on to the next screen.

My question is how to do this, and whenever the quantity value is = 0 does not save to the local bank, only if > 0.

And I think it can not be the "Continue Ordering" button because I believe there's no way to save a full array (I'm not sure about that).

Well, my view is this:

My View:

<ion-view view-title="Comprar Bebidas Adicionais" hide-nav-bar="false" >     

        <ion-refresher pulling-text="Puxe para atualizar..."  on-refresh="doRefresh()"></ion-refresher>
        <ion-list class="card list">
            <div class="item item-input">
                <i class="icon ion-search placeholder-icon"></i>
                <input type="search" ng-model="q" placeholder="Procurar" aria-label="filter bebidasextras" />
            </div>
        </ion-list>

        <div class="list" ng-repeat="bebida in bebidasextras" >

          <div class="item item-button-right">
            <b>{{bebida.ad_bebida_titulo}}</b> - R$ {{bebida.ad_bebida_valor}}

          <!-- AQUI SÃO OS BOTÕES DE ADICIONAR E DIMINUIR ITENS -->      
           <div class="button-bar">
                 <button class="button button-clear button-block button-positive"> <!-- adiciona-->
                      <i class="ion-plus"></i>
                 </button>
                 <button class="button button-stable button-clear button-block button-small">{{item.cart_item_qty}}</button> <!-- aqui quero mostrar quantidade, este campo ainda não existe -->
                  <button class="button button-clear button-block button-positive"> <!-- botão de dominuir -->
                      <i class="ion-minus"></i>
                 </button> 
              </div>               
          </div>            

        </div>  

         <button class="button button-block button-assertive" ng-click="updateBebida()"> <!-- Chama para armazenar num WebSQL -->
                Continuar o Pedido
         </button>  

That presents this result:

MyController:

.controller("exBebidasCtrl", function($scope,$rootScope,$state,$ionicScrollDelegate,$http,$httpParamSerializer,$stateParams,$timeout,$ionicLoading,$ionicPopup,$ionicPopover,$ionicSlideBoxDelegate,$ionicHistory,ionicMaterialInk,ionicMaterialMotion, sharedCartService,CartServiceBebidasEx, $location, DBLocalAdBebidas){

    // VERIFICA SE HÁ BEBIDAS EXTRAS

    $scope.bebidasextras = [];

    var promise = $http.get('http://nhac.esy.es/api_carrinho/lista_bebida_extra.php?json=restaurantes')
      .success(function(retorno) {
        console.log(retorno);
        $scope.bebidasextras = retorno; // não precisa fazer retorno.data

            $scope.user = {
                bebidasextras: [$scope.bebidasextras[1]]
              };
              $scope.checkAll = function() {
                $scope.user.bebidasextras = angular.copy($scope.bebidasextras);
              };
              $scope.uncheckAll = function() {
                $scope.user.bebidasextras = [];
              };
              $scope.checkFirst = function() {
                $scope.user.bebidasextras = [];
                $scope.user.bebidasextras.push($scope.bebidasextras[0]);
              };
              $scope.setToNull = function() {
                $scope.user.bebidasextras = null;
              };


    })
    .error(function(erro) {        
        console.log(erro);
    });    


        // PEGA BEBIDAS SELECIONADAS      
        $scope.updateBebida = function(){
            var p = [];
            for (var i = 0; i < $scope.bebidasextras.length; i++) {
               var item = $scope.bebidasextras[i];
                console.log(item);
               if ( item.selected) {
                p.push(item )  
               }

            }

            $scope.selectedItems = p;
             var item;

    //aqi vai percorrer todo o conteudo da vriavep p, poderia ate dar
    //uma otimaizada e deixar junto com o p.push(item), ai "economiza" um for
    for(var i in p){
        item = p[i];
        console.log(item);
        var titulo = p.filter(function(e) {
            return e.titulo_promo == item.ad_bebida_titulo
            conlole.log(titulo);
        })


        // TESTA SE GUARDA A BEBIDA SELECIONADA

        // INSERINDO DADOS LOCALMENTE
        DBLocal.localdb();

        DBLocal.db.transaction(function(res) {
            res.executeSql("INSERT INTO AD_BEBIDAS (nome_bebida_ad, valor, quantidade) VALUES(?,?,?);", [item.ad_bebida_titulo, item.ad_bebida_valor, CAMPO QUANTIDADE???]);
        });
    }
}
})

My question is how to do this, and whenever the value of amount is = 0 do not save in the local bank.

    
asked by anonymous 27.08.2016 / 19:52

0 answers