Skip to content

Commit

Permalink
Finish #22
Browse files Browse the repository at this point in the history
  • Loading branch information
orweinberger committed Mar 13, 2015
2 parents cb35fd0 + aa1c5b5 commit d894d4a
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 13 deletions.
110 changes: 105 additions & 5 deletions www/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ angular.module('starter.controllers', [])
}

$scope.pockets = result;
console.log(result);
$scope.$digest();
}).error(function (err) {
if (err)
throw err;
Expand All @@ -125,6 +125,80 @@ angular.module('starter.controllers', [])
else
$state.go('tab.pocket-details', {pocketName: pocketName});
};

$scope.editPocket = function(pocketName) {
console.log(pocketName);
engine.pockets.get({name: pocketName}).then(function(result) {
$scope.result = result;
var myPopup = $ionicPopup.show({
template: '<div class="list">' +
'<label class="item item-input item-select">' +
'<span class="input-label">Parent</span>' +
'<select ng-model="result.parent">' +
'<option value="root">root</option>' +
'<option ng-repeat="(key, pocket) in result.pockets" value="{{result.name}}">{{pocket.name}}</option>' +
'</select>' +
'</label>' +
'<label class="item item-input">' +
'<span class="input-label">Pocket name</span>' +
'<input ng-model="result.name" type="text" placeholder="My new pocket">' +
'</label>' +
'<label class="item item-input">' +
'<span class="input-label">Ratio</span>' +
'<input ng-model="result.hard_ratio" type="number" placeholder="20">' +
'</label>' +
'<label class="item item-input">' +
'<span class="input-label">Color</span>' +
'<input ng-model="result.color" type="text" placeholder="#cccccc">' +
'</label>' +
'<label class="item item-input item-select">' +
'<span class="input-label">Importance</span>' +
'<select>' +
'<option value="low">Low</option>' +
'<option value="high">High</option>' +
'</select>' +
'</label>' +
'<label class="item item-input">' +
'<span class="input-label">Limit</span>' +
'<input ng-model="result.limit" type="number" placeholder="1">' +
'</label>' +
'</div>',
title: 'Add a new pocket',
scope: $scope,
buttons: [
{text: 'Cancel'},
{
text: '<b>Add</b>',
type: 'button-positive',
onTap: function (e) {
if (!$scope.result) {
//don't allow the user to close unless he enters wifi password
e.preventDefault();
} else {
return $scope.result;
}
}
}
]
});
myPopup.then(function (res) {
console.log(res);
/*
$scope.newpocket.hard_ratio = $scope.newpocket.hard_ratio / 100;
engine.pockets.create($scope.newpocket).then(function () {
//$state.go('')
}).error(function (err) {
if (err)
throw err;
});
*/
});
}).error(function(err) {
if (err)
throw err;
});
};

$scope.pocketHold = function (pocketName) {
var myPopup = $ionicPopup.alert({
template: "<div>Delete?</div>",
Expand Down Expand Up @@ -235,7 +309,7 @@ angular.module('starter.controllers', [])
});
$scope.scanQR = function () {
$cordovaBarcodeScanner.scan().then(function (imageData) {
$scope.toAddress = imageData.text;
$scope.data.toAddress = imageData.text;
}, function (error) {
console.log("An error happened -> " + error);
});
Expand All @@ -247,22 +321,48 @@ angular.module('starter.controllers', [])
'<span class="input-label">Amount</span>' +
'<input ng-model="data.amount" type="number" placeholder="0.01">' +
'</label>' +
'<br><div ng-click="scanQR()">Scan</div><br><button class="btn btn-danger">Send</button>',
'<label class="item item-input">' +
'<span class="input-label">To address</span>' +
'<input ng-model="data.toAddress" type="text" placeholder="0.01">' +
'</label>' +
'<br><div style="text-align:center"><button class="btn btn-primary" ng-click="scanQR()">Scan</button></div>',
title: 'Info',
scope: $scope,
buttons: [
{text: 'Cancel'},
{
text: '<b>OK</b>',
text: '<b>Send!</b>',
type: 'button-positive'
}
]
});
myPopup.then(function (res) {
console.log($scope.pockets.name, $scope.toAddress, $scope.amount);
engine.bitcoin.sendMoney({
from: {
name: $scope.pockets.name,
wallet: {
address: $scope.pockets.wallet.address,
key: $scope.pockets.wallet.key
}
},
to: {
name: 'test',
wallet: {
address: $scope.data.toAddress
}
},
amount: $scope.data.amount
}).then(function (result) {
console.log(result);
}).error(function (err) {
console.log(err);
});
console.log($scope.pockets.name, $scope.data.toAddress, $scope.data.amount);
});
};
})
.controller('DashCtrl', function ($scope) {

})

.controller('ChatsCtrl', function ($scope, Chats) {
Expand Down
8 changes: 5 additions & 3 deletions www/js/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ angular.module('starter.directives', [])
.directive('qrcode', function () {
function link(scope, element, attrs) {
var handled = false;
scope.$watch(function() {
if (scope.pockets && !handled) {
scope.$watch(function () {
if (scope.pockets && scope.pockets.wallet && scope.pockets.wallet.address && !handled) {
handled = true;
new QRCode(document.getElementById("qrcode"), scope.pockets.wallet.address);
new QRCode(element[0], scope.pockets.wallet.address);
}
});
}

return {
restrict: 'E',
template: '<div id="qrcode"></div>',
link: link,
replace: true,
scope: "="
};
});
5 changes: 3 additions & 2 deletions www/templates/tab-pocket-details.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<ion-view view-title="{{pocketName}}">
<ion-view view-title="{{pockets.name}}">
<ion-content class="padding">
<div style="text-align:center;padding-top:50px;">
<br><div style="text-align:center;"><h3>{{pockets.wallet.balance}} BTC</h3></div>
<div style="text-align:center;">
<qrcode></qrcode><br>
<button class="btn btn-lg btn-danger button-positive" ng-click="spendDialog()">SPEND</button>
</div>
Expand Down
16 changes: 13 additions & 3 deletions www/templates/tab-pockets.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,20 @@
</div>
</div>
</ion-content>
<div style="position:absolute;top:50px; right: 8px;">
<button type="button" ng-click="rootInfo()" class="btn btn-primary btn-rootinfo btn-circle btn-lg"><i
class="fa fa-info"></i></button>
<div ng-if="pockets.name == 'root'">
<div style="position:absolute;top:50px; right: 8px;">
<button type="button" ng-click="rootInfo()" class="btn btn-primary btn-rootinfo btn-circle btn-lg"><i
class="fa fa-info"></i></button>
</div>
</div>

<div ng-if="pockets.name != 'root'">
<div style="position:absolute;top:50px; right: 8px;">
<button type="button" ng-click="editPocket('{{pockets.name}}')" class="btn btn-primary btn-rootinfo btn-circle btn-lg"><i
class="fa fa-pencil"></i></button>
</div>
</div>

<div style="position:absolute;bottom:8px; right: 8px;">
<button type="button" ng-click="addPocket()" class="btn btn-primary btn-addpocket btn-circle btn-lg"><i
class="fa fa-plus"></i></button>
Expand Down

0 comments on commit d894d4a

Please sign in to comment.