first try with TypeScript: timesheet app.js incl. new egw_app base-class

This commit is contained in:
Ralf Becker 2020-01-15 08:47:33 +01:00
parent 3d87f13365
commit 55ae9c1c7b
9 changed files with 4216 additions and 197 deletions

148
api/js/etemplate/et2_types.d.ts vendored Normal file
View File

@ -0,0 +1,148 @@
declare module eT2
{
}
declare var etemplate2 : any;
declare var et2_DOMWidget : any;
declare var et2_surroundingsMgr : any;
declare var et2_arrayMgr : any;
declare var et2_readonlysArrayMgr : any;
declare var et2_baseWidget : any;
declare var et2_container : any;
declare var et2_placeholder : any;
declare var et2_validTypes : any;
declare var et2_typeDefaults : any;
declare var et2_no_init : any;
declare var et2_editableWidget : any;
declare var et2_inputWidget : any;
declare var et2_IDOMNode : any;
declare var et2_IInput : any;
declare var et2_IResizeable : any;
declare var et2_IAligned : any;
declare var et2_ISubmitListener : any;
declare var et2_IDetachedDOM : any;
declare var et2_IPrint : any;
declare var et2_valueWidget : any;
declare var et2_registry : any;
declare var et2_widget : any;
declare var et2_dataview : any;
declare var et2_dataview_controller : any;
declare var et2_dataview_selectionManager : any;
declare var et2_dataview_IInvalidatable : any;
declare var et2_dataview_IViewRange : any;
declare var et2_IDataProvider : any;
declare var et2_dataview_column : any;
declare var et2_dataview_columns : any;
declare var et2_dataview_container : any;
declare var et2_dataview_grid : any;
declare var et2_dataview_row : any;
declare var et2_dataview_rowProvider : any;
declare var et2_dataview_spacer : any;
declare var et2_dataview_tile : any;
declare var et2_customfields_list : any;
declare var et2_INextmatchHeader : any;
declare var et2_INextmatchSortable : any;
declare var et2_nextmatch : any;
declare var et2_nextmatch_header_bar : any;
declare var et2_nextmatch_header : any;
declare var et2_nextmatch_customfields : any;
declare var et2_nextmatch_sortheader : any;
declare var et2_nextmatch_filterheader : any;
declare var et2_nextmatch_accountfilterheader : any;
declare var et2_nextmatch_taglistheader : any;
declare var et2_nextmatch_entryheader : any;
declare var et2_nextmatch_customfilter : any;
declare var et2_nextmatch_controller : any;
declare var et2_dynheight : any;
declare var et2_nextmatch_rowProvider : any;
declare var et2_nextmatch_rowWidget : any;
declare var et2_nextmatch_rowTemplateWidget : any;
declare var et2_ajaxSelect : any;
declare var et2_ajaxSelect_ro : any;
declare var et2_barcode : any;
declare var et2_box : any;
declare var et2_details : any;
declare var et2_button : any;
declare var et2_checkbox : any;
declare var et2_checkbox_ro : any;
declare var et2_color : any;
declare var et2_color_ro : any;
declare var et2_date : any;
declare var et2_date_duration : any;
declare var et2_date_duration_ro : any;
declare var et2_date_ro : any;
declare var et2_date_range : any;
declare var et2_description : any;
declare var et2_dialog : any;
declare var et2_diff : any;
declare var et2_dropdown_button : any;
declare var et2_entry : any;
declare var et2_favorites : any;
declare var et2_file : any;
declare var et2_grid : any;
declare var et2_groupbox : any;
declare var et2_groupbox_legend : any;
declare var et2_hbox : any;
declare var et2_historylog : any;
declare var et2_hrule : any;
declare var et2_html : any;
declare var et2_htmlarea : any;
declare var et2_iframe : any;
declare var et2_image : any;
declare var et2_appicon : any;
declare var et2_avatar : any;
declare var et2_avatar_ro : any;
declare var et2_lavatar : any;
declare var et2_itempicker : any;
declare var et2_link_to : any;
declare var et2_link_apps : any;
declare var et2_link_entry : any;
declare var et2_link_string : any;
declare var et2_link_list : any;
declare var et2_link_add : any;
declare var et2_number : any;
declare var et2_number_ro : any;
declare var et2_portlet : any;
declare var et2_progress : any;
declare var et2_radiobox : any;
declare var et2_radiobox_ro : any;
declare var et2_radioGroup : any;
declare var et2_script : any;
declare var et2_selectAccount : any;
declare var et2_selectAccount_ro : any;
declare var et2_selectbox : any;
declare var et2_selectbox_ro : any;
declare var et2_menulist : any;
declare var et2_split : any;
declare var et2_styles : any;
declare var et2_tabbox : any;
declare var et2_taglist : any;
declare var et2_taglist_account : any;
declare var et2_taglist_email : any;
declare var et2_taglist_category : any;
declare var et2_taglist_thumbnail : any;
declare var et2_taglist_state : any;
declare var et2_taglist_ro : any;
declare var et2_template : any;
declare var et2_textbox : any;
declare var et2_textbox_ro : any;
declare var et2_searchbox : any;
declare var et2_timestamper : any;
declare var et2_toolbar : any;
declare var et2_tree : any;
declare var et2_url : any;
declare var et2_url_ro : any;
declare var et2_vfs : any;
declare var et2_vfsName : any;
declare var et2_vfsPath : any;
declare var et2_vfsName_ro : any;
declare var et2_vfsMime : any;
declare var et2_vfsSize : any;
declare var et2_vfsMode : any;
declare var et2_vfsUid : any;
declare var et2_vfsUpload : any;
declare var et2_vfsSelect : any;
declare var et2_video : any;
declare var et2_IExposable : any;
declare function et2_createWidget(type : string, params : {}, parent? : any) : any;
declare function nm_action(_action : {}, _senders : [], _target : any, _ids? : any) : void;

View File

@ -437,6 +437,13 @@
};
})();
// get TypeScript modules working with our loader
function require(_file)
{
return { EgwApp: window.EgwApp};
}
var exports = {};
/**
* Call a function specified by it's name (possibly dot separated, eg. "app.myapp.myfunc")
*

1634
api/js/jsapi/egw_app.js Normal file

File diff suppressed because it is too large Load Diff

2029
api/js/jsapi/egw_app.ts Normal file

File diff suppressed because it is too large Load Diff

16
api/js/jsapi/egw_global.d.ts vendored Normal file
View File

@ -0,0 +1,16 @@
/**
* for now use "somehow" created global egw
*/
declare function egw_getFramework() : any;
//declare var window : Window & typeof globalThis;
declare var chrome : any;
declare var InstallTrigger : any;
//declare function egw(string, object) : object;
declare var egw : any;
declare var app : {classes: any};
declare var egw_globalObjectManager : any;
declare var framework : any;
declare var mailvelope : any;
declare function egw_refresh(_msg : string, app : string, id? : string|number, _type?, targetapp?, replace?, _with?, msgtype?);

View File

@ -6,6 +6,8 @@
"dependencies": {},
"repository": {},
"devDependencies": {
"@types/jquery": "^1.10.35",
"@types/jqueryui": "^1.11.37",
"grunt": "^1.0.3",
"grunt-contrib-cssmin": "^2.2.1",
"grunt-contrib-uglify-es": "^3.3.0",

View File

@ -1,3 +1,4 @@
"use strict";
/**
* EGroupware - Timesheet - Javascript UI
*
@ -6,102 +7,83 @@
* @author Hadi Nategh <hn-AT-stylite.de>
* @copyright (c) 2008-16 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @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
*/
require("jquery");
require("jqueryui");
require("../jsapi/egw_global");
require("../etemplate/et2_types");
var egw_app_1 = require("../../api/js/jsapi/egw_app");
/**
* UI for timesheet
*
* @augments AppJS
*/
app.classes.timesheet = AppJS.extend(
{
appname: 'timesheet',
/**
* et2 widget container
*/
et2: null,
/**
* path widget
*/
/**
* Constructor
*
* @memberOf app.timesheet
*/
init: function()
{
// call parent
this._super.apply(this, arguments);
},
/**
* Destructor
*/
destroy: function()
{
delete this.et2;
// call parent
this._super.apply(this, arguments);
},
var TimesheetApp = /** @class */ (function (_super) {
__extends(TimesheetApp, _super);
function TimesheetApp() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* 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
*/
et2_ready: function(et2)
{
TimesheetApp.prototype.et2_ready = function (et2, name) {
// call parent
this._super.apply(this, arguments);
if (typeof et2.templates['timesheet.index'] != "undefined")
{
_super.prototype.et2_ready.call(this, et2, name);
if (typeof et2.templates['timesheet.index'] != "undefined") {
this.filter_change();
this.filter2_change();
}
},
};
/**
*
*/
filter_change: function()
{
TimesheetApp.prototype.filter_change = function () {
var filter = this.et2.getWidgetById('filter');
var dates = this.et2.getWidgetById('timesheet.index.dates');
if (filter && dates)
{
if (filter && dates) {
dates.set_disabled(filter.get_value() !== "custom");
if (filter.value == "custom")
{
if (filter.value == "custom") {
jQuery(this.et2.getWidgetById('startdate').getDOMNode()).find('input').focus();
}
}
return true;
},
};
/**
* show or hide the details of rows by selecting the filter2 option
* either 'all' for details or 'no_description' for no details
*
*/
filter2_change: function()
{
TimesheetApp.prototype.filter2_change = function () {
var nm = this.et2.getWidgetById('nm');
var filter2 = this.et2.getWidgetById('filter2');
if (nm && filter2)
{
if (nm && filter2) {
egw.css("#timesheet-index span.timesheet_titleDetails", "font-weight:" + (filter2.getValue() == '1' ? "bold;" : "normal;"));
// Show / hide descriptions
egw.css(".et2_label.ts_description", "display:" + (filter2.getValue() == '1' ? "block;" : "none;"));
}
},
};
/**
* Wrapper so add action in the context menu can pass current
* filter values into new edit dialog
@ -111,51 +93,39 @@ app.classes.timesheet = AppJS.extend(
* @param {egwAction} action
* @param {egwActionObject[]} selected
*/
add_action_handler: function(action, selected)
{
TimesheetApp.prototype.add_action_handler = function (action, selected) {
var nm = action.getManager().data.nextmatch || false;
if(nm)
{
if (nm) {
this.add_with_extras(nm);
}
},
};
/**
* Opens a new edit dialog with some extra url parameters pulled from
* nextmatch filters.
*
* @param {et2_widget} widget Originating/calling widget
*/
add_with_extras: function(widget)
{
TimesheetApp.prototype.add_with_extras = function (widget) {
var nm = widget.getRoot().getWidgetById('nm');
var nm_value = nm.getValue() || {};
var extras = {};
if(nm_value.cat_id)
{
if (nm_value.cat_id) {
extras.cat_id = nm_value.cat_id;
}
if(nm_value.col_filter && nm_value.col_filter.linked)
{
if (nm_value.col_filter && nm_value.col_filter.linked) {
var split = nm_value.col_filter.linked.split(':') || '';
extras.link_app = split[0] || '';
extras.link_id = split[1] || '';
}
if(nm_value.col_filter && nm_value.col_filter.pm_id)
{
if (nm_value.col_filter && nm_value.col_filter.pm_id) {
extras.link_app = 'projectmanager';
extras.link_id = nm_value.col_filter.pm_id;
}
else if (nm_value.col_filter && nm_value.col_filter.ts_project)
{
else if (nm_value.col_filter && nm_value.col_filter.ts_project) {
extras.ts_project = nm_value.col_filter.ts_project;
}
egw.open('', 'timesheet', 'add', extras);
},
};
/**
* Change handler for project selection to set empty ts_project string, if project get deleted
*
@ -163,31 +133,24 @@ app.classes.timesheet = AppJS.extend(
* @param {et2_widget_link_entry} _widget
* @returns {undefined}
*/
pm_id_changed: function(_egw, _widget)
{
TimesheetApp.prototype.pm_id_changed = function (_egw, _widget) {
// Update price list
var ts_pricelist = _widget.getRoot().getWidgetById('pl_id');
egw.json('projectmanager_widget::ajax_get_pricelist', [_widget.getValue()], function (value) {
ts_pricelist.set_select_options(value||{})
ts_pricelist.set_select_options(value || {});
}).sendRequest(true);
var ts_project = this.et2.getWidgetById('ts_project');
if (ts_project)
{
if (ts_project) {
ts_project.set_blur(_widget.getValue() ? _widget.search.val() : '');
}
},
};
/**
* Update custom filter timespan, without triggering a change
*/
update_timespan: function(start, end)
{
if(this && this.et2)
{
TimesheetApp.prototype.update_timespan = function (start, end) {
if (this && this.et2) {
var nm = this.et2.getWidgetById('nm');
if(nm)
{
if (nm) {
// Toggle update_in_progress to avoid another request
nm.update_in_progress = true;
this.et2.getWidgetById('startdate').set_value(start);
@ -197,15 +160,16 @@ app.classes.timesheet = AppJS.extend(
nm.update_in_progress = false;
}
}
},
};
/**
* Get title in order to set it as document title
* @returns {string}
*/
getWindowTitle: function()
{
TimesheetApp.prototype.getWindowTitle = function () {
var widget = this.et2.getWidgetById('ts_title');
if(widget) return widget.options.value;
}
});
if (widget)
return widget.options.value;
};
return TimesheetApp;
}(egw_app_1.EgwApp));
app.classes.timesheet = TimesheetApp;

196
timesheet/js/app.ts Normal file
View File

@ -0,0 +1,196 @@
/**
* EGroupware - Timesheet - Javascript UI
*
* @link http://www.egroupware.org
* @package timesheet
* @author Hadi Nategh <hn-AT-stylite.de>
* @copyright (c) 2008-16 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
*/
/*egw:uses
/api/js/jsapi/egw_app.js
*/
import 'jquery';
import 'jqueryui';
import '../jsapi/egw_global';
import '../etemplate/et2_types';
import { EgwApp } from '../../api/js/jsapi/egw_app';
/**
* UI for timesheet
*
* @augments AppJS
*/
class TimesheetApp extends EgwApp
{
readonly appname: 'timesheet';
/**
* 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
*/
et2_ready(et2, name : string)
{
// call parent
super.et2_ready(et2, name);
if (typeof et2.templates['timesheet.index'] != "undefined")
{
this.filter_change();
this.filter2_change();
}
}
/**
*
*/
filter_change()
{
var filter = this.et2.getWidgetById('filter');
var dates = this.et2.getWidgetById('timesheet.index.dates');
if (filter && dates)
{
dates.set_disabled(filter.get_value() !== "custom");
if (filter.value == "custom")
{
jQuery(this.et2.getWidgetById('startdate').getDOMNode()).find('input').focus();
}
}
return true;
}
/**
* show or hide the details of rows by selecting the filter2 option
* either 'all' for details or 'no_description' for no details
*
*/
filter2_change()
{
var nm = this.et2.getWidgetById('nm');
var filter2 = this.et2.getWidgetById('filter2');
if (nm && filter2)
{
egw.css("#timesheet-index span.timesheet_titleDetails","font-weight:" + (filter2.getValue() == '1' ? "bold;" : "normal;"));
// Show / hide descriptions
egw.css(".et2_label.ts_description","display:" + (filter2.getValue() == '1' ? "block;" : "none;"));
}
}
/**
* Wrapper so add action in the context menu can pass current
* filter values into new edit dialog
*
* @see add_with_extras
*
* @param {egwAction} action
* @param {egwActionObject[]} selected
*/
add_action_handler(action, selected)
{
var nm = action.getManager().data.nextmatch || false;
if(nm)
{
this.add_with_extras(nm);
}
}
/**
* Opens a new edit dialog with some extra url parameters pulled from
* nextmatch filters.
*
* @param {et2_widget} widget Originating/calling widget
*/
add_with_extras(widget)
{
var nm = widget.getRoot().getWidgetById('nm');
var nm_value = nm.getValue() || {};
var extras : any = {};
if (nm_value.cat_id)
{
extras.cat_id = nm_value.cat_id;
}
if (nm_value.col_filter && nm_value.col_filter.linked)
{
var split = nm_value.col_filter.linked.split(':') || '';
extras.link_app = split[0] || '';
extras.link_id = split[1] || '';
}
if (nm_value.col_filter && nm_value.col_filter.pm_id)
{
extras.link_app = 'projectmanager';
extras.link_id = nm_value.col_filter.pm_id;
}
else if (nm_value.col_filter && nm_value.col_filter.ts_project)
{
extras.ts_project = nm_value.col_filter.ts_project;
}
egw.open('','timesheet','add',extras);
}
/**
* Change handler for project selection to set empty ts_project string, if project get deleted
*
* @param {type} _egw
* @param {et2_widget_link_entry} _widget
* @returns {undefined}
*/
pm_id_changed(_egw, _widget)
{
// Update price list
var ts_pricelist = _widget.getRoot().getWidgetById('pl_id');
egw.json('projectmanager_widget::ajax_get_pricelist',[_widget.getValue()],function(value) {
ts_pricelist.set_select_options(value||{})
}).sendRequest(true);
var ts_project = this.et2.getWidgetById('ts_project');
if (ts_project)
{
ts_project.set_blur(_widget.getValue() ? _widget.search.val() : '');
}
}
/**
* Update custom filter timespan, without triggering a change
*/
update_timespan(start, end)
{
if(this && this.et2)
{
var nm = this.et2.getWidgetById('nm');
if(nm)
{
// Toggle update_in_progress to avoid another request
nm.update_in_progress = true;
this.et2.getWidgetById('startdate').set_value(start);
this.et2.getWidgetById('enddate').set_value(end);
nm.activeFilters.startdate = start;
nm.activeFilters.enddate = end;
nm.update_in_progress = false;
}
}
}
/**
* Get title in order to set it as document title
* @returns {string}
*/
getWindowTitle()
{
var widget = this.et2.getWidgetById('ts_title');
if(widget) return widget.options.value;
}
}
app.classes.timesheet = TimesheetApp;

23
tsconfig.json Normal file
View File

@ -0,0 +1,23 @@
{
"compileOnSave": true,
"compilerOptions": {
"target": "es5",
"lib": ["es2015","dom"],
"outDir": "",
"rootDir": "./",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"moduleResolution": "node",
"noImplicitAny": false
},
"include" : [
"**/js/*",
"api/js/**/*",
"node_modules/@types/**/*",
"*"
],
"exclude": [
"node_modules"
]
}