diff --git a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/admin/personaBar/Dnn.ConfigConsole/scripts/ConfigConsole.js b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/admin/personaBar/Dnn.ConfigConsole/scripts/ConfigConsole.js
index 60bf95c83d7..5e24e930989 100644
--- a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/admin/personaBar/Dnn.ConfigConsole/scripts/ConfigConsole.js
+++ b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/admin/personaBar/Dnn.ConfigConsole/scripts/ConfigConsole.js
@@ -7,314 +7,316 @@
'use strict';
define(['jquery',
- 'knockout',
- 'knockout.mapping',
- 'jquery-ui.min',
- 'main/config',
- 'jquery.easydropdown.min',
- 'dnn.jquery',
- 'main/koBindingHandlers/jScrollPane'],
- function ($, ko, koMapping, jqueryUI, cf) {
- var config = cf.init();
-
- var utility, $panel, viewModel, monacoConfigFilesEditor, configFilesEditor, configFilesModel, configFilesContent, monacoMergeScriptsEditor, mergeScriptsEditor, mergeScriptsModel, mergeScriptsContent, curConfigName;
-
- var requestService = function (type, method, params, callback, failure) {
- utility.sf.moduleRoot = "personaBar";
- utility.sf.controller = "ConfigConsole";
-
- utility.sf[type].call(utility.sf, method, params, callback, failure);
+ 'knockout',
+ 'knockout.mapping',
+ 'jquery-ui.min',
+ 'main/config',
+ 'jquery.easydropdown.min',
+ 'dnn.jquery',
+ 'main/koBindingHandlers/jScrollPane'],
+ function ($, ko, koMapping, jqueryUI, cf) {
+ var config = cf.init();
+
+ var utility, $panel, viewModel, monacoConfigFilesEditor, configFilesEditor, configFilesModel, configFilesContent, monacoMergeScriptsEditor, mergeScriptsEditor, mergeScriptsModel, mergeScriptsContent, curConfigName;
+
+ var requestService = function (type, method, params, callback, failure) {
+ utility.sf.moduleRoot = "personaBar";
+ utility.sf.controller = "ConfigConsole";
+
+ utility.sf[type].call(utility.sf, method, params, callback, failure);
+ }
+
+ var getConfigs = function () {
+ requestService('get', 'GetConfigFilesList', {}, function (data) {
+ // add the caption as first option
+ data.Results.unshift(viewModel.resx.plConfigHelp);
+
+ viewModel.configs(data.Results);
+
+ $('.configConsolePanel select').easyDropDown({ wrapperClass: 'pb-dropdown', cutOff: 10, inFocus: true });
+ }, function () {
+ // failed
+ utility.notifyError('Failed...');
+ });
+ }
+
+ var getConfigFile = function () {
+ if (curConfigName === viewModel.resx.plConfigHelp) {
+ // it's the caption, so empty the editor
+ configFilesContent.setValue('');
+ } else {
+ requestService('get', 'GetConfigFile', { 'fileName': curConfigName }, function (data) {
+ if (curConfigName.endsWith("config")) {
+ configFilesEditor.setModelLanguage(configFilesModel, "xml");
+ }
+ else if (curConfigName.endsWith("txt")) {
+ configFilesEditor.setModelLanguage(configFilesModel, "plain/text");
+ }
+ configFilesContent.setValue(data.FileContent);
+ }, function () {
+ // failed
+ utility.notifyError('Failed...');
+ });
+ }
+ }
+
+ var saveConfigFile = function () {
+ utility.confirm(
+ utility.resx.ConfigConsole.SaveConfirm,
+ utility.resx.ConfigConsole.SaveButton,
+ utility.resx.ConfigConsole.CancelButton,
+ function () {
+ validate({
+ 'fileName': curConfigName,
+ 'fileContent': configFilesContent.getValue()
+ });
}
-
- var getConfigs = function () {
- requestService('get', 'GetConfigFilesList', {}, function (data) {
- // add the caption as first option
- data.Results.unshift(viewModel.resx.plConfigHelp);
-
- viewModel.configs(data.Results);
-
- $('.configConsolePanel select').easyDropDown({ wrapperClass: 'pb-dropdown', cutOff: 10, inFocus: true });
- }, function () {
- // failed
- utility.notifyError('Failed...');
- });
+ );
+ }
+
+ var validate = function (configFile) {
+ var callback = function (data) {
+ if (data && data.ValidationErrors && data.ValidationErrors.length) {
+ confirmValidationErrors(data.ValidationErrors, configFile);
+ } else {
+ update(configFile);
}
+ };
- var getConfigFile = function () {
- if (curConfigName === viewModel.resx.plConfigHelp) {
- // it's the caption, so empty the editor
- configFilesContent.setValue('');
- } else {
- requestService('get', 'GetConfigFile', { 'fileName': curConfigName }, function (data) {
- if (curConfigName.endsWith("config")) {
- configFilesEditor.setModelLanguage(configFilesModel, "xml");
- }
- else if (curConfigName.endsWith("txt")) {
- configFilesEditor.setModelLanguage(configFilesModel, "plain/text");
- }
- configFilesContent.setValue(data.FileContent);
- }, function () {
- // failed
- utility.notifyError('Failed...');
- });
- }
- }
+ requestService('post', 'ValidateConfigFile', configFile, callback, fail);
+ }
- var saveConfigFile = function () {
- utility.confirm(
- utility.resx.ConfigConsole.SaveConfirm,
- utility.resx.ConfigConsole.SaveButton,
- utility.resx.ConfigConsole.CancelButton,
- function () {
- validate({
- 'fileName': curConfigName,
- 'fileContent': configFilesContent.getValue()
- });
- }
- );
- }
+ var confirmValidationErrors = function (validationErrors, configFile) {
+ const BR = '
';
+ const TOP = 5;
- var validate = function(configFile) {
- var callback = function(data) {
- if (data && data.ValidationErrors && data.ValidationErrors.length) {
- confirmValidationErrors(data.ValidationErrors, configFile);
- } else {
- update(configFile);
- }
- };
+ var question = utility.resx.ConfigConsole.ValidationErrorsConfirm.replace('{0}', BR);
- requestService('post', 'ValidateConfigFile', configFile, callback, fail);
- }
+ // remove duplicates and take top N
+ var errors = validationErrors
+ .filter((value, index, self) => self.indexOf(value) === index)
+ .slice(0, TOP)
+ .concat(validationErrors.length > TOP ? ['...'] : []);
- var confirmValidationErrors = function(validationErrors, configFile) {
- const BR = '
';
- const TOP = 5;
-
- var question = utility.resx.ConfigConsole.ValidationErrorsConfirm.replace('{0}', BR);
-
- // remove duplicates and take top N
- var errors = validationErrors
- .filter((value, index, self) => self.indexOf(value) === index)
- .slice(0, TOP)
- .concat(validationErrors.length > TOP ? ['...'] : []);
-
- utility.confirm(
- question + BR + BR + errors.join(BR),
- utility.resx.ConfigConsole.SaveButton,
- utility.resx.ConfigConsole.CancelButton,
- function () {
- update(configFile);
- }
- );
+ utility.confirm(
+ question + BR + BR + errors.join(BR),
+ utility.resx.ConfigConsole.SaveButton,
+ utility.resx.ConfigConsole.CancelButton,
+ function () {
+ update(configFile);
}
-
- var update = function(configFile) {
- requestService('post', 'UpdateConfigFile', configFile, succeed, fail);
+ );
+ }
+
+ var update = function (configFile) {
+ requestService('post', 'UpdateConfigFile', configFile, succeed, fail);
+ }
+
+ var succeed = () => {
+ utility.notify(utility.resx.ConfigConsole.Success);
+ }
+
+ var fail = () => {
+ utility.notifyError(utility.resx.ConfigConsole.ERROR_ConfigurationFormat);
+ }
+
+ var mergeConfigFile = function () {
+ var confirmText = utility.resx.ConfigConsole.MergeConfirm;
+ if (curConfigName != null && curConfigName == 'web.config') {
+ confirmText = utility.resx.ConfigConsole.SaveWarning;
+ }
+ utility.confirm(confirmText, utility.resx.ConfigConsole.SaveButton, utility.resx.ConfigConsole.CancelButton, function () {
+ requestService('post', 'MergeConfigFile', { 'fileName': '', 'fileContent': mergeScriptsContent.getValue() }, function (data) {
+ utility.notify(utility.resx.ConfigConsole.Success);
+ }, function () {
+ // failed
+ utility.notifyError(utility.resx.ConfigConsole.ERROR_Merge);
+ });
+ });
+ }
+
+ var initViewModel = function () {
+ viewModel = {
+ resx: utility.resx.ConfigConsole,
+ configxml: ko.observable(''),
+ mergexml: ko.observable(''),
+ saveConfig: saveConfigFile,
+ mergeConfig: mergeConfigFile,
+ configs: ko.observableArray([]),
+ config: ko.observable('')
+ };
+ }
+
+ var configSelectionChanged = function (data) {
+ if (data != null && data != curConfigName) {
+ curConfigName = data;
+ getConfigFile();
+ }
+ }
+
+ var initUpload = function () {
+ var $uploadContainer = $panel.find('.fileupload-wrapper');
+ var $uploadControl = $uploadContainer.find('input');
+
+ if (typeof FileReader === "undefined") {
+ $uploadContainer.hide();
+ return;
+ }
+
+ $uploadControl.on('change', function (e) {
+ var file = $uploadControl[0].files[0];
+ var textType = /text|xml.*/;
+
+ if (file.type.match(textType) || file.name.toLowerCase().split('.').pop() === 'config') {
+ var reader = new FileReader();
+
+ reader.onload = function (e) {
+ mergeScriptsContent.setValue(reader.result);
+ }
+
+ reader.readAsText(file);
+ } else {
+ utility.notifyError('File not supported');
}
+ });
+ }
- var succeed = () => {
- utility.notify(utility.resx.ConfigConsole.Success);
- }
-
- var fail = () => {
- utility.notifyError(utility.resx.ConfigConsole.ERROR_ConfigurationFormat);
- }
-
- var mergeConfigFile = function () {
- var confirmText = utility.resx.ConfigConsole.MergeConfirm;
- if (curConfigName != null && curConfigName == 'web.config') {
- confirmText = utility.resx.ConfigConsole.SaveWarning;
- }
- utility.confirm(confirmText, utility.resx.ConfigConsole.SaveButton, utility.resx.ConfigConsole.CancelButton, function () {
- requestService('post', 'MergeConfigFile', { 'fileName': '', 'fileContent': mergeScriptsContent.getValue() }, function (data) {
- utility.notify(utility.resx.ConfigConsole.Success);
- }, function () {
- // failed
- utility.notifyError(utility.resx.ConfigConsole.ERROR_Merge);
- });
- });
- }
-
- var initViewModel = function () {
- viewModel = {
- resx: utility.resx.ConfigConsole,
- configxml: ko.observable(''),
- mergexml: ko.observable(''),
- saveConfig: saveConfigFile,
- mergeConfig: mergeConfigFile,
- configs: ko.observableArray([]),
- config: ko.observable('')
- };
- }
-
- var configSelectionChanged = function (data) {
- if (data != null && data != curConfigName) {
- curConfigName = data;
- getConfigFile();
- }
- }
-
- var initUpload = function () {
- var $uploadContainer = $panel.find('.fileupload-wrapper');
- var $uploadControl = $uploadContainer.find('input');
-
- if (typeof FileReader === "undefined") {
- $uploadContainer.hide();
- return;
- }
-
- $uploadControl.on('change', function (e) {
- var file = $uploadControl[0].files[0];
- var textType = /text|xml.*/;
-
- if (file.type.match(textType) || file.name.toLowerCase().split('.').pop() === 'config') {
- var reader = new FileReader();
+ var init = function (wrapper, util, params, callback) {
+ utility = util;
+ $panel = wrapper;
- reader.onload = function (e) {
- mergeScriptsContent.setValue(reader.result);
- }
+ initViewModel();
- reader.readAsText(file);
- } else {
- utility.notifyError('File not supported');
- }
- });
- }
+ ko.applyBindings(viewModel, $panel[0]);
- var init = function (wrapper, util, params, callback) {
- utility = util;
- $panel = wrapper;
+ curConfigName = config.portalId;
- initViewModel();
+ getConfigs();
- ko.applyBindings(viewModel, $panel[0]);
+ initConfigConsole();
- curConfigName = config.portalId;
+ initUpload();
- getConfigs();
+ $('.configConsolePanel .body').dnnTabs({ selected: 0, activate: initTabsClickEvent() });
+ setEditorHeight();
- initConfigConsole();
+ if (typeof callback === 'function') {
+ callback();
+ }
+ };
- initUpload();
+ var initTabsClickEvent = function () {
+ const tabs = document.querySelectorAll('.configConsolePanel .tabs-nav li');
+ tabs.forEach(tab => {
+ tab.addEventListener('click', setEditorHeight);
+ });
+ }
- $('.configConsolePanel .body').dnnTabs({ selected: 0, activate: initTabsClickEvent() });
- setEditorHeight();
+ var setEditorHeight = function () {
+ setTimeout(() => {
+ var panelHeight = $('#ConfigConsole-panel').height();
+ if (panelHeight > 400) {
- if (typeof callback === 'function') {
- callback();
- }
- };
+ if (document.querySelector('#configConsole-files').style.display !== 'none') {
+ $('#monaco-editor-config-files').height(panelHeight - 400);
+ }
- var initTabsClickEvent = function() {
- const tabs = document.querySelectorAll('.configConsolePanel .tabs-nav li');
- tabs.forEach(tab => {
- tab.addEventListener('click', setEditorHeight);
- });
+ if (document.querySelector('#configConsole-merge').style.display !== 'none') {
+ $('#monaco-editor-merge-scripts').height(panelHeight - 400);
+ }
}
-
- var setEditorHeight = function() {
- setTimeout(() => {
- var panelHeight = $('#ConfigConsole-panel').height();
- if (panelHeight > 400) {
-
- if(document.querySelector('#configConsole-files').style.display !== 'none') {
- $('#monaco-editor-config-files').height(panelHeight - 400);
- }
-
- if(document.querySelector('#configConsole-merge').style.display !== 'none') {
- $('#monaco-editor-merge-scripts').height(panelHeight - 400);
- }
- }
- }, 300);
- }
-
- var initConfigConsole = function() {
- var monacoEditorLoaderScript = document.createElement('script');
- monacoEditorLoaderScript.type = 'text/javascript';
- monacoEditorLoaderScript.src = '/Resources/Shared/components/MonacoEditor/loader.js';
- document.body.appendChild(monacoEditorLoaderScript);
-
- require.config({ paths: { 'vs': '/Resources/Shared/components/MonacoEditor' }});
- require(['vs/editor/editor.main'], function(monaco) {
-
- self.MonacoEnvironment = {
- getWorkerUrl: function (moduleId, label) {
- if (label === 'typescript' || label === 'javascript') {
- return `data:text/javascript;charset=utf-8,${encodeURIComponent(`
+ }, 300);
+ }
+
+ var initConfigConsole = function () {
+ let siteRoot = dnn.getVar("sf_siteRoot");
+ if (!siteRoot) siteRoot = '/';
+ var monacoEditorLoaderScript = document.createElement('script');
+ monacoEditorLoaderScript.type = 'text/javascript';
+ monacoEditorLoaderScript.src = siteRoot + 'Resources/Shared/components/MonacoEditor/loader.js';
+ document.body.appendChild(monacoEditorLoaderScript);
+
+ require.config({ paths: { 'vs': siteRoot + 'Resources/Shared/components/MonacoEditor' } });
+ require(['vs/editor/editor.main'], function (monaco) {
+
+ self.MonacoEnvironment = {
+ getWorkerUrl: function (moduleId, label) {
+ if (label === 'typescript' || label === 'javascript') {
+ return `data:text/javascript;charset=utf-8,${encodeURIComponent(`
importScripts('${process.env.ASSET_PATH}/typescript.worker.js');`
- )}`;
- }
-
- return `data:text/javascript;charset=utf-8,${encodeURIComponent(`
- importScripts('${process.env.ASSET_PATH}/editor.worker.js');`
- )}`;
- }
- }
-
- configFilesEditor = monaco.editor;
- mergeScriptsEditor = monaco.editor;
-
- configFilesContent = configFilesEditor.createModel("", "xml");
- mergeScriptsContent = mergeScriptsEditor.createModel("", "xml");
-
- initMonacoEditors();
-
- configFilesModel = monacoConfigFilesEditor.getModel();
- mergeScriptsModel = monacoMergeScriptsEditor.getModel();
-
- viewModel.config.subscribe(configSelectionChanged);
- });
-
- }
-
- var initMonacoEditors = function() {
- var theme = "vs-light";
- if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
- theme = "vs-dark";
+ )}`;
}
- window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => {
- theme = e.matches ? "vs-dark" : "vs-light";
- });
-
- monacoConfigFilesEditor = configFilesEditor.create(document.getElementById("monaco-editor-config-files"), {
- model: configFilesContent,
- language: "xml",
- wordWrap: 'wordWrapColumn',
- wordWrapColumn: 80,
- wordWrapMinified: true,
- wrappingIndent: "indent",
- lineNumbers: "on",
- roundedSelection: false,
- scrollBeyondLastLine: false,
- readOnly: false,
- theme: theme,
- automaticLayout: true
- });
-
- monacoMergeScriptsEditor = mergeScriptsEditor.create(document.getElementById("monaco-editor-merge-scripts"), {
- model: mergeScriptsContent,
- language: "xml",
- wordWrap: 'wordWrapColumn',
- wordWrapColumn: 80,
- wordWrapMinified: true,
- wrappingIndent: "indent",
- lineNumbers: "on",
- roundedSelection: false,
- scrollBeyondLastLine: false,
- readOnly: false,
- theme: theme,
- automaticLayout: true
- });
- }
- var load = function (params, callback) {
- if (typeof callback === 'function') {
- callback();
- }
- };
+ return `data:text/javascript;charset=utf-8,${encodeURIComponent(`
+ importScripts('${process.env.ASSET_PATH}/editor.worker.js');`
+ )}`;
+ }
+ }
- return {
- init: init,
- load: load
- };
- });
+ configFilesEditor = monaco.editor;
+ mergeScriptsEditor = monaco.editor;
+
+ configFilesContent = configFilesEditor.createModel("", "xml");
+ mergeScriptsContent = mergeScriptsEditor.createModel("", "xml");
+
+ initMonacoEditors();
+
+ configFilesModel = monacoConfigFilesEditor.getModel();
+ mergeScriptsModel = monacoMergeScriptsEditor.getModel();
+
+ viewModel.config.subscribe(configSelectionChanged);
+ });
+
+ }
+
+ var initMonacoEditors = function () {
+ var theme = "vs-light";
+ if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
+ theme = "vs-dark";
+ }
+ window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => {
+ theme = e.matches ? "vs-dark" : "vs-light";
+ });
+
+ monacoConfigFilesEditor = configFilesEditor.create(document.getElementById("monaco-editor-config-files"), {
+ model: configFilesContent,
+ language: "xml",
+ wordWrap: 'wordWrapColumn',
+ wordWrapColumn: 80,
+ wordWrapMinified: true,
+ wrappingIndent: "indent",
+ lineNumbers: "on",
+ roundedSelection: false,
+ scrollBeyondLastLine: false,
+ readOnly: false,
+ theme: theme,
+ automaticLayout: true
+ });
+
+ monacoMergeScriptsEditor = mergeScriptsEditor.create(document.getElementById("monaco-editor-merge-scripts"), {
+ model: mergeScriptsContent,
+ language: "xml",
+ wordWrap: 'wordWrapColumn',
+ wordWrapColumn: 80,
+ wordWrapMinified: true,
+ wrappingIndent: "indent",
+ lineNumbers: "on",
+ roundedSelection: false,
+ scrollBeyondLastLine: false,
+ readOnly: false,
+ theme: theme,
+ automaticLayout: true
+ });
+ }
+
+ var load = function (params, callback) {
+ if (typeof callback === 'function') {
+ callback();
+ }
+ };
+
+ return {
+ init: init,
+ load: load
+ };
+ });
diff --git a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/admin/personaBar/Dnn.SqlConsole/scripts/SqlConsole.js b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/admin/personaBar/Dnn.SqlConsole/scripts/SqlConsole.js
index 3995f2cd3e8..e6fddc34116 100644
--- a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/admin/personaBar/Dnn.SqlConsole/scripts/SqlConsole.js
+++ b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/admin/personaBar/Dnn.SqlConsole/scripts/SqlConsole.js
@@ -5,803 +5,805 @@
* Module responsible to Sql Console
*/
define(['jquery',
- 'knockout',
- 'knockout.mapping',
- './sort',
- './exportData',
- './clipboard.min',
- './html2canvas',
- './FileSaver.min',
- 'dnn.jquery',
- 'main/koBindingHandlers/jScrollPane'],
- function ($, ko, koMapping, sort, exportData, Clipboard) {
- 'use strict';
-
- var utility, resx, $panel, viewModel, sqlConsole, sqlContent, jsPdf;
-
- var pagesCount = 7;
-
- var requestService = function (type, method, params, callback, error) {
- utility.sf.moduleRoot = "personaBar";
- utility.sf.controller = "SqlConsole";
-
- utility.sf[type].call(utility.sf, method, params, callback, error);
- }
-
- var getSavedQueries = function (selectedId) {
- requestService('get', 'GetSavedQueries', {}, function (data) {
- viewModel.connections(data.connections);
- viewModel.connection(data.connections[0]);
-
- var newQuery = {
- id: -1,
- name: resx.NewQuery,
- connection: viewModel.connection(),
- query: ''
- };
-
- viewModel.savedQueries.removeAll();
- viewModel.savedQueries.push(newQuery);
- for (var i = 0; i < data.queries.length; i++) {
- viewModel.savedQueries.push(data.queries[i]);
- }
-
- viewModel.selectedQuery(selectedId);
+ 'knockout',
+ 'knockout.mapping',
+ './sort',
+ './exportData',
+ './clipboard.min',
+ './html2canvas',
+ './FileSaver.min',
+ 'dnn.jquery',
+ 'main/koBindingHandlers/jScrollPane'],
+ function ($, ko, koMapping, sort, exportData, Clipboard) {
+ 'use strict';
+
+ var utility, resx, $panel, viewModel, sqlConsole, sqlContent, jsPdf;
+
+ var pagesCount = 7;
+
+ var requestService = function (type, method, params, callback, error) {
+ utility.sf.moduleRoot = "personaBar";
+ utility.sf.controller = "SqlConsole";
+
+ utility.sf[type].call(utility.sf, method, params, callback, error);
+ }
+
+ var getSavedQueries = function (selectedId) {
+ requestService('get', 'GetSavedQueries', {}, function (data) {
+ viewModel.connections(data.connections);
+ viewModel.connection(data.connections[0]);
+
+ var newQuery = {
+ id: -1,
+ name: resx.NewQuery,
+ connection: viewModel.connection(),
+ query: ''
+ };
- if (!viewModel.name()) {
- viewModel.name(newQuery.name);
- }
- });
+ viewModel.savedQueries.removeAll();
+ viewModel.savedQueries.push(newQuery);
+ for (var i = 0; i < data.queries.length; i++) {
+ viewModel.savedQueries.push(data.queries[i]);
}
- var initUpload = function () {
- var $uploadContainer = $panel.find('.fileupload-wrapper');
- var $uploadControl = $uploadContainer.find('input');
-
- if (typeof FileReader === "undefined") {
- $uploadContainer.hide();
- return;
- }
-
- $uploadControl.on('change', function (e) {
- var file = $uploadControl[0].files[0];
- var textType = /text.*/;
- if (file.type.match(textType) || file.name.toLowerCase().split('.').pop() === 'sql') {
- var reader = new FileReader();
-
- reader.onload = function (e) {
- viewModel.query(reader.result);
- }
+ viewModel.selectedQuery(selectedId);
- reader.readAsText(file);
- } else {
- utility.notifyError('File not supported');
- }
-
- $uploadControl.val('');
- });
+ if (!viewModel.name()) {
+ viewModel.name(newQuery.name);
}
-
- var changeTab = function (data) {
- var index = data.index;
-
- $panel.find('.tables-container > div').hide();
- $panel.find('.tables-container > div#result' + index).show();
- var $tableContainer = $panel.find('.tables-container > div#result' + index).find('> div.table-container');
- if ($tableContainer.data('jsp')) {
- $tableContainer.data('jsp').destroy();
- $tableContainer = $panel.find('.tables-container > div#result' + index).find('> div.table-container');
- }
- $tableContainer.jScrollPane();
-
- $panel.find('.result-tabs ul li').removeClass('selected').eq(index).addClass('selected');
+ });
+ }
+
+ var initUpload = function () {
+ var $uploadContainer = $panel.find('.fileupload-wrapper');
+ var $uploadControl = $uploadContainer.find('input');
+
+ if (typeof FileReader === "undefined") {
+ $uploadContainer.hide();
+ return;
+ }
+
+ $uploadControl.on('change', function (e) {
+ var file = $uploadControl[0].files[0];
+ var textType = /text.*/;
+ if (file.type.match(textType) || file.name.toLowerCase().split('.').pop() === 'sql') {
+ var reader = new FileReader();
+
+ reader.onload = function (e) {
+ viewModel.query(reader.result);
+ }
+
+ reader.readAsText(file);
+ } else {
+ utility.notifyError('File not supported');
}
- var scrollPaneInitialised = function (table, e) {
- var $table = $panel.find('.tables-container > div#result' + table.index).find('table');
- if (!$table.attr('width') || $table.attr('width') === '0') {
- $table.attr('width', $table.width());
- }
+ $uploadControl.val('');
+ });
+ }
+
+ var changeTab = function (data) {
+ var index = data.index;
+
+ $panel.find('.tables-container > div').hide();
+ $panel.find('.tables-container > div#result' + index).show();
+ var $tableContainer = $panel.find('.tables-container > div#result' + index).find('> div.table-container');
+ if ($tableContainer.data('jsp')) {
+ $tableContainer.data('jsp').destroy();
+ $tableContainer = $panel.find('.tables-container > div#result' + index).find('> div.table-container');
+ }
+ $tableContainer.jScrollPane();
+
+ $panel.find('.result-tabs ul li').removeClass('selected').eq(index).addClass('selected');
+ }
+
+ var scrollPaneInitialised = function (table, e) {
+ var $table = $panel.find('.tables-container > div#result' + table.index).find('table');
+ if (!$table.attr('width') || $table.attr('width') === '0') {
+ $table.attr('width', $table.width());
+ }
+ }
+
+ var savedQueryChanged = function (val) {
+ var id = viewModel.selectedQuery();
+ var query;
+ var savedQueries = viewModel.savedQueries();
+ for (var i = 0; i < savedQueries.length; i++) {
+ if (savedQueries[i].id === id) {
+ query = savedQueries[i];
+ break;
}
-
- var savedQueryChanged = function (val) {
- var id = viewModel.selectedQuery();
- var query;
- var savedQueries = viewModel.savedQueries();
- for (var i = 0; i < savedQueries.length; i++) {
- if (savedQueries[i].id === id) {
- query = savedQueries[i];
- break;
- }
- }
-
- if (!query || !query.name) {
- return;
- }
-
- viewModel.query(query.query || '');
- viewModel.name(query.name);
- viewModel.connection(query.connection);
- viewModel.id(query.id || -1);
+ }
+
+ if (!query || !query.name) {
+ return;
+ }
+
+ viewModel.query(query.query || '');
+ viewModel.name(query.name);
+ viewModel.connection(query.connection);
+ viewModel.id(query.id || -1);
+ }
+
+ var startSaveQuery = function () {
+ viewModel.query(sqlContent.getValue());
+
+ if (!viewModel.query()) {
+ return;
+ }
+
+ viewModel.saving(true);
+
+ if (viewModel.id() <= 0) {
+ viewModel.name('');
+ }
+
+ $('#query-name').focus();
+ }
+
+ var saveQuery = function () {
+ viewModel.query(sqlContent.getValue());
+
+ if (!viewModel.query()) {
+ return;
+ }
+
+ if (!viewModel.name()) {
+ utility.notify(resx.EmptyName);
+ return;
+ }
+
+ var query = {
+ id: viewModel.id(),
+ name: viewModel.name(),
+ query: viewModel.query(),
+ connection: viewModel.connection()
+ }
+
+ viewModel.loading(true);
+
+ requestService('post', 'SaveQuery', query, function (data) {
+ getSavedQueries(data.id);
+ viewModel.saving(false);
+ viewModel.loading(false);
+ });
+ }
+
+ var cancelSave = function () {
+ viewModel.saving(false);
+ }
+
+ var deleteQuery = function () {
+ var confirmText = resx.DeleteConfirm;
+ var deleteText = resx.Delete;
+ var cancelText = resx.Cancel;
+
+ utility.confirm(confirmText, deleteText, cancelText, function () {
+ viewModel.loading(true);
+ requestService('post', 'DeleteQuery', { id: viewModel.id() }, function () {
+ getSavedQueries();
+ viewModel.loading(false);
+ });
+ });
+ }
+
+ var clone = function (data) {
+ var cloneData = {};
+ for (var name in data) {
+ if (data.hasOwnProperty(name)) {
+ cloneData[name] = data[name];
}
+ }
- var startSaveQuery = function() {
- viewModel.query(sqlContent.getValue());
-
- if (!viewModel.query()) {
- return;
- }
-
- viewModel.saving(true);
+ return cloneData;
+ }
- if (viewModel.id() <= 0) {
- viewModel.name('');
- }
-
- $('#query-name').focus();
+ var encode = function (item) {
+ for (var name in item) {
+ if (item.hasOwnProperty(name) && item[name]) {
+ item[name] = $('