2020-07-09 21:14:24 +02:00
|
|
|
/**
|
|
|
|
* 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$
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2021-06-30 22:09:12 +02:00
|
|
|
import "../../vendor/bower-asset/jquery/dist/jquery.min.js";
|
2021-07-02 08:52:18 +02:00
|
|
|
//import "../../vendor/bower-asset/jquery-ui/jquery-ui.js";
|
2020-07-09 21:14:24 +02:00
|
|
|
import {EgwApp} from '../../api/js/jsapi/egw_app';
|
2021-06-10 15:40:49 +02:00
|
|
|
import {egw} from "../../api/js/jsapi/egw_global";
|
2020-07-09 21:14:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2020-07-10 17:14:29 +02:00
|
|
|
let app_templates = this.egw.top.etemplate2.getByApplication(framework.activeApp.appName);
|
2020-07-09 21:14:24 +02:00
|
|
|
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());
|
2022-10-26 17:57:34 +02:00
|
|
|
// TD gets the class too
|
|
|
|
preview.parent().show();
|
|
|
|
jQuery('.content', preview).empty()
|
2020-07-09 21:14:24 +02:00
|
|
|
.append('<div class="loading" style="width:100%;height:100%"></div>');
|
|
|
|
|
|
|
|
preview
|
2022-10-26 17:57:34 +02:00
|
|
|
.show(100, jQuery.proxy(function()
|
|
|
|
{
|
2020-07-09 21:14:24 +02:00
|
|
|
widget.clicked = true;
|
|
|
|
widget.getInstanceManager().submit(false, true);
|
|
|
|
widget.clicked = false;
|
2022-10-26 17:57:34 +02:00
|
|
|
}, this));
|
2020-07-09 21:14:24 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
import_preview(event, widget)
|
|
|
|
{
|
|
|
|
var test = widget.getRoot().getWidgetById('dry-run');
|
2022-10-26 17:57:34 +02:00
|
|
|
if(test.getValue() == test.options.unselected_value)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2020-07-09 21:14:24 +02:00
|
|
|
|
|
|
|
// Show preview
|
|
|
|
var preview = jQuery(widget.getRoot().getWidgetById('preview_box').getDOMNode());
|
2022-10-26 17:57:34 +02:00
|
|
|
// TD gets the class too
|
|
|
|
preview.parent().show();
|
|
|
|
jQuery('.content', preview).empty();
|
2020-07-09 21:14:24 +02:00
|
|
|
preview
|
|
|
|
.addClass('loading')
|
2022-10-26 17:57:34 +02:00
|
|
|
.show(100, jQuery.proxy(function()
|
|
|
|
{
|
2020-07-09 21:14:24 +02:00
|
|
|
widget.clicked = true;
|
|
|
|
widget.getInstanceManager().submit(false, true);
|
2022-10-26 17:57:34 +02:00
|
|
|
widget.clicked = false;
|
|
|
|
jQuery(widget.getRoot().getWidgetById('preview_box').getDOMNode())
|
|
|
|
.removeClass('loading');
|
|
|
|
}, this));
|
2020-07-09 21:14:24 +02:00
|
|
|
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.
|
|
|
|
*/
|
2022-11-21 17:24:28 +01:00
|
|
|
allowed_users_change(event, widget)
|
2020-07-09 21:14:24 +02:00
|
|
|
{
|
|
|
|
var value = widget.getValue();
|
|
|
|
|
|
|
|
// Only 1 selected, no checking needed
|
2022-11-21 17:24:28 +01:00
|
|
|
if(value == null || value.length <= 1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2020-07-09 21:14:24 +02:00
|
|
|
|
|
|
|
// Don't jump it to the top, it's weird
|
|
|
|
widget.selected_first = false;
|
|
|
|
|
|
|
|
var index = null;
|
2022-11-21 17:24:28 +01:00
|
|
|
var specials = ['', 'all']
|
2020-07-09 21:14:24 +02:00
|
|
|
for(var i = 0; i < specials.length; i++)
|
|
|
|
{
|
|
|
|
var special = specials[i];
|
|
|
|
if((index = value.indexOf(special)) >= 0)
|
|
|
|
{
|
2022-11-21 17:24:28 +01:00
|
|
|
if(value.indexOf(special) == value.length - 1)
|
2020-07-09 21:14:24 +02:00
|
|
|
{
|
2022-11-21 17:24:28 +01:00
|
|
|
// Just clicked all/private (it's at the end), clear the others
|
2020-07-09 21:14:24 +02:00
|
|
|
value = [special];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Just added another, clear special
|
2022-11-21 17:24:28 +01:00
|
|
|
value.splice(index, 1);
|
2020-07-09 21:14:24 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(index >= 0)
|
|
|
|
{
|
|
|
|
widget.set_value(value);
|
|
|
|
}
|
|
|
|
}
|
2023-01-19 21:36:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Open a specific import/export definition dialog by clicking on the icon from the list
|
|
|
|
* @param widget
|
|
|
|
*/
|
|
|
|
open_definition(event, widget)
|
|
|
|
{
|
|
|
|
const mgr = widget.getArrayMgr("content");
|
|
|
|
const data = mgr.getEntry(mgr.perspectiveData.row) || {};
|
|
|
|
const type = data.type || "";
|
|
|
|
const application = data.application || "";
|
|
|
|
const definition_id = data.definition_id || "";
|
|
|
|
this.egw.openPopup(
|
|
|
|
this.egw.link("/index.php", {
|
|
|
|
menuaction: "importexport.importexport_" + type + "_ui." + type + "_dialog",
|
|
|
|
appname: application,
|
|
|
|
definition: definition_id
|
|
|
|
}),
|
|
|
|
850, 440
|
|
|
|
)
|
|
|
|
}
|
2020-07-09 21:14:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
app.classes.importexport = ImportExportApp;
|