forked from ValYouW/jqPropertyGrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
165 lines (153 loc) · 7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>jqPropertyGrid Example</title>
<!-- https://getbootstrap.com/docs/3.3/getting-started/ -->
<!-- bootstrap - is used for example navbar _AND_ validation of grid/forms itself -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- vendor css for different control types & validator-->
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/spectrum/1.8.0/spectrum.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.3.26/theme-default.min.css" type="text/css" />
<!-- toast - is used for form processing messages (not part of grid itself) -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-toast-plugin/1.3.2/jquery.toast.min.css" />
<!-- lib css -->
<link rel='stylesheet' href='./dist/jqPropertyGrid.css' />
<!-- overrides and styles for just this page -->
<style>
</style>
<!-- vendor js for different control types & validator-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/spectrum/1.8.0/spectrum.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.maskedinput/1.4.1/jquery.maskedinput.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/autoNumeric.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.3.26/jquery.form-validator.min.js"></script>
<!-- toast - is used for form processing messages (not part of grid itself) -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-toast-plugin/1.3.2/jquery.toast.min.js"></script>
<!-- lib js -->
<script src="./dist/jqPropertyGrid.js"></script>
<script>
$(function() {
// This is our data structure
var dataStructure = {
accumulateTicks: true,
filter: false,
filterSize: 200,
buyColor: '#00ff00',
sellColor: '#ff0000',
someOption: 'Maybe',
noGroup: 'I have no group',
dontShowMe: 'please',
readOnly: 'I am read only',
icon: 'home',
choices: ["Choice 1", "Choice 2", "A really long choice which should trigger the horizontal scrollbar!"],
plaintext: "plain text for a text area (i.e. not an array)",
iHaveNoMeta: 'Never mind...',
};
// This is our meta object / form design
var colorOptions = { preferredFormat: 'hex', showInput: true, showInitial: true };
var formDesignSettings = {
dontShowMe: {browsable: false},
filter: {group: 'Behavior', name: 'Filter', type: 'boolean'},
filterSize: {group: 'Behavior', name: 'Filter size', type: 'number', options: { min: 0, max: 500, step: 10 }},
accumulateTicks: {group: 'Behavior', name: 'Accumulate ticks', type: 'boolean'},
buyColor: {group: 'Appearance', name: 'Buy color', type: 'color', options: colorOptions},
sellColor: {group: 'Appearance', name: 'Sell color', type: 'color', options: colorOptions},
someOption: {name: 'Some option', type: 'options', options: ['Yes', 'No', {text:'Not sure', value: 'Maybe'}]},
readOnly: {name: 'Read Only', type: 'label', description: 'This is a label', showHelp: false},
icon: {name: 'Icon', type: 'icon'},
choices: {name: 'n/a', group: 'Choices (1 per line):', type: 'textarea', colspan2: true},
plaintext: {group: 'Plaintext Textarea:', type: 'textarea', colspan2: true},
};
// define some extra custom types to use with jqPropertyGrid
var theCustomTypes = {
icon: {
html: function(elemId, name, value, meta) { // custom renderer for type (required)
return '<i class="fa fa-' + value + '"></i>';
},
valueFunction: function(elemId, name, value, meta) { // custom getter for current value (required)
return function () {
return value;
}
},
postCreateInitFunction: function(elemId, name, value, meta) { // custom post-DOM init function (optional)
return function () {
console.log('no postCreateInitFunction for icon type');
}
}
}
};
// Lets create the grid for it
function initPropertyGrid(data) {
$('#propGrid').jqPropertyGrid(data, {
useFontAwesome: true,
meta: formDesignSettings,
customTypes: theCustomTypes
});
}
// data
function getFormValues() {
var first = JSON.stringify($('#propGrid').jqPropertyGrid('get'), null, ' ');
$('#txtValues').val(first);
}
function setFormValues() {
var newData = JSON.parse($('#txtValues').val())
initPropertyGrid(newData);
}
// design
function getFormDesign() {
var currentDesign = JSON.stringify(formDesignSettings, null, ' ');
$('#txtDesign').val(currentDesign);
}
function setFormDesign() {
var currentData = $('#propGrid').jqPropertyGrid('get');
var newDesign = JSON.parse($('#txtDesign').val())
formDesignSettings = newDesign;
initPropertyGrid(currentData);
}
initPropertyGrid(dataStructure);
getFormValues();
getFormDesign();
$('#btnGetValues').click(getFormValues);
$('#btnSetValues').click(setFormValues);
$('#btnGetDesign').click(getFormDesign);
$('#btnSetDesign').click(setFormDesign);
});
</script>
</head>
<body>
<!-- navbar -->
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="index.html">jqPropertyGrid</a>
</div>
<div>
<ul class="nav navbar-nav">
<li class="active"><a href="index.html">Example 1</a></li>
<li><a href="index2.html">Example 2</a></li>
<li><a href="index3.html">Example 3</a></li>
</ul>
</div>
</div>
</nav>
<!-- page content -->
<div id="propGrid" class="pgContainer" style="float:left; margin-left: 20px;"></div>
<div style="border: 0px solid gold; float:left; margin-left: 20px;">
<h2>Form Data:</h2>
<textarea id="txtValues" rows="20" cols="50"></textarea><br>
<input id="btnSetValues" type="button" value="<--- Set Form Data"/>
<input id="btnGetValues" type="button" value="Get Form Data --->"/>
</div>
<div style="border: 0px solid gold; float:left; margin-left: 20px;">
<h2>Form Design:</h2>
<textarea id="txtDesign" rows="20" cols="50"></textarea><br>
<input id="btnSetDesign" type="button" value="<--- Set Form Design"/>
<input id="btnGetDesign" type="button" value="Get Form Design --->"/>
</div>
</body>
</html>