gun/examples/admin/index.html
2014-09-09 01:53:53 -06:00

83 lines
1.9 KiB
HTML

<!DOCTYPE html>
<html ng-app="admin">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.js"></script>
<!--
<script src="https://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script>
-->
<script src="../../gun.js"></script>
</head>
<body ng-controller="editor">
<style>
html, body {
font-family: Verdana, Geneva, sans-serif;
}
a {
color: skyblue;
text-decoration: none;
}
ul, li {
list-style-type: none;
}
ul:hover, li:hover {
list-style-type: inherit;
}
input {
border: none;
border-bottom: dashed 1px gainsboro;
}
.none {
display: none;
}
</style>
<h3>Admin Data Editor</h3>
<ul name="list">
<li ng-repeat="(key, val) in data">
<div ng-if="key != '_'">
<b>{{key}}</b>:
<span contenteditable="true" gun>{{val}}</span>
<!--
<br>{{key}}: {{val}}
-->
</div>
</li>
<li>
<form ng-submit="add()">
<label>
<input ng-model="field" placeholder="key" ng-submit="add()">
<a href="#" ng-click="add()">add</a>
<input type="submit" class="none"/>
</label>
</form>
</li>
</ul>
<script>
gun = Gun('http://localhost:8888/gun');
angular.module('admin', [
]).controller('editor', function($scope){
$scope.data = {};
$scope.$data = gun.load('blob/data', function(data){
console.log("got it", data);
$scope.data = data;
$scope.$apply();
});
$scope.add = function(a,b,c){
$scope.$data.path($scope.field).set(
$scope.data[$scope.field] = 'value'
);
$scope.field = '';
};
window.$data = $scope.$data;
}).directive('gun', function(){
return function(scope, elem){
elem.on('keyup', function(){
scope.data[scope.key] = elem.text();
scope.$apply();
});
};
});
</script>
</body>
</html>