-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
router.js
1 lines (1 loc) · 3.78 KB
/
router.js
1
define(["jQuery","Underscore","Backbone","libs/renderTerminator","fiddle_backbone/models/UsedFiddle"],function(e,t,n,r,i){var s=function(s,o,u,a,f){var l=n.Router.extend({routes:{"!:db_type_id":"DBType","!:db_type_id/:short_code":"SchemaDef","!:db_type_id/:short_code/:query_id":"Query","!:db_type_id/:short_code/:query_id/:set_id":"SetAnchor"},DBType:function(e){s.setSelectedType(e,!0),f.render()},SchemaDef:function(e,t){this.loadContent(e,"!"+e+"/"+t)},Query:function(e,t,n){this.loadContent(e,"!"+e+"/"+t+"/"+n)},SetAnchor:function(n,r,i,a){var f=function(){e("#set_"+a).length&&(window.scrollTo(0,e("#set_"+a).offset().top-50),e("#set_"+a).addClass("highlight"))};!s.getSelectedType()||s.getSelectedType().get("id")!=n||o.get("short_code")!=r||u.get("id")!=i?(u.bind("reloaded",t.once(f)),this.loadContent(n,"!"+n+"/"+r+"/"+i)):(e(".set").removeClass("highlight"),f())},loadContent:function(n,f){this.DBType(n);if(u.get("pendingChanges")&&!confirm("Warning! You have made changes to your query which will be lost. Continue?'"))return!1;o.set("loading",!0),e(".helpTip").css("display","none"),e("body").block({message:"Loading..."}),e.getJSON("index.cfm/fiddles/loadContent",{fragment:f},function(f){o.set("loading",!1);if(f.short_code){var l=s.getSelectedType();l.get("context")=="browser"?(l.get("className")=="sqljs"&&o.get("browserEngines").websql.nativeSQLite&&confirm("Fiddle originally built with SQL.js, but you have WebSQL available - would you like to use that instead (it'll be faster to load)?")&&(s.setSelectedType(e("#db_type_id a:contains('WebSQL')").closest("li").attr("db_type_id")),l=s.getSelectedType(),o.set({ddl:f.ddl,dbType:l,statement_separator:f.schema_statement_separator}),f.sql&&(u.set({schemaDef:o,sql:f.sql,statement_separator:f.query_statement_separator}),o.on("built",t.once(function(){u.execute()}))),o.build(s)),o.get("browserEngines")[l.get("className")].buildSchema({short_code:e.trim(f.short_code),statement_separator:f.schema_statement_separator,ddl:f.ddl,success:function(){o.set({short_code:f.short_code,ddl:f.ddl,ready:!0,valid:!0,errorMessage:"",statement_separator:f.schema_statement_separator,dbType:s.getSelectedType()}),r(e(".panel.schema"),f.schema_statement_separator),f.sql?(a.insert(new i({fragment:"!"+n+"/"+f.short_code+"/"+f.id})),u.set({id:f.id,sql:f.sql,statement_separator:f.query_statement_separator})):a.insert(new i({fragment:"!"+n+"/"+f.short_code})),o.get("browserEngines")[l.get("className")].getSchemaStructure({callback:function(t){o.set({schema_structure:t}),o.trigger("reloaded"),f.sql?o.get("browserEngines")[l.get("className")].executeQuery({sql:f.sql,statement_separator:f.query_statement_separator,success:function(t){u.set({sets:t}),u.trigger("reloaded"),e("body").unblock()},error:function(t){u.set({sets:[]}),u.trigger("reloaded"),e("body").unblock()}}):e("body").unblock()}})},error:function(t){o.set({short_code:f.short_code,ddl:f.ddl,ready:!0,valid:!1,errorMessage:t,dbType:s.getSelectedType(),statement_separator:f.schema_statement_separator,schema_structure:[]}),r(e(".panel.schema"),f.schema_statement_separator),f.sql&&(u.set({id:f.id,sql:f.sql,statement_separator:f.query_statement_separator,schemaDef:o}),u.trigger("reloaded")),o.trigger("failed"),o.trigger("reloaded"),e("body").unblock()}})):(o.set({short_code:f.short_code,ddl:f.ddl,ready:!0,valid:!0,errorMessage:"",statement_separator:f.schema_statement_separator,schema_structure:f.schema_structure}),r(e(".panel.schema"),f.schema_statement_separator),o.trigger("reloaded"),f.sql?(a.insert(new i({fragment:"!"+n+"/"+f.short_code+"/"+f.id})),u.set({id:f.id,sql:f.sql,sets:f.sets,statement_separator:f.query_statement_separator}),u.trigger("reloaded")):a.insert(new i({fragment:"!"+n+"/"+f.short_code})),e("body").unblock())}else e("body").unblock()})}}),c=new l;return n.history.start({pushState:!1}),c};return{initialize:s}})