File tree 2 files changed +79
-2
lines changed
2 files changed +79
-2
lines changed Original file line number Diff line number Diff line change 21
21
< body ng-app ="starter " ng-controller ="VibrationsCtrl ">
22
22
< ion-pane >
23
23
< 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 >
24
28
< 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 >
25
33
</ ion-header-bar >
26
34
< ion-content >
27
- < ion-list >
35
+ < ion-list show-delete =" list.showDelete " >
28
36
< ion-item ng-repeat ="vibration in vibrations ">
37
+ < ion-delete-button class ="ion-minus-circled "
38
+ ng-click ="delete(vibration) ">
39
+ </ ion-delete-button >
29
40
{{ vibration.name }}: {{ vibration.duration }}ms
30
41
</ ion-item >
31
42
</ ion-list >
32
43
</ ion-content >
33
44
</ 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 >
34
69
</ body >
35
70
</ html >
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ angular.module('starter', ['ionic'])
18
18
} ) ;
19
19
} )
20
20
21
- . controller ( 'VibrationsCtrl' , function ( $scope ) {
21
+ . controller ( 'VibrationsCtrl' , function ( $scope , $ionicPopup , $ionicModal ) {
22
22
$scope . vibrations = [
23
23
{
24
24
name : 'Foo' ,
@@ -33,4 +33,46 @@ angular.module('starter', ['ionic'])
33
33
duration : 499
34
34
}
35
35
] ;
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
+ } ;
36
78
} ) ;
You can’t perform that action at this time.
0 commit comments