RandomSec/extensions/database/module/scripts/index/database-source-ui.js

529 lines
20 KiB
JavaScript
Raw Normal View History

2018-01-14 03:24:56 +01:00
/*
* Copyright (c) 2017, Tony Opara
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
2018-11-26 05:24:41 +01:00
* - Redistributions of source code must retain the above copyright notice, this
2018-01-14 03:24:56 +01:00
* list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of Google nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
$(function(){
$.contextMenu({
selector: '.context-menu-one',
trigger: 'left',
build: function($trigger, e) {
return {
callback: function(key, options) {
var m = "clicked: " + key;
DatabaseExtension.handleSavedConnectionClicked(key, $(this).text());
},
items: {
"edit": {name: " Edit "},
"sep0": "",
"delete": {name: " Delete "},
"sep1": "---------",
"connect": {name: " Connect "},
"dummy": {name: "", icon: ""}
}
};
}
});
});
2018-01-14 03:24:56 +01:00
Refine.DatabaseSourceUI = function(controller) {
this._controller = controller;
};
Refine.DatabaseSourceUI.prototype.attachUI = function(body) {
this._body = body;
this._body.html(DOM.loadHTML("database", "scripts/index/database-import-form.html"));
this._elmts = DOM.bind(this._body);
var self = this;
Only show the database login fields when necessary (#2615) * DB login fields visibility controled by CSS The database login field’s visibility is now controled by CSS styling. * Change field name from Database to Database file. Change field name from Database to Database file. * Use full db name as CSS classes Use full db name instead of diminutives for the CSS classes. * Added translation to placeholders Added translation to the Input placeholders. * Undo a change, remerge Database field & File remerge Database field and DatabaseFile Field like before. * Created DatabaseSourceUI._updateDatabaseType(dbType) Created Refine.DatabaseSourceUI.prototype._updateDatabaseType(databaseType) * Make MySQL the default database <option value="mysql" selected="selected"">MySQL</option> * Update database-import-form.html Fixed typo. (<option value="mysql" selected="selected">MySQL</option>) * New default connection name value New default connection name value, translation of it, changing cssClassName from options to dbtype-options, adding the prefix "dbt-" to the db types and fix the changing of placeholder databaseName/databaseFileName when neccessary. * Fix issue with « saved connections » Fix issue with « saved connections » and added 2 defaults values for dbHost and dbType. * Default DB back to MySQL. <option value="mysql" selected="selected">MySQL</option> * Update extensions/database/module/langs/translation-en.json Co-authored-by: Thad Guidry <thadguidry@gmail.com> * Better default with « mysql » * Fix sqlite #databaseHost before calling self._updateDatabaseType() Fix $( "#databaseHost" ).val(self._defaultDatabaseHost) to be set before calling self._updateDatabaseType(self._defaultDatabaseType) that may change it. * Removed field name & fixed default connection name Removed field name text since it's populated from i18n and fixed the default connection name so that it has no space in it. * Little update to placeholder text Co-authored-by: Thad Guidry <thadguidry@gmail.com>
2020-05-30 10:20:05 +02:00
self._defaultDatabaseHost = "localhost";
self._defaultDatabaseType = $( "select#databaseTypeSelect" ).val();
if (self._defaultDatabaseType == "") { self._defaultDatabaseType = "mysql"; }
2018-11-21 18:30:00 +01:00
$('#database-title').text($.i18n('database-import/title'));
$('#new-connection-legend').text($.i18n('database-source/new-connection-legend'));
2018-11-21 18:30:00 +01:00
$('#connectionNameLabel').html($.i18n('database-source/connectionNameLabel'));
$('#databaseTypeLabel').html($.i18n('database-source/databaseTypeLabel'));
$('#databaseHostLabel').text($.i18n('database-source/databaseHostLabel'));
$('#databasePortLabel').text($.i18n('database-source/databasePortLabel'));
$('#databaseUserLabel').text($.i18n('database-source/databaseUserLabel'));
$('#databasePasswordLabel').text($.i18n('database-source/databasePasswordLabel'));
$('#databaseNameLabel').text($.i18n('database-source/databaseNameLabel'));
$('#databaseSchemaLabel').text($.i18n('database-source/databaseSchemaLabel'));
$('#databaseTestButton').text($.i18n('database-source/databaseTestButton'));
$('#databaseSaveButton').text($.i18n('database-source/databaseSaveButton'));
$('#databaseConnectButton').text($.i18n('database-source/databaseConnectButton'));
$('#newConnectionButtonDiv').text($.i18n('database-source/newConnectionButtonDiv'));
$('#savedConnectionSpan').text($.i18n('database-source/savedConnectionSpan'));
2018-01-14 03:24:56 +01:00
Only show the database login fields when necessary (#2615) * DB login fields visibility controled by CSS The database login field’s visibility is now controled by CSS styling. * Change field name from Database to Database file. Change field name from Database to Database file. * Use full db name as CSS classes Use full db name instead of diminutives for the CSS classes. * Added translation to placeholders Added translation to the Input placeholders. * Undo a change, remerge Database field & File remerge Database field and DatabaseFile Field like before. * Created DatabaseSourceUI._updateDatabaseType(dbType) Created Refine.DatabaseSourceUI.prototype._updateDatabaseType(databaseType) * Make MySQL the default database <option value="mysql" selected="selected"">MySQL</option> * Update database-import-form.html Fixed typo. (<option value="mysql" selected="selected">MySQL</option>) * New default connection name value New default connection name value, translation of it, changing cssClassName from options to dbtype-options, adding the prefix "dbt-" to the db types and fix the changing of placeholder databaseName/databaseFileName when neccessary. * Fix issue with « saved connections » Fix issue with « saved connections » and added 2 defaults values for dbHost and dbType. * Default DB back to MySQL. <option value="mysql" selected="selected">MySQL</option> * Update extensions/database/module/langs/translation-en.json Co-authored-by: Thad Guidry <thadguidry@gmail.com> * Better default with « mysql » * Fix sqlite #databaseHost before calling self._updateDatabaseType() Fix $( "#databaseHost" ).val(self._defaultDatabaseHost) to be set before calling self._updateDatabaseType(self._defaultDatabaseType) that may change it. * Removed field name & fixed default connection name Removed field name text since it's populated from i18n and fixed the default connection name so that it has no space in it. * Little update to placeholder text Co-authored-by: Thad Guidry <thadguidry@gmail.com>
2020-05-30 10:20:05 +02:00
$('input#connectionName').attr('placeholder', $.i18n('database-source/connectionNamePlaceholder'));
$('input#databaseHost').attr('placeholder', $.i18n('database-source/databaseHostPlaceholder'));
$('input#databasePort').attr('placeholder', $.i18n('database-source/databasePortPlaceholder'));
$('input#databaseUser').attr('placeholder', $.i18n('database-source/databaseUserPlaceholder'));
$('input#databasePassword').attr('placeholder', $.i18n('database-source/databasePasswordPlaceholder'));
$('input#initialDatabase').attr('placeholder', $.i18n('database-source/databaseNamePlaceholder'));
$('input#initialSchema').attr('placeholder', $.i18n('database-source/databaseSchemaPlaceholder'));
$('input#connectionName').val($.i18n('database-source/connectionNameDefaultValue'));
Only show the database login fields when necessary (#2615) * DB login fields visibility controled by CSS The database login field’s visibility is now controled by CSS styling. * Change field name from Database to Database file. Change field name from Database to Database file. * Use full db name as CSS classes Use full db name instead of diminutives for the CSS classes. * Added translation to placeholders Added translation to the Input placeholders. * Undo a change, remerge Database field & File remerge Database field and DatabaseFile Field like before. * Created DatabaseSourceUI._updateDatabaseType(dbType) Created Refine.DatabaseSourceUI.prototype._updateDatabaseType(databaseType) * Make MySQL the default database <option value="mysql" selected="selected"">MySQL</option> * Update database-import-form.html Fixed typo. (<option value="mysql" selected="selected">MySQL</option>) * New default connection name value New default connection name value, translation of it, changing cssClassName from options to dbtype-options, adding the prefix "dbt-" to the db types and fix the changing of placeholder databaseName/databaseFileName when neccessary. * Fix issue with « saved connections » Fix issue with « saved connections » and added 2 defaults values for dbHost and dbType. * Default DB back to MySQL. <option value="mysql" selected="selected">MySQL</option> * Update extensions/database/module/langs/translation-en.json Co-authored-by: Thad Guidry <thadguidry@gmail.com> * Better default with « mysql » * Fix sqlite #databaseHost before calling self._updateDatabaseType() Fix $( "#databaseHost" ).val(self._defaultDatabaseHost) to be set before calling self._updateDatabaseType(self._defaultDatabaseType) that may change it. * Removed field name & fixed default connection name Removed field name text since it's populated from i18n and fixed the default connection name so that it has no space in it. * Little update to placeholder text Co-authored-by: Thad Guidry <thadguidry@gmail.com>
2020-05-30 10:20:05 +02:00
2018-01-14 03:24:56 +01:00
this._elmts.newConnectionButton.click(function(evt) {
self._resetDatabaseImportForm();
$( "#newConnectionDiv" ).show();
$( "#sqlEditorDiv" ).hide();
// self._body.find('.newConnectionDiv').show();
// self._body.find('.sqlEditorDiv').hide();
});
this._elmts.databaseTypeSelect.change(function(event) {
Only show the database login fields when necessary (#2615) * DB login fields visibility controled by CSS The database login field’s visibility is now controled by CSS styling. * Change field name from Database to Database file. Change field name from Database to Database file. * Use full db name as CSS classes Use full db name instead of diminutives for the CSS classes. * Added translation to placeholders Added translation to the Input placeholders. * Undo a change, remerge Database field & File remerge Database field and DatabaseFile Field like before. * Created DatabaseSourceUI._updateDatabaseType(dbType) Created Refine.DatabaseSourceUI.prototype._updateDatabaseType(databaseType) * Make MySQL the default database <option value="mysql" selected="selected"">MySQL</option> * Update database-import-form.html Fixed typo. (<option value="mysql" selected="selected">MySQL</option>) * New default connection name value New default connection name value, translation of it, changing cssClassName from options to dbtype-options, adding the prefix "dbt-" to the db types and fix the changing of placeholder databaseName/databaseFileName when neccessary. * Fix issue with « saved connections » Fix issue with « saved connections » and added 2 defaults values for dbHost and dbType. * Default DB back to MySQL. <option value="mysql" selected="selected">MySQL</option> * Update extensions/database/module/langs/translation-en.json Co-authored-by: Thad Guidry <thadguidry@gmail.com> * Better default with « mysql » * Fix sqlite #databaseHost before calling self._updateDatabaseType() Fix $( "#databaseHost" ).val(self._defaultDatabaseHost) to be set before calling self._updateDatabaseType(self._defaultDatabaseType) that may change it. * Removed field name & fixed default connection name Removed field name text since it's populated from i18n and fixed the default connection name so that it has no space in it. * Little update to placeholder text Co-authored-by: Thad Guidry <thadguidry@gmail.com>
2020-05-30 10:20:05 +02:00
var type = $( "select#databaseTypeSelect" ).val();
self._updateDatabaseType(type);
2018-01-14 03:24:56 +01:00
});
Only show the database login fields when necessary (#2615) * DB login fields visibility controled by CSS The database login field’s visibility is now controled by CSS styling. * Change field name from Database to Database file. Change field name from Database to Database file. * Use full db name as CSS classes Use full db name instead of diminutives for the CSS classes. * Added translation to placeholders Added translation to the Input placeholders. * Undo a change, remerge Database field & File remerge Database field and DatabaseFile Field like before. * Created DatabaseSourceUI._updateDatabaseType(dbType) Created Refine.DatabaseSourceUI.prototype._updateDatabaseType(databaseType) * Make MySQL the default database <option value="mysql" selected="selected"">MySQL</option> * Update database-import-form.html Fixed typo. (<option value="mysql" selected="selected">MySQL</option>) * New default connection name value New default connection name value, translation of it, changing cssClassName from options to dbtype-options, adding the prefix "dbt-" to the db types and fix the changing of placeholder databaseName/databaseFileName when neccessary. * Fix issue with « saved connections » Fix issue with « saved connections » and added 2 defaults values for dbHost and dbType. * Default DB back to MySQL. <option value="mysql" selected="selected">MySQL</option> * Update extensions/database/module/langs/translation-en.json Co-authored-by: Thad Guidry <thadguidry@gmail.com> * Better default with « mysql » * Fix sqlite #databaseHost before calling self._updateDatabaseType() Fix $( "#databaseHost" ).val(self._defaultDatabaseHost) to be set before calling self._updateDatabaseType(self._defaultDatabaseType) that may change it. * Removed field name & fixed default connection name Removed field name text since it's populated from i18n and fixed the default connection name so that it has no space in it. * Little update to placeholder text Co-authored-by: Thad Guidry <thadguidry@gmail.com>
2020-05-30 10:20:05 +02:00
var defaultDatabase = $( "select#databaseTypeSelect" ).val();
self._updateDatabaseType(defaultDatabase);
2018-01-14 03:24:56 +01:00
this._elmts.testDatabaseButton.click(function(evt) {
if(self._validateNewConnectionForm() === true){
self._testDatabaseConnect(self._getConnectionInfo());
}
});
this._elmts.databaseConnectButton.click(function(evt) {
if(self._validateNewConnectionForm() === true){
self._connect(self._getConnectionInfo());
}
});
this._elmts.saveConnectionButton.click(function(evt) {
if(self._validateNewConnectionForm() == true){
var connectionNameInput = $.trim(self._elmts.connectionNameInput[0].value);
2018-01-14 03:24:56 +01:00
if (connectionNameInput.length === 0) {
2018-11-21 18:30:00 +01:00
window.alert($.i18n('database-source/alert-connection-name'));
2018-01-14 03:24:56 +01:00
} else{
self._saveConnection(self._getConnectionInfo());
2018-01-14 03:24:56 +01:00
}
}
});
this._elmts.executeQueryButton.click(function(evt) {
var jdbcQueryInfo = {};
jdbcQueryInfo.connectionName = $( "#currentConnectionNameInput" ).val();
jdbcQueryInfo.databaseType = $( "#currentDatabaseTypeInput" ).val();
jdbcQueryInfo.databaseServer = $( "#currentDatabaseHostInput" ).val();
jdbcQueryInfo.databasePort = $( "#currentDatabasePortInput" ).val();
jdbcQueryInfo.databaseUser = $( "#currentDatabaseUserInput" ).val();
jdbcQueryInfo.databasePassword = $( "#currentDatabasePasswordInput" ).val();
jdbcQueryInfo.initialDatabase = $( "#currentInitialDatabaseInput" ).val();
jdbcQueryInfo.query = $.trim($( "#queryTextArea" ).val());
2019-09-15 06:07:23 +02:00
2018-01-14 03:24:56 +01:00
if(self.validateQuery(jdbcQueryInfo.query)) {
self._executeQuery(jdbcQueryInfo);
}
2019-09-15 06:07:23 +02:00
2018-01-14 03:24:56 +01:00
});
this._elmts.editConnectionButton.click(function(evt) {
if(self._validateNewConnectionForm() == true){
var connectionNameInput = $.trim(self._elmts.connectionNameInput[0].value);
if (connectionNameInput.length === 0) {
2018-11-21 18:30:00 +01:00
window.alert($.i18n('database-source/alert-connection-name'));
2018-01-14 03:24:56 +01:00
} else{
self._editConnection(self._getConnectionInfo());
}
}
});
this._elmts.cancelEditConnectionButton.click(function(evt) {
self._resetDatabaseImportForm();
});
//load saved connections from settings file in user home directory
self._loadSavedConnections();
};//end Refine.createUI
Refine.DatabaseSourceUI.prototype.focus = function() {
};
Refine.DatabaseSourceUI.prototype.validateQuery = function(query) {
//alert("query::" + query);
if(!query || query.length <= 0 ) {
2018-11-21 18:30:00 +01:00
window.alert($.i18n('database-source/alert-query'));
2018-01-14 03:24:56 +01:00
return false;
}
var allCapsQuery = query.toUpperCase();
if(allCapsQuery.indexOf('DROP') > -1){
2018-11-21 18:30:00 +01:00
window.alert($.i18n('database-source/alert-invalid-query-keyword') + " DROP");
2018-01-14 03:24:56 +01:00
return false;
}else if(allCapsQuery.indexOf('TRUNCATE') > -1){
2018-11-21 18:30:00 +01:00
window.alert($.i18n('database-source/alert-invalid-query-keyword') + " TRUNCATE");
2018-01-14 03:24:56 +01:00
return false;
}else if(allCapsQuery.indexOf('DELETE') > -1){
2018-11-21 18:30:00 +01:00
window.alert($.i18n('database-source/alert-invalid-query-keyword') + " DELETE");
2018-01-14 03:24:56 +01:00
return false;
}else if(allCapsQuery.indexOf('ROLLBACK') > -1){
2018-11-21 18:30:00 +01:00
window.alert($.i18n('database-source/alert-invalid-query-keyword') + " ROLLBACK");
2018-01-14 03:24:56 +01:00
return false;
}else if(allCapsQuery.indexOf('SHUTDOWN') > -1){
2018-11-21 18:30:00 +01:00
window.alert($.i18n('database-source/alert-invalid-query-keyword') + " SHUTDOWN");
2018-01-14 03:24:56 +01:00
return false;
}else if(allCapsQuery.indexOf('INSERT') > -1){
2018-11-21 18:30:00 +01:00
window.alert($.i18n('database-source/alert-invalid-query-keyword') + " INSERT");
2018-01-14 03:24:56 +01:00
return false;
}else if(allCapsQuery.indexOf('ALTER') > -1){
2018-11-21 18:30:00 +01:00
window.alert($.i18n('database-source/alert-invalid-query-keyword') + " ALTER");
2018-01-14 03:24:56 +01:00
return false;
}else if(allCapsQuery.indexOf('UPDATE') > -1){
2018-11-21 18:30:00 +01:00
window.alert($.i18n('database-source/alert-invalid-query-keyword') + " UPDATE");
2018-01-14 03:24:56 +01:00
return false;
}
2018-11-25 22:30:28 +01:00
2018-01-14 03:24:56 +01:00
if(!allCapsQuery.startsWith('SELECT')) {
2018-11-21 18:30:00 +01:00
window.alert($.i18n('database-source/alert-invalid-query-select'));
2018-01-14 03:24:56 +01:00
return false;
}
return true;
};
Only show the database login fields when necessary (#2615) * DB login fields visibility controled by CSS The database login field’s visibility is now controled by CSS styling. * Change field name from Database to Database file. Change field name from Database to Database file. * Use full db name as CSS classes Use full db name instead of diminutives for the CSS classes. * Added translation to placeholders Added translation to the Input placeholders. * Undo a change, remerge Database field & File remerge Database field and DatabaseFile Field like before. * Created DatabaseSourceUI._updateDatabaseType(dbType) Created Refine.DatabaseSourceUI.prototype._updateDatabaseType(databaseType) * Make MySQL the default database <option value="mysql" selected="selected"">MySQL</option> * Update database-import-form.html Fixed typo. (<option value="mysql" selected="selected">MySQL</option>) * New default connection name value New default connection name value, translation of it, changing cssClassName from options to dbtype-options, adding the prefix "dbt-" to the db types and fix the changing of placeholder databaseName/databaseFileName when neccessary. * Fix issue with « saved connections » Fix issue with « saved connections » and added 2 defaults values for dbHost and dbType. * Default DB back to MySQL. <option value="mysql" selected="selected">MySQL</option> * Update extensions/database/module/langs/translation-en.json Co-authored-by: Thad Guidry <thadguidry@gmail.com> * Better default with « mysql » * Fix sqlite #databaseHost before calling self._updateDatabaseType() Fix $( "#databaseHost" ).val(self._defaultDatabaseHost) to be set before calling self._updateDatabaseType(self._defaultDatabaseType) that may change it. * Removed field name & fixed default connection name Removed field name text since it's populated from i18n and fixed the default connection name so that it has no space in it. * Little update to placeholder text Co-authored-by: Thad Guidry <thadguidry@gmail.com>
2020-05-30 10:20:05 +02:00
Refine.DatabaseSourceUI.prototype._updateDatabaseType = function(databaseType) {
if(databaseType === "postgresql") {
$( "#databaseUser" ).val("postgres");
$( "#databasePort" ).val("5432");
} else if(databaseType === "mysql") {
$( "#databaseUser" ).val("root");
$( "#databasePort" ).val("3306");
} else if(databaseType === "mariadb") {
$( "#databaseUser" ).val("root");
$( "#databasePort" ).val("3306");
} else if(databaseType === "sqlite") {
$( "#databaseUser" ).val("na");
$( "#databasePort" ).val("0");
$( "#databaseHost" ).val("na");
} else {
$( "#databaseUser" ).val("root");
$( "#databasePort" ).val("3306");
databaseType = "mysql";
}
$("div.pure-control-group.dbtype-options").hide();
$("div.pure-control-group.dbtype-options.dbt-"+databaseType).show();
if (databaseType == "sqlite") {
$('#databaseNameLabel').text($.i18n('database-source/databaseFileNameLabel'));
$('input#initialDatabase').attr('placeholder', $.i18n('database-source/databaseFileNamePlaceholder'));
} else {
$('#databaseNameLabel').text($.i18n('database-source/databaseNameLabel'));
$('input#initialDatabase').attr('placeholder', $.i18n('database-source/databaseNamePlaceholder'));
}
};
2018-01-14 03:24:56 +01:00
Refine.DatabaseSourceUI.prototype._editConnection = function(connectionInfo) {
//alert("database user:" + connectionInfo.databaseUser);
var self = this;
$.ajax({
url: 'command/database/saved-connection',
type: 'PUT',
contentType:'application/x-www-form-urlencoded',
data: connectionInfo,
success: function(settings) {
if(settings){
$( "#menuListUl" ).empty();
var menuList = $('#menuListUl');
2018-01-14 03:24:56 +01:00
var items = [];
$.each(settings.savedConnections,function(index,savedConnection){
2019-09-15 06:07:23 +02:00
var li = $('<li class="pure-menu-item sc-list"></li>').appendTo(menuList);
var a = $('<a href="#" class="pure-menu-link context-menu-one"></a>').appendTo(li);
$('<span class="context-menu-text"></span>').text(savedConnection.connectionName)
.appendTo(a);
$('<span class="sc-context-more-vert pull-right"> </span>').appendTo(a);
2018-01-14 03:24:56 +01:00
})
$( "#menuListUl" ).append(items.join(''));
2018-11-21 18:30:00 +01:00
window.alert($.i18n('database-source/alert-connection-edit'));
2018-01-14 03:24:56 +01:00
}
}
}).fail(function( jqXhr, textStatus, errorThrown ){
alert( textStatus + ':' + errorThrown );
});
};
Refine.DatabaseSourceUI.prototype._executeQuery = function(jdbcQueryInfo) {
var self = this;
//remove start line
2018-11-21 18:30:00 +01:00
var dismiss = DialogSystem.showBusy($.i18n('database-import/checking'));
2019-10-17 10:10:28 +02:00
Refine.postCSRF(
2018-01-14 03:24:56 +01:00
"command/database/test-query",
jdbcQueryInfo,
function(jdbcConnectionResult) {
2019-09-15 06:07:23 +02:00
2018-01-14 03:24:56 +01:00
dismiss();
self._controller.startImportingDocument(jdbcQueryInfo);
},
2019-10-17 10:10:28 +02:00
"json",
function( jqXhr, textStatus, errorThrown ){
2019-09-15 06:07:23 +02:00
2018-01-14 03:24:56 +01:00
dismiss();
alert( textStatus + ':' + errorThrown );
});
2019-09-15 06:07:23 +02:00
2018-01-14 03:24:56 +01:00
}
Refine.DatabaseSourceUI.prototype._saveConnection = function(jdbcConnectionInfo) {
var self = this;
2019-10-17 10:10:28 +02:00
Refine.postCSRF(
2018-01-14 03:24:56 +01:00
"command/database/saved-connection",
jdbcConnectionInfo,
function(settings) {
if(settings){
2019-09-15 06:07:23 +02:00
2018-01-14 03:24:56 +01:00
self._elmts.menuListUl.empty();
var items = [];
$.each(settings.savedConnections,function(index,savedConnection){
2019-09-15 06:07:23 +02:00
2018-01-14 03:24:56 +01:00
items.push('<li class="pure-menu-item sc-list"><a href="#" class="pure-menu-link context-menu-one">'
+ '<span class="context-menu-text" >' + savedConnection.connectionName + '</span>'
+ '<span class="sc-context-more-vert pull-right"> </span></a></li>');
})
self._elmts.menuListUl.append(items.join(''));
}
},
2019-10-17 10:10:28 +02:00
"json",
function( jqXhr, textStatus, errorThrown ){
2018-01-14 03:24:56 +01:00
alert( textStatus + ':' + errorThrown );
});
};
Refine.DatabaseSourceUI.prototype._loadSavedConnections = function() {
var self = this;
$.get(
"command/database/saved-connection",
null,
function(settings) {
if(settings){
self._elmts.menuListUl.empty();
2019-09-15 06:07:23 +02:00
2018-01-14 03:24:56 +01:00
var items = [];
$.each(settings.savedConnections,function(index,savedConnection){
items.push('<li class="pure-menu-item sc-list"><a href="#" class="pure-menu-link context-menu-one">'
+ '<span class="context-menu-text" >' + savedConnection.connectionName + '</span>'
+ '<span class="sc-context-more-vert pull-right"> </span></a></li>');
})
self._elmts.menuListUl.append(items.join(''));
2019-09-15 06:07:23 +02:00
2018-01-14 03:24:56 +01:00
}
},
"json"
);
};
Refine.DatabaseSourceUI.prototype._testDatabaseConnect = function(jdbcConnectionInfo) {
var self = this;
2019-10-17 10:10:28 +02:00
Refine.postCSRF(
2018-01-14 03:24:56 +01:00
"command/database/test-connect",
jdbcConnectionInfo,
function(jdbcConnectionResult) {
if(jdbcConnectionResult && jdbcConnectionResult.connectionResult == true){
window.alert("Test Connection Succeeded!");
}else{
window.alert("Unable to establish connection to database");
}
},
2019-10-17 10:10:28 +02:00
"json",
function( jqXhr, textStatus, errorThrown ){
2018-01-14 03:24:56 +01:00
alert( textStatus + ':' + errorThrown );
});
};
Refine.DatabaseSourceUI.prototype._connect = function(jdbcConnectionInfo) {
var self = this;
2019-10-17 10:10:28 +02:00
Refine.postCSRF(
2018-01-14 03:24:56 +01:00
"command/database/connect",
jdbcConnectionInfo,
function(databaseInfo) {
if(databaseInfo){
$( "#currentConnectionNameInput" ).val(jdbcConnectionInfo.connectionName);
$( "#currentDatabaseTypeInput" ).val(jdbcConnectionInfo.databaseType);
$( "#currentDatabaseUserInput" ).val(jdbcConnectionInfo.databaseUser);
$( "#currentDatabasePasswordInput" ).val(jdbcConnectionInfo.databasePassword);
$( "#currentDatabaseHostInput" ).val(jdbcConnectionInfo.databaseServer);
$( "#currentDatabasePortInput" ).val(jdbcConnectionInfo.databasePort);
$( "#currentInitialDatabaseInput" ).val(jdbcConnectionInfo.initialDatabase);
var connectionParam = "Connection :: "
+ "jdbc:"
+ jdbcConnectionInfo.databaseType + "://"
+ jdbcConnectionInfo.databaseServer + ":"
+ jdbcConnectionInfo.databasePort + "/"
+ jdbcConnectionInfo.initialDatabase;
2019-09-15 06:07:23 +02:00
2018-01-14 03:24:56 +01:00
$( "#connectionParameterSpan" ).text(connectionParam);
2019-09-15 06:07:23 +02:00
$( "#newConnectionDiv" ).hide();
$( "#sqlEditorDiv" ).show();
2018-01-14 03:24:56 +01:00
}else{
window.alert("Unable to establish connection to database");
return;
}
},
2019-10-17 10:10:28 +02:00
"json",
function( jqXhr, textStatus, errorThrown ){
2018-01-14 03:24:56 +01:00
alert( textStatus + ':' + errorThrown );
});
};
Refine.DatabaseSourceUI.prototype._getConnectionInfo = function() {
2019-09-15 06:07:23 +02:00
var self = this;
var jdbcConnectionInfo = {};
jdbcConnectionInfo.connectionName = $.trim(self._elmts.connectionNameInput[0].value);
jdbcConnectionInfo.databaseType = $.trim(self._elmts.databaseTypeSelect[0].value);
jdbcConnectionInfo.databaseServer = $.trim(self._elmts.databaseHostInput[0].value);
jdbcConnectionInfo.databasePort = $.trim(self._elmts.databasePortInput[0].value);
jdbcConnectionInfo.databaseUser = $.trim(self._elmts.databaseUserInput[0].value);
jdbcConnectionInfo.databasePassword = $.trim(self._elmts.databasePasswordInput[0].value);
jdbcConnectionInfo.initialDatabase = $.trim(self._elmts.initialDatabaseInput[0].value);
jdbcConnectionInfo.initialSchema = $.trim(self._elmts.initialSchemaInput[0].value);
return jdbcConnectionInfo;
2018-01-14 03:24:56 +01:00
}
2018-01-14 03:24:56 +01:00
Refine.DatabaseSourceUI.prototype._validateNewConnectionForm = function() {
var self = this;
var connectionNameInput = $.trim(self._elmts.connectionNameInput[0].value);
var databaseTypeSelect = $.trim(self._elmts.databaseTypeSelect[0].value);
var databaseHostInput = $.trim(self._elmts.databaseHostInput[0].value);
var databasePortInput = $.trim(self._elmts.databasePortInput[0].value);
var databaseUserInput = $.trim(self._elmts.databaseUserInput[0].value);
var databasePasswordInput = $.trim(self._elmts.databasePasswordInput[0].value);
var initialDatabaseInput = $.trim(self._elmts.initialDatabaseInput[0].value);
var initialSchemaInput = $.trim(self._elmts.initialSchemaInput[0].value);
var alphaNumRE = /^[a-zA-Z0-9._-]*$/;
var numRE = /^[0-9]*$/;
var alphaNumConnNameTestResult = alphaNumRE.test(connectionNameInput);
var databaseHostTestResult = alphaNumRE.test(databaseHostInput);
var databasePortTestResult = numRE.test(databasePortInput);
var databaseUserTestResult = alphaNumRE.test(databaseUserInput);
if(alphaNumConnNameTestResult == false){
window.alert($.i18n('database-source/alert-conn-name-invalid-character'));
return false;
}else if (databaseHostInput.length === 0) {
2018-11-21 18:30:00 +01:00
window.alert($.i18n('database-source/alert-server'));
2018-01-14 03:24:56 +01:00
return false;
}else if(databasePortInput.length === 0){
window.alert($.i18n('database-source/alert-port'));
return false;
2018-01-14 03:24:56 +01:00
}else if(databaseUserInput.length === 0){
window.alert($.i18n('database-source/alert-user'));
return false;
2018-01-14 03:24:56 +01:00
}else if(initialDatabaseInput.length === 0){
window.alert($.i18n('database-source/alert-initial-database'));
return false;
}else if(databasePortTestResult == false){
window.alert($.i18n('database-source/alert-db-port-invalid-character'));
return false;
2018-01-14 03:24:56 +01:00
}
else{
return true;
2018-01-14 03:24:56 +01:00
}
return true;
};
Only show the database login fields when necessary (#2615) * DB login fields visibility controled by CSS The database login field’s visibility is now controled by CSS styling. * Change field name from Database to Database file. Change field name from Database to Database file. * Use full db name as CSS classes Use full db name instead of diminutives for the CSS classes. * Added translation to placeholders Added translation to the Input placeholders. * Undo a change, remerge Database field & File remerge Database field and DatabaseFile Field like before. * Created DatabaseSourceUI._updateDatabaseType(dbType) Created Refine.DatabaseSourceUI.prototype._updateDatabaseType(databaseType) * Make MySQL the default database <option value="mysql" selected="selected"">MySQL</option> * Update database-import-form.html Fixed typo. (<option value="mysql" selected="selected">MySQL</option>) * New default connection name value New default connection name value, translation of it, changing cssClassName from options to dbtype-options, adding the prefix "dbt-" to the db types and fix the changing of placeholder databaseName/databaseFileName when neccessary. * Fix issue with « saved connections » Fix issue with « saved connections » and added 2 defaults values for dbHost and dbType. * Default DB back to MySQL. <option value="mysql" selected="selected">MySQL</option> * Update extensions/database/module/langs/translation-en.json Co-authored-by: Thad Guidry <thadguidry@gmail.com> * Better default with « mysql » * Fix sqlite #databaseHost before calling self._updateDatabaseType() Fix $( "#databaseHost" ).val(self._defaultDatabaseHost) to be set before calling self._updateDatabaseType(self._defaultDatabaseType) that may change it. * Removed field name & fixed default connection name Removed field name text since it's populated from i18n and fixed the default connection name so that it has no space in it. * Little update to placeholder text Co-authored-by: Thad Guidry <thadguidry@gmail.com>
2020-05-30 10:20:05 +02:00
Refine.DatabaseSourceUI.prototype._resetDatabaseImportForm = function() {
var self = this;
$( "#databaseHost" ).val(self._defaultDatabaseHost);
$('input#connectionName').val($.i18n('database-source/connectionNameDefaultValue'));
Only show the database login fields when necessary (#2615) * DB login fields visibility controled by CSS The database login field’s visibility is now controled by CSS styling. * Change field name from Database to Database file. Change field name from Database to Database file. * Use full db name as CSS classes Use full db name instead of diminutives for the CSS classes. * Added translation to placeholders Added translation to the Input placeholders. * Undo a change, remerge Database field & File remerge Database field and DatabaseFile Field like before. * Created DatabaseSourceUI._updateDatabaseType(dbType) Created Refine.DatabaseSourceUI.prototype._updateDatabaseType(databaseType) * Make MySQL the default database <option value="mysql" selected="selected"">MySQL</option> * Update database-import-form.html Fixed typo. (<option value="mysql" selected="selected">MySQL</option>) * New default connection name value New default connection name value, translation of it, changing cssClassName from options to dbtype-options, adding the prefix "dbt-" to the db types and fix the changing of placeholder databaseName/databaseFileName when neccessary. * Fix issue with « saved connections » Fix issue with « saved connections » and added 2 defaults values for dbHost and dbType. * Default DB back to MySQL. <option value="mysql" selected="selected">MySQL</option> * Update extensions/database/module/langs/translation-en.json Co-authored-by: Thad Guidry <thadguidry@gmail.com> * Better default with « mysql » * Fix sqlite #databaseHost before calling self._updateDatabaseType() Fix $( "#databaseHost" ).val(self._defaultDatabaseHost) to be set before calling self._updateDatabaseType(self._defaultDatabaseType) that may change it. * Removed field name & fixed default connection name Removed field name text since it's populated from i18n and fixed the default connection name so that it has no space in it. * Little update to placeholder text Co-authored-by: Thad Guidry <thadguidry@gmail.com>
2020-05-30 10:20:05 +02:00
$( "select#databaseTypeSelect" ).val(self._defaultDatabaseType);
self._updateDatabaseType(self._defaultDatabaseType);
$( "#databasePassword" ).val("");
$( "#initialDatabase" ).val("");
$( "#initialSchema" ).val("");
$( "#editConnectionControlDiv" ).hide();
$( "#newConnectionControlDiv" ).show();
$('#connectionName').removeAttr('readonly');
2018-01-14 03:24:56 +01:00
};