Skip to content

Commit 8c8cabb

Browse files
committed
Saving works, kinda
1 parent 58885b9 commit 8c8cabb

File tree

1 file changed

+45
-16
lines changed

1 file changed

+45
-16
lines changed

examples/bootstrap-example.html

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,23 @@
2828
.ace_editor { font-size: 20px !important;}
2929
.form { height: 400px; }
3030
.schema { height: 800px; }
31+
[ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {
32+
display: none !important;
33+
}
3134
</style>
3235
</head>
33-
<body ng-app="test" ng-controller="TestCtrl">
36+
<body ng-app="test" ng-controller="TestCtrl" ng-cloak>
3437

3538
<div class="col-md-12">
3639
<h1>Schema Form Example</h1>
40+
<div class="row">
41+
<div class="col-md-4"><p ng-if="error" class="alert alert-danger ">{{error}}</p></div>
42+
</div>
3743
<div class="row">
3844
<div class="col-sm-4">
39-
<button ng-click="loadGist();">Save</button>
40-
<button ng-click="saveToGist();">Save as new</button>
41-
45+
<button ng-click="save();">Save</button>
46+
<br>
47+
<p>{{link}}</p>
4248
</div>
4349
</div>
4450
<div class="row">
@@ -125,12 +131,16 @@ <h3>Schema</h3>
125131
// Load data from gist.
126132
if ($location.path().length > 4) {
127133
var gistId = $location.path().replace('/','');
128-
$http.get('https://api.github.com/gists/' + gistId).then(function(res) {
129-
var data = JSON.parse(res.data.files['schemaform.json'].content);
130-
setNewData(data);
134+
$scope.loading = true;
135+
$http.get('https://api.github.com/gists/' + gistId).success(function(res) {
136+
$scope.loading = false;
137+
//var data = JSON.parse(res.files['schemaform.json'].content);
138+
$scope.schemaJson = res.files['schema.json'].content;
139+
$scope.formJson = res.files['form.json'].content;
140+
$scope.modelData = res.files['model.json'].content; // Knasig
141+
}).error(function(res) {
142+
$scope.error = 'Failed to load gist.';
131143
});
132-
133-
// ERROR HANDLING.
134144
}
135145

136146
$scope.selectedTest = $scope.tests[0];
@@ -194,13 +204,32 @@ <h3>Schema</h3>
194204
};
195205

196206
$scope.save = function() {
197-
// $http.get(val.data).then(function(res){
198-
// $scope.schema = res.data.schema;
199-
// $scope.form = res.data.form;
200-
// $scope.schemaJson = JSON.stringify($scope.schema,undefined,2);
201-
// $scope.formJson = JSON.stringify($scope.form,undefined,2);
202-
// $scope.modelData = res.data.model || {};
203-
// });
207+
// To be able to save invalid json and point out errors, we
208+
// don't save the schema/form but rather the ones in the input.
209+
210+
var gist = {
211+
"description": "A saved configuration for a schema form example, http://textalk.github.io/angular-schema-form/examples/bootstrap-example.html",
212+
"public": true,
213+
"files": {
214+
"schema.json": {
215+
"content": $scope.schemaJson
216+
},
217+
"form.json": {
218+
"content": $scope.formJson
219+
},
220+
"model.json": {
221+
"content": JSON.stringify($scope.modelData, undefined, 2)
222+
}
223+
}
224+
};
225+
226+
$http.post('https://api.github.com/gists', gist).success(function(data) {
227+
$scope.savedGistData = data;
228+
$location.path('/' + data.id);
229+
$scope.link = data.html_url;
230+
}).error(function(data) {
231+
$scope.error = 'Failed to save gist.'
232+
});
204233
}
205234

206235
$scope.submitForm = function(form, model) {

0 commit comments

Comments
 (0)