All Downloads are FREE. Search and download functionalities are using the official Maven repository.

static.admintool.dbbrowser.js.dbbrowser.js Maven / Gradle / Ivy

There is a newer version: 1.1.7.3
Show newest version

(function( $, window, document, undefined ) {
	
	var Tab = function(_root, selector, number) {
		this.root = _root;
		this.selector = selector;
		this.number = number;
	    this.$elem = $(selector);
	    
	    this.cm = null;
	    
	    this.supportedVendors = {
    		'oracle' : 'text/x-plsql', 
    		'mysql'	 : 'text/x-mysql', 
    		'mssql'  : 'text/x-mssql', 
    		'postgre': 'text/x-pgsql', 
            'maria'  : 'text/x-mariadb', 
            'cass'   : 'text/x-cassandra', 
            'hive'   : 'text/x-hive', 
            'default': 'text/x-sql'
	    };
	    
	    this._init();
	};
	
	Tab.prototype = {
		constructor: Tab,
			
		_init: function() {
			this.initCheckboxes();
			this.initCodeMirror();
			this.initFunctions();
			setTimeout(function(my){my.showDBInfo();}, 3000, this);
			return this;
		},
		
		initCheckboxes: function() {
			this.$elem.find('input').iCheck('destroy');
			this.$elem.find('input').iCheck({
				checkboxClass: 'icheckbox_minimal',
				radioClass: 'iradio_minimal',
	//					increaseArea: '20%' // optional
			});
		},
		
		initFunctions: function() {
			this.deactivateBindings();
			$("#execute_" + this.number).on({'click': $.proxy(this.executeQuery, this)});
			$("#examples_" + this.number).on({'change': $.proxy(this.applyExample, this)});
			$("#datasourceName_" + this.number).on({'change': $.proxy(this.changeDataSource, this)});
		},
		
		deactivateBindings: function() {
			$("#execute_" + this.number).off();
			$("#examples_" + this.number).off();
			$("#datasourceName_" + this.number).off();
			$('#removeTab_' + this.number).off();
		},
		
		initAddTab: function() {
			this.executeQuery(this);
		},
		
		removeMe: function() {
			if (this.number == 1) {
				return;
			}
			this.$elem.find('input').iCheck('destroy');
			this.deactivateBindings();
			this.cm.setValue("");
			this.cm.clearHistory();
			this.cm.toTextArea();
			delete this.cm;
			$('#tab_' + this.number).remove();
			$('#tabPane_' + this.number).remove();
			this.root.removeTab(this.number);
		},
		
		changeDataSource: function (event) {
			var datasourceName = $('#datasourceName_' + this.number).val();
			this.showDBInfo(datasourceName);
			var $select = $("#examples_" + this.number);
			$select.html('');
			
			if (this.root.examples.hasOwnProperty(datasourceName)) {
				$select.html('');
				var examples = this.root.examples[datasourceName];
				$.each(examples, function (cluster, example) {
					$select.append($('', { 
						label: cluster
					}));
					for(var i = 0, len= example.length; i < len; i++) {
						$select.append($('
'); $('#tabNavAdd').before('
  • Tab '+newNumber+'
  • '); newTab.initAddTab(); }, addTab: function (selector, number) { this.tabs.push(new Tab(this, selector, number)); }, removeTab: function(number){ if (number == 1) { return; } var i = 0; for(var len = this.tabs.length; i < len; i++) { if (number == this.tabs[i].number) { break; } } this.tabs.splice(i, 1); }, getStaticObjects: function() { if (null == this.datasourceNames) { this.admintool.sendRequest({url: '/admintool/dbbrowser/getDatasourceNames', my: this}, function (result, query) { query.my.datasourceNames = result; query.my.getMetaData(); }); } if (null == this.examples) { this.admintool.sendRequest({url: '/admintool/dbbrowser/getExamples', my: this}, function (result, query) { query.my.examples = result; }); } }, getMetaData: function() { for (var key in this.datasourceNames) { var datasourceName = this.datasourceNames[key]; if (!this.metaData.hasOwnProperty(datasourceName)) { this.admintool.sendRequest({url: '/admintool/dbbrowser/getMetaData/' + datasourceName, my: this, dsn: datasourceName}, function (result, query) { query.my.metaData[query.dsn] = result; }); } } } }; $.fn.dbBrowser = function( option ) { var args = Array.apply(null, arguments); args.shift(); return this.each(function () { var $this = $(this), data = $this.data('admintool.dbBrowser'), options = typeof option === 'object' && option; if (!data) { return new DbBrowser(this, options); } if (typeof option === 'string') { data[option].apply(data, args); } }); }; $.fn.dbBrowser.Constructor = DbBrowser; })(jQuery, window, document); $( document ).ready(function() { $('#admintool').admintool(); $("#dbBrowser").dbBrowser(); $("#dbBrowser").dbBrowser('addTab', "#tabInclude_1", 1); });




    © 2015 - 2025 Weber Informatics LLC | Privacy Policy