Convert et2_widget_taglist to TS

This commit is contained in:
Hadi Nategh 2020-02-10 15:17:09 +01:00
parent e0ec34493b
commit b98ce00079
3 changed files with 372 additions and 180 deletions

View File

@ -169,6 +169,8 @@ declare var et2_vfsSelect : any;
declare var et2_video : any;
declare var et2_IExposable : any;
declare var tinymce : any;
declare var date : any;
declare var tinyMCE : any;
declare class et2_nextmatch_sortheader extends et2_nextmatch_header {}
declare class et2_nextmatch_filterheader extends et2_nextmatch_header {}
declare class et2_nextmatch_accountfilterheader extends et2_nextmatch_header {}

View File

@ -1,3 +1,4 @@
"use strict";
/**
* EGroupware eTemplate2 - JS Timestamp button object
*
@ -8,11 +9,26 @@
* @author Nathan Gray
* @copyright Nathan Gray 2017
*/
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
et2_button;
et2_button;
*/
var et2_core_widget_1 = require("./et2_core_widget");
var et2_widget_button_1 = require("./et2_widget_button");
var et2_core_inheritance_1 = require("./et2_core_inheritance");
/**
* Class which implements the "button-timestamper" XET-Tag
*
@ -21,180 +37,153 @@
*
* @augments et2_button
*/
var et2_timestamper = (function(){ "use strict"; return et2_button.extend([],
{
attributes: {
target: {
name: "Target field",
type: "string",
default: et2_no_init,
description: "Which field to place the timestamp in"
},
format: {
name: "Time format",
type: "string",
default: et2_no_init,
description: "Format for the timestamp. User is always after."
},
timezone: {
name: "Timezone",
type: "string",
default: et2_no_init,
description: "Timezone. Default is user time."
},
statustext: {
default: "Insert timestamp into description field"
},
image: {
default: "timestamp"
},
background_image: {
default: true
}
},
/**
* Constructor
*
* @memberOf et2_button
*/
init: function() {
this._super.apply(this, arguments);
jQuery(this.getDOMNode()).addClass('et2_timestamper');
},
/**
* Overwritten to maintain an internal clicked attribute
*
* @param _ev
* @returns {Boolean}
*/
click: function(_ev) {
// ignore click on readonly button
if (this.options.readonly) return false;
this._insert_text();
return false;
},
_insert_text: function() {
var text = "";
var now = new Date(new Date().toLocaleString('en-US', {
timeZone: this.options.timezone ? this.options.timezone : egw.preference('tz')
}));
var format = (this.options.format ?
this.options.format :
egw.preference('dateformat') + ' ' + (egw.preference("timeformat") === "12" ? "h:ia" : "H:i"))+' ';
text += date(format, now);
// Get properly formatted user name
var user = parseInt(egw.user('account_id'));
var accounts = egw.accounts('accounts');
for(var j = 0; j < accounts.length; j++)
{
if(accounts[j].value === user)
{
text += accounts[j].label;
break;
}
}
text += ': ';
var widget = this._get_input(this.target);
var input = widget.input ? widget.input : widget.getDOMNode();
if(input.context)
{
input = input.get(0);
}
var scrollPos = input.scrollTop;
var browser = ((input.selectionStart || input.selectionStart == "0") ?
"standards" : (document.selection ? "ie" : false ) );
var pos = 0;
var tinymce = tinyMCE && tinyMCE.EditorManager.get(input.id) || false;
// Find cursor or selection
if (browser == "ie")
{
input.focus();
var range = document.selection.createRange();
range.moveStart ("character", -input.value.length);
pos = range.text.length;
}
else if (browser == "standards")
{
pos = input.selectionStart;
};
// If tinymce, update it
if(tinymce)
{
tinymce.insertContent(text);
}
else
{
// Insert the text
var front = (input.value).substring(0, pos);
var back = (input.value).substring(pos, input.value.length);
input.value = front+text+back;
// Clean up a little
pos = pos + text.length;
if (browser == "ie") {
input.focus();
var range = document.selection.createRange();
range.moveStart ("character", -input.value.length);
range.moveStart ("character", pos);
range.moveEnd ("character", 0);
range.select();
}
else if (browser == "standards") {
input.selectionStart = pos;
input.selectionEnd = pos;
input.focus();
}
input.scrollTop = scrollPos;
input.focus();
}
// If on a tab, switch to that tab so user can see it
var tab = widget;
while(tab._parent && tab._type != 'tabbox')
{
tab = tab._parent;
}
if (tab._type == 'tabbox') tab.activateTab(widget);
},
_get_input: function _get_input(target)
{
var input = null;
var widget = null;
if (typeof target == 'string')
{
widget = this.getRoot().getWidgetById(target);
}
else if (target.instanceOf && target.instanceOf(et2_IInput))
{
widget = target;
}
else if(typeof target == 'string' && target.indexOf('#') < 0 && jQuery('#'+this.target).is('input'))
{
input = this.target;
}
if(widget)
{
return widget;
}
if(input.context)
{
input = input.get(0);
}
return input;
}
});}).call(this);
et2_register_widget(et2_timestamper, ["button-timestamp", "timestamper"]);
var et2_timestamper = /** @class */ (function (_super) {
__extends(et2_timestamper, _super);
function et2_timestamper(_parent, _attrs, _child) {
var _this =
// Call the inherited constructor
_super.call(this, _parent, _attrs, et2_core_inheritance_1.ClassWithAttributes.extendAttributes(et2_timestamper._attributes, _child || {})) || this;
jQuery(_this.getDOMNode()).addClass('et2_timestamper');
return _this;
}
/**
* Overwritten to maintain an internal clicked attribute
*
* @param _ev
* @returns {Boolean}
*/
et2_timestamper.prototype.click = function (_ev) {
// ignore click on readonly button
if (this.options.readonly)
return false;
this._insert_text();
return false;
};
et2_timestamper.prototype._insert_text = function () {
var text = "";
var now = new Date(new Date().toLocaleString('en-US', {
timeZone: this.options.timezone ? this.options.timezone : egw.preference('tz')
}));
var format = (this.options.format ?
this.options.format :
egw.preference('dateformat') + ' ' + (egw.preference("timeformat") === "12" ? "h:ia" : "H:i")) + ' ';
text += date(format, now);
// Get properly formatted user name
var user = parseInt(egw.user('account_id'));
var accounts = egw.accounts('accounts');
for (var j = 0; j < accounts.length; j++) {
if (accounts[j]["value"] === user) {
text += accounts[j]["label"];
break;
}
}
text += ': ';
var widget = this._get_input(this.target);
var input = widget.input ? widget.input : widget.getDOMNode();
if (input.context) {
input = input.get(0);
}
var scrollPos = input.scrollTop;
var browser = ((input.selectionStart || input.selectionStart == "0") ?
"standards" : (document["selection"] ? "ie" : false));
var pos = 0;
var tinymce = tinyMCE && tinyMCE.EditorManager.get(input.id) || false;
// Find cursor or selection
if (browser == "ie") {
input.focus();
var range = document["selection"].createRange();
range.moveStart("character", -input.value.length);
pos = range.text.length;
}
else if (browser == "standards") {
pos = input.selectionStart;
}
// If tinymce, update it
if (tinymce) {
tinymce.insertContent(text);
}
else {
// Insert the text
var front = (input.value).substring(0, pos);
var back = (input.value).substring(pos, input.value.length);
input.value = front + text + back;
// Clean up a little
pos = pos + text.length;
if (browser == "ie") {
input.focus();
var range = document["selection"].createRange();
range.moveStart("character", -input.value.length);
range.moveStart("character", pos);
range.moveEnd("character", 0);
range.select();
}
else if (browser == "standards") {
input.selectionStart = pos;
input.selectionEnd = pos;
input.focus();
}
input.scrollTop = scrollPos;
input.focus();
}
// If on a tab, switch to that tab so user can see it
var tab = widget;
while (tab._parent && tab._type != 'tabbox') {
tab = tab._parent;
}
if (tab._type == 'tabbox')
tab.activateTab(widget);
};
et2_timestamper.prototype._get_input = function (target) {
var _a;
var input = null;
var widget = null;
if (typeof target == 'string') {
widget = this.getRoot().getWidgetById(target);
}
else if (target.instanceOf && target.instanceOf(et2_IInput)) {
widget = target;
}
else if (typeof target == 'string' && target.indexOf('#') < 0 && jQuery('#' + this.target).is('input')) {
input = this.target;
}
if (widget) {
return widget;
}
if ((_a = input) === null || _a === void 0 ? void 0 : _a.context) {
input = input.get(0);
}
return input;
};
et2_timestamper._attributes = {
target: {
name: "Target field",
type: "string",
default: et2_no_init,
description: "Which field to place the timestamp in"
},
format: {
name: "Time format",
type: "string",
default: et2_no_init,
description: "Format for the timestamp. User is always after."
},
timezone: {
name: "Timezone",
type: "string",
default: et2_no_init,
description: "Timezone. Default is user time."
},
statustext: {
default: "Insert timestamp into description field"
},
image: {
default: "timestamp"
},
background_image: {
default: true
}
};
return et2_timestamper;
}(et2_widget_button_1.et2_button));
et2_core_widget_1.et2_register_widget(et2_timestamper, ["button-timestamp", "timestamper"]);
//# sourceMappingURL=et2_widget_timestamper.js.map

View File

@ -0,0 +1,201 @@
/**
* EGroupware eTemplate2 - JS Timestamp button object
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package etemplate
* @subpackage api
* @link http://www.egroupware.org
* @author Nathan Gray
* @copyright Nathan Gray 2017
*/
/*egw:uses
et2_button;
*/
import {et2_register_widget, WidgetConfig} from "./et2_core_widget";
import {et2_button} from "./et2_widget_button";
import {ClassWithAttributes} from "./et2_core_inheritance";
/**
* Class which implements the "button-timestamper" XET-Tag
*
* Clicking the button puts the current time and current user at the end of
* the provided field.
*
* @augments et2_button
*/
class et2_timestamper extends et2_button
{
static readonly _attributes : any = {
target: {
name: "Target field",
type: "string",
default: et2_no_init,
description: "Which field to place the timestamp in"
},
format: {
name: "Time format",
type: "string",
default: et2_no_init,
description: "Format for the timestamp. User is always after."
},
timezone: {
name: "Timezone",
type: "string",
default: et2_no_init,
description: "Timezone. Default is user time."
},
statustext: {
default: "Insert timestamp into description field"
},
image: {
default: "timestamp"
},
background_image: {
default: true
}
};
target : string;
constructor(_parent, _attrs? : WidgetConfig, _child? : object)
{
// Call the inherited constructor
super(_parent, _attrs, ClassWithAttributes.extendAttributes(et2_timestamper._attributes, _child || {}));
jQuery(this.getDOMNode()).addClass('et2_timestamper');
}
/**
* Overwritten to maintain an internal clicked attribute
*
* @param _ev
* @returns {Boolean}
*/
click(_ev) {
// ignore click on readonly button
if (this.options.readonly) return false;
this._insert_text();
return false;
}
private _insert_text() {
let text = "";
let now = new Date(new Date().toLocaleString('en-US', {
timeZone: this.options.timezone ? this.options.timezone : egw.preference('tz')
}));
let format = (this.options.format ?
this.options.format :
egw.preference('dateformat') + ' ' + (egw.preference("timeformat") === "12" ? "h:ia" : "H:i"))+' ';
text += date(format, now);
// Get properly formatted user name
let user = parseInt(egw.user('account_id'));
let accounts = egw.accounts('accounts');
for(let j = 0; j < accounts.length; j++)
{
if(accounts[j]["value"] === user)
{
text += accounts[j]["label"];
break;
}
}
text += ': ';
let widget = this._get_input(this.target);
let input = widget.input ? widget.input : widget.getDOMNode();
if(input.context)
{
input = input.get(0);
}
let scrollPos = input.scrollTop;
let browser = ((input.selectionStart || input.selectionStart == "0") ?
"standards" : (document["selection"] ? "ie" : false ) );
let pos = 0;
let tinymce = tinyMCE && tinyMCE.EditorManager.get(input.id) || false;
// Find cursor or selection
if (browser == "ie")
{
input.focus();
let range = document["selection"].createRange();
range.moveStart ("character", -input.value.length);
pos = range.text.length;
}
else if (browser == "standards")
{
pos = input.selectionStart;
}
// If tinymce, update it
if(tinymce)
{
tinymce.insertContent(text);
}
else
{
// Insert the text
let front = (input.value).substring(0, pos);
let back = (input.value).substring(pos, input.value.length);
input.value = front+text+back;
// Clean up a little
pos = pos + text.length;
if (browser == "ie") {
input.focus();
let range = document["selection"].createRange();
range.moveStart ("character", -input.value.length);
range.moveStart ("character", pos);
range.moveEnd ("character", 0);
range.select();
}
else if (browser == "standards") {
input.selectionStart = pos;
input.selectionEnd = pos;
input.focus();
}
input.scrollTop = scrollPos;
input.focus();
}
// If on a tab, switch to that tab so user can see it
let tab = widget;
while(tab._parent && tab._type != 'tabbox')
{
tab = tab._parent;
}
if (tab._type == 'tabbox') tab.activateTab(widget);
}
private _get_input(target)
{
let input = null;
let widget = null;
if (typeof target == 'string')
{
widget = this.getRoot().getWidgetById(target);
}
else if (target.instanceOf && target.instanceOf(et2_IInput))
{
widget = target;
}
else if(typeof target == 'string' && target.indexOf('#') < 0 && jQuery('#'+this.target).is('input'))
{
input = this.target;
}
if(widget)
{
return widget;
}
if(input?.context)
{
input = input.get(0);
}
return input;
}
}
et2_register_widget(et2_timestamper, ["button-timestamp", "timestamper"]);