@@ -126,9 +126,51 @@ angular.module('starter.controllers', [])
126
126
$state . go ( 'tab.pocket-details' , { pocketName : pocketName } ) ;
127
127
} ;
128
128
129
- $scope . editPocket = function ( pocketName ) {
130
- console . log ( pocketName ) ;
131
- engine . pockets . get ( { name : pocketName } ) . then ( function ( result ) {
129
+ $scope . spend = function ( ) {
130
+ $scope . data = { } ;
131
+ var myPopup = $ionicPopup . show ( {
132
+ template : '<div class="list">' +
133
+ '<label class="item item-input item-select">' +
134
+ '<span class="input-label">Spend from</span>' +
135
+ '<select ng-model="data.pocket">' +
136
+ '<option ng-repeat="(key, pocket) in pockets.pockets" value="{{pocket.name}}">{{pocket.name}}</option>' +
137
+ '</select>' +
138
+ '</label>' +
139
+ '<label class="item item-input">' +
140
+ '<span class="input-label">Amount</span>' +
141
+ '<input ng-model="data.amount" type="number" placeholder="0.01">' +
142
+ '</label>' +
143
+ '<label class="item item-input">' +
144
+ '<span class="input-label">To address</span>' +
145
+ '<input ng-model="data.toAddress" type="text" placeholder="0.01">' +
146
+ '</label>' +
147
+ '<br><div style="text-align:center"><button class="btn btn-primary" ng-click="scanQR()">Scan</button></div>' +
148
+ '</div>' ,
149
+ title : 'Send money' ,
150
+ scope : $scope ,
151
+ buttons : [
152
+ { text : 'Cancel' } ,
153
+ {
154
+ text : '<b>Send</b>' ,
155
+ type : 'button-positive' ,
156
+ onTap : function ( e ) {
157
+ if ( ! $scope . data ) {
158
+ //don't allow the user to close unless he enters wifi password
159
+ e . preventDefault ( ) ;
160
+ } else {
161
+ return $scope . result ;
162
+ }
163
+ }
164
+ }
165
+ ]
166
+ } ) ;
167
+ myPopup . then ( function ( res ) {
168
+ console . log ( $scope . data ) ;
169
+ } ) ;
170
+ } ;
171
+
172
+ $scope . editPocket = function ( pocketName ) {
173
+ engine . pockets . get ( { name : pocketName } ) . then ( function ( result ) {
132
174
$scope . result = result ;
133
175
var myPopup = $ionicPopup . show ( {
134
176
template : '<div class="list">' +
@@ -163,12 +205,12 @@ angular.module('starter.controllers', [])
163
205
'<input ng-model="result.limit" type="number" placeholder="1">' +
164
206
'</label>' +
165
207
'</div>' ,
166
- title : 'Add a new pocket' ,
208
+ title : 'Edit pocket' ,
167
209
scope : $scope ,
168
210
buttons : [
169
211
{ text : 'Cancel' } ,
170
212
{
171
- text : '<b>Add </b>' ,
213
+ text : '<b>Save </b>' ,
172
214
type : 'button-positive' ,
173
215
onTap : function ( e ) {
174
216
if ( ! $scope . result ) {
@@ -182,18 +224,14 @@ angular.module('starter.controllers', [])
182
224
]
183
225
} ) ;
184
226
myPopup . then ( function ( res ) {
185
- console . log ( res ) ;
186
- /*
187
- $scope.newpocket.hard_ratio = $scope.newpocket.hard_ratio / 100;
188
- engine.pockets.create($scope.newpocket).then(function () {
189
- //$state.go('')
227
+ engine . pockets . update ( res ) . then ( function ( ) {
228
+
190
229
} ) . error ( function ( err ) {
191
- if (err)
192
- throw err;
230
+ if ( err ) throw err ;
193
231
} ) ;
194
- */
232
+
195
233
} ) ;
196
- } ) . error ( function ( err ) {
234
+ } ) . error ( function ( err ) {
197
235
if ( err )
198
236
throw err ;
199
237
} ) ;
@@ -286,22 +324,14 @@ angular.module('starter.controllers', [])
286
324
} ) ;
287
325
} ;
288
326
$scope . rootInfo = function ( ) {
289
- var myPopup = $ionicPopup . show ( {
290
- template : '<div>QR</div>' ,
291
- title : 'Info' ,
292
- scope : $scope ,
293
- buttons : [
294
- {
295
- text : '<b>OK</b>' ,
296
- type : 'button-positive'
297
- }
298
- ]
299
- } ) ;
300
- myPopup . then ( function ( res ) {
327
+ $state . go ( 'tab.rootinfo' ) ;
328
+ }
329
+ } )
301
330
302
- } ) ;
303
- } ;
331
+ . controller ( 'rootinfoCtrl' , function ( $scope ) {
332
+ console . log ( 'in root' ) ;
304
333
} )
334
+
305
335
. controller ( 'pocketDetailsCtrl' , function ( $scope , $state , $ionicPopup , $stateParams , $cordovaBarcodeScanner ) {
306
336
engine . pockets . get ( { name : $stateParams . pocketName } ) . then ( function ( result ) {
307
337
$scope . pockets = result ;
@@ -326,7 +356,7 @@ angular.module('starter.controllers', [])
326
356
'<input ng-model="data.toAddress" type="text" placeholder="0.01">' +
327
357
'</label>' +
328
358
'<br><div style="text-align:center"><button class="btn btn-primary" ng-click="scanQR()">Scan</button></div>' ,
329
- title : 'Info' ,
359
+ title : 'Spend from ' + $scope . pockets . name ,
330
360
scope : $scope ,
331
361
buttons : [
332
362
{ text : 'Cancel' } ,
@@ -337,27 +367,29 @@ angular.module('starter.controllers', [])
337
367
]
338
368
} ) ;
339
369
myPopup . then ( function ( res ) {
340
- engine . bitcoin . sendMoney ( {
341
- from : {
342
- name : $scope . pockets . name ,
343
- wallet : {
344
- address : $scope . pockets . wallet . address ,
345
- key : $scope . pockets . wallet . key
346
- }
347
- } ,
348
- to : {
349
- name : 'test' ,
350
- wallet : {
351
- address : $scope . data . toAddress
352
- }
353
- } ,
354
- amount : $scope . data . amount
355
- } ) . then ( function ( result ) {
356
- console . log ( result ) ;
357
- } ) . error ( function ( err ) {
358
- console . log ( err ) ;
359
- } ) ;
360
- console . log ( $scope . pockets . name , $scope . data . toAddress , $scope . data . amount ) ;
370
+ if ( res ) {
371
+ engine . bitcoin . sendMoney ( {
372
+ from : {
373
+ name : $scope . pockets . name ,
374
+ wallet : {
375
+ address : $scope . pockets . wallet . address ,
376
+ key : $scope . pockets . wallet . key
377
+ }
378
+ } ,
379
+ to : {
380
+ name : 'test' ,
381
+ wallet : {
382
+ address : $scope . data . toAddress
383
+ }
384
+ } ,
385
+ amount : $scope . data . amount
386
+ } ) . then ( function ( result ) {
387
+ console . log ( result ) ;
388
+ } ) . error ( function ( err ) {
389
+ console . log ( err ) ;
390
+ } ) ;
391
+ console . log ( $scope . pockets . name , $scope . data . toAddress , $scope . data . amount ) ;
392
+ }
361
393
} ) ;
362
394
} ;
363
395
} )
0 commit comments