Skip to content

Commit 58885b9

Browse files
committed
Initial loading is done
1 parent 0d0b416 commit 58885b9

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

examples/bootstrap-example.html

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434

3535
<div class="col-md-12">
3636
<h1>Schema Form Example</h1>
37+
<div class="row">
38+
<div class="col-sm-4">
39+
<button ng-click="loadGist();">Save</button>
40+
<button ng-click="saveToGist();">Save as new</button>
41+
42+
</div>
43+
</div>
3744
<div class="row">
3845
<div class="col-sm-4">
3946
<h3>The Generated Form</h3>
@@ -97,18 +104,14 @@ <h3>Schema</h3>
97104
<script type="text/javascript" src="../bower_components/angular-schema-form-datepicker/bootstrap-datepicker.min.js"></script>
98105
<script type="text/javascript" src="../bower_components/angular-schema-form-colorpicker/bootstrap-colorpicker.min.js"></script>
99106

100-
<!-- <script src="//tinymce.cachefly.net/4.0/tinymce.min.js"></script>
101-
<script type="text/javascript" src="../bower_components/tx-tinymce/tx-tinymce.js"></script>
102-
<script type="text/javascript" src="../bower_components/angular-schema-form-tinymce/bootstrap-tinymce.js"></script> -->
103-
104107
<script type="text/javascript">
105108
// @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt Expat
106109
//
107110
// To test the tinymce addon, uncomment the files above and inject 'tx-tinymce' below.
108-
angular.module('test',['schemaForm','ui.ace']).controller('TestCtrl', function($scope,$http){
111+
angular.module('test',['schemaForm','ui.ace']).controller('TestCtrl', function($scope, $http, $location){
109112

110113
$scope.tests = [
111-
{ name: "Simple", data: 'data/simple.json' },
114+
//{ name: "Simple", data: 'data/simple.json' },
112115
{ name: "Basic JSON Schema Type", data: 'data/types.json' },
113116
{ name: "Bootstrap Grid", data: 'data/grid.json' },
114117
{ name: "Complex Key Support", data: 'data/complex-keys.json' },
@@ -119,17 +122,22 @@ <h3>Schema</h3>
119122
{ name: "Hack: Conditional required", data: 'data/conditional-required.json' },
120123
];
121124

125+
// Load data from gist.
126+
if ($location.path().length > 4) {
127+
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);
131+
});
132+
133+
// ERROR HANDLING.
134+
}
135+
122136
$scope.selectedTest = $scope.tests[0];
123137

124138
$scope.$watch('selectedTest',function(val){
125139
if (val) {
126-
$http.get(val.data).then(function(res){
127-
$scope.schema = res.data.schema;
128-
$scope.form = res.data.form;
129-
$scope.schemaJson = JSON.stringify($scope.schema,undefined,2);
130-
$scope.formJson = JSON.stringify($scope.form,undefined,2);
131-
$scope.modelData = res.data.model || {};
132-
});
140+
$http.get(val.data).then(function(res) {setNewData(res.data);});
133141
}
134142
});
135143

@@ -161,6 +169,14 @@ <h3>Schema</h3>
161169
}
162170
});
163171

172+
var setNewData = function(data) {
173+
$scope.schema = data.schema;
174+
$scope.form = data.form;
175+
$scope.schemaJson = JSON.stringify($scope.schema,undefined,2);
176+
$scope.formJson = JSON.stringify($scope.form,undefined,2);
177+
$scope.modelData = data.model || {};
178+
};
179+
164180
$scope.pretty = function(){
165181
return JSON.stringify($scope.modelData,undefined,2,2);
166182
};
@@ -177,6 +193,16 @@ <h3>Schema</h3>
177193
alert(msg);
178194
};
179195

196+
$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+
// });
204+
}
205+
180206
$scope.submitForm = function(form, model) {
181207
// First we broadcast an event so all fields validate themselves
182208
$scope.$broadcast('schemaFormValidate');

0 commit comments

Comments
 (0)