<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width" />
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet" />
<link href="css/style.css" rel="stylesheet" />
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/clientesController.js"></script>
<script src="js/services.js"></script>
</head>
<body ng-app="smartOffice">
<ion-nav-view></ion-nav-view>
</body>
</html>
// Ionic Starter App
var app = angular.module('smartOffice', ['ionic', 'smartOffice.services']);
app.run(function($ionicPlatform, dbFactory) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
});
dbFactory.init();
})
app.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('app', {
url: '/app',
abstract: true,
templateUrl: 'templates/menu.html',
controller: 'AppCtrl'
})
.state('app.clientes', {
url: '/clientes',
views: {
'menuContent': {
templateUrl: 'templates/clientes.html',
controller: 'clientesController'
}
}
})
.state('app.clientes_formularioCadastro', {
url: '/clientes/dadosCliente/:id',
views: {
'menuContent': {
templateUrl: 'templates/clientes_formularioCadastro.html',
controller: 'clientes_formularioCadastroController'
}
}
});
$urlRouterProvider.otherwise('/app/clientes');
});
app.service('clientesTable', function(dbFactory) {
var self = this;
var table = 'clientes';
dbFactory.setTable(table);
return dbFactory;
});
app.controller('clientesController', function($scope, clientesTable) {
var self = this;
$scope.clientes = [];
$scope.data = {};
self.init = function() {
clientesTable.fetch().then(function(result) {
$scope.clientes = result;
});
}
return self.init();
});
app.controller('clientes_formularioCadastroController', function($scope, $stateParams, $location, clientesTable) {
var self = this;
$scope.data = {};
self.init = function() {
if ($stateParams.id) {
clientesTable.find($stateParams.id).then(function(result) {
$scope.data = result;
});
}
}
$scope.salvarDados = function() {
clientesTable.save($scope.data).then(function(result) {
console.log($scope.clientes);
console.log('Registro salvo com sucesso.');
$location.path('/clientes');
});
}
return self.init();
});
<ion-view view-title="Clientes">
<ion-nav-bar class="bar-stable">
<ion-nav-back-button></ion-nav-back-button>
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left"></button>
</ion-nav-buttons>
<ion-nav-buttons side="right">
<button class="button button-icon ion-android-search"></button>
<a class="button button-icon ion-plus-round" href="#/app/clientes/novoCliente"></a>
</ion-nav-buttons>
</ion-nav-bar>
<ion-content>
<ion-list>
<ion-item ng-repeat="cliente in clientes" href="#/app/clientes/dadosCliente/{{cliente.id}}">
{{cliente.nome}}
</ion-item>
</ion-list>
<p ng-show="!clientes.length">Nenhum resultado encontrado</p>
</ion-content>
</ion-view>
<ion-view view-title="Dados do Cliente">
<ion-nav-bar class="bar-stable">
<ion-nav-back-button></ion-nav-back-button>
<ion-nav-buttons side="right">
<a class="button button-icon ion-android-done" href="#"></a>
</ion-nav-buttons>
</ion-nav-bar>
<ion-content>
<h1>Formulario de Cadastro</h1>
<form ng-submit="salvarDados()">
<div class="list">
<label class="item item-input">
<span class="input-label">Nome/Razão Social</span>
<input type="text" ng-model="data.nome">
</label>
<label class="item item-input">
<span class="input-label">CNPJ/CPF</span>
<input type="text" ng-model="data.documento">
</label>
<label class="item item-input">
<span class="input-label">Telefone</span>
<input type="text" ng-model="data.telefone">
</label>
<label class="item item-input">
<span class="input-label">E-mail</span>
<input type="text" ng-model="data.email">
</label>
<label class="item">
<button class="button button-block button-positive" type="submit">Concluir</button>
</label>
</div>
</form>
</ion-content>
</ion-view>