Skip to content

Commit f287cf6

Browse files
committed
Implement CRUD
1 parent 3c14149 commit f287cf6

File tree

2 files changed

+79
-2
lines changed

2 files changed

+79
-2
lines changed

www/index.html

+36-1
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,50 @@
2121
<body ng-app="starter" ng-controller="VibrationsCtrl">
2222
<ion-pane>
2323
<ion-header-bar class="bar-stable">
24+
<div class="buttons">
25+
<button class="button button-icon ion-ios-minus-outline"
26+
ng-click="list.showDelete=!list.showDelete"></button>
27+
</div>
2428
<h1 class="title">PHPmagazin: Vibrations</h1>
29+
<div class="buttons">
30+
<button class="button button-icon ion-ios-plus-outline"
31+
ng-click="new()"></button>
32+
</div>
2533
</ion-header-bar>
2634
<ion-content>
27-
<ion-list>
35+
<ion-list show-delete="list.showDelete">
2836
<ion-item ng-repeat="vibration in vibrations">
37+
<ion-delete-button class="ion-minus-circled"
38+
ng-click="delete(vibration)">
39+
</ion-delete-button>
2940
{{ vibration.name }}: {{ vibration.duration }}ms
3041
</ion-item>
3142
</ion-list>
3243
</ion-content>
3344
</ion-pane>
45+
46+
<script id="create.html" type="text/ng-template">
47+
<ion-modal-view>
48+
<ion-header-bar>
49+
<h1 class="title">Create New Vibration</h1>
50+
<button class="button button-clear" ng-click="close()">Cancel</button>
51+
</ion-header-bar>
52+
<ion-content>
53+
<form ng-submit="create(vibration)">
54+
<div class="list">
55+
<label class="item item-input">
56+
<input type="text" placeholder="Name" ng-model="vibration.name">
57+
</label>
58+
<label class="item item-input">
59+
<input type="text" placeholder="Duration" ng-model="vibration.duration">
60+
</label>
61+
</div>
62+
<div class="padding">
63+
<button type="submit" class="button button-block button-primary">Create Vibration</button>
64+
</div>
65+
</form>
66+
</ion-content>
67+
</ion-modal-view>
68+
</script>
3469
</body>
3570
</html>

www/js/app.js

+43-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ angular.module('starter', ['ionic'])
1818
});
1919
})
2020

21-
.controller('VibrationsCtrl', function($scope){
21+
.controller('VibrationsCtrl', function($scope, $ionicPopup, $ionicModal){
2222
$scope.vibrations = [
2323
{
2424
name: 'Foo',
@@ -33,4 +33,46 @@ angular.module('starter', ['ionic'])
3333
duration: 499
3434
}
3535
];
36+
37+
$scope.list = {
38+
showDelete: false
39+
};
40+
41+
$scope.delete = function(item) {
42+
$scope.vibrations.splice($scope.vibrations.indexOf(item), 1);
43+
};
44+
45+
46+
$scope.vibration = {
47+
name: '',
48+
duration: ''
49+
};
50+
51+
$ionicModal.fromTemplateUrl('create.html', function(modal) {
52+
$scope.createModal = modal;
53+
}, {
54+
focusFirstInput: true,
55+
scope: $scope
56+
});
57+
58+
$scope.new = function() {
59+
$scope.createModal.show();
60+
};
61+
62+
$scope.close = function() {
63+
$scope.createModal.hide();
64+
};
65+
66+
$scope.create = function(vibration) {
67+
if (!vibration.name || !vibration.duration) {
68+
$ionicPopup.alert({
69+
title: 'Validation Error',
70+
template: 'Please enter name and duration'
71+
});
72+
return;
73+
}
74+
$scope.vibrations.push(angular.copy(vibration));
75+
$scope.createModal.hide();
76+
vibration.name = vibration.duration = '';
77+
};
3678
});

0 commit comments

Comments
 (0)