1var test_holder = document.getElementById('test_holder'); 2var form_holder = document.getElementById('form_holder'); 3 4if (test_holder != null || form_holder != null) { 5 6 var schema= null; 7 var required= null; 8 var editor = null; 9 if (test_holder != null) { 10 schema = { 11 type: "object", 12 title: "Test", 13 properties: { 14 ExecutionTime: { 15 type: "number", 16 title: "Execution time", 17 description: "Time of examination in seconds", 18 }, 19 TotalPoints: { 20 type: "number", 21 title: "Total points", 22 description: "Number of points in the test", 23 }, 24 MinimumPoints: { 25 type: "number", 26 title: "Minimum points", 27 description: "Minimum points to pass the test", 28 }, 29 Questions: { 30 type: "array", 31 title: "Questions", 32 items: { 33 type: "object", 34 title: "Question", 35 properties: { 36 QuestionName: { 37 type: "string", 38 title: "Title" 39 }, 40 Description: { 41 type: "string", 42 title: "Explanation" 43 }, 44 Answers: { 45 type: "array", 46 format: "table", 47 title: "Answers", 48 items: { 49 type: "object", 50 title: "Answer", 51 properties: { 52 Text: { 53 type: "string", 54 title: "Title" 55 }, 56 IsCorrect: { 57 type: "boolean", 58 title: "Is Correct" 59 } 60 }, 61 required: [ 62 "QuestionName", 63 "IsCorrect" 64 ] 65 } 66 }, 67 SucessPointValue: { 68 type: "number", 69 title: "Points if success", 70 description: "Points of this question if aswered correctly", 71 }, 72 FailedPointValue: { 73 type: "number", 74 title: "Points if fail", 75 description: "Points of this question if the answer is wrong (usually negative: -0.5)", 76 } 77 }, 78 required: [ 79 "QuestionName", 80 "Answers" 81 ] 82 } 83 } 84 }, 85 required : [ 86 "ExecutionTime", 87 "TotalPoints", 88 "MinimumPoints" 89 ] 90 }; 91 92 editor = new JSONEditor(test_holder, { 93 94 schema: schema, 95 required: required 96 } 97 ); 98 99 }; 100 101 if (form_holder != null) { 102 schema = { 103 type: "object", 104 title: "Form", 105 properties: { 106 User: { 107 type: "string", 108 title: "User ident",
109 description: "¿Como se va a identificar al usuario?", 110 enum: ["Anonymous", "User Identified", "User Registered"], 111 default: "User Registered" 112 }, 113 Cardinality: { 114 type: "number", 115 title: "Cardinality", 116 description: "Number of times a user can fill the form", 117 default: 1, 118 minimum: 1 119 }, 120 FormTitle: { 121 type: "string", 122 title: "Form title", 123 description: "Title of the form" 124 }, 125 AcceptMessage: { 126 type: "string", 127 title: "Accept message", 128 description: "Accepting message after filling the form" 129 }, 130 ButtonCaption1: { 131 type: "string", 132 title: "Fill button caption", 133 description: "Text of the fill buttton" 134 }, 135 ButtonCaption2: { 136 type: "string", 137 title: "Send caption", 138 description: "Text of the send buttton" 139 }, 140 Groups: { 141 type: "array", 142 title: "Groups", 143 items: { 144 type: "object", 145 title: "Group", 146 properties: { 147 GroupName: { 148 type: "string", 149 title: "Title" 150 }, 151 Description: { 152 type: "string", 153 title: "Sub title" 154 }, 155 Footer: { 156 type: "string", 157 title: "Footer" 158 }, 159 Fields: { 160 type: "array", 161 title: "Fields", 162 items: { 163 type: "object", 164 title: "Field", 165 properties: { 166 Tag: { 167 type: "string", 168 title: "Tag" 169 }, 170 Title: { 171 type: "string", 172 title: "Title" 173 }, 174 Description: { 175 type: "string", 176 title: "Description" 177 }, 178 Type: { 179 type: "string", 180 enum: ["int", "string", "text", "date", "boolean", "number"], 181 title: "Data type", 182 default: "string" 183 }, 184 Values: { 185 type: "string", 186 title: "Valid values", 187 description: "Lista de valores validos separados por ',' o en blanco si es un campo abierto" 188 }, 189 Default: { 190 type: "string", 191 title: "Default value", 192 description: "Default value if applicable" 193 }, 194 Select: { 195 type: "string", 196 enum: ["combo", "radio", "slider", "multiple"], 197 title: "Select values", 198 default: "string" 199 }, 200 Mandatory: { 201 type: "boolean", 202 title: "Mandatory field" 203 } 204 }, 205 required: [ 206 "Tag", 207 "Title", 208 "Type", 209 "Mandatory" 210 ] 211 } 212 } 213 }, 214 additionalProperties: false, 215 required: [ 216 "GroupName", 217 "Fields" 218 ] 219 } 220 } 221 }, 222 additionalProperties: false, 223 required : [ 224 "User", 225 "Cardinality", 226 "Groups" 227 ] 228 }; 229 230 editor = new JSONEditor(form_holder, { 231 232 schema: schema, 233 required: required 234 } 235 ); 236 }; 237 238 239 if (editor != null) { 240 editor.on('change', function () { 241 document.getElementById("body").value = JSON.stringify(editor.getValue()); 242 }); 243 244 var valStr = document.getElementById("body").value; 245 if (valStr != null && valStr.trim() != '') { 246 editor.setValue(JSON.parse(valStr)) 247 } 248 249 $(".button-submit").on("click", function () { 250 document.getElementById("body").value = JSON.stringify(editor.getValue()); 251 console.log(editor.getValue()); 252 }); 253 } 254 255 256 257 /* 258 // Hook up the submit button to log to the console 259 document.getElementById('submit').addEventListener('click', function () { 260 // Get the value from the editor 261 262 });
263 */ 264}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.