Convert vfsSelectUI to TS

This commit is contained in:
Hadi Nategh 2020-02-26 12:19:17 +01:00
parent de426e1232
commit e48000d149
5 changed files with 669 additions and 343 deletions

View File

@ -606,7 +606,7 @@ export class et2_dialog extends et2_widget {
* @param {integer|array} _buttons One of the BUTTONS_ constants defining the set of buttons at the bottom of the box * @param {integer|array} _buttons One of the BUTTONS_ constants defining the set of buttons at the bottom of the box
* @param {string|egw} _egw_or_appname egw object with already laoded translations or application name to load translations for * @param {string|egw} _egw_or_appname egw object with already laoded translations or application name to load translations for
*/ */
static show_prompt(_callback, _message, _title, _value, _buttons, _egw_or_appname) { static show_prompt(_callback, _message, _title?, _value?, _buttons?, _egw_or_appname?) {
var callback = _callback; var callback = _callback;
// Just pass them along, widget handles defaults & missing // Just pass them along, widget handles defaults & missing
return et2_createWidget("dialog", { return et2_createWidget("dialog", {

View File

@ -213,6 +213,7 @@ var et2_vfs = /** @class */ (function (_super) {
et2_vfs.DIR_MIME_TYPE = 'httpd/unix-directory'; et2_vfs.DIR_MIME_TYPE = 'httpd/unix-directory';
return et2_vfs; return et2_vfs;
}(et2_core_valueWidget_1.et2_valueWidget)); }(et2_core_valueWidget_1.et2_valueWidget));
exports.et2_vfs = et2_vfs;
et2_core_widget_1.et2_register_widget(et2_vfs, ["vfs"]); et2_core_widget_1.et2_register_widget(et2_vfs, ["vfs"]);
/** /**
* vfs-name * vfs-name
@ -378,6 +379,7 @@ var et2_vfsPath = /** @class */ (function (_super) {
}; };
return et2_vfsPath; return et2_vfsPath;
}(et2_vfsName)); }(et2_vfsName));
exports.et2_vfsPath = et2_vfsPath;
et2_core_widget_1.et2_register_widget(et2_vfsPath, ["vfs-path"]); et2_core_widget_1.et2_register_widget(et2_vfsPath, ["vfs-path"]);
/** /**
* vfs-name * vfs-name
@ -1321,6 +1323,7 @@ var et2_vfsSelect = /** @class */ (function (_super) {
}; };
return et2_vfsSelect; return et2_vfsSelect;
}(et2_core_inputWidget_1.et2_inputWidget)); }(et2_core_inputWidget_1.et2_inputWidget));
exports.et2_vfsSelect = et2_vfsSelect;
; ;
et2_core_widget_1.et2_register_widget(et2_vfsSelect, ["vfs-select"]); et2_core_widget_1.et2_register_widget(et2_vfsSelect, ["vfs-select"]);
//# sourceMappingURL=et2_widget_vfs.js.map //# sourceMappingURL=et2_widget_vfs.js.map

View File

@ -35,7 +35,7 @@ import {et2_inputWidget} from "./et2_core_inputWidget";
* *
* @augments et2_valueWidget * @augments et2_valueWidget
*/ */
class et2_vfs extends et2_valueWidget implements et2_IDetachedDOM export class et2_vfs extends et2_valueWidget implements et2_IDetachedDOM
{ {
static readonly _attributes : any = { static readonly _attributes : any = {
"value": { "value": {
@ -284,7 +284,7 @@ et2_register_widget(et2_vfsName, ["vfs-name"]);
* *
* @augments et2_textbox * @augments et2_textbox
*/ */
class et2_vfsPath extends et2_vfsName export class et2_vfsPath extends et2_vfsName
{ {
static readonly _attributes : any = { static readonly _attributes : any = {
noicon: { noicon: {
@ -1128,7 +1128,7 @@ class et2_vfsUpload extends et2_file
et2_register_widget(et2_vfsUpload, ["vfs-upload"]); et2_register_widget(et2_vfsUpload, ["vfs-upload"]);
class et2_vfsSelect extends et2_inputWidget export class et2_vfsSelect extends et2_inputWidget
{ {
// Allowed mode options // Allowed mode options
modes : string[] = ['open','open-multiple','saveas','select-dir']; modes : string[] = ['open','open-multiple','saveas','select-dir'];
@ -1244,7 +1244,7 @@ class et2_vfsSelect extends et2_inputWidget
this.setDOMNode(this.button[0]); this.setDOMNode(this.button[0]);
} }
private _content(_content, _callback) _content(_content, _callback)
{ {
egw(window).loading_prompt('vfs-select', true, '', 'body'); egw(window).loading_prompt('vfs-select', true, '', 'body');
let self = this; let self = this;

View File

@ -1,3 +1,4 @@
"use strict";
/** /**
* EGroupware - VFS SELECT Widget UI * EGroupware - VFS SELECT Widget UI
* *
@ -8,345 +9,311 @@
* @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 });
/*egw:uses
/api/js/jsapi/egw_app.js
*/
var egw_app_1 = require("../jsapi/egw_app");
require("../jsapi/egw_global");
require("../etemplate/et2_types");
/** /**
* UI for VFS Select widget * UI for VFS Select widget
* *
* @augments AppJS
*/ */
app.classes.vfsSelectUI = (function(){ "use strict"; return AppJS.extend( var vfsSelectUI = /** @class */ (function (_super) {
{ __extends(vfsSelectUI, _super);
appname: 'filemanager', /**
dirContent: {}, * Constructor
vfsSelectWidget: {}, *
path_widget: {}, */
/** function vfsSelectUI() {
* Constructor var _this =
* // call parent
* @memberOf app.filemanager _super.call(this) || this;
*/ _this.egw.langRequireApp(_this.egw.window, 'filemanager');
init: function() return _this;
{ }
// call parent /**
this._super.apply(this, arguments); * Destructor
*/
this.egw.langRequireApp(this.egw.window, 'filemanager'); vfsSelectUI.prototype.destroy = function (_app) {
}, delete this.path_widget;
delete this.vfsSelectWidget;
/** // call parent
* Destructor _super.prototype.destroy.call(this, _app);
*/ };
destroy: function() /**
{ * This function is called when the etemplate2 object is loaded
delete this.path_widget; * and ready. If you must store a reference to the et2 object,
delete this.vfsSelectWidget; * make sure to clean it up in destroy().
// call parent *
this._super.apply(this, arguments); * @param et2 etemplate2 Newly ready object
}, * @param {string} name template name
*/
/** vfsSelectUI.prototype.et2_ready = function (et2, name) {
* This function is called when the etemplate2 object is loaded this.path_widget = this.et2.getWidgetById('path');
* and ready. If you must store a reference to the et2 object, this.dirContent = this.et2.getArrayMgr('content').data.dir;
* make sure to clean it up in destroy(). };
* /**
* @param et2 etemplate2 Newly ready object * Get directory of a path
* @param {string} name template name *
*/ * @param {string} _path
et2_ready: function(et2,name) * @returns string
{ */
this.path_widget = this.et2.getWidgetById('path'); vfsSelectUI.prototype.dirname = function (_path) {
this.dirContent = this.et2.getArrayMgr('content').data.dir; var parts = _path.split('/');
}, parts.pop();
return parts.join('/') || '/';
/** };
* Get directory of a path /**
* * Get name of a path
* @param {string} _path *
* @returns string * @param {string} _path
*/ * @returns string
dirname: function(_path) */
{ vfsSelectUI.prototype.basename = function (_path) {
var parts = _path.split('/'); return _path.split('/').pop();
parts.pop(); };
return parts.join('/') || '/'; /**
}, * Get current working directory
*
/** * @return string
* Get name of a path */
* vfsSelectUI.prototype.get_path = function () {
* @param {string} _path return this.path_widget.get_value();
* @returns string };
*/ /**
basename: function(_path) * Send names of uploaded files (again) to server,
{ * to process them: either copy to vfs or ask overwrite/rename
return _path.split('/').pop(); *
}, * @param {event} _event
*/
/** vfsSelectUI.prototype.storeFile = function (_event) {
* Get current working directory var path = this.get_path();
* if (!jQuery.isEmptyObject(_event.data.getValue())) {
* @return string var widget = _event.data;
*/ egw(window).json('EGroupware\\Api\\Etemplate\\Widget\\Vfs::ajax_vfsSelect_storeFile', [widget.getValue(), path], this._storeFile_callback, this, true, this).sendRequest(true);
get_path: function() widget.set_value('');
{ }
return this.path_widget.get_value(); };
}, /**
* Callback for server response to storeFile request:
/** * - display message and refresh list
* Send names of uploaded files (again) to server, * - ask use to confirm overwritting existing files or rename upload
* to process them: either copy to vfs or ask overwrite/rename *
* * @param {object} _data values for attributes msg, files, ...
* @param {event} _event */
*/ vfsSelectUI.prototype._storeFile_callback = function (_data) {
storeFile: function(_event) if (_data.msg || _data.uploaded)
{ egw(window).message(_data.msg);
var path = this.get_path(); var that = this;
for (var file in _data.uploaded) {
if (!jQuery.isEmptyObject(_event.data.getValue())) if (_data.uploaded[file].confirm && !_data.uploaded[file].confirmed) {
{ var buttons = [
var widget = _event.data; { text: this.egw.lang("Yes"), id: "overwrite", class: "ui-priority-primary", "default": true, image: 'check' },
egw(window).json('EGroupware\\Api\\Etemplate\\Widget\\Vfs::ajax_vfsSelect_storeFile', [widget.getValue(), path], { text: this.egw.lang("Rename"), id: "rename", image: 'edit' },
this._storeFile_callback, this, true, this { text: this.egw.lang("Cancel"), id: "cancel" }
).sendRequest(true); ];
widget.set_value(''); if (_data.uploaded[file].confirm === "is_dir")
} buttons.shift();
}, var dialog = et2_dialog.show_prompt(function (_button_id, _value) {
var uploaded = {};
/** uploaded[this.my_data.file] = this.my_data.data;
* Callback for server response to storeFile request: switch (_button_id) {
* - display message and refresh list case "overwrite":
* - ask use to confirm overwritting existing files or rename upload uploaded[this.my_data.file].confirmed = true;
* // fall through
* @param {object} _data values for attributes msg, files, ... case "rename":
*/ uploaded[this.my_data.file].name = _value;
_storeFile_callback: function(_data) delete uploaded[this.my_data.file].confirm;
{ // send overwrite-confirmation and/or rename request to server
if (_data.msg || _data.uploaded) egw(window).message(_data.msg); egw.json('EGroupware\\Api\\Etemplate\\Widget\\Vfs::ajax_vfsSelect_storeFile', [uploaded, this.my_data.path], that._storeFile_callback, that, true, that).sendRequest();
return;
var that = this; case "cancel":
for(var file in _data.uploaded) // Remove that file from every file widget...
{ that.et2.iterateOver(function (_widget) {
if (_data.uploaded[file].confirm && !_data.uploaded[file].confirmed) _widget.remove_file(this.my_data.data.name);
{ }, this, et2_file);
var buttons = [ }
{text: this.egw.lang("Yes"), id: "overwrite", class: "ui-priority-primary", "default": true, image: 'check'}, }, _data.uploaded[file].confirm === "is_dir" ?
{text: this.egw.lang("Rename"), id:"rename", image: 'edit'}, this.egw.lang("There's already a directory with that name!") :
{text: this.egw.lang("Cancel"), id:"cancel"} this.egw.lang('Do you want to overwrite existing file %1 in directory %2?', _data.uploaded[file].name, _data.path), this.egw.lang('File %1 already exists', _data.uploaded[file].name), _data.uploaded[file].name, buttons, file);
]; // setting required data for callback in as my_data
if (_data.uploaded[file].confirm === "is_dir") dialog.my_data = {
buttons.shift(); file: file,
var dialog = et2_dialog.show_prompt(function(_button_id, _value) { path: _data.path,
var uploaded = {}; data: _data.uploaded[file],
uploaded[this.my_data.file] = this.my_data.data; };
switch (_button_id) }
{ else {
case "overwrite": this.submit();
uploaded[this.my_data.file].confirmed = true; }
// fall through }
case "rename": };
uploaded[this.my_data.file].name = _value; /**
delete uploaded[this.my_data.file].confirm; * Prompt user for directory to create
// send overwrite-confirmation and/or rename request to server *
egw.json('EGroupware\\Api\\Etemplate\\Widget\\Vfs::ajax_vfsSelect_storeFile', [uploaded, this.my_data.path], * @param {egwAction|undefined|jQuery.Event} action Action, event or undefined if called directly
that._storeFile_callback, that, true, that * @param {egwActionObject[] | undefined} selected Selected row, or undefined if called directly
).sendRequest(); */
return; vfsSelectUI.prototype.createdir = function (action, selected) {
case "cancel": var self = this;
// Remove that file from every file widget... et2_dialog.show_prompt(function (button, dir) {
that.et2.iterateOver(function(_widget) { if (button && dir) {
_widget.remove_file(this.my_data.data.name); var path_1 = self.get_path();
}, this, et2_file); self.egw.json('EGroupware\\Api\\Etemplate\\Widget\\Vfs::ajax_create_dir', [dir, path_1], function (msg) {
} self.egw.message(msg);
}, self.change_dir((path_1 == '/' ? '' : path_1) + '/' + dir);
_data.uploaded[file].confirm === "is_dir" ? }).sendRequest(false);
this.egw.lang("There's already a directory with that name!") : }
this.egw.lang('Do you want to overwrite existing file %1 in directory %2?', _data.uploaded[file].name, _data.path), }, this.egw.lang('New directory'), this.egw.lang('Create directory'));
this.egw.lang('File %1 already exists', _data.uploaded[file].name), };
_data.uploaded[file].name, buttons, file); /**
// setting required data for callback in as my_data * Change directory
dialog.my_data = { *
file: file, * @param {string} _dir directory to change to incl. '..' for one up
path: _data.path, */
data: _data.uploaded[file], vfsSelectUI.prototype.change_dir = function (_dir) {
}; if (_dir == '..') {
} _dir = this.dirname(this.get_path());
else }
{ this.path_widget.set_value(_dir);
this.submit(); };
} /**
} * Row or filename in select-file dialog clicked
}, *
* @param {jQuery.event} event
/** * @param {et2_widget} widget
* Prompt user for directory to create */
* vfsSelectUI.prototype.select_clicked = function (event, widget) {
* @param {egwAction|undefined|jQuery.Event} action Action, event or undefined if called directly if (!widget || typeof widget.value != 'object') {
* @param {egwActionObject[] | undefined} selected Selected row, or undefined if called directly }
*/ else if (widget.value.is_dir) // true for "httpd/unix-directory" and "egw/*"
createdir: function(action, selected) {
{ var path_2 = null;
var self = this; // Cannot do this, there are multiple widgets named path
et2_dialog.show_prompt(function(button, dir){ // widget.getRoot().getWidgetById("path");
if (button && dir) widget.getRoot().iterateOver(function (widget) {
{ if (widget.id == "path")
var path = self.get_path(); path_2 = widget;
self.egw.json('EGroupware\\Api\\Etemplate\\Widget\\Vfs::ajax_create_dir', [dir, path], function(msg){ }, null, et2_textbox);
self.egw.message(msg); if (path_2) {
self.change_dir((path == '/' ? '' : path)+'/'+ dir); path_2.set_value(widget.value.path);
}).sendRequest(false); }
} }
},this.egw.lang('New directory'),this.egw.lang('Create directory')); else if (this.et2 && this.et2.getArrayMgr('content').getEntry('mode') != 'open-multiple') {
}, var editfield = this.et2.getWidgetById('name');
if (editfield) {
/** editfield.set_value(widget.value.name);
* Change directory }
* }
* @param {string} _dir directory to change to incl. '..' for one up else {
* @param {et2_widget} widget var file_1 = widget.value.name;
*/ widget.getParent().iterateOver(function (widget) {
change_dir: function(_dir, widget) if (widget.options.selected_value == file_1) {
{ widget.set_value(widget.get_value() == file_1 ? widget.options.unselected_value : file_1);
switch (_dir) }
{ }, null, et2_checkbox);
case '..': }
_dir = this.dirname(this.get_path()); // Stop event or it will toggle back off
break; event.preventDefault();
event.stopPropagation();
} return false;
};
this.path_widget.set_value(_dir); /**
}, * Handles action and offer it to the submit
*
/** * @param {string} action action name
* Row or filename in select-file dialog clicked * @param {object} widget widget which action was called from
* */
* @param {jQuery.event} event vfsSelectUI.prototype.do_action = function (action, widget) {
* @param {et2_widget} widget if (!action)
*/ return;
select_clicked: function(event, widget) var field = '', value = '';
{ switch (action) {
if (!widget || typeof widget.value != 'object') case 'path':
{ field = 'path';
value = widget.getValue();
} break;
else if (widget.value.is_dir) // true for "httpd/unix-directory" and "egw/*" case 'home':
{ field = 'action';
var path = null; value = 'home';
// Cannot do this, there are multiple widgets named path break;
// widget.getRoot().getWidgetById("path"); case 'app':
widget.getRoot().iterateOver(function(widget) { field = 'app';
if(widget.id == "path") path = widget; value = widget.getValue();
},null, et2_textbox); break;
if(path) case 'mime':
{ field = 'mime';
path.set_value(widget.value.path); value = widget.getValue();
} break;
} }
else if (this.et2 && this.et2.getArrayMgr('content').getEntry('mode') != 'open-multiple') this.submit(field, value);
{ };
var editfield = this.et2.getWidgetById('name'); /**
if(editfield) * Sumbits content value after modification
{ *
editfield.set_value(widget.value.name); * @param {string} _field content field to be modified
} * @param {any} _val value of field
} * @param {function} _callback
else */
{ vfsSelectUI.prototype.submit = function (_field, _val, _callback) {
var file = widget.value.name; var arrMgrs = this.et2.getArrayMgrs();
widget.getParent().iterateOver(function(widget) if (_field) {
{ arrMgrs.content.data[_field] = _val;
if(widget.options.selected_value == file) jQuery.extend(arrMgrs.content.data, arrMgrs.modifications.data);
{ this.et2.setArrayMgrs(arrMgrs);
widget.set_value(widget.get_value() == file ? widget.options.unselected_value : file); }
} // preserve value of the name
}, null, et2_checkbox); if (arrMgrs && this.et2.getWidgetById('name')) {
arrMgrs.content.data['name'] = this.et2.getWidgetById('name').get_value();
} }
// Stop event or it will toggle back off this.vfsSelectWidget._content(arrMgrs.content.data, _callback);
event.preventDefault(); };
event.stopPropagation(); /**
return false; * search through dir content and set its content base on searched query
}, * @returns
*/
/** vfsSelectUI.prototype.search = function (_widget) {
* Handles action and offer it to the submit var dir = this.et2.getWidgetById('dir');
* var query = _widget.get_value();
* @param {string} action action name if (query == "") {
* @param {object} widget widget which action was called from dir.set_value({ content: this.dirContent });
*/ return;
do_action: function (action, widget) }
{ var self = this;
if (!action) return; var searchQuery = function (_query) {
var field = '', value = ''; var result = {};
switch (action) var reg = RegExp(_query, 'ig');
{ var key = 0;
case 'path': field = 'path'; value = widget.getValue(); break; for (var i in self.dirContent) {
case 'home': field = 'action'; value = 'home'; break; if (typeof self.dirContent[i]['name'] != 'undefined' && self.dirContent[i]['name'].match(reg)) {
case 'app': field = 'app'; value = widget.getValue(); break; result[key] = self.dirContent[i];
case 'mime': field = 'mime'; value = widget.getValue(); break; key++;
} }
this.submit(field, value); else if (typeof self.dirContent[i]['name'] == 'undefined' && isNaN(i)) {
}, result[i] = self.dirContent[i];
}
/** }
* Sumbits content value after modification return result;
* };
* @param {string} _field content field to be modified dir.set_value({ content: searchQuery(query) });
* @param {any} _val value of field };
* @param {function} _callback return vfsSelectUI;
*/ }(egw_app_1.EgwApp));
submit: function(_field, _val, _callback) exports.vfsSelectUI = vfsSelectUI;
{ app.classes.vfsSelectUI = vfsSelectUI;
var arrMgrs = this.et2.getArrayMgrs(); //# sourceMappingURL=vfsSelectUI.js.map
if (_field)
{
arrMgrs.content.data[_field] = _val;
jQuery.extend(arrMgrs.content.data, arrMgrs.modifications.data);
this.et2.setArrayMgrs(arrMgrs);
}
// preserve value of the name
if (arrMgrs && this.et2.getWidgetById('name'))
{
arrMgrs.content.data['name'] = this.et2.getWidgetById('name').get_value();
}
this.vfsSelectWidget._content(arrMgrs.content.data, _callback);
},
/**
* search through dir content and set its content base on searched query
* @returns
*/
search: function(_widget)
{
var dir = this.et2.getWidgetById('dir');
var query = _widget.get_value();
if (query == "")
{
dir.set_value({content: this.dirContent});
return;
}
var self = this;
var searchQuery = function (_query)
{
var result = {};
var reg = RegExp(_query, 'ig');
var key = 0;
for (var i in self.dirContent)
{
if (typeof self.dirContent[i]['name'] != 'undefined' && self.dirContent[i]['name'].match(reg))
{
result[key] = self.dirContent[i];
key++;
}
else if (typeof self.dirContent[i]['name'] == 'undefined' && isNaN(i))
{
result[i] = self.dirContent[i];
}
}
return result;
};
dir.set_value({content: searchQuery(query)});
}
});}).call(this);

View File

@ -0,0 +1,356 @@
/**
* EGroupware - VFS SELECT Widget UI
*
* @link http://www.egroupware.org
* @package et2_vfsSelect
* @author Hadi Nategh <hn@egroupware.org>
* @copyright (c) 2013-2017 by Hadi Nategh <hn@egroupware.org>
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
*/
/*egw:uses
/api/js/jsapi/egw_app.js
*/
import {EgwApp} from "../jsapi/egw_app";
import {et2_vfs, et2_vfsPath, et2_vfsSelect} from "./et2_widget_vfs";
import '../jsapi/egw_global';
import '../etemplate/et2_types';
/**
* UI for VFS Select widget
*
*/
export class vfsSelectUI extends EgwApp
{
readonly appname: 'filemanager';
private dirContent: {};
private vfsSelectWidget : et2_vfsSelect;
private path_widget: et2_vfsPath;
/**
* Constructor
*
*/
constructor()
{
// call parent
super();
this.egw.langRequireApp(this.egw.window, 'filemanager');
}
/**
* Destructor
*/
destroy(_app)
{
delete this.path_widget;
delete this.vfsSelectWidget;
// 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 et2 etemplate2 Newly ready object
* @param {string} name template name
*/
et2_ready(et2,name)
{
this.path_widget = this.et2.getWidgetById('path');
this.dirContent = this.et2.getArrayMgr('content').data.dir;
}
/**
* Get directory of a path
*
* @param {string} _path
* @returns string
*/
dirname(_path)
{
let parts = _path.split('/');
parts.pop();
return parts.join('/') || '/';
}
/**
* Get name of a path
*
* @param {string} _path
* @returns string
*/
basename(_path)
{
return _path.split('/').pop();
}
/**
* Get current working directory
*
* @return string
*/
get_path()
{
return this.path_widget.get_value();
}
/**
* Send names of uploaded files (again) to server,
* to process them: either copy to vfs or ask overwrite/rename
*
* @param {event} _event
*/
storeFile(_event)
{
let path = this.get_path();
if (!jQuery.isEmptyObject(_event.data.getValue()))
{
let widget = _event.data;
egw(window).json('EGroupware\\Api\\Etemplate\\Widget\\Vfs::ajax_vfsSelect_storeFile', [widget.getValue(), path],
this._storeFile_callback, this, true, this
).sendRequest(true);
widget.set_value('');
}
}
/**
* Callback for server response to storeFile request:
* - display message and refresh list
* - ask use to confirm overwritting existing files or rename upload
*
* @param {object} _data values for attributes msg, files, ...
*/
_storeFile_callback(_data : {msg : string, uploaded : any[], path : string})
{
if (_data.msg || _data.uploaded) egw(window).message(_data.msg);
let that = this;
for(let file in _data.uploaded)
{
if (_data.uploaded[file].confirm && !_data.uploaded[file].confirmed)
{
let buttons = [
{text: this.egw.lang("Yes"), id: "overwrite", class: "ui-priority-primary", "default": true, image: 'check'},
{text: this.egw.lang("Rename"), id:"rename", image: 'edit'},
{text: this.egw.lang("Cancel"), id:"cancel"}
];
if (_data.uploaded[file].confirm === "is_dir")
buttons.shift();
let dialog = et2_dialog.show_prompt(function(_button_id, _value) {
let uploaded = {};
uploaded[this.my_data.file] = this.my_data.data;
switch (_button_id)
{
case "overwrite":
uploaded[this.my_data.file].confirmed = true;
// fall through
case "rename":
uploaded[this.my_data.file].name = _value;
delete uploaded[this.my_data.file].confirm;
// send overwrite-confirmation and/or rename request to server
egw.json('EGroupware\\Api\\Etemplate\\Widget\\Vfs::ajax_vfsSelect_storeFile', [uploaded, this.my_data.path],
that._storeFile_callback, that, true, that
).sendRequest();
return;
case "cancel":
// Remove that file from every file widget...
that.et2.iterateOver(function(_widget) {
_widget.remove_file(this.my_data.data.name);
}, this, et2_file);
}
},
_data.uploaded[file].confirm === "is_dir" ?
this.egw.lang("There's already a directory with that name!") :
this.egw.lang('Do you want to overwrite existing file %1 in directory %2?', _data.uploaded[file].name, _data.path),
this.egw.lang('File %1 already exists', _data.uploaded[file].name),
_data.uploaded[file].name, buttons, file);
// setting required data for callback in as my_data
dialog.my_data = {
file: file,
path: _data.path,
data: _data.uploaded[file],
};
}
else
{
this.submit();
}
}
}
/**
* Prompt user for directory to create
*
* @param {egwAction|undefined|jQuery.Event} action Action, event or undefined if called directly
* @param {egwActionObject[] | undefined} selected Selected row, or undefined if called directly
*/
createdir(action, selected)
{
let self = this;
et2_dialog.show_prompt(function(button, dir){
if (button && dir)
{
let path = self.get_path();
self.egw.json('EGroupware\\Api\\Etemplate\\Widget\\Vfs::ajax_create_dir', [dir, path], function(msg){
self.egw.message(msg);
self.change_dir((path == '/' ? '' : path)+'/'+ dir);
}).sendRequest(false);
}
},this.egw.lang('New directory'),this.egw.lang('Create directory'));
}
/**
* Change directory
*
* @param {string} _dir directory to change to incl. '..' for one up
*/
change_dir(_dir : string)
{
if (_dir == '..')
{
_dir = this.dirname(this.get_path());
}
this.path_widget.set_value(_dir);
}
/**
* Row or filename in select-file dialog clicked
*
* @param {jQuery.event} event
* @param {et2_widget} widget
*/
select_clicked(event : JQueryEventObject, widget : et2_vfs)
{
if (!widget || typeof widget.value != 'object')
{
}
else if (widget.value.is_dir) // true for "httpd/unix-directory" and "egw/*"
{
let path = null;
// Cannot do this, there are multiple widgets named path
// widget.getRoot().getWidgetById("path");
widget.getRoot().iterateOver(function(widget) {
if(widget.id == "path") path = widget;
},null, et2_textbox);
if(path)
{
path.set_value(widget.value.path);
}
}
else if (this.et2 && this.et2.getArrayMgr('content').getEntry('mode') != 'open-multiple')
{
let editfield = this.et2.getWidgetById('name');
if(editfield)
{
editfield.set_value(widget.value.name);
}
}
else
{
let file = widget.value.name;
widget.getParent().iterateOver(function(widget)
{
if(widget.options.selected_value == file)
{
widget.set_value(widget.get_value() == file ? widget.options.unselected_value : file);
}
}, null, et2_checkbox);
}
// Stop event or it will toggle back off
event.preventDefault();
event.stopPropagation();
return false;
}
/**
* Handles action and offer it to the submit
*
* @param {string} action action name
* @param {object} widget widget which action was called from
*/
do_action(action : string, widget : et2_button | et2_selectbox | et2_vfsPath)
{
if (!action) return;
let field = '', value = '';
switch (action)
{
case 'path': field = 'path'; value = (<et2_vfsPath>widget).getValue(); break;
case 'home': field = 'action'; value = 'home'; break;
case 'app': field = 'app'; value = (<et2_selectbox>widget).getValue(); break;
case 'mime': field = 'mime'; value = (<et2_selectbox>widget).getValue(); break;
}
this.submit(field, value);
}
/**
* Sumbits content value after modification
*
* @param {string} _field content field to be modified
* @param {any} _val value of field
* @param {function} _callback
*/
submit(_field? : string, _val? : any, _callback? : Function)
{
let arrMgrs = this.et2.getArrayMgrs();
if (_field)
{
arrMgrs.content.data[_field] = _val;
jQuery.extend(arrMgrs.content.data, arrMgrs.modifications.data);
this.et2.setArrayMgrs(arrMgrs);
}
// preserve value of the name
if (arrMgrs && this.et2.getWidgetById('name'))
{
arrMgrs.content.data['name'] = this.et2.getWidgetById('name').get_value();
}
this.vfsSelectWidget._content(arrMgrs.content.data, _callback);
}
/**
* search through dir content and set its content base on searched query
* @returns
*/
search(_widget)
{
let dir = this.et2.getWidgetById('dir');
let query = _widget.get_value();
if (query == "")
{
dir.set_value({content: this.dirContent});
return;
}
let self = this;
let searchQuery = function (_query)
{
let result = {};
let reg = RegExp(_query, 'ig');
let key = 0;
for (let i in self.dirContent)
{
if (typeof self.dirContent[i]['name'] != 'undefined' && self.dirContent[i]['name'].match(reg))
{
result[key] = self.dirContent[i];
key++;
}
else if (typeof self.dirContent[i]['name'] == 'undefined' && isNaN(<number><unknown>i))
{
result[i] = self.dirContent[i];
}
}
return result;
};
dir.set_value({content: searchQuery(query)});
}
}
app.classes.vfsSelectUI = vfsSelectUI;