Import/Export: Fix export destroyed list's etemplate request

This commit is contained in:
nathangray 2020-07-09 13:14:24 -06:00
parent 76c36cfbcd
commit 1a3582536a
3 changed files with 368 additions and 158 deletions

View File

@ -363,7 +363,7 @@ class importexport_export_ui {
{ {
$link_query['filename'] = $plugin_filename; $link_query['filename'] = $plugin_filename;
} }
$response->redirect( $GLOBALS['egw']->link('/index.php',$link_query),true); $response->apply('app.importexport.download', [$GLOBALS['egw']->link('/index.php',$link_query)]);
Framework::window_close(); Framework::window_close();
return; return;
} }

View File

@ -1,3 +1,4 @@
"use strict";
/** /**
* EGroupware - Import/Export - Javascript UI * EGroupware - Import/Export - Javascript UI
* *
@ -8,165 +9,173 @@
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$ * @version $Id$
*/ */
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
require("jquery");
require("jqueryui");
require("../jsapi/egw_global");
require("../etemplate/et2_types");
var egw_app_1 = require("../../api/js/jsapi/egw_app");
/** /**
* JS for Import/Export * JS for Import/Export
* *
* @augments AppJS * @augments AppJS
*/ */
app.classes.importexport = AppJS.extend( var ImportExportApp = /** @class */ (function (_super) {
{ __extends(ImportExportApp, _super);
appname: 'importexport', /**
* Constructor
/** *
* Constructor * @memberOf app.infolog
* */
* @memberOf app.timesheet function ImportExportApp() {
*/ // call parent
init: function() return _super.call(this, 'importexport') || this;
{ }
// call parent /**
this._super.apply(this, arguments); * Destructor
}, */
ImportExportApp.prototype.destroy = function (_app) {
/** // call parent
* Destructor _super.prototype.destroy.call(this, _app);
*/ };
destroy: function() /**
{ * This function is called when the etemplate2 object is loaded
// call parent * and ready. If you must store a reference to the et2 object,
this._super.apply(this, arguments); * make sure to clean it up in destroy().
}, *
* @param {etemplate2} _et2 newly ready object
/** * @param {string} _name template name
* This function is called when the etemplate2 object is loaded */
* and ready. If you must store a reference to the et2 object, ImportExportApp.prototype.et2_ready = function (_et2, _name) {
* make sure to clean it up in destroy(). // call parent
* _super.prototype.et2_ready.call(this, _et2, _name);
* @param et2 etemplate2 Newly ready object if (this.et2.getWidgetById('export')) {
*/ if (!this.et2.getArrayMgr("content").getEntry("definition")) {
et2_ready: function(et2) // et2 doesn't understand a disabled button in the normal sense
{ jQuery(this.et2.getDOMWidgetById('export').getDOMNode()).attr('disabled', 'disabled');
// call parent jQuery(this.et2.getDOMWidgetById('preview').getDOMNode()).attr('disabled', 'disabled');
this._super.apply(this, arguments); }
if (!this.et2.getArrayMgr("content").getEntry("filter")) {
if(this.et2.getWidgetById('export')) jQuery('input[value="filter"]').parent().hide();
{ }
if(!this.et2.getArrayMgr("content").getEntry("definition")) // Disable / hide definition filter if not selected
{ if (this.et2.getArrayMgr("content").getEntry("selection") != 'filter') {
// et2 doesn't understand a disabled button in the normal sense jQuery('div.filters').hide();
jQuery(this.et2.getWidgetById('export').getDOMNode()).attr('disabled','disabled'); }
jQuery(this.et2.getWidgetById('preview').getDOMNode()).attr('disabled','disabled'); }
} };
if(!this.et2.getArrayMgr("content").getEntry("filter")) /**
{ * Callback to download the file without destroying the etemplate request
jQuery('input[value="filter"]').parent().hide(); *
} * @param data URL to get the export file
*/
// Disable / hide definition filter if not selected ImportExportApp.prototype.download = function (data) {
if(this.et2.getArrayMgr("content").getEntry("selection") != 'filter') // Try to get the file to download in the parent window
{ var app_templates = this.egw.top.etemplate2.getByApplication(framework.activeApp);
jQuery('div.filters').hide(); if (app_templates.length > 0) {
} app_templates[0].download(data);
} }
}, else {
// Couldn't download in opener, download here before popup closes
export_preview: function(event, widget) this.et2.getInstanceManager().download(data);
{ }
var preview = jQuery(widget.getRoot().getWidgetById('preview_box').getDOMNode()); };
jQuery('.content',preview).empty() ImportExportApp.prototype.export_preview = function (event, widget) {
.append('<div class="loading" style="width:100%;height:100%"></div>'); var preview = jQuery(widget.getRoot().getWidgetById('preview_box').getDOMNode());
jQuery('.content', preview).empty()
preview .append('<div class="loading" style="width:100%;height:100%"></div>');
.show(100, jQuery.proxy(function() { preview
widget.clicked = true; .show(100, jQuery.proxy(function () {
widget.getInstanceManager().submit(false, true); widget.clicked = true;
widget.clicked = false; widget.getInstanceManager().submit(false, true);
},this)); widget.clicked = false;
return false; }, this));
}, return false;
};
import_preview: function(event, widget) ImportExportApp.prototype.import_preview = function (event, widget) {
{ var test = widget.getRoot().getWidgetById('dry-run');
var test = widget.getRoot().getWidgetById('dry-run'); if (test.getValue() == test.options.unselected_value)
if(test.getValue() == test.options.unselected_value) return true; return true;
// Show preview
// Show preview var preview = jQuery(widget.getRoot().getWidgetById('preview_box').getDOMNode());
var preview = jQuery(widget.getRoot().getWidgetById('preview_box').getDOMNode()); jQuery('.content', preview).empty();
jQuery('.content',preview).empty(); preview
preview .addClass('loading')
.addClass('loading') .show(100, jQuery.proxy(function () {
.show(100, jQuery.proxy(function() { widget.clicked = true;
widget.clicked = true; widget.getInstanceManager().submit(false, true);
widget.getInstanceManager().submit(false, true); widget.clicked = false;
widget.clicked = false; jQuery(widget.getRoot().getWidgetById('preview_box').getDOMNode())
jQuery(widget.getRoot().getWidgetById('preview_box').getDOMNode()) .removeClass('loading');
.removeClass('loading'); }, this));
},this)); return false;
return false; };
}, /**
* Open a popup to run a given definition
/** *
* Open a popup to run a given definition * @param {egwAction} action
* * @param {egwActionObject[]} selected
* @param {egwAction} action */
* @param {egwActionObject[]} selected ImportExportApp.prototype.run_definition = function (action, selected) {
*/ if (!selected || selected.length != 1)
run_definition: function(action, selected) return;
{ var id = selected[0].id || null;
if(!selected || selected.length != 1) return; var data = egw.dataGetUIDdata(id).data;
if (!data || !data.type)
var id = selected[0].id||null; return;
var data = egw.dataGetUIDdata(id).data; egw.open_link(egw.link('/index.php', {
if(!data || !data.type) return; menuaction: 'importexport.importexport_' + data.type + '_ui.' + data.type + '_dialog',
appname: data.application,
egw.open_link(egw.link('/index.php',{ definition: data.definition_id
menuaction: 'importexport.importexport_' + data.type + '_ui.' + data.type + '_dialog', }), "", '850x440', data.application);
appname: data.application, };
definition: data.definition_id /**
}), false, '850x440', app); * Allowed users widget has been changed, if 'All users' or 'Just me'
}, * was selected, turn off any other options.
*/
/** ImportExportApp.prototype.allowed_users_change = function (node, widget) {
* Allowed users widget has been changed, if 'All users' or 'Just me' var value = widget.getValue();
* was selected, turn off any other options. // Only 1 selected, no checking needed
*/ if (value == null || value.length <= 1)
allowed_users_change: function(node, widget) return;
{ // Don't jump it to the top, it's weird
var value = widget.getValue(); widget.selected_first = false;
var index = null;
// Only 1 selected, no checking needed var specials = ['', 'all'];
if(value == null || value.length <= 1) return; for (var i = 0; i < specials.length; i++) {
var special = specials[i];
// Don't jump it to the top, it's weird if ((index = value.indexOf(special)) >= 0) {
widget.selected_first = false; if (window.event.target.value == special) {
// Just clicked all/private, clear the others
var index = null; value = [special];
var specials = ['','all'] }
for(var i = 0; i < specials.length; i++) else {
{ // Just added another, clear special
var special = specials[i]; value.splice(index, 1);
if((index = value.indexOf(special)) >= 0) }
{ // A little highlight to call attention to the change
if(window.event.target.value == special) jQuery('input[value="' + special + '"]', node).parent().parent().effect('highlight', {}, 500);
{ break;
// Just clicked all/private, clear the others }
value = [special]; }
} if (index >= 0) {
else widget.set_value(value);
{ }
// Just added another, clear special };
value.splice(index,1); return ImportExportApp;
} }(egw_app_1.EgwApp));
app.classes.importexport = ImportExportApp;
// A little highlight to call attention to the change //# sourceMappingURL=app.js.map
jQuery('input[value="'+special+'"]',node).parent().parent().effect('highlight',{},500);
break;
}
}
if(index >= 0)
{
widget.set_value(value);
}
}
});

201
importexport/js/app.ts Normal file
View File

@ -0,0 +1,201 @@
/**
* EGroupware - Import/Export - Javascript UI
*
* @link http://www.egroupware.org
* @package importexport
* @author Nathan Gray
* @copyright (c) 2013 Nathan Gray
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
*/
import 'jquery';
import 'jqueryui';
import '../jsapi/egw_global';
import '../etemplate/et2_types';
import {EgwApp} from '../../api/js/jsapi/egw_app';
/**
* JS for Import/Export
*
* @augments AppJS
*/
class ImportExportApp extends EgwApp
{
/**
* Constructor
*
* @memberOf app.infolog
*/
constructor()
{
// call parent
super('importexport');
}
/**
* Destructor
*/
destroy(_app)
{
// call parent
super.destroy(_app);
}
/**
* This function is called when the etemplate2 object is loaded
* and ready. If you must store a reference to the et2 object,
* make sure to clean it up in destroy().
*
* @param {etemplate2} _et2 newly ready object
* @param {string} _name template name
*/
et2_ready(_et2, _name)
{
// call parent
super.et2_ready(_et2, _name);
if(this.et2.getWidgetById('export'))
{
if(!this.et2.getArrayMgr("content").getEntry("definition"))
{
// et2 doesn't understand a disabled button in the normal sense
jQuery(this.et2.getDOMWidgetById('export').getDOMNode()).attr('disabled','disabled');
jQuery(this.et2.getDOMWidgetById('preview').getDOMNode()).attr('disabled','disabled');
}
if(!this.et2.getArrayMgr("content").getEntry("filter"))
{
jQuery('input[value="filter"]').parent().hide();
}
// Disable / hide definition filter if not selected
if(this.et2.getArrayMgr("content").getEntry("selection") != 'filter')
{
jQuery('div.filters').hide();
}
}
}
/**
* Callback to download the file without destroying the etemplate request
*
* @param data URL to get the export file
*/
download(data:string)
{
// Try to get the file to download in the parent window
let app_templates = this.egw.top.etemplate2.getByApplication(framework.activeApp);
if(app_templates.length > 0)
{
app_templates[0].download(data);
}
else
{
// Couldn't download in opener, download here before popup closes
this.et2.getInstanceManager().download(data);
}
}
export_preview(event, widget)
{
var preview = jQuery(widget.getRoot().getWidgetById('preview_box').getDOMNode());
jQuery('.content',preview).empty()
.append('<div class="loading" style="width:100%;height:100%"></div>');
preview
.show(100, jQuery.proxy(function() {
widget.clicked = true;
widget.getInstanceManager().submit(false, true);
widget.clicked = false;
},this));
return false;
}
import_preview(event, widget)
{
var test = widget.getRoot().getWidgetById('dry-run');
if(test.getValue() == test.options.unselected_value) return true;
// Show preview
var preview = jQuery(widget.getRoot().getWidgetById('preview_box').getDOMNode());
jQuery('.content',preview).empty();
preview
.addClass('loading')
.show(100, jQuery.proxy(function() {
widget.clicked = true;
widget.getInstanceManager().submit(false, true);
widget.clicked = false;
jQuery(widget.getRoot().getWidgetById('preview_box').getDOMNode())
.removeClass('loading');
},this));
return false;
}
/**
* Open a popup to run a given definition
*
* @param {egwAction} action
* @param {egwActionObject[]} selected
*/
run_definition(action, selected)
{
if(!selected || selected.length != 1) return;
var id = selected[0].id||null;
var data = egw.dataGetUIDdata(id).data;
if(!data || !data.type) return;
egw.open_link(egw.link('/index.php',{
menuaction: 'importexport.importexport_' + data.type + '_ui.' + data.type + '_dialog',
appname: data.application,
definition: data.definition_id
}), "", '850x440', data.application);
}
/**
* Allowed users widget has been changed, if 'All users' or 'Just me'
* was selected, turn off any other options.
*/
allowed_users_change(node, widget)
{
var value = widget.getValue();
// Only 1 selected, no checking needed
if(value == null || value.length <= 1) return;
// Don't jump it to the top, it's weird
widget.selected_first = false;
var index = null;
var specials = ['','all']
for(var i = 0; i < specials.length; i++)
{
var special = specials[i];
if((index = value.indexOf(special)) >= 0)
{
if(window.event.target.value == special)
{
// Just clicked all/private, clear the others
value = [special];
}
else
{
// Just added another, clear special
value.splice(index,1);
}
// A little highlight to call attention to the change
jQuery('input[value="'+special+'"]',node).parent().parent().effect('highlight',{},500);
break;
}
}
if(index >= 0)
{
widget.set_value(value);
}
}
}
app.classes.importexport = ImportExportApp;