/** * Run SQL Query and receive feedback about the success. */ var ReportDebugger = (function ($) { 'use strict'; var me = { isInitialized: false, url: { ajaxRunSql: 'index.php?module=report&action=edit&cmd=ajaxTryQuery' }, selector: { resultTextBox: '#reportEditResult', queryTextBox: '#reportEditQuery', runDebugButton: '#structureRun', paramViewElement: '.parameter-view', }, /** * @return void */ init: function () { if (me.isInitialized === true) { return; } me.registerEvents(); me.isInitialized = true; }, /** * @return {void} */ registerEvents: function () { $(me.selector.runDebugButton).on('click', function (event) { event.preventDefault(); me.ajaxDebugRequest(); }); }, /** * @param {string} message * @param {boolean} error */ showDebugMessage: function(message, error = false) { var $textArea = $(me.selector.resultTextBox); if (error === true) { $textArea.attr('error', 'true'); } else { $textArea.attr('error', 'false'); } $textArea.text(message); }, /** * @return {void} */ ajaxDebugRequest: function() { var params = {}; $(me.selector.paramViewElement).each(function (index, element) { params[$(element).data('key')] = $(element).data('value'); }); var sql = $(me.selector.queryTextBox).val(); $.ajax({ url: me.url.ajaxRunSql, data:{ statement: sql, parameters: params }, dataType: 'json', method: 'post', beforeSend: function () { App.loading.open(); }, success: function (data) { App.loading.close(); if (data.messagetype === 'error') { me.showDebugMessage(data.message, true); } else { me.showDebugMessage(data.message); } if (data.error) { throw('request error: ' + data.error); } }, }); }, }; return { init: me.init, }; })(jQuery); /** * Add/Edit/Remove columns */ var ReportColumns = (function ($) { 'use strict'; var me = { isInitialized: false, selector: { columnDialog: '#editColumnDialog', dialogMessageBox: '#editColMessage', inputFormId: '#reportEditId', inputId: '#editColId', inputKey: '#editColKey', inputTitle: '#editColTitle', inputWidth: '#editColWidth', inputAlign: '#editColAlignment', inputSort: '#editColSort', inputFormat: '#edit-col-format', inputFormatStatement: '#edit-col-format-statement', inputFormatRow: '#edit-col-format-statement-row', inputSum: '#chkColSum', inputSequence: '#editColSequence', buttonAddColumn: '#btnAddColumn', buttonAutoCreate: '#btnAutoCreateColumns', buttonDeleteAll: '#btnDeleteAllColumns', allColumnViews: 'a.table-button-col-edit', allColumnDelete: 'a.table-button-col-delete', dataTable: '#report_columns', resultTextBox: '#reportEditResult', queryTextBox: '#reportEditQuery', }, url: { ajaxGetColumn: 'index.php?module=report&action=edit&cmd=ajaxGetColumn', ajaxSaveColumn: 'index.php?module=report&action=edit&cmd=ajaxSaveColumn', ajaxDeleteColumn: 'index.php?module=report&action=edit&cmd=ajaxDeleteColumn', ajaxDeleteAllColumns: 'index.php?module=report&action=edit&cmd=ajaxDeleteColumn', ajaxAutoCreateColumns: 'index.php?module=report&action=edit&cmd=ajaxAutoCreateColumns' }, storage: { $dialog: null, formId: 0 }, /** * @return {void} */ init: function () { if (me.isInitialized === true) { return; } me.storage.$dialog = $(me.selector.columnDialog); me.storage.formId = $(me.selector.inputFormId).data('form-id'); me.dialogInit(); me.registerEvents(); me.isInitialized = true; }, /** * @return {void} */ dialogInit: function () { me.storage.$dialog.dialog({ modal: true, bgiframe: true, closeOnEscape: false, minWidth: 500, minHeight: 320, maxHeight: 700, autoOpen: false, buttons: [ { text: 'ABBRECHEN', click: function () { me.dialogClose(); } }, { text: 'SPEICHERN', click: function () { me.dialogSave(); } }], open: function () { $(me.selector.inputKey).trigger('focus'); }, close: function () { //me.dialogReset(); } }); }, /** * @param {number} id data-id of the Column to be edited * * @return {void} */ dialogOpen: function (id = 0) { if (me.storage.formId < 1 && id < 1) { alert('Bitte speichern Sie zuerst den Bericht.'); return; } if (id < 1) { me.dialogReset(); me.storage.$dialog.dialog('open'); return; } $.ajax({ url: me.url.ajaxGetColumn, data: { id: id }, method: 'post', dataType: 'json', beforeSend: function () { App.loading.open(); }, success: function (data) { me.dialogReset(); me.setDialogData(data); App.loading.close(); me.storage.$dialog.dialog('open'); } }); }, /** * @return {void} */ dialogClose: function () { me.storage.$dialog.dialog('close'); }, /** * @return {void} */ dialogReset: function () { me.dialogSetMessage(''); me.setDialogData(null); }, /** * @return {void} */ dialogSave: function () { me.ajaxSaveColumn(me.getDialogData()); }, /** * @return {void} */ dialogDelete: function () { var deleteId = me.storage.$dialog.find(me.selector.inputId).val(); me.ajaxDeleteColumn(deleteId); }, /** * @param {string} message * * @return {void} */ dialogSetMessage: function(message) { me.storage.$dialog.find(me.selector.dialogMessageBox).text(message); }, /** * @return {Object} */ getDialogData: function() { return { reportId: me.storage.formId, id: me.storage.$dialog.find(me.selector.inputId).val(), key_name: me.storage.$dialog.find(me.selector.inputKey).val(), title: me.storage.$dialog.find(me.selector.inputTitle).val(), width: me.storage.$dialog.find(me.selector.inputWidth).val(), alignment: me.storage.$dialog.find(me.selector.inputAlign).val(), sorting: me.storage.$dialog.find(me.selector.inputSort).val(), format_type: me.storage.$dialog.find(me.selector.inputFormat).val(), format_statement: me.storage.$dialog.find(me.selector.inputFormatStatement).val(), sum: ((me.storage.$dialog.find(me.selector.inputSum).prop('checked') === true) ? 1 : 0), sequence: me.storage.$dialog.find(me.selector.inputSequence).val() }; }, /** * @param {Object} data * * @return {void} */ setDialogData: function(data) { if (data == null) { data = {}; } me.storage.$dialog.find(me.selector.inputId).val('id' in data ? data.id : ''); me.storage.$dialog.find(me.selector.inputKey).val('key_name' in data ? data.key_name : ''); me.storage.$dialog.find(me.selector.inputTitle).val('title' in data ? data.title : ''); me.storage.$dialog.find(me.selector.inputWidth).val('width' in data ? data.width : ''); me.storage.$dialog.find(me.selector.inputAlign).val( (('alignment' in data && data.alignment !== '') ? data.alignment : 'left') ); me.storage.$dialog.find(me.selector.inputSort).val( (('sorting' in data && data.sorting !== '') ? data.sorting : 'numeric') ); me.storage.$dialog.find(me.selector.inputFormat).val('format_type' in data ? data.format_type : null); me.storage.$dialog.find(me.selector.inputFormatStatement) .val('format_statement' in data ? data.format_statement : null); me.storage.$dialog.find(me.selector.inputSum).prop('checked', 'sum' in data ? data.sum : false); me.storage.$dialog.find(me.selector.inputSequence).val('sequence' in data ? data.sequence : ''); me.toggleReportStatementField(); }, /** * @return {void} */ registerEvents: function () { $(me.selector.buttonAddColumn).on('click', function (event) { event.preventDefault(); me.dialogOpen(0) }); $(me.selector.buttonAutoCreate).on('click', function (event) { event.preventDefault(); me.autoCreateColumns(); }); $(me.selector.buttonDeleteAll).on('click', function (event) { event.preventDefault(); var confirmValue = confirm('Wirklich alle Spalten Löschen?'); if (confirmValue === false) { return; } me.ajaxDeleteColumn(0, true); }); $(me.selector.inputFormat).on('change', function (event) { me.toggleReportStatementField(); }); $(document).on('click', me.selector.allColumnViews, function (event) { var id = $(event.currentTarget).data('column-id'); me.dialogOpen(id); }); $(document).on('click', me.selector.allColumnDelete, function (event) { var id = $(event.currentTarget).data('column-id'); if (id > 0) { var confirmValue = confirm('Wirklich Löschen?'); if (confirmValue === false) { return; } me.ajaxDeleteColumn(id); } }); }, tableRefresh: function () { if ($.fn.DataTable.isDataTable(me.selector.dataTable)) { $(me.selector.dataTable).DataTable().ajax.reload(); } }, /** * @param {Object} dialogData * * @return {void} */ ajaxSaveColumn: function(dialogData) { $.ajax({ url: me.url.ajaxSaveColumn, data: dialogData, dataType: 'json', method: 'post', beforeSend: function () { App.loading.open(); }, success: function (response) { me.dialogClose(); me.tableRefresh(); }, error: function (xhr, status, httpStatus) { console.log(status + ' ' + httpStatus + ': ' + xhr.responseText); me.dialogSetMessage(xhr.responseText); }, complete: function () { App.loading.close(); } }); }, /** * @param {number} id * @param {boolean} deleteAll * * @return {void} */ ajaxDeleteColumn: function(id, deleteAll = false) { $.ajax({ url: me.url.ajaxDeleteColumn, data:{ id:id, delete_all:deleteAll, report_id: me.storage.formId }, dataType: 'json', method: 'post', beforeSend: function () { App.loading.open(); }, success: function (data) { me.tableRefresh(); }, error: function (xhr, status, httpStatus) { console.log(status + ' ' + httpStatus + ': ' + xhr.responseText); }, complete: function () { App.loading.close(); } }); }, /** * @return {void} */ toggleReportStatementField: function() { var formatType = me.storage.$dialog.find(me.selector.inputFormat).val(); if (formatType === 'custom') { me.storage.$dialog.find(me.selector.inputFormatRow) .removeClass('report-edit-inactive') .addClass('report-edit-active'); } else { me.storage.$dialog.find(me.selector.inputFormatRow) .removeClass('report-edit-active') .addClass('report-edit-inactive'); } }, /** * @return {void} */ autoCreateColumns: function() { if (me.storage.formId < 1) { alert('Bitte speichern Sie zuerst den Bericht.') return; } $.ajax({ url: me.url.ajaxAutoCreateColumns, data:{ id:me.storage.formId }, dataType: 'json', method: 'post', beforeSend: function () { App.loading.open(); }, success: function (data) { console.log('response', data); if (data.success === true) { me.tableRefresh(); } else { alert(data.message); } }, error: function (xhr, status, httpStatus) { console.log(status + ' ' + httpStatus + ': ' + xhr.responseText); }, complete: function () { App.loading.close(); } }); }, }; return { init: me.init, }; })(jQuery); /** * Add/Edit/Remove params */ var ReportParams = (function ($) { 'use strict'; var me = { isInitialized: false, storage: { $dialog: null, formId: 0 }, url: { ajaxGetParam: 'index.php?module=report&action=edit&cmd=ajaxGetParam', ajaxSaveParam: 'index.php?module=report&action=edit&cmd=ajaxSaveParam', ajaxDeleteParam: 'index.php?module=report&action=edit&cmd=ajaxDeleteParam' }, selector: { dialog: '#editParamDialog', dialogMessageBox: '#editParamMessage', inputReportId: '#reportEditId', inputId: '#editParamId', inputVarname: '#editParamVarname', inputValue: '#editParamValue', inputLabel: '#editParamLabel', inputDescription: '#editParamDescription', inputOptions: '#editParamOptions', inputControl: '#editParamControl', inputEditable: '#chkParamEditable', buttonAddParameter: '#btnAddParam', allParamViews: '#paramListing > .parameter-view', paramsView: '#paramListing' }, template: { paramView: '