validation-options.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * Backbone model denoting the remote Fuseki server.
  3. */
  4. define(
  5. function( require ) {
  6. "use strict";
  7. var Marionette = require( "marionette" ),
  8. Backbone = require( "backbone" ),
  9. _ = require( "underscore" ),
  10. fui = require( "app/fui" ),
  11. sprintf = require( "sprintf" );
  12. /**
  13. * This model represents the users current choice of options to the
  14. * validation service.
  15. */
  16. var ValidationOptions = Backbone.Model.extend( {
  17. initialize: function() {
  18. this.set( {validateAs: "sparql"} );
  19. this.set( {outputFormat: "algebra"} );
  20. },
  21. validateAs: function() {
  22. return this.get( "validateAs" );
  23. },
  24. validateAsQuery: function() {
  25. return this.validateAs() === "sparql" || this.validateAs() === "arq";
  26. },
  27. setValidateAs: function( va ) {
  28. this.set( "validateAs", va );
  29. console.log( JSON.stringify( this.toJSON() ));
  30. console.log( "----" );
  31. },
  32. outputFormat: function() {
  33. return this.get( "outputFormat" );
  34. },
  35. setOutputFormat: function( of ) {
  36. this.set( "outputFormat", of );
  37. },
  38. validationURL: function() {
  39. switch (this.get( "validateAs" )) {
  40. case "sparql": return "/validate/query";
  41. case "arq": return "/validate/query";
  42. case "Turtle": return "/validate/data";
  43. case "TriG": return "/validate/data";
  44. case "N-Triples": return "/validate/data";
  45. case "N-Quads": return "/validate/data";
  46. }
  47. },
  48. payloadParam: function() {
  49. return this.validateAsQuery() ? "query" : "data";
  50. },
  51. toJSON: function() {
  52. var json = {
  53. languageSyntax: this.validateAs(),
  54. lineNumbers: true
  55. };
  56. if (this.validateAsQuery()) {
  57. json.outputFormat = this.outputFormat();
  58. }
  59. return json;
  60. }
  61. } );
  62. // when the models module starts, create the model
  63. fui.models.addInitializer( function( options ) {
  64. fui.models.validationOptions = new ValidationOptions();
  65. fui.vent.trigger( "models.validation-options.ready" );
  66. } );
  67. return ValidationOptions;
  68. }
  69. );